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