Struct cobs::CobsDecoder
source · pub struct CobsDecoder<'a> { /* private fields */ }
Expand description
The CobsDecoder
type is used to decode a stream of bytes to a
given mutable output slice. This is often useful when heap data
structures are not available, or when not all message bytes are
received at a single point in time.
Implementations§
source§impl<'a> CobsDecoder<'a>
impl<'a> CobsDecoder<'a>
sourcepub fn new(dest: &'a mut [u8]) -> CobsDecoder<'a>
pub fn new(dest: &'a mut [u8]) -> CobsDecoder<'a>
Create a new streaming Cobs Decoder. Provide the output buffer for the decoded message to be placed in
sourcepub fn feed(&mut self, data: u8) -> Result<Option<usize>, usize>
pub fn feed(&mut self, data: u8) -> Result<Option<usize>, usize>
Push a single byte into the streaming CobsDecoder. Return values mean:
- Ok(None) - State machine okay, more data needed
- Ok(Some(N)) - A message of N bytes was successfully decoded
- Err(M) - Message decoding failed, and M bytes were written to output
NOTE: Sentinel value must be included in the input to this function for the decoding to complete
sourcepub fn push(&mut self, data: &[u8]) -> Result<Option<(usize, usize)>, usize>
pub fn push(&mut self, data: &[u8]) -> Result<Option<(usize, usize)>, usize>
Push a slice of bytes into the streaming CobsDecoder. Return values mean:
- Ok(None) - State machine okay, more data needed
- Ok(Some((N, M))) - A message of N bytes was successfully decoded,
using M bytes from
data
(and earlier data) - Err(J) - Message decoding failed, and J bytes were written to output
NOTE: Sentinel value must be included in the input to this function for the decoding to complete
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for CobsDecoder<'a>
impl<'a> RefUnwindSafe for CobsDecoder<'a>
impl<'a> Send for CobsDecoder<'a>
impl<'a> Sync for CobsDecoder<'a>
impl<'a> Unpin for CobsDecoder<'a>
impl<'a> !UnwindSafe for CobsDecoder<'a>
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