MCPcopy Create free account
hub / github.com/cwida/ALP / BitReader

Class BitReader

publication/source_code/include/chimp/bit_reader.hpp:10–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8//! Within a byte we need to mask off the bits that we're interested in
9
10struct BitReader {
11private:
12 //! Align the masks to the right
13 static constexpr uint8_t MASKS[] = {
14 0, // 0b00000000,
15 128, // 0b10000000,
16 192, // 0b11000000,
17 224, // 0b11100000,
18 240, // 0b11110000,
19 248, // 0b11111000,
20 252, // 0b11111100,
21 254, // 0b11111110,
22 255, // 0b11111111,
23 // These later masks are for the cases where index + SIZE exceeds 8
24 254, // 0b11111110,
25 252, // 0b11111100,
26 248, // 0b11111000,
27 240, // 0b11110000,
28 224, // 0b11100000,
29 192, // 0b11000000,
30 128, // 0b10000000,
31 };
32
33 static constexpr uint8_t REMAINDER_MASKS[] = {
34 0,
35 0,
36 0,
37 0,
38 0,
39 0,
40 0,
41 0,
42 0,
43 128, // 0b10000000,
44 192, // 0b11000000,
45 224, // 0b11100000,
46 240, // 0b11110000,
47 248, // 0b11111000,
48 252, // 0b11111100,
49 254, // 0b11111110,
50 255, // 0b11111111,
51 };
52
53public:
54public:
55 BitReader()
56 : input(nullptr)
57 , index(0) {}
58 uint8_t* input;
59 uint32_t index;
60
61public:
62 void SetStream(uint8_t* input) {
63 this->input = input;
64 index = 0;
65 }
66
67 inline uint8_t BitIndex() const { return (index & 7); }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected