Skip to main content

parse_server_frame

Function parse_server_frame 

Source
pub fn parse_server_frame(
    buf: &[u8],
    max_payload: usize,
) -> Result<Option<(ServerFrame, usize)>, ServerFrameError>
Expand description

Try to decode one broker frame from the front of buf.

Ok(None) means “only part of a frame has arrived” — read more and try again — and is the normal case on a stream. Ok(Some((frame, consumed))) gives the number of bytes to remove from the front, which for a MSG includes its byte-counted payload and the CRLF after it.

A bare LF is accepted as well as CRLF, so a hand-rolled broker (or nc on the other end of a test) behaves rather than producing an error on every line.