Skip to main content

encode_frame

Function encode_frame 

Source
pub fn encode_frame(
    session_id: u32,
    channel_id: u16,
    seq: u8,
    frame_type: FrameType,
    payload: &[u8],
) -> Result<Vec<u8>, FrameError>
Expand description

Serializes and encodes a protocol frame with the 13-byte binary header, 1-byte header checksum (HdrChk), and trailing CRC-32 checksum.

Layout: [Sync (2B)] + [Session (4B)] + [Channel (2B)] + [Seq (1B)] + [Type (1B)] + [Len (2B)] + [HdrChk (1B)] + [Payload (L B)] + [CRC-32 (4B)]

ยงErrors

Returns FrameError::PayloadTooLarge if payload.len() > MAX_PAYLOAD_SIZE.