pub struct FrameDecoder { /* private fields */ }Expand description
A streaming decoder that turns a byte stream of DELIMITER-framed data
into decoded packets, buffering across arbitrarily sized chunks.
This is the natural way to read COBS packets from a serial/UART link. Feed
raw bytes with push; the callback is invoked once per
completed frame.
use cobs_codec_rs::framing::{frame_to_vec, FrameDecoder};
let wire = frame_to_vec(&[0x11, 0x00, 0x22]);
let mut rx = FrameDecoder::new();
let mut packets = Vec::new();
// Feed one byte at a time to prove reassembly works across chunks.
for b in &wire {
rx.push(&[*b], |frame| packets.push(frame.unwrap()));
}
assert_eq!(packets, vec![vec![0x11, 0x00, 0x22]]);Implementations§
Source§impl FrameDecoder
impl FrameDecoder
Sourcepub fn skip_empty(self, skip_empty: bool) -> Self
pub fn skip_empty(self, skip_empty: bool) -> Self
Whether to skip empty frames (from consecutive or leading delimiters)
rather than emit empty packets. Defaults to true.
Sourcepub fn max_frame_len(self, max_frame_len: usize) -> Self
pub fn max_frame_len(self, max_frame_len: usize) -> Self
Bound the number of bytes buffered for a single unterminated frame. When
exceeded, the buffer is discarded and the callback receives
DecodeError::FrameTooLong. 0 (the default) means unbounded.
Trait Implementations§
Source§impl Clone for FrameDecoder
impl Clone for FrameDecoder
Source§fn clone(&self) -> FrameDecoder
fn clone(&self) -> FrameDecoder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FrameDecoder
impl Debug for FrameDecoder
Source§impl Default for FrameDecoder
impl Default for FrameDecoder
Source§fn default() -> FrameDecoder
fn default() -> FrameDecoder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for FrameDecoder
impl RefUnwindSafe for FrameDecoder
impl Send for FrameDecoder
impl Sync for FrameDecoder
impl Unpin for FrameDecoder
impl UnsafeUnpin for FrameDecoder
impl UnwindSafe for FrameDecoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more