ORE Studio 0.0.4
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
reader Class Reference

Helper class to read binary data in network byte order. More...

#include <reader.hpp>

Collaboration diagram for reader:
Collaboration graph

Static Public Member Functions

static std::expected< std::uint8_t, error_code > read_uint8 (std::span< const std::byte > &data)
 Read a single byte.
 
static std::expected< std::uint16_t, error_code > read_uint16 (std::span< const std::byte > &data)
 Read a 16-bit integer in network byte order.
 
static std::expected< std::uint32_t, error_code > read_uint32 (std::span< const std::byte > &data)
 Read a 32-bit integer in network byte order.
 
static std::expected< std::uint32_t, error_code > read_count (std::span< const std::byte > &data, std::uint32_t max_count=MAX_ELEMENT_COUNT)
 Read a 32-bit count with validation against maximum.
 
static std::expected< std::int64_t, error_code > read_int64 (std::span< const std::byte > &data)
 Read a signed 64-bit integer in network byte order.
 
static std::expected< std::uint64_t, error_code > read_uint64 (std::span< const std::byte > &data)
 Read an unsigned 64-bit integer in network byte order.
 
static std::expected< std::string, error_code > read_string (std::span< const std::byte > &data)
 Read a string with 16-bit length prefix.
 
static std::expected< std::string, error_code > read_string32 (std::span< const std::byte > &data)
 Read a string with 32-bit length prefix.
 
static std::expected< boost::uuids::uuid, error_code > read_uuid (std::span< const std::byte > &data)
 Read a UUID (16 bytes).
 
static std::expected< uuid::tenant_id, error_code > read_tenant_id (std::span< const std::byte > &data)
 Read a tenant_id (16 bytes UUID with validation).
 
static std::expected< bool, error_code > read_bool (std::span< const std::byte > &data)
 Read a boolean (1 byte).
 

Detailed Description

Helper class to read binary data in network byte order.

Provides static methods to deserialize various data types from a byte span. All multi-byte integers are read in big-endian (network) byte order. The span is advanced past the read data on success.

Member Function Documentation

◆ read_count()

std::expected< std::uint32_t, error_code > read_count ( std::span< const std::byte > &  data,
std::uint32_t  max_count = MAX_ELEMENT_COUNT 
)
static

Read a 32-bit count with validation against maximum.

Use this for reading collection sizes to prevent memory exhaustion from corrupted data. Returns limit_exceeded if count > max_count.

Parameters
dataThe byte span to read from (advanced on success).
max_countMaximum allowed count (default: MAX_ELEMENT_COUNT).
Returns
The count value, or error_code on failure.

◆ read_string()

std::expected< std::string, error_code > read_string ( std::span< const std::byte > &  data)
static

Read a string with 16-bit length prefix.

Note
Maximum string length is 65535 bytes. For larger strings, use read_string32.

◆ read_string32()

std::expected< std::string, error_code > read_string32 ( std::span< const std::byte > &  data)
static

Read a string with 32-bit length prefix.

Use this for strings that may exceed 65535 bytes (e.g., SVG data, large text).

◆ read_tenant_id()

std::expected< uuid::tenant_id, error_code > read_tenant_id ( std::span< const std::byte > &  data)
static

Read a tenant_id (16 bytes UUID with validation).

Reads a UUID and converts it to a tenant_id. Returns invalid_request error if the UUID is nil (which is rejected by tenant_id::from_uuid).