|
1 | 1 | #pragma once |
2 | 2 |
|
| 3 | +#include <cstdint> |
| 4 | +#include <vector> |
| 5 | + |
3 | 6 | // Packed Bits classes copied from the original Wind Waker Randomizer |
4 | 7 | class PackedBitsWriter |
5 | 8 | { |
| 9 | +private: |
| 10 | + size_t bits_left_in_byte = 8; |
| 11 | + uint8_t current_byte = 0; |
| 12 | + std::vector<uint8_t> bytes = {}; |
| 13 | + |
6 | 14 | public: |
7 | 15 | PackedBitsWriter() = default; |
8 | 16 | ~PackedBitsWriter() = default; |
9 | 17 |
|
10 | | - uint8_t bits_left_in_byte = 8; |
11 | | - size_t current_byte = 0; |
12 | | - std::vector<char> bytes = {}; |
13 | | - |
14 | 18 | template <typename T> |
15 | 19 | void write(T value, size_t length) |
16 | 20 | { |
@@ -49,17 +53,21 @@ class PackedBitsWriter |
49 | 53 | bits_left_in_byte = 8; |
50 | 54 | } |
51 | 55 |
|
| 56 | + const std::vector<uint8_t>& getBytes() const { |
| 57 | + return bytes; |
| 58 | + } |
52 | 59 | }; |
53 | 60 |
|
54 | 61 | class PackedBitsReader |
55 | 62 | { |
56 | | -public: |
57 | | - PackedBitsReader(const std::vector<char>& bytes_) : bytes(bytes_) {} |
58 | | - ~PackedBitsReader() = default; |
59 | | - |
| 63 | +private: |
60 | 64 | size_t current_bit_index = 0; |
61 | 65 | size_t current_byte_index = 0; |
62 | | - std::vector<char> bytes = {}; |
| 66 | + std::vector<uint8_t> bytes = {}; |
| 67 | + |
| 68 | +public: |
| 69 | + PackedBitsReader(const std::vector<uint8_t>& bytes_) : bytes(bytes_) {} |
| 70 | + ~PackedBitsReader() = default; |
63 | 71 |
|
64 | 72 | size_t read(size_t length) |
65 | 73 | { |
@@ -103,4 +111,8 @@ class PackedBitsReader |
103 | 111 |
|
104 | 112 | return value; |
105 | 113 | } |
| 114 | + |
| 115 | + bool reachedLastByte() const { |
| 116 | + return current_byte_index == bytes.size() - 1; |
| 117 | + } |
106 | 118 | }; |
0 commit comments