blob: eb45f153b84e7cf7f1219268078f30ee8bd1dbff [file] [log] [blame]
#include <string>
#include <vector>
#include "rive/span.hpp"
#include "rive/core/type_conversions.hpp"
namespace rive {
class BinaryReader {
Span<const uint8_t> m_Bytes;
const uint8_t* m_Position;
bool m_Overflowed;
bool m_IntRangeError;
void overflow();
void intRangeError();
explicit BinaryReader(Span<const uint8_t>);
bool didOverflow() const;
bool didIntRangeError() const;
bool hasError() const { return m_Overflowed || m_IntRangeError; }
bool reachedEnd() const;
size_t lengthInBytes() const;
std::string readString();
Span<const uint8_t> readBytes();
double readFloat64();
float readFloat32();
uint8_t readByte();
uint32_t readUint32();
uint64_t readVarUint64(); // Reads a LEB128 encoded uint64_t
// This will cast the uint read to the requested size, but if the
// raw value was out-of-range, instead returns 0 and sets the IntRangeError.
template <typename T> T readVarUintAs() {
auto value = this->readVarUint64();
if (!fitsIn<T>(value)) {
value = 0;
return static_cast<T>(value);
} // namespace rive