1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.dns;
17
18 import static io.netty.util.internal.ObjectUtil.checkNotNull;
19
20
21
22
23 public class DnsOpCode implements Comparable<DnsOpCode> {
24
25
26
27
28 public static final DnsOpCode QUERY = new DnsOpCode(0x00, "QUERY");
29
30
31
32
33 public static final DnsOpCode IQUERY = new DnsOpCode(0x01, "IQUERY");
34
35
36
37
38 public static final DnsOpCode STATUS = new DnsOpCode(0x02, "STATUS");
39
40
41
42
43 public static final DnsOpCode NOTIFY = new DnsOpCode(0x04, "NOTIFY");
44
45
46
47
48 public static final DnsOpCode UPDATE = new DnsOpCode(0x05, "UPDATE");
49
50
51
52
53 public static DnsOpCode valueOf(int b) {
54 switch (b) {
55 case 0x00:
56 return QUERY;
57 case 0x01:
58 return IQUERY;
59 case 0x02:
60 return STATUS;
61 case 0x04:
62 return NOTIFY;
63 case 0x05:
64 return UPDATE;
65 default:
66 break;
67 }
68
69 return new DnsOpCode(b);
70 }
71
72 private final byte byteValue;
73 private final String name;
74 private String text;
75
76 private DnsOpCode(int byteValue) {
77 this(byteValue, "UNKNOWN");
78 }
79
80 public DnsOpCode(int byteValue, String name) {
81 this.byteValue = (byte) byteValue;
82 this.name = checkNotNull(name, "name");
83 }
84
85 public byte byteValue() {
86 return byteValue;
87 }
88
89 @Override
90 public int hashCode() {
91 return byteValue;
92 }
93
94 @Override
95 public boolean equals(Object obj) {
96 if (this == obj) {
97 return true;
98 }
99
100 if (!(obj instanceof DnsOpCode)) {
101 return false;
102 }
103
104 return byteValue == ((DnsOpCode) obj).byteValue;
105 }
106
107 @Override
108 public int compareTo(DnsOpCode o) {
109 return byteValue - o.byteValue;
110 }
111
112 @Override
113 public String toString() {
114 String text = this.text;
115 if (text == null) {
116 this.text = text = name + '(' + (byteValue & 0xFF) + ')';
117 }
118 return text;
119 }
120 }