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

Complete frame with header and payload. More...

#include <frame.hpp>

Collaboration diagram for frame:
Collaboration graph

Public Member Functions

 frame (message_type type, std::uint32_t sequence, std::vector< std::byte > payload, compression_type compression=compression_type::none)
 
 frame (message_type type, std::uint32_t sequence, std::uint32_t correlation_id, std::vector< std::byte > payload, compression_type compression=compression_type::none)
 
std::uint32_t correlation_id () const
 Get the correlation ID for request/response matching.
 
const frame_headerheader () const
 Get the frame header.
 
const std::vector< std::byte > & payload () const
 Get the raw payload (compressed if compression is enabled).
 
compression_type compression () const
 Get the compression type used for the payload.
 
std::expected< std::vector< std::byte >, error_code > decompressed_payload () const
 Decompress and return the payload.
 
std::vector< std::byte > serialize () const
 Serialize frame to bytes.
 
std::expected< void, error_code > validate () const
 Validate frame integrity.
 

Static Public Member Functions

static std::expected< frame_header, error_code > deserialize_header (std::span< const std::byte > data, bool skip_version_check=false)
 Deserialize and validate header from bytes.
 
static std::expected< frame, error_code > deserialize (const frame_header &header, std::span< const std::byte > data)
 Deserialize complete frame using a pre-parsed header.
 

Detailed Description

Complete frame with header and payload.

Member Function Documentation

◆ decompressed_payload()

std::expected< std::vector< std::byte >, error_code > decompressed_payload ( ) const

Decompress and return the payload.

If no compression was used, returns a copy of the raw payload.

Returns
The decompressed payload, or error_code on failure
Here is the caller graph for this function:

◆ serialize()

std::vector< std::byte > serialize ( ) const

Serialize frame to bytes.

Calculates CRC32 over header (excluding CRC field) and payload, then serializes to network byte order.

Here is the caller graph for this function:

◆ deserialize_header()

std::expected< frame_header, error_code > deserialize_header ( std::span< const std::byte >  data,
bool  skip_version_check = false 
)
static

Deserialize and validate header from bytes.

Validates magic number, version, message type, reserved fields, and payload size. Does NOT validate CRC as that requires the full frame. Returns the validated header which can be used to determine how much payload to read.

Parameters
dataThe data buffer containing the header
skip_version_checkIf true, skips protocol version validation. This is useful during handshake to allow the server to send a proper version mismatch response instead of rejecting the frame immediately.
Here is the caller graph for this function:

◆ deserialize()

std::expected< frame, error_code > deserialize ( const frame_header header,
std::span< const std::byte >  data 
)
static

Deserialize complete frame using a pre-parsed header.

Takes the header from deserialize_header() and the complete buffer (header + payload). Validates CRC32 checksum over the entire frame. Returns error if validation fails.

Here is the caller graph for this function:

◆ validate()

std::expected< void, error_code > validate ( ) const

Validate frame integrity.

Checks magic number, version compatibility, and CRC.