12#ifndef O2_FRAMEWORK_AODNATIVE_CURSOR_H_
13#define O2_FRAMEWORK_AODNATIVE_CURSOR_H_
35 : mBuf(
buf), mFile(
file), mFileOffset(fileOffset), mOrigin(
origin)
39 size_t pos()
const {
return mPos; }
41 size_t remaining()
const {
return mBuf.size() - mPos; }
42 std::span<const uint8_t>
buffer()
const {
return mBuf; }
46 if (p > mBuf.size()) {
47 fail(
"seek past the end of the buffer");
55 fail(
"seek before the start of the buffer");
60 std::span<const uint8_t>
bytes(
size_t n)
64 return mBuf.subspan(p,
n);
68 uint16_t
u16() {
return load<uint16_t>(); }
69 uint32_t
u32() {
return load<uint32_t>(); }
70 uint64_t
u64() {
return load<uint64_t>(); }
71 int16_t
i16() {
return (int16_t)
u16(); }
72 int32_t
i32() {
return (int32_t)
u32(); }
74 double f64() {
return std::bit_cast<double>(
u64()); }
84 return {(
char const*)
b.data(),
b.size()};
93 return {(
char const*)mBuf.data() +
start, mPos -
start - 1};
96 [[noreturn]]
void fail(std::string
const& what)
const
101 std::string
const&
file()
const {
return mFile; }
104 size_t need(
size_t n)
const
106 if (
n > mBuf.size() - mPos) {
112 template <
typename T>
116 std::memcpy(&
v,
bytes(
sizeof(T)).
data(),
sizeof(T));
117 if constexpr (std::endian::native == std::endian::little) {
123 std::span<const uint8_t> mBuf;
124 std::string
const& mFile;
125 uint64_t mFileOffset;
std::span< const uint8_t > buffer() const
std::span< const uint8_t > bytes(size_t n)
std::string const & file() const
int64_t displacement() const
std::string string()
TString: 1-byte length, or 0xFF followed by a 4-byte length.
void fail(std::string const &what) const
Cursor(std::span< const uint8_t > buf, std::string const &file, uint64_t fileOffset=0, int64_t origin=0)
std::string cstring()
NUL-terminated string, as used for class names after kNewClassTag.
GLboolean GLboolean GLboolean b
GLenum GLuint GLenum GLsizei const GLchar * buf
consteval header::DataOrigin origin()
std::string to_string(gsl::span< T, Size > span)