Merge branch 'main' into add-bjson-binary-data-type

This commit is contained in:
MihailRis 2024-09-12 16:22:50 +03:00
commit 62c002252f
2 changed files with 8 additions and 2 deletions

View File

@ -9,7 +9,7 @@ void ByteBuilder::put(ubyte b) {
}
void ByteBuilder::putCStr(const char* str) {
size_t size = strlen(str) + 1;
size_t size = std::strlen(str) + 1;
buffer.reserve(buffer.size() + size);
for (size_t i = 0; i < size; i++) {
buffer.push_back(str[i]);
@ -188,7 +188,7 @@ const char* ByteReader::getCString() {
}
std::string ByteReader::getString() {
uint32_t length = (uint32_t)getInt32();
uint32_t length = static_cast<uint32_t>(getInt32());
if (pos + length > size) {
throw std::runtime_error("buffer underflow");
}
@ -202,6 +202,10 @@ bool ByteReader::hasNext() const {
return pos < size;
}
size_t ByteReader::remaining() const {
return size - pos;
}
const ubyte* ByteReader::pointer() const {
return data + pos;
}

View File

@ -74,6 +74,8 @@ public:
std::string getString();
/// @return true if there is at least one byte remains
bool hasNext() const;
/// @return Number of remaining bytes in buffer
size_t remaining() const;
const ubyte* pointer() const;
void skip(size_t n);