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.util.internal.StringUtil;
20
21
22
23
24
25 public class MqttMessageIdVariableHeader {
26
27 private final int messageId;
28
29 public static MqttMessageIdVariableHeader from(int messageId) {
30 if (messageId < 1 || messageId > 0xffff) {
31 throw new IllegalArgumentException("messageId: " + messageId + " (expected: 1 ~ 65535)");
32 }
33 return new MqttMessageIdVariableHeader(messageId);
34 }
35
36 protected MqttMessageIdVariableHeader(int messageId) {
37 this.messageId = messageId;
38 }
39
40 public int messageId() {
41 return messageId;
42 }
43
44 @Override
45 public String toString() {
46 return new StringBuilder(StringUtil.simpleClassName(this))
47 .append('[')
48 .append("messageId=").append(messageId)
49 .append(']')
50 .toString();
51 }
52
53 public MqttMessageIdAndPropertiesVariableHeader withEmptyProperties() {
54 return new MqttMessageIdAndPropertiesVariableHeader(messageId, MqttProperties.NO_PROPERTIES);
55 }
56
57 MqttMessageIdAndPropertiesVariableHeader withDefaultEmptyProperties() {
58 return withEmptyProperties();
59 }
60 }