|
intnslib 0.1
A library to hold common functionality used across multiple projects.
|
A memory-based binary reader with configurable endianness. More...
#include <BinaryReader.hpp>
Public Member Functions | |
| MemoryReader (const std::vector< uint8_t > &buffer, size_t position=0) | |
| Constructs a MemoryReader from a vector buffer. | |
| MemoryReader (std::span< const uint8_t > buffer, size_t position=0) | |
| Constructs a MemoryReader from a span buffer. | |
| size_t | size () const noexcept |
| Returns the total size of the buffer. | |
| size_t | position () const noexcept |
| Returns the current read position. | |
| size_t | remaining () const noexcept |
| Returns the number of bytes remaining to be read. | |
| void | set_position (size_t pos) noexcept |
| Sets the read position within the buffer. | |
| void | skip (size_t bytes) noexcept |
| Advances the read position by the specified number of bytes. | |
| uint8_t | read_u8 () |
| Reads an unsigned 8-bit integer. | |
| uint16_t | read_u16 () |
| Reads an unsigned 16-bit integer with endianness conversion. | |
| uint32_t | read_u32 () |
| Reads an unsigned 32-bit integer with endianness conversion. | |
| uint64_t | read_u64 () |
| Reads an unsigned 64-bit integer with endianness conversion. | |
| int8_t | read_s8 () |
| Reads a signed 8-bit integer. | |
| int16_t | read_s16 () |
| Reads a signed 16-bit integer with endianness conversion. | |
| int32_t | read_s32 () |
| Reads a signed 32-bit integer with endianness conversion. | |
| int64_t | read_s64 () |
| Reads a signed 64-bit integer with endianness conversion. | |
| float | read_f32 () |
| Reads a 32-bit floating-point value with endianness conversion. | |
| double | read_f64 () |
| Reads a 64-bit floating-point value with endianness conversion. | |
| void | read_bytes (void *dest, size_t bytes) |
| Reads raw bytes into a destination buffer. | |
| void | read_u16_array (uint16_t *array, size_t count) |
| Reads an array of unsigned 16-bit integers with endianness conversion. | |
| void | read_u32_array (uint32_t *array, size_t count) |
| Reads an array of unsigned 32-bit integers with endianness conversion. | |
| std::string | read_string (size_t length) |
| Reads a fixed-length string from the buffer. | |
| std::string | read_cstring () |
| Reads a null-terminated C-style string from the buffer. | |
| uint8_t | peek_u8 () const |
| Peeks at an unsigned 8-bit integer without advancing position. | |
| uint16_t | peek_u16 () const |
| Peeks at an unsigned 16-bit integer without advancing position. | |
A memory-based binary reader with configurable endianness.
MemoryReader provides efficient reading of binary data from memory buffers with automatic endianness conversion. It supports reading primitive types, arrays, and strings from a contiguous memory region.
| E | The endianness for data interpretation (default: little endian). |
Construct with a buffer and read data sequentially:
All read operations throw std::out_of_range if attempting to read beyond the buffer boundary. Position manipulation methods provide the no-throw guarantee.
|
inlineexplicit |
Constructs a MemoryReader from a vector buffer.
| buffer | The source buffer to read from. |
| position | Initial read position (default: 0). |
| std::out_of_range | If position is beyond buffer size. |
|
inlineexplicit |
Constructs a MemoryReader from a span buffer.
| buffer | The source buffer to read from. |
| position | Initial read position (default: 0). |
| std::out_of_range | If position is beyond buffer size. |
|
inline |
Peeks at an unsigned 16-bit integer without advancing position.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Peeks at an unsigned 8-bit integer without advancing position.
| std::out_of_range | If the position is at or beyond the buffer end. |
|
inlinenoexcept |
Returns the current read position.
|
inline |
Reads raw bytes into a destination buffer.
| dest | Pointer to the destination buffer. |
| bytes | Number of bytes to read. |
| std::invalid_argument | If dest is nullptr. |
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads a null-terminated C-style string from the buffer.
Reads until a null terminator is found or the end of buffer is reached. If no null terminator is found, reads all remaining bytes.
|
inline |
Reads a 32-bit floating-point value with endianness conversion.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads a 64-bit floating-point value with endianness conversion.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads a signed 16-bit integer with endianness conversion.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads a signed 32-bit integer with endianness conversion.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads a signed 64-bit integer with endianness conversion.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads a signed 8-bit integer.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads a fixed-length string from the buffer.
| length | Number of bytes to read. |
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads an unsigned 16-bit integer with endianness conversion.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads an array of unsigned 16-bit integers with endianness conversion.
| array | Pointer to the destination array. |
| count | Number of elements to read. |
| std::invalid_argument | If array is nullptr. |
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads an unsigned 32-bit integer with endianness conversion.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads an array of unsigned 32-bit integers with endianness conversion.
| array | Pointer to the destination array. |
| count | Number of elements to read. |
| std::invalid_argument | If array is nullptr. |
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads an unsigned 64-bit integer with endianness conversion.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inline |
Reads an unsigned 8-bit integer.
| std::out_of_range | If insufficient bytes remain in the buffer. |
|
inlinenoexcept |
Returns the number of bytes remaining to be read.
|
inlinenoexcept |
Sets the read position within the buffer.
If the specified position exceeds the buffer size, it is clamped to the buffer size.
| pos | The new position to set. |
|
inlinenoexcept |
Returns the total size of the buffer.
|
inlinenoexcept |
Advances the read position by the specified number of bytes.
If skipping would move beyond the buffer end, the position is set to the buffer end.
| bytes | The number of bytes to skip. |