1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.handler.codec.mqtt;
18
19 import io.netty.handler.codec.DecoderResult;
20 import io.netty.util.internal.StringUtil;
21
22
23
24
25 public class MqttMessage {
26
27 private final MqttFixedHeader mqttFixedHeader;
28 private final Object variableHeader;
29 private final Object payload;
30 private final DecoderResult decoderResult;
31
32
33
34 public static final MqttMessage PINGREQ = new MqttMessage(new MqttFixedHeader(MqttMessageType.PINGREQ, false,
35 MqttQoS.AT_MOST_ONCE, false, 0));
36
37 public static final MqttMessage PINGRESP = new MqttMessage(new MqttFixedHeader(MqttMessageType.PINGRESP, false,
38 MqttQoS.AT_MOST_ONCE, false, 0));
39
40 public static final MqttMessage DISCONNECT = new MqttMessage(new MqttFixedHeader(MqttMessageType.DISCONNECT, false,
41 MqttQoS.AT_MOST_ONCE, false, 0));
42
43 public MqttMessage(MqttFixedHeader mqttFixedHeader) {
44 this(mqttFixedHeader, null, null);
45 }
46
47 public MqttMessage(MqttFixedHeader mqttFixedHeader, Object variableHeader) {
48 this(mqttFixedHeader, variableHeader, null);
49 }
50
51 public MqttMessage(MqttFixedHeader mqttFixedHeader, Object variableHeader, Object payload) {
52 this(mqttFixedHeader, variableHeader, payload, DecoderResult.SUCCESS);
53 }
54
55 public MqttMessage(
56 MqttFixedHeader mqttFixedHeader,
57 Object variableHeader,
58 Object payload,
59 DecoderResult decoderResult) {
60 this.mqttFixedHeader = mqttFixedHeader;
61 this.variableHeader = variableHeader;
62 this.payload = payload;
63 this.decoderResult = decoderResult;
64 }
65
66 public MqttFixedHeader fixedHeader() {
67 return mqttFixedHeader;
68 }
69
70 public Object variableHeader() {
71 return variableHeader;
72 }
73
74 public Object payload() {
75 return payload;
76 }
77
78 public DecoderResult decoderResult() {
79 return decoderResult;
80 }
81
82 @Override
83 public String toString() {
84 return new StringBuilder(StringUtil.simpleClassName(this))
85 .append('[')
86 .append("fixedHeader=").append(fixedHeader() != null ? fixedHeader().toString() : "")
87 .append(", variableHeader=").append(variableHeader() != null ? variableHeader.toString() : "")
88 .append(", payload=").append(payload() != null ? payload.toString() : "")
89 .append(']')
90 .toString();
91 }
92 }