Skip to main content

read_frame

Function read_frame 

Source
pub async fn read_frame<R: AsyncRead + Unpin>(
    r: &mut R,
    max: u32,
) -> Result<Vec<u8>, FrameError>
Expand description

Read one length-prefixed frame from an async reader.

The length prefix is validated against max before any payload allocation, so a peer cannot make the reader buffer more than max bytes. Pass the frame ceiling for the messages that can arrive at this read (ADR 013 § Wire Framing): a ceiling sized to the largest legitimate message keeps a stalled oversized frame from pinning memory.

§Errors

FrameError::TooLarge when the announced length exceeds max, FrameError::Varint for a malformed length prefix, and FrameError::Io when the stream fails or ends mid-frame.