Skip to content

Commit

Permalink
feat: encode uint8_t with binarystream
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Feb 12, 2024
1 parent 2986005 commit 288613e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main/io/BinaryStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ BinaryStream& BinaryStream::operator>>(char& value) {
return *this;
}

BinaryStream& BinaryStream::operator>>(uint8_t& value) {
ensureReadable();
istr->read((char*)&value, 1);
return *this;
}

BinaryStream& BinaryStream::operator>>(std::byte& value) {
ensureReadable();
istr->read((char*)&value, 1);
Expand Down Expand Up @@ -109,6 +115,13 @@ BinaryStream& BinaryStream::operator<<(std::byte value) {
return *this;
}

BinaryStream& BinaryStream::operator<<(uint8_t value) {
ensureWritable();
ostr->write((const char*)&value, sizeof(value));

return *this;
}

BinaryStream& BinaryStream::operator<<(int16_t value) {
ensureWritable();
if (flipBytes)
Expand Down
2 changes: 2 additions & 0 deletions main/io/include/BinaryStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class BinaryStream {
// Read operations
BinaryStream& operator>>(char& value);
BinaryStream& operator>>(std::byte& value);
BinaryStream& operator>>(uint8_t& value);
BinaryStream& operator>>(int16_t& value);
BinaryStream& operator>>(uint16_t& value);
BinaryStream& operator>>(int32_t& value);
Expand All @@ -69,6 +70,7 @@ class BinaryStream {
// Write operations
BinaryStream& operator<<(char value);
BinaryStream& operator<<(std::byte value);
BinaryStream& operator<<(uint8_t value);
BinaryStream& operator<<(int16_t value);
BinaryStream& operator<<(uint16_t value);
BinaryStream& operator<<(int32_t value);
Expand Down

0 comments on commit 288613e

Please sign in to comment.