1 #include "core/binary_reader.hpp"
2 #include "core/reader.h"
6 BinaryReader::BinaryReader(uint8_t* bytes, size_t length) :
14 size_t BinaryReader::lengthInBytes() const { return m_Length; }
16 bool BinaryReader::didOverflow() const { return m_Overflowed; }
18 void BinaryReader::overflow()
24 uint64_t BinaryReader::readVarUint()
27 auto readBytes = decode_uint_leb(m_Position, m_End, &value);
33 m_Position += readBytes;
37 std::string BinaryReader::readString()
39 uint64_t length = readVarUint();
45 char rawValue[length];
46 auto readBytes = decode_string(length, m_Position, m_End, &rawValue[0]);
47 if (readBytes != length)
52 m_Position += readBytes;
53 return std::string(rawValue);
56 double BinaryReader::readFloat64()
59 auto readBytes = decode_double(m_Position, m_End, &value);
65 m_Position += readBytes;
69 float BinaryReader::readFloat32()
72 auto readBytes = decode_float(m_Position, m_End, &value);
78 m_Position += readBytes;
82 uint8_t BinaryReader::readByte()
84 if (m_End - m_Position < 1)
92 uint32_t BinaryReader::readUint32()
95 auto readBytes = decode_uint_32(m_Position, m_End, &value);
101 m_Position += readBytes;