Pixie
Loading...
Searching...
No Matches
pixie::BinaryReader Class Reference

Bounds-checked reader for canonical little-endian binary data. More...

#include <serialization.h>

Public Member Functions

 BinaryReader (std::span< const std::byte > data)
 Construct a reader over caller-owned data.
 
bool empty () const noexcept
 Return whether all input bytes have been consumed.
 
std::size_t size_bytes () const noexcept
 Return the total number of bytes in this reader.
 
std::size_t position () const noexcept
 Return the number of bytes consumed by this reader.
 
std::size_t byte_offset () const noexcept
 Return the current byte offset in the outermost input.
 
std::size_t remaining () const noexcept
 Return the number of unconsumed bytes.
 
std::span< const std::byte > remaining_bytes () const noexcept
 Return all currently unconsumed bytes.
 
std::uint8_t read_u8 ()
 Read an unsigned eight-bit integer.
 
std::uint16_t read_u16 ()
 Read an unsigned little-endian 16-bit integer.
 
std::uint32_t read_u32 ()
 Read an unsigned little-endian 32-bit integer.
 
std::uint64_t read_u64 ()
 Read an unsigned little-endian 64-bit integer.
 
std::int8_t read_i8 ()
 Read a signed eight-bit integer.
 
std::int16_t read_i16 ()
 Read a signed little-endian 16-bit integer.
 
std::int32_t read_i32 ()
 Read a signed little-endian 32-bit integer.
 
std::int64_t read_i64 ()
 Read a signed little-endian 64-bit integer.
 
std::size_t read_size ()
 Read an unsigned 64-bit size and convert it to size_t.
 
std::span< const std::byte > read_bytes (std::size_t count)
 Read exactly count uninterpreted bytes.
 
BinaryReader read_subreader (std::size_t count)
 Read a bounded region as an independent child reader.
 
void skip (std::size_t count)
 Advance by exactly count bytes.
 
void require_zero_padding (std::size_t maximum)
 Consume at most maximum trailing zero-padding bytes.
 

Detailed Description

Bounds-checked reader for canonical little-endian binary data.

The reader does not own its input. Copies have independent cursors, which allows a compound deserializer to parse into a temporary reader and assign it back only after validation succeeds.

Member Function Documentation

◆ read_bytes()

std::span< const std::byte > pixie::BinaryReader::read_bytes ( std::size_t count)
inline

Read exactly count uninterpreted bytes.

Exceptions
SerializationErrorif the input is truncated.

◆ read_size()

std::size_t pixie::BinaryReader::read_size ( )
inline

Read an unsigned 64-bit size and convert it to size_t.

Exceptions
std::length_errorif the value is not representable.

◆ read_subreader()

BinaryReader pixie::BinaryReader::read_subreader ( std::size_t count)
inline

Read a bounded region as an independent child reader.

Exceptions
SerializationErrorif the input is truncated.

◆ require_zero_padding()

void pixie::BinaryReader::require_zero_padding ( std::size_t maximum)
inline

Consume at most maximum trailing zero-padding bytes.

Exceptions
SerializationErrorfor excessive or non-zero trailing bytes.

◆ skip()

void pixie::BinaryReader::skip ( std::size_t count)
inline

Advance by exactly count bytes.

Exceptions
SerializationErrorif the input is truncated.

The documentation for this class was generated from the following file: