Skip to main content

Framer

Trait Framer 

Source
pub trait Framer {
    // Required methods
    fn encode(&self, frame: &[u8], out: &mut Vec<u8>) -> Result<(), FrameFault>;
    fn push_bytes(&mut self, bytes: &[u8]);
    fn next_frame(&mut self) -> Option<Result<Vec<u8>, FrameFault>>;
}
Expand description

Frames a byte stream: COBS, length-prefix, NDJSON.

Required Methods§

Source

fn encode(&self, frame: &[u8], out: &mut Vec<u8>) -> Result<(), FrameFault>

Encode one logical frame, appending its wire bytes to out.

On Err nothing is appended, so a rejected frame never reaches the wire half-written.

Source

fn push_bytes(&mut self, bytes: &[u8])

Feed received bytes into the accumulator.

Source

fn next_frame(&mut self) -> Option<Result<Vec<u8>, FrameFault>>

Pull the next complete frame: Some(Ok(frame)), Some(Err(fault)) (see FrameFault), or None when more bytes are needed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§