Skip to main content

try_read_frame

Function try_read_frame 

Source
pub fn try_read_frame(
    data: &[u8],
) -> Result<Option<(usize, usize)>, ProtocolError>
Expand description

Try to extract a single frame from the given buffer.

Returns Ok(Some((varint_size, frame_len))) if a complete frame is available, Ok(None) if more data is needed, or Err if the frame is malformed.

The frame body starts at offset varint_size and spans frame_len bytes. The total bytes consumed is varint_size + frame_len. This function does not copy or allocate — callers should use BytesMut::split_to() or equivalent zero-copy operations to extract the frame data.

§Errors

Returns ProtocolError::FrameTooLarge if the frame exceeds MAX_FRAME_SIZE. Returns ProtocolError::VarIntTooLong if the length prefix is malformed.