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

Class ByteReader

publication/source_code/include/chimp/byte_reader.hpp:17–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15namespace alp_bench {
16
17class ByteReader {
18public:
19 ByteReader()
20 : buffer(nullptr)
21 , index(0) {}
22
23public:
24 void SetStream(const uint8_t* buffer) {
25 this->buffer = buffer;
26 index = 0;
27 }
28
29 size_t Index() const { return index; }
30
31 template <class T>
32 T ReadValue() {
33 auto result = Load<T>(buffer + index);
34 index += sizeof(T);
35 return result;
36 }
37
38 template <class T, uint8_t SIZE>
39 T ReadValue() {
40 return ReadValue<T>(SIZE);
41 }
42
43 template <class T>
44 inline T ReadValue(uint8_t bytes, uint8_t trailing_zero) {
45 T result = 0;
46 switch (bytes) {
47 case 1:
48 result = Load<uint8_t>(buffer + index);
49 index++;
50 return result;
51 case 2:
52 result = Load<uint16_t>(buffer + index);
53 index += 2;
54 return result;
55 case 3:
56 memcpy(&result, (void*)(buffer + index), 3);
57 index += 3;
58 return result;
59 case 4:
60 result = Load<uint32_t>(buffer + index);
61 index += 4;
62 return result;
63 case 5:
64 memcpy(&result, (void*)(buffer + index), 5);
65 index += 5;
66 return result;
67 case 6:
68 memcpy(&result, (void*)(buffer + index), 6);
69 index += 6;
70 return result;
71 case 7:
72 memcpy(&result, (void*)(buffer + index), 7);
73 index += 7;
74 return result;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected