-
Notifications
You must be signed in to change notification settings - Fork 1
/
gdb-packet.h
87 lines (64 loc) · 1.53 KB
/
gdb-packet.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include <vector>
#include <string_view>
enum class gdb_packet_type
{
invalid,
ack, // '+'
nak, // '-'
brk, // '\03'
dat, // "$packet-data#cc", where CC - two hex digit CRC
};
class gdb_packet
{
public:
enum class state {
invalid,
data,
run_length_coding,
crc,
complete
};
static gdb_packet packet_ack()
{
return gdb_packet_type::ack;
}
static gdb_packet packet_nak()
{
return gdb_packet_type::nak;
}
static gdb_packet packet_break()
{
return gdb_packet_type::brk;
}
static gdb_packet packet_data()
{
return gdb_packet_type::dat;
}
static gdb_packet packet_empty()
{
gdb_packet pkt(gdb_packet_type::dat);
pkt.finalize();
return pkt;
}
gdb_packet() = default;
gdb_packet(gdb_packet_type type) noexcept;
gdb_packet_type type() const noexcept;
bool is_complete() const noexcept;
std::string_view data() const noexcept;
std::string_view raw_data() const noexcept;
uint8_t data_crc() const;
uint8_t calc_crc() const noexcept;
bool is_invalid() const noexcept;
state state() const noexcept;
void reserve(size_t capacity);
size_t parse(const char *data, size_t size);
size_t parse(const char *data);
size_t parse(std::string_view view);
bool finalize();
void reset() noexcept;
protected:
std::vector<char> m_data;
enum state m_state = state::invalid;
uint8_t m_csum = 0;
};