Skip to main content

decode_frames_with_codec

Function decode_frames_with_codec 

Source
pub fn decode_frames_with_codec<F: FrameCodec>(
    codec: &F,
    bytes: Vec<u8>,
) -> Result<Vec<F::Frame>>
Expand description

Decode raw wire bytes into frames using codec.

The byte vector is fed into the codec’s decoder until no more complete frames can be extracted. After the main decode loop, decode_eof is called to flush any partial frame remaining in the buffer. If the buffer still contains unconsumed bytes after decode_eof returns None, an error is returned — this catches truncation bugs where the server emits incomplete trailing data. Decoder errors are preserved so callers can inspect any underlying structured codec errors through the io::Error source chain.

§Errors

Returns an error if the decoder encounters malformed data or if trailing bytes remain that do not form a complete frame.

use wireframe::codec::examples::HotlineFrameCodec;
use wireframe_testing::{decode_frames_with_codec, encode_payloads_with_codec};

let codec = HotlineFrameCodec::new(4096);
let wire: Vec<u8> = encode_payloads_with_codec(&codec, vec![vec![42]])
    .expect("encoding should succeed")
    .into_iter()
    .flatten()
    .collect();
let frames = decode_frames_with_codec(&codec, wire)
    .expect("decoding should succeed for well-formed wire bytes");
assert_eq!(frames.len(), 1);