-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathparser.h
More file actions
52 lines (50 loc) · 1.77 KB
/
parser.h
File metadata and controls
52 lines (50 loc) · 1.77 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
#pragma once
#include <queue>
#include <vector>
#include <string>
#include <memory>
class Parser
{
public:
Parser();
~Parser();
bool add_header(const unsigned char header);
bool add_headers(const std::vector<unsigned char>& header);
bool add_header_mask(const unsigned char mask);
bool add_header_masks(const std::vector<unsigned char>& mask);
bool add_footer(const unsigned char footer);
bool add_footers(const std::vector<unsigned char>& footer);
bool parse_byte(const unsigned char byte);
bool verify_checksum(const std::vector<unsigned char>& checksums);
bool has_header();
bool has_footer();
void clear();
const std::vector<unsigned char> header();
const std::vector<unsigned char> data(const std::vector<unsigned char>& mask = {});
const std::vector<unsigned char> buffer();
const std::vector<unsigned char> apply_mask(const std::vector<unsigned char>& data, const std::vector<unsigned char>& mask);
bool parse_header();
bool parse_footer();
bool parse_length();
bool available();
void set_checksum_len(size_t len);
void set_total_len(size_t len);
void set_buffer_len(size_t len);
void set_data_length(uint8_t offset, uint8_t length, bool big_endian, int8_t adjust);
private:
bool calculate_dynamic_length();
std::vector<unsigned char> header_;
std::vector<unsigned char> header_mask_;
std::vector<unsigned char> footer_;
std::vector<unsigned char> buffer_;
size_t checksum_len_;
size_t total_len_;
size_t buffer_len_;
// Dynamic data length parsing
bool has_data_length_{false};
uint8_t data_length_offset_{0};
uint8_t data_length_size_{1};
bool data_length_big_endian_{true};
int8_t data_length_adjust_{0};
size_t dynamic_total_len_{0};
};