1
2
3
4 package javax.jmdns.impl.constants;
5
6
7
8
9
10
11 public enum DNSLabel {
12
13
14
15 Unknown("", 0x80),
16
17
18
19 Standard("standard label", 0x00),
20
21
22
23 Compressed("compressed label", 0xC0),
24
25
26
27 Extended("extended label", 0x40);
28
29
30
31
32 static final int LABEL_MASK = 0xC0;
33 static final int LABEL_NOT_MASK = 0x3F;
34
35 private final String _externalName;
36
37 private final int _index;
38
39 DNSLabel(String name, int index) {
40 _externalName = name;
41 _index = index;
42 }
43
44
45
46
47
48
49 public String externalName() {
50 return _externalName;
51 }
52
53
54
55
56
57
58 public int indexValue() {
59 return _index;
60 }
61
62
63
64
65
66 public static DNSLabel labelForByte(int index) {
67 int maskedIndex = index & LABEL_MASK;
68 for (DNSLabel aLabel : DNSLabel.values()) {
69 if (aLabel._index == maskedIndex) return aLabel;
70 }
71 return Unknown;
72 }
73
74
75
76
77
78 public static int labelValue(int index) {
79 return index & LABEL_NOT_MASK;
80 }
81
82 @Override
83 public String toString() {
84 return this.name() + " index " + this.indexValue();
85 }
86
87 }