1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.socksx.v4;
17
18 import io.netty.util.internal.ObjectUtil;
19
20
21
22
23 public class Socks4CommandType implements Comparable<Socks4CommandType> {
24
25 public static final Socks4CommandType CONNECT = new Socks4CommandType(0x01, "CONNECT");
26 public static final Socks4CommandType BIND = new Socks4CommandType(0x02, "BIND");
27
28 public static Socks4CommandType valueOf(byte b) {
29 switch (b) {
30 case 0x01:
31 return CONNECT;
32 case 0x02:
33 return BIND;
34 }
35
36 return new Socks4CommandType(b);
37 }
38
39 private final byte byteValue;
40 private final String name;
41 private String text;
42
43 public Socks4CommandType(int byteValue) {
44 this(byteValue, "UNKNOWN");
45 }
46
47 public Socks4CommandType(int byteValue, String name) {
48 this.name = ObjectUtil.checkNotNull(name, "name");
49 this.byteValue = (byte) byteValue;
50 }
51
52 public byte byteValue() {
53 return byteValue;
54 }
55
56 @Override
57 public int hashCode() {
58 return byteValue;
59 }
60
61 @Override
62 public boolean equals(Object obj) {
63 if (!(obj instanceof Socks4CommandType)) {
64 return false;
65 }
66
67 return byteValue == ((Socks4CommandType) obj).byteValue;
68 }
69
70 @Override
71 public int compareTo(Socks4CommandType o) {
72 return byteValue - o.byteValue;
73 }
74
75 @Override
76 public String toString() {
77 String text = this.text;
78 if (text == null) {
79 this.text = text = name + '(' + (byteValue & 0xFF) + ')';
80 }
81 return text;
82 }
83 }