1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http2;
17
18
19
20
21 public final class Http2Flags {
22 public static final short END_STREAM = 0x1;
23 public static final short END_HEADERS = 0x4;
24 public static final short ACK = 0x1;
25 public static final short PADDED = 0x8;
26 public static final short PRIORITY = 0x20;
27
28 private short value;
29
30 public Http2Flags() {
31 }
32
33 public Http2Flags(short value) {
34 this.value = value;
35 }
36
37
38
39
40 public short value() {
41 return value;
42 }
43
44
45
46
47
48 public boolean endOfStream() {
49 return isFlagSet(END_STREAM);
50 }
51
52
53
54
55
56 public boolean endOfHeaders() {
57 return isFlagSet(END_HEADERS);
58 }
59
60
61
62
63
64 public boolean priorityPresent() {
65 return isFlagSet(PRIORITY);
66 }
67
68
69
70
71
72 public boolean ack() {
73 return isFlagSet(ACK);
74 }
75
76
77
78
79
80 public boolean paddingPresent() {
81 return isFlagSet(PADDED);
82 }
83
84
85
86
87
88 public int getNumPriorityBytes() {
89 return priorityPresent() ? 5 : 0;
90 }
91
92
93
94
95
96 public int getPaddingPresenceFieldLength() {
97 return paddingPresent() ? 1 : 0;
98 }
99
100
101
102
103 public Http2Flags endOfStream(boolean endOfStream) {
104 return setFlag(endOfStream, END_STREAM);
105 }
106
107
108
109
110 public Http2Flags endOfHeaders(boolean endOfHeaders) {
111 return setFlag(endOfHeaders, END_HEADERS);
112 }
113
114
115
116
117 public Http2Flags priorityPresent(boolean priorityPresent) {
118 return setFlag(priorityPresent, PRIORITY);
119 }
120
121
122
123
124 public Http2Flags paddingPresent(boolean paddingPresent) {
125 return setFlag(paddingPresent, PADDED);
126 }
127
128
129
130
131 public Http2Flags ack(boolean ack) {
132 return setFlag(ack, ACK);
133 }
134
135
136
137
138
139
140
141 public Http2Flags setFlag(boolean on, short mask) {
142 if (on) {
143 value |= mask;
144 } else {
145 value &= ~mask;
146 }
147 return this;
148 }
149
150
151
152
153
154
155 public boolean isFlagSet(short mask) {
156 return (value & mask) != 0;
157 }
158
159 @Override
160 public int hashCode() {
161 final int prime = 31;
162 int result = 1;
163 result = prime * result + value;
164 return result;
165 }
166
167 @Override
168 public boolean equals(Object obj) {
169 if (this == obj) {
170 return true;
171 }
172 if (obj == null) {
173 return false;
174 }
175 if (getClass() != obj.getClass()) {
176 return false;
177 }
178
179 return value == ((Http2Flags) obj).value;
180 }
181
182 @Override
183 public String toString() {
184 StringBuilder builder = new StringBuilder();
185 builder.append("value = ").append(value).append(" (");
186 if (ack()) {
187 builder.append("ACK,");
188 }
189 if (endOfHeaders()) {
190 builder.append("END_OF_HEADERS,");
191 }
192 if (endOfStream()) {
193 builder.append("END_OF_STREAM,");
194 }
195 if (priorityPresent()) {
196 builder.append("PRIORITY_PRESENT,");
197 }
198 if (paddingPresent()) {
199 builder.append("PADDING_PRESENT,");
200 }
201 builder.append(')');
202 return builder.toString();
203 }
204 }