MC Protocol Serial C++ 0.2.3
MC protocol serial library for MCU-oriented environments
Loading...
Searching...
No Matches
mcprotocol::serial::FrameCodec Class Reference

Frame-level encode/decode helper for complete serial MC frames. More...

#include <codec.hpp>

Static Public Member Functions

static Status validate_config (const ProtocolConfig &config) noexcept
 Validates a static protocol configuration before encoding requests.
 
static Status encode_request (const ProtocolConfig &config, std::span< const std::uint8_t > request_data, std::span< std::uint8_t > out_frame, std::size_t &out_size) noexcept
 Wraps command data in the configured serial frame format.
 
static Status encode_success_response (const ProtocolConfig &config, std::span< const std::uint8_t > response_data, std::span< std::uint8_t > out_frame, std::size_t &out_size) noexcept
 Builds a success response frame for tests and local tools.
 
static Status encode_error_response (const ProtocolConfig &config, std::uint16_t error_code, std::span< std::uint8_t > out_frame, std::size_t &out_size) noexcept
 Builds a PLC-error response frame for tests and local tools.
 
static DecodeResult decode_response (const ProtocolConfig &config, std::span< const std::uint8_t > bytes) noexcept
 Decodes one response frame from the front of bytes.
 

Detailed Description

Frame-level encode/decode helper for complete serial MC frames.

Use this class when you already have a command payload and only need the outer serial frame layer, or when you need to decode a stream of returned bytes before passing the payload to a command-specific parser.

Definition at line 80 of file codec.hpp.

Member Function Documentation

◆ decode_response()

static DecodeResult mcprotocol::serial::FrameCodec::decode_response ( const ProtocolConfig config,
std::span< const std::uint8_t bytes 
)
staticnoexcept

Decodes one response frame from the front of bytes.

The caller can use bytes_consumed to drop the decoded prefix and continue stream processing.

◆ encode_error_response()

static Status mcprotocol::serial::FrameCodec::encode_error_response ( const ProtocolConfig config,
std::uint16_t  error_code,
std::span< std::uint8_t out_frame,
std::size_t out_size 
)
staticnoexcept

Builds a PLC-error response frame for tests and local tools.

◆ encode_request()

static Status mcprotocol::serial::FrameCodec::encode_request ( const ProtocolConfig config,
std::span< const std::uint8_t request_data,
std::span< std::uint8_t out_frame,
std::size_t out_size 
)
staticnoexcept

Wraps command data in the configured serial frame format.

request_data must already contain the command payload generated by CommandCodec.

◆ encode_success_response()

static Status mcprotocol::serial::FrameCodec::encode_success_response ( const ProtocolConfig config,
std::span< const std::uint8_t response_data,
std::span< std::uint8_t out_frame,
std::size_t out_size 
)
staticnoexcept

Builds a success response frame for tests and local tools.

This is mainly used by tests and local validation helpers. Library users typically decode real target responses instead of constructing synthetic ones.

◆ validate_config()

static Status mcprotocol::serial::FrameCodec::validate_config ( const ProtocolConfig config)
staticnoexcept

Validates a static protocol configuration before encoding requests.

This checks frame-family / code-mode compatibility, route constraints, and combinations that are compiled out by feature macros.


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