15 explicit ReadStream(std::vector<uint8_t> data) : _data(std::move(data)) {}
19 return _data.size() - _offset;
22 void reset(
const size_t offset = 0)
27 void skip(
const size_t bytes)
34 _offset = (_offset + bytes - 1) & (~(bytes - 1));
39 return static_cast<char>(
readU8());
45 result.reserve(numChars);
46 for (
size_t i = 0; i < numChars; ++i) {
55 return _data[_offset++];
60 const auto index = increment(2);
61 return static_cast<uint16_t
>(_data[index] | (_data[index + 1] << 8));
66 const auto index = increment(4);
67 return static_cast<uint32_t
>(_data[index] |
68 (_data[index + 1] << 8) |
69 (_data[index + 2] << 16) |
70 (_data[index + 3] << 24));
76 const uint64_t high =
readU32();
77 return low + (high << 32);
82 const auto index = increment(4);
83 return static_cast<uint32_t
>((_data[index] << 24) |
84 (_data[index + 1] << 16) |
85 (_data[index + 2] << 8) |
91 for (
auto& value : result) {
99 while (_offset < _data.size()) {
110 void ensure(
const size_t amount)
const
112 if (_offset + amount > _data.size()) {
113 throw std::out_of_range(
"ReadStream overflow");
117 size_t increment(
const size_t amount)
121 return _offset - amount;
124 std::vector<uint8_t> _data;
void readArray(std::vector< uint8_t > &result)
ReadStream(std::vector< uint8_t > data)
std::string readChars(const size_t numChars)
size_t remainingBytes() const
void align(const size_t bytes)
void reset(const size_t offset=0)
void skip(const size_t bytes)