Function framed::decode_to_slice [] [src]

pub fn decode_to_slice(e: &Encoded, dest: &mut [u8]) -> Result<usize>

Decode the supplied encoded frame, placing the payload at the beginning of the supplied buffer dest.

When reading from a stream, the caller can continue reading data and buffering it until a FRAME_END_SYMBOL is read, then pass the whole buffer including FRAME_END_SYMBOL to this function for decoding.

If there is more than 1 FRAME_END_SYMBOL within e, the result is undefined. Make sure you only pass 1 frame at a time.

Returns the length of the payload it has decoded.

Errors

Returns Err(Error::EofDuringFrame if e is not a complete encoded frame, which should have FRAME_END_SYMBOL as the last byte.

Panics

This function will panic if dest is not large enough for the decoded frame. Ensure dest.len() >= max_decoded_len(e.len())?.