Mercurial > minori
comparison src/core/byte_stream.cc @ 364:99c961c91809
core: refactor out byte stream into its own file
easy dubs
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Tue, 16 Jul 2024 21:15:59 -0400 |
| parents | |
| children | 47c9f8502269 |
comparison
equal
deleted
inserted
replaced
| 363:f10507d8f686 | 364:99c961c91809 |
|---|---|
| 1 #include "core/byte_stream.h" | |
| 2 | |
| 3 ByteStream::ByteStream(std::uint8_t *bytes, std::size_t size) { | |
| 4 bytes_ = bytes; | |
| 5 size_ = size; | |
| 6 } | |
| 7 | |
| 8 void ByteStream::ResetOffset() { | |
| 9 offset_ = 0; | |
| 10 } | |
| 11 | |
| 12 void ByteStream::SetEndianness(ByteStream::ByteOrder endian) { | |
| 13 endian_ = endian; | |
| 14 } | |
| 15 | |
| 16 bool ByteStream::ReadString(std::string& str, std::size_t size) { | |
| 17 if (offset_ + size >= size_) | |
| 18 return false; | |
| 19 | |
| 20 str.assign(reinterpret_cast<const char *>(bytes_ + offset_), size); | |
| 21 Advance(size); | |
| 22 return true; | |
| 23 } | |
| 24 | |
| 25 bool ByteStream::Advance(std::size_t amount) { | |
| 26 if (offset_ + amount >= size_) | |
| 27 return false; | |
| 28 | |
| 29 offset_ += amount; | |
| 30 return true; | |
| 31 } |
