MsgHandlerUtil.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.ruoyi.device.mqtt.util;
  2. import com.ruoyi.device.mqtt.enums.MsgTypeEnum;
  3. /**
  4. * MsgHandlerUtil 消息类型处理工具类
  5. * 将消息的一级类型和二级类型拼接成key
  6. *
  7. * @author lwm
  8. */
  9. public final class MsgHandlerUtil
  10. {
  11. private static final String UNDERLINE = "_";
  12. private MsgHandlerUtil()
  13. {
  14. }
  15. /**
  16. * 获取消息处理key
  17. *
  18. * @param msgTypeEnum 消息类型枚举
  19. * @return 消息处理key
  20. */
  21. public static String getDecoderKey(MsgTypeEnum msgTypeEnum)
  22. {
  23. return getDecoderKey(msgTypeEnum.getFirstType(), msgTypeEnum.getSecondType());
  24. }
  25. public static String getDecoderKey(Integer firstKey, Integer secondKey)
  26. {
  27. return Integer.toHexString(firstKey) + UNDERLINE + Integer.toHexString(secondKey);
  28. }
  29. /**
  30. * 获取消息处理key
  31. *
  32. * @param msgTypeEnum 消息类型枚举
  33. * @return 消息处理key
  34. */
  35. public static String getEncoderKey(MsgTypeEnum msgTypeEnum)
  36. {
  37. return getEncoderKey(msgTypeEnum.getFirstType(), msgTypeEnum.getSecondType());
  38. }
  39. public static String getEncoderKey(Integer firstKey, Integer secondKey)
  40. {
  41. return Integer.toHexString(firstKey) + UNDERLINE + Integer.toHexString(secondKey);
  42. }
  43. }