| 117 | } |
| 118 | |
| 119 | class BitPacker { |
| 120 | public: |
| 121 | // Constructor |
| 122 | BitPacker(int bits, std::ofstream& fo) |
| 123 | : current_value(0), current_bits(0), bits(bits), fo(fo) {} |
| 124 | |
| 125 | // Member function to push a new value to the stream |
| 126 | void push(int value) { |
| 127 | current_value += (value << current_bits); |
| 128 | current_bits += bits; |
| 129 | while (current_bits >= 8) { |
| 130 | uint8_t lower_8bits = current_value & 0xff; |
| 131 | current_bits -= 8; |
| 132 | current_value >>= 8; |
| 133 | fo.write(reinterpret_cast<char*>(&lower_8bits), sizeof(lower_8bits)); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // Member function to flush the remaining partial uint8 |
| 138 | void flush() { |
| 139 | if (current_bits) { |
| 140 | fo.write(reinterpret_cast<char*>(¤t_value), sizeof(uint8_t)); |
| 141 | current_value = 0; |
| 142 | current_bits = 0; |
| 143 | } |
| 144 | fo.flush(); |
| 145 | } |
| 146 | |
| 147 | private: |
| 148 | int current_value; |
| 149 | int current_bits; |
| 150 | int bits; |
| 151 | std::ofstream & fo; |
| 152 | }; |
| 153 | |
| 154 | class BitUnpacker { |
| 155 | public: |
nothing calls this directly
no outgoing calls
no test coverage detected