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
20
21
22 public enum MqttMessageType {
23 CONNECT(1),
24 CONNACK(2),
25 PUBLISH(3),
26 PUBACK(4),
27 PUBREC(5),
28 PUBREL(6),
29 PUBCOMP(7),
30 SUBSCRIBE(8),
31 SUBACK(9),
32 UNSUBSCRIBE(10),
33 UNSUBACK(11),
34 PINGREQ(12),
35 PINGRESP(13),
36 DISCONNECT(14),
37 AUTH(15);
38
39 private static final MqttMessageType[] VALUES;
40
41 static {
42
43
44 final MqttMessageType[] values = values();
45 VALUES = new MqttMessageType[values.length + 1];
46 for (MqttMessageType mqttMessageType : values) {
47 final int value = mqttMessageType.value;
48 if (VALUES[value] != null) {
49 throw new AssertionError("value already in use: " + value);
50 }
51 VALUES[value] = mqttMessageType;
52 }
53 }
54
55 private final int value;
56
57 MqttMessageType(int value) {
58 this.value = value;
59 }
60
61 public int value() {
62 return value;
63 }
64
65 public static MqttMessageType valueOf(int type) {
66 if (type <= 0 || type >= VALUES.length) {
67 throw new IllegalArgumentException("unknown message type: " + type);
68 }
69 return VALUES[type];
70 }
71 }
72