REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
data_frame.h
Go to the documentation of this file.
1#pragma once
2
3#include "websockets/common.h"
4
5namespace websockets { namespace internals {
7 // None as error value
8 None = -1,
9 // Default value for empty messages
11
12 // Data opcdoes
13 Text = 0x1,
14 Binary = 0x2,
15
16 // Control opcodes
17 Close = 0x8,
18 Ping = 0x9,
19 Pong = 0xA
20 };
21
23 uint8_t fin : 1;
24 uint8_t opcode : 4;
25 uint8_t mask : 1;
26 uint8_t mask_buf[4];
28 std::string payload;
29
31 return fin && (opcode == 0x8 || opcode == 0x9 || opcode == 0xA);
32 }
33
34 bool isEmpty() {
35 return (fin == 0) && (opcode == 0) && (payload_length == 0);
36 }
37
39 return (fin == 0) && (opcode != 0);
40 }
41
42 bool isContinuesFragment() const {
43 return (fin == 0) && (opcode == 0);
44 }
45
47 return (fin == 1) && (opcode == 0);
48 }
49
51 return (fin == 1) && (opcode != 0);
52 }
53 };
54
55 template <class HeaderTy> HeaderTy MakeHeader(size_t len, uint8_t opcode, bool fin, bool mask) {
56 HeaderTy header;
57 header.fin = fin;
58 header.flags = 0;
59 header.opcode = opcode;
60 header.mask = mask? 1: 0;
61
62 // set payload
63 if(len < 126) {
64 header.payload = len;
65 } else if(len < 65536) {
66 header.payload = 126;
67 } else {
68 header.payload = 127;
69 }
70
71 return header;
72 }
73
74 struct Header {
75 uint8_t opcode : 4;
76 uint8_t flags : 3;
77 uint8_t fin : 1;
78 uint8_t payload : 7;
79 uint8_t mask : 1;
80 };
81
85
89}} // websockets::internals
HeaderTy MakeHeader(size_t len, uint8_t opcode, bool fin, bool mask)
Definition data_frame.h:55