Repository navigation
Expand file tree
/
Copy pathpacket.h
More file actions
72 lines (62 loc) · 1.54 KB
/
Copy pathpacket.h
File metadata and controls
72 lines (62 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <string>
#include <stdint.h>
class Packet final
{
public:
enum
{
packet_header_soh = 0x01,
packet_header_version = 3,
packet_header_id = 0x4afb,
};
Packet() = delete;
Packet(const Packet &) = delete;
static bool valid(std::string_view packet);
static bool complete(std::string_view packet);
static unsigned int length(std::string_view data);
static std::string encapsulate(bool packetised, std::string_view data, std::string_view oob_data);
static void decapsulate(bool packetised, std::string_view packet, std::string &data, std::string &oob_data);
private:
typedef struct __attribute__((packed))
{
uint8_t soh;
uint8_t version;
uint16_t id;
uint16_t header_length;
uint16_t payload_length;
uint16_t oob_length;
union
{
struct __attribute__((packed))
{
unsigned int spare_0:1;
unsigned int spare_1:1;
unsigned int spare_2:1;
unsigned int spare_3:1;
unsigned int spare_4:1;
unsigned int spare_5:1;
unsigned int spare_6:1;
unsigned int spare_7:1;
unsigned int spare_8:1;
unsigned int spare_9:1;
unsigned int spare_10:1;
unsigned int spare_11:1;
unsigned int spare_12:1;
unsigned int spare_13:1;
unsigned int spare_14:1;
unsigned int spare_15:1;
} flag;
uint16_t flags;
};
uint16_t spare[2];
uint32_t header_checksum;
uint32_t packet_checksum;
uint8_t data[];
} packet_header_t;
public:
static unsigned int packet_header_size()
{
return(sizeof(packet_header_t));
}
};