HttpServerBoxed 0.0.11 alpha
A simple http server for C# and .NET
Loading...
Searching...
No Matches
HSB.Components.WebSockets.Frame Class Reference

Public Member Functions

 Frame (bool fin=true, bool rsv1=false, bool rsv2=false, bool rsv3=false, Opcode opcode=Opcode.TEXT, bool mask=false)
 Use this constructor to create a frame.
 
 Frame (byte[] data)
 Use this costructor to decode a frame </summary

Parameters
data

 
byte[] Build ()
 Build the frame.
 
void SetOpcode (Opcode opcode)
 Set the opcode of the frame.
 
Opcode GetOpcode ()
 Get frame opcode.
 
void SetPayload (byte[] payload)
 
void SetPayload (string payload)
 
override string ToString ()
 
byte[] GetPayload ()
 
override bool Equals (object? obj)
 
bool GetFIN ()
 
bool GetRSV1 ()
 
bool GetRSV2 ()
 
bool GetRSV3 ()
 
bool GetMask ()
 
bool[] GetPayloadLength ()
 
byte?[] GetExtendedPayloadLength ()
 
byte?[] GetExtendedPayloadLengthContinued ()
 
override int GetHashCode ()
 
 Frame (bool fin=true, bool rsv1=false, bool rsv2=false, bool rsv3=false, Opcode opcode=Constants.WebSocket.Opcode.TEXT, bool mask=false)
 Use this constructor to create a frame.
 
 Frame (byte[] data)
 Use this costructor to decode a frame.
 
byte[] Build ()
 Build the frame.
 
void SetOpcode (Opcode opcode)
 Set the opcode of the frame.
 
Opcode GetOpcode ()
 Get frame opcode.
 
void SetPayload (byte[] payload)
 
void SetPayload (string payload)
 
override string ToString ()
 
byte[] GetPayload ()
 
override bool Equals (object? obj)
 
bool GetFIN ()
 
bool GetRSV1 ()
 
bool GetRSV2 ()
 
bool GetRSV3 ()
 
bool GetMask ()
 
bool[] GetPayloadLength ()
 
byte?[] GetExtendedPayloadLength ()
 
byte?[] GetExtendedPayloadLengthContinued ()
 
override int GetHashCode ()
 
void Dispose ()
 

Detailed Description

Definition at line 6 of file Frame.cs.

Constructor & Destructor Documentation

◆ Frame() [1/4]

HSB.Components.WebSockets.Frame.Frame ( bool  fin = true,
bool  rsv1 = false,
bool  rsv2 = false,
bool  rsv3 = false,
Opcode  opcode = Opcode::TEXT,
bool  mask = false 
)

Use this constructor to create a frame.

Parameters
fin
rsv1
rsv2
rsv3
opcode
mask

Definition at line 31 of file Frame.cs.

32 {
33 FIN = fin;
34 RSV1 = rsv1;
35 RSV2 = rsv2;
36 RSV3 = rsv3;
37 SetOpcode(opcode);
38 Mask = mask;
39 PayloadLength = new bool[] { false, false, false, false, false, false, false };
40
41 /* PayloadLength = payloadLength;
42 ExtendedPayloadLength = extendedPayloadLength;
43 ExtendedPayloadLengthContinued = extendedPayloadLengthContinued;
44 MaskingKey = maskingKey;
45 MaskingKeyContinued = maskinKeyContinued;
46 PayloadData = payloadData;*/
47 }
void SetOpcode(Opcode opcode)
Set the opcode of the frame.
Definition Frame.cs:160

◆ Frame() [2/4]

HSB.Components.WebSockets.Frame.Frame ( byte[]  data)

Use this costructor to decode a frame </summary

Parameters
data

Definition at line 53 of file Frame.cs.

54 {
55 //minimum length of a frame is 2 bytes
56 if (data.Length < 2)
57 throw new Exception("Frame: data.Length < 2");
58
59 var first8bits = data[0].ToBitArray();
60 FIN = first8bits[0];
61 RSV1 = first8bits[1];
62 RSV2 = first8bits[2];
63 RSV3 = first8bits[3];
64 opcode = first8bits[4..];//new bool[] { first8bits[4], first8bits[5], first8bits[6], first8bits[7] };
65 var maskAndPayloadLength = data[1].ToBitArray();
66 Mask = maskAndPayloadLength[0];
67 PayloadLength = maskAndPayloadLength[1..];
68
69 if (PayloadLength.ToInt() == 126)
70 {
71 //ExtendedPayloadLength is present
72 if (data.Length < 4)
73 throw new Exception("Frame: data.Length < 4 and Payload length is 126");
74 ExtendedPayloadLength = new byte[] { data[2], data[3] };
75 }
76 else if (PayloadLength.ToInt() == 127)
77 {
78 //ExtendedPayloadLengthContinued is present
79 if (data.Length < 10)
80 throw new Exception("Frame: data.Length < 10 and Payload length is 127");
81 ExtendedPayloadLengthContinued = new byte[] { data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9] };
82 }
83
84 //masking key
85 int offset = 0; //from the start of the frame byte data
86 if (Mask)
87 {
88 //Mask position dependd on the size of the payload
89
90 if (PayloadLength.ToInt() < 126) //ExtendedPayloadLength and ExtendedPayloadLengthContinued are not present
91 offset = 2;
92 if (PayloadLength.ToInt() == 126)
93 offset = 4;
94 if (PayloadLength.ToInt() == 127)
95 offset = 10; //{flags, opcode, mask, payload length} = 2, extended payload length = 8
96
97
98 if (data.Length < offset + 4)
99 throw new Exception($"Frame: data.Length < {offset} + 4 and a mask is present");
100
101 MaskingKey = data[offset..(offset + 4)];
102 offset += 4;
103 //PayloadData = new byte[data[position..].Length];
104 }
105
106 PayloadData = data[offset..];
107 /*.Reverse().ToArray();
108 var x = PayloadData.ToBitArray();
109 Terminal.INFO($"{x.Length} bits ({x.Length/8} bytes)");*/
110
111 }

◆ Frame() [3/4]

HSB.Components.WebSockets.Frame.Frame ( bool  fin = true,
bool  rsv1 = false,
bool  rsv2 = false,
bool  rsv3 = false,
Opcode  opcode = Constants::WebSocket::Opcode::TEXT,
bool  mask = false 
)

Use this constructor to create a frame.

Parameters
fin
rsv1
rsv2
rsv3
opcode
mask

Definition at line 30 of file Frame.cs.

31 {
32 FIN = fin;
33 RSV1 = rsv1;
34 RSV2 = rsv2;
35 RSV3 = rsv3;
36 SetOpcode(opcode);
37 Mask = mask;
38 PayloadLength = [false, false, false, false, false, false, false];
39 }

◆ Frame() [4/4]

HSB.Components.WebSockets.Frame.Frame ( byte[]  data)

Use this costructor to decode a frame.

Parameters
data

Definition at line 45 of file Frame.cs.

46 {
47 //minimum length of a frame is 2 bytes
48 if (data.Length < 2)
49 throw new Exception("Frame: data.Length < 2");
50
51 var first8bits = data[0].ToBitArray();
52 FIN = first8bits[0];
53 RSV1 = first8bits[1];
54 RSV2 = first8bits[2];
55 RSV3 = first8bits[3];
56 Opcode = first8bits[4..];
57 var maskAndPayloadLength = data[1].ToBitArray();
58 Mask = maskAndPayloadLength[0];
59 PayloadLength = maskAndPayloadLength[1..];
60
61 if (PayloadLength.ToInt() == 126)
62 {
63 //ExtendedPayloadLength is present
64 if (data.Length < 4)
65 throw new Exception("Frame: data.Length < 4 and Payload length is 126");
66 ExtendedPayloadLength = [data[2], data[3]];
67 }
68 else if (PayloadLength.ToInt() == 127)
69 {
70 //ExtendedPayloadLengthContinued is present
71 if (data.Length < 10)
72 throw new Exception("Frame: data.Length < 10 and Payload length is 127");
73 ExtendedPayloadLengthContinued = [data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9]];
74 }
75
76 //masking key
77 int offset = 0; //from the start of the frame byte data
78 if (Mask)
79 {
80 //Mask position dependd on the size of the payload
81
82 if (PayloadLength.ToInt() < 126) //ExtendedPayloadLength and ExtendedPayloadLengthContinued are not present
83 offset = 2;
84 if (PayloadLength.ToInt() == 126)
85 offset = 4;
86 if (PayloadLength.ToInt() == 127)
87 offset = 10; //{flags, opcode, mask, payload length} = 2, extended payload length = 8
88
89 if (data.Length < offset + 4)
90 throw new Exception($"Frame: data.Length < {offset} + 4 and a mask is present");
91
92 MaskingKey = data[offset..(offset + 4)];
93 offset += 4;
94 }
95
96 PayloadData = data[offset..];
97 }
Opcode
The opcodes for the WebSocket protocol.
Definition WSOpcodes.cs:8

Member Function Documentation

◆ Build() [1/2]

byte[] HSB.Components.WebSockets.Frame.Build ( )

Build the frame.

Returns

Definition at line 116 of file Frame.cs.

117 {
118 List<byte> bytes = new(){
119 Utils.GetByte(
120 FIN,
121 RSV1,
122 RSV2,
123 RSV3,
124 opcode?[0] ?? false,
125 opcode?[1] ?? false,
126 opcode?[2] ?? false,
127 opcode?[3] ?? false
128 ),
129 Utils.GetByte(
130 //mask and payload length
131 Mask,
132 PayloadLength[0],
133 PayloadLength[1],
134 PayloadLength[2],
135 PayloadLength[3],
136 PayloadLength[4],
137 PayloadLength[5],
138 PayloadLength[6]
139 )
140 };
141 if (ExtendedPayloadLength != null) //two bytes
142 {
143 Terminal.INFO("This message has an extended payload length of 2 bytes");
144 bytes.AddRange(ExtendedPayloadLength);
145 }
146 if (Mask)
147 {
148 Terminal.INFO("This message has a mask, is this normal?");
149 bytes.AddRange(MaskingKey ?? Array.Empty<byte>());
150 }
151 if (PayloadData != null) //some frames don't have a payload, like close frame and ping/pong frames
152 bytes.AddRange(PayloadData);
153
154 return bytes.ToArray();
155 }

◆ Build() [2/2]

byte[] HSB.Components.WebSockets.Frame.Build ( )

Build the frame.

Returns

Definition at line 102 of file Frame.cs.

103 {
104 List<byte> bytes = [
105 Utils.GetByte(
106 FIN,
107 RSV1,
108 RSV2,
109 RSV3,
110 Opcode?[0] ?? false,
111 Opcode?[1] ?? false,
112 Opcode?[2] ?? false,
113 Opcode?[3] ?? false
114 ),
115 Utils.GetByte(
116 //mask and payload length
117 Mask,
118 PayloadLength[0],
119 PayloadLength[1],
120 PayloadLength[2],
121 PayloadLength[3],
122 PayloadLength[4],
123 PayloadLength[5],
124 PayloadLength[6]
125 )
126 ];
127 if (ExtendedPayloadLength != null) //two bytes
128 {
129 // Terminal.INFO("This message has an extended payload length of 2 bytes");
130 bytes.AddRange(ExtendedPayloadLength);
131 }
132 if (Mask)
133 {
134 //Terminal.INFO("This message has a mask, is this normal?");
135 bytes.AddRange(MaskingKey ?? []);
136 }
137 if (PayloadData != null) //some frames don't have a payload, like close frame and ping/pong frames
138 bytes.AddRange(PayloadData);
139
140 return [.. bytes];
141 }

◆ Dispose()

void HSB.Components.WebSockets.Frame.Dispose ( )

Definition at line 323 of file Frame.cs.

324 {
325 FIN = false;
326 RSV1 = false;
327 RSV2 = false;
328 RSV3 = false;
329 Opcode = null;
330 Mask = false;
331 PayloadLength = [false, false, false, false, false, false, false];
332 ExtendedPayloadLength = null;
333 ExtendedPayloadLengthContinued = null;
334 MaskingKey = null;
335 MaskingKeyContinued = null;
336 PayloadData = null;
337 }

◆ Equals() [1/2]

override bool HSB.Components.WebSockets.Frame.Equals ( object?  obj)

Definition at line 290 of file Frame.cs.

291 {
292 if (obj == null) return false;
293
294 if (obj is bool[])
295 {
296
297 //this is wrong
298 //compare bool[]
299 bool[] o = (bool[])obj;
300 bool equal = o[0] == FIN;
301 equal = equal && o[1] == RSV1;
302 equal = equal && o[2] == RSV2;
303 equal = equal && o[3] == RSV3;
304 equal = equal && o[4] == opcode?[0] && o[5] == opcode?[1] && o[6] == opcode?[2] && o[7] == opcode?[3];
305 equal = equal && o[8] == Mask;
306
307
308
309 return equal;
310 }
311 //compare frame
312 if (obj is Frame f)
313 {
314 bool equal = f.GetFIN() == FIN;
315 equal = equal && f.GetRSV1() == RSV1;
316 equal = equal && f.GetRSV2() == RSV2;
317 equal = equal && f.GetRSV3() == RSV3;
318 equal = equal && f.GetOpcode() == this.GetOpcode();
319 equal = equal && f.GetMask() == Mask;
320 equal = equal && f.GetPayloadLength() == PayloadLength;
321 equal = equal && f.GetExtendedPayloadLength() == ExtendedPayloadLength;
322 equal = equal && f.GetExtendedPayloadLengthContinued() == ExtendedPayloadLengthContinued;
323 return equal;
324
325 }
326 return false;
327 }
Opcode GetOpcode()
Get frame opcode.
Definition Frame.cs:189

◆ Equals() [2/2]

override bool HSB.Components.WebSockets.Frame.Equals ( object?  obj)

Definition at line 273 of file Frame.cs.

274 {
275 if (obj == null) return false;
276
277
278 if (obj is bool[] o)
279 {
280 bool equal = o[0] == FIN;
281 equal = equal && o[1] == RSV1;
282 equal = equal && o[2] == RSV2;
283 equal = equal && o[3] == RSV3;
284 equal = equal && o[4] == Opcode?[0] && o[5] == Opcode?[1] && o[6] == Opcode?[2] && o[7] == Opcode?[3];
285 equal = equal && o[8] == Mask;
286 //todo add missing checks
287 return equal;
288 }
289 //compare frame
290 if (obj is Frame f)
291 {
292 bool equal = f.GetFIN() == FIN;
293 equal = equal && f.GetRSV1() == RSV1;
294 equal = equal && f.GetRSV2() == RSV2;
295 equal = equal && f.GetRSV3() == RSV3;
296 equal = equal && f.GetOpcode() == this.GetOpcode();
297 equal = equal && f.GetMask() == Mask;
298 equal = equal && f.GetPayloadLength() == PayloadLength;
299 equal = equal && f.GetExtendedPayloadLength() == ExtendedPayloadLength;
300 equal = equal && f.GetExtendedPayloadLengthContinued() == ExtendedPayloadLengthContinued;
301 return equal;
302
303 }
304 return false;
305 }

◆ GetHashCode() [1/2]

override int HSB.Components.WebSockets.Frame.GetHashCode ( )

Definition at line 339 of file Frame.cs.

340 {
341 return base.GetHashCode();
342 }

◆ GetHashCode() [2/2]

override int HSB.Components.WebSockets.Frame.GetHashCode ( )

Definition at line 317 of file Frame.cs.

318 {
319 return base.GetHashCode();
320 }

◆ GetOpcode() [1/2]

Opcode HSB.Components.WebSockets.Frame.GetOpcode ( )

Get frame opcode.

Returns
Exceptions
Exception

Definition at line 189 of file Frame.cs.

190 {
191 if (opcode == null)
192 throw new Exception("Frame: opcode == null");
193 if (opcode[0] == false && opcode[1] == false && opcode[2] == false && opcode[3] == false)
194 return Opcode.CONTINUATION;
195 if (opcode[0] == false && opcode[1] == false && opcode[2] == false && opcode[3] == true)
196 return Opcode.TEXT;
197 if (opcode[0] == false && opcode[1] == false && opcode[2] == true && opcode[3] == false)
198 return Opcode.BINARY;
199 if (opcode[0] == true && opcode[1] == false && opcode[2] == false && opcode[3] == false)
200 return Opcode.CLOSE;
201 if (opcode[0] == true && opcode[1] == false && opcode[2] == false && opcode[3] == true)
202 return Opcode.PING;
203 if (opcode[0] == true && opcode[1] == false && opcode[2] == true && opcode[3] == false)
204 return Opcode.PONG;
205 throw new Exception("Frame: opcode not recognized");
206 }

◆ GetOpcode() [2/2]

Opcode HSB.Components.WebSockets.Frame.GetOpcode ( )

Get frame opcode.

Returns
Exceptions
Exception

Definition at line 175 of file Frame.cs.

176 {
177 if (Opcode == null)
178 throw new Exception("Frame: opcode == null");
179 if (Opcode[0] == false && Opcode[1] == false && Opcode[2] == false && Opcode[3] == false)
180 return Constants.WebSocket.Opcode.CONTINUATION;
181 if (Opcode[0] == false && Opcode[1] == false && Opcode[2] == false && Opcode[3] == true)
182 return Constants.WebSocket.Opcode.TEXT;
183 if (Opcode[0] == false && Opcode[1] == false && Opcode[2] == true && Opcode[3] == false)
184 return Constants.WebSocket.Opcode.BINARY;
185 if (Opcode[0] == true && Opcode[1] == false && Opcode[2] == false && Opcode[3] == false)
186 return Constants.WebSocket.Opcode.CLOSE;
187 if (Opcode[0] == true && Opcode[1] == false && Opcode[2] == false && Opcode[3] == true)
188 return Constants.WebSocket.Opcode.PING;
189 if (Opcode[0] == true && Opcode[1] == false && Opcode[2] == true && Opcode[3] == false)
190 return Constants.WebSocket.Opcode.PONG;
191 throw new Exception("Frame: opcode not recognized");
192 }

◆ GetPayload() [1/2]

byte[] HSB.Components.WebSockets.Frame.GetPayload ( )

Definition at line 251 of file Frame.cs.

252 {
253 if (PayloadData == null) return Array.Empty<byte>();
254
255 //if the frame is masked, unmask the payload
256 if (Mask && MaskingKey != null)
257 {
258 /*
259 * src: https://www.rfc-editor.org/rfc/rfc6455.html#section-5.3
260
261 * Octet i of the transformed data ("transformed-octet-i") is the XOR of
262 * octet i of the original data ("original-octet-i") with octet at index
263 * i modulo 4 of the masking key ("masking-key-octet-j"):
264
265 * j = i MOD 4
266 * transformed-octet-i = original-octet-i XOR masking-key-octet-j
267 */
268 //this operation must be done bit level and not byte level
269
270 /* bool[] payloadBits = PayloadData.ToBitArray();
271 bool[] maskBits = MaskingKey.ToBitArray();*/
272
273 var payloadBits = new BitArray(PayloadData);
274 BitArray maskBits = MaskingKey.Length != PayloadData.Length ?
275 new BitArray(MaskingKey.ExtendRepeating(PayloadData.Length)):
276 new BitArray(MaskingKey) ;
277
278
279 payloadBits = payloadBits.Xor(maskBits);
280
281
282 byte[] resultBytes = new byte[(payloadBits.Length - 1) / 8 + 1];
283 payloadBits.CopyTo(resultBytes, 0);
284 return resultBytes;
285 }
286
287 return PayloadData;
288 }

◆ GetPayload() [2/2]

byte[] HSB.Components.WebSockets.Frame.GetPayload ( )

Definition at line 237 of file Frame.cs.

238 {
239 if (PayloadData == null) return [];
240
241 //if the frame is masked, unmask the payload
242 if (Mask && MaskingKey != null)
243 {
244 /*
245 * src: https://www.rfc-editor.org/rfc/rfc6455.html#section-5.3
246
247 * Octet i of the transformed data ("transformed-octet-i") is the XOR of
248 * octet i of the original data ("original-octet-i") with octet at index
249 * i modulo 4 of the masking key ("masking-key-octet-j"):
250
251 * j = i MOD 4
252 * transformed-octet-i = original-octet-i XOR masking-key-octet-j
253 */
254 //this operation must be done bit level and not byte level
255
256 var payloadBits = new BitArray(PayloadData);
257 BitArray maskBits = MaskingKey.Length != PayloadData.Length ?
258 new BitArray(MaskingKey.ExtendRepeating(PayloadData.Length)) :
259 new BitArray(MaskingKey);
260
261
262 payloadBits = payloadBits.Xor(maskBits);
263
264
265 byte[] resultBytes = new byte[(payloadBits.Length - 1) / 8 + 1];
266 payloadBits.CopyTo(resultBytes, 0);
267 return resultBytes;
268 }
269
270 return PayloadData;
271 }

◆ SetOpcode() [1/2]

void HSB.Components.WebSockets.Frame.SetOpcode ( Opcode  opcode)

Set the opcode of the frame.

Parameters
opcode

Definition at line 160 of file Frame.cs.

161 {
162 switch (opcode)
163 {
164 case Opcode.CONTINUATION:
165 this.opcode = new bool[] { false, false, false, false };
166 break;
167 case Opcode.TEXT:
168 this.opcode = new bool[] { false, false, false, true };
169 break;
170 case Opcode.BINARY:
171 this.opcode = new bool[] { false, false, true, false };
172 break;
173 case Opcode.CLOSE:
174 this.opcode = new bool[] { true, false, false, false };
175 break;
176 case Opcode.PING:
177 this.opcode = new bool[] { true, false, false, true };
178 break;
179 case Opcode.PONG:
180 this.opcode = new bool[] { true, false, true, false };
181 break;
182 }
183 }

◆ SetOpcode() [2/2]

void HSB.Components.WebSockets.Frame.SetOpcode ( Opcode  opcode)

Set the opcode of the frame.

Parameters
opcode

Definition at line 146 of file Frame.cs.

147 {
148 switch (opcode)
149 {
150 case Constants.WebSocket.Opcode.CONTINUATION:
151 this.Opcode = [false, false, false, false];
152 break;
153 case Constants.WebSocket.Opcode.TEXT:
154 this.Opcode = [false, false, false, true];
155 break;
156 case Constants.WebSocket.Opcode.BINARY:
157 this.Opcode = [false, false, true, false];
158 break;
159 case Constants.WebSocket.Opcode.CLOSE:
160 this.Opcode = [true, false, false, false];
161 break;
162 case Constants.WebSocket.Opcode.PING:
163 this.Opcode = [true, false, false, true];
164 break;
165 case Constants.WebSocket.Opcode.PONG:
166 this.Opcode = [true, false, true, false];
167 break;
168 }
169 }

◆ SetPayload() [1/4]

void HSB.Components.WebSockets.Frame.SetPayload ( byte[]  payload)

Definition at line 207 of file Frame.cs.

208 {
209 PayloadData = payload;
210 if (payload.Length < 126)
211 {
212 PayloadLength = Utils.IntTo7Bits(payload.Length);
213 return;
214 }
215
216 if (payload.Length < 65536)
217 {
218 PayloadLength = Utils.IntTo7Bits(126);
219 ExtendedPayloadLength = BitConverter.GetBytes(payload.Length - 125);
220 return;
221 }
222 //a the moment the extended pauload length continued is not supported
223 }

◆ SetPayload() [2/4]

void HSB.Components.WebSockets.Frame.SetPayload ( byte[]  payload)

Definition at line 193 of file Frame.cs.

194 {
195 PayloadData = payload;
196 if (payload.Length < 126)
197 {
198 PayloadLength = Utils.IntTo7Bits(payload.Length);
199 return;
200 }
201
202 if (payload.Length < 65536)
203 {
204 PayloadLength = Utils.IntTo7Bits(126);
205 ExtendedPayloadLength = BitConverter.GetBytes(payload.Length - 125);
206 return;
207 }
208 //a the moment the extended payload length continued is not supported
209 }

◆ SetPayload() [3/4]

void HSB.Components.WebSockets.Frame.SetPayload ( string  payload)

Definition at line 224 of file Frame.cs.

225 {
226 SetOpcode(Opcode.TEXT);
227 SetPayload(Encoding.UTF8.GetBytes(payload));
228 }

◆ SetPayload() [4/4]

void HSB.Components.WebSockets.Frame.SetPayload ( string  payload)

Definition at line 210 of file Frame.cs.

211 {
212 SetOpcode(Constants.WebSocket.Opcode.TEXT);
213 SetPayload(Encoding.UTF8.GetBytes(payload));
214 }

◆ ToString() [1/2]

override string HSB.Components.WebSockets.Frame.ToString ( )

Definition at line 230 of file Frame.cs.

231 {
232 var sb = "WebSocket Frame:{\n";
233 sb += "\tFIN(AL): " + (FIN ? "YES" : "NO") + "\n";
234 sb += "\tRSV1: " + (RSV1 ? "✅" : "❌ (Good)") + "\n";
235 sb += "\tRSV2: " + (RSV2 ? "✅" : "❌ (Good)") + "\n";
236 sb += "\tRSV3: " + (RSV3 ? "✅" : "❌ (Good)") + "\n";
237 sb += "\tOpcode: " + (opcode == null ? "Not set??" : GetOpcode().ToString()) + "\n";
238 sb += "\tMask: " + (Mask ? "YES" : "NO") + "\n";
239 sb += "\tPayloadLength: " + (PayloadLength == null ? "not set" : PayloadLength.ToInt()) + " bytes\n";
240 sb += "\tExtendedPayloadLength: " + (ExtendedPayloadLength == null ? "not set" : BitConverter.ToInt16(ExtendedPayloadLength)) + "\n";
241 sb += "\tExtendedPayloadLengthContinued: " + (ExtendedPayloadLengthContinued == null ? "not set" : BitConverter.ToInt64(ExtendedPayloadLengthContinued)) + "\n";
242 sb += $"\tMaskingKey: {(MaskingKey == null ? "Not set" : "0x" + BitConverter.ToString(MaskingKey).Replace("-", " 0x"))}\n";
243 sb += "\tPayloadData: " + (PayloadData == null ? "Not set??" : "0x" + BitConverter.ToString(PayloadData).Replace("-", " 0x")) + "\n";
244 if (Mask)
245 {
246 sb += "\tUnmaskedPayloadData: " + (PayloadData == null ? "Not set??" : "0x" + BitConverter.ToString(GetPayload()).Replace("-", " 0x")) + "\n";
247 }
248 sb += "}";
249 return sb;
250 }

◆ ToString() [2/2]

override string HSB.Components.WebSockets.Frame.ToString ( )

Definition at line 216 of file Frame.cs.

217 {
218 var sb = "WebSocket Frame:{\n";
219 sb += "\tFIN(AL): " + (FIN ? "YES" : "NO") + "\n";
220 sb += "\tRSV1: " + (RSV1 ? "✅" : "❌ (Good)") + "\n";
221 sb += "\tRSV2: " + (RSV2 ? "✅" : "❌ (Good)") + "\n";
222 sb += "\tRSV3: " + (RSV3 ? "✅" : "❌ (Good)") + "\n";
223 sb += "\tOpcode: " + (Opcode == null ? "Not set??" : GetOpcode().ToString()) + "\n";
224 sb += "\tMask: " + (Mask ? "YES" : "NO") + "\n";
225 sb += "\tPayloadLength: " + (PayloadLength == null ? "not set" : PayloadLength.ToInt()) + " bytes\n";
226 sb += "\tExtendedPayloadLength: " + (ExtendedPayloadLength == null ? "not set" : BitConverter.ToInt16(ExtendedPayloadLength)) + "\n";
227 sb += "\tExtendedPayloadLengthContinued: " + (ExtendedPayloadLengthContinued == null ? "not set" : BitConverter.ToInt64(ExtendedPayloadLengthContinued)) + "\n";
228 sb += $"\tMaskingKey: {(MaskingKey == null ? "Not set" : "0x" + BitConverter.ToString(MaskingKey).Replace("-", " 0x"))}\n";
229 sb += "\tPayloadData: " + (PayloadData == null ? "Not set??" : "0x" + BitConverter.ToString(PayloadData).Replace("-", " 0x")) + "\n";
230 if (Mask)
231 {
232 sb += "\tUnmaskedPayloadData: " + (PayloadData == null ? "Not set??" : "0x" + BitConverter.ToString(GetPayload()).Replace("-", " 0x")) + "\n";
233 }
234 sb += "}";
235 return sb;
236 }

The documentation for this class was generated from the following files: