-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhpack_decoder.h
61 lines (45 loc) · 1.2 KB
/
hpack_decoder.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
#ifndef HPACK_DECODER_H
#define HPACK_DECODER_H
#include <cstddef>
#include <vector>
#include <memory>
#include <utility>
#include <string>
#include <optional>
#include "buffer_view.h"
#include "hpack_types.h"
namespace hpack {
class hpack_dynamic_table;
struct decoding_context {
std::unique_ptr<hpack_dynamic_table> dynamic_table;
decoding_context();
~decoding_context();
};
class hpack_decoder {
private:
buffer_view<unsigned char> buffer_view_;
std::size_t decode_pos_;
public:
using header_list_type = std::vector<header_type>;
public:
hpack_decoder(const unsigned char* buffer, std::size_t length);
header_list_type decode(decoding_context& context);
private:
struct decoded_result {
std::optional<header_type> header;
bool end;
decoded_result()
: end(false) {}
// T: std::optional<header_type>, header_type, std::nullopt
template<typename T>
decoded_result(T&& h, bool e)
: header(std::forward<T>(h)),
end(e) {}
};
int fetch_integer(std::size_t n);
std::string fetch_string();
header_type fetch_header(const decoding_context& context, std::size_t index);
decoded_result decode_representation(decoding_context& context);
};
}
#endif