Skip to main content

encode_frame

Function encode_frame 

pub fn encode_frame<T: Serialize>(
    message: &T,
    max_frame_len: u32,
) -> Result<Vec<u8>, FramingError>
Expand description

Encode a message into a single length-prefixed CBOR frame.

§Arguments

  • message - The value to serialize into a frame.
  • max_frame_len - Largest body, in bytes, to emit (the negotiated send limit).

§Returns

The framed bytes: a big-endian u32 body length followed by the CBOR body.

§Errors

Returns FramingError::FrameTooLarge if the serialized body would exceed max_frame_len, or FramingError::Encode for any other serialization failure.