Skip to main content

decode_frame

Function decode_frame 

Source
pub fn decode_frame<T>(frame: &[u8]) -> Result<T, ProtocolError>
Expand description

Decode a length-prefixed protocol frame into a value.

The input must contain a complete frame:

  • 4-byte big-endian payload length (u32)
  • exactly that many payload bytes

Extra trailing bytes after the declared payload are ignored by this helper. A streaming decoder can later handle multi-frame buffers more precisely.

§Returns

Ok(impl: DeserializeOwned) decoded frame on success.

§Errors

Returns an error if:

  • the header is missing or malformed,
  • the payload is truncated,
  • the decoded frame length cannot be represented as usize,
  • or JSON deserialization fails.