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>

source

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

source

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

source

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§

source§

impl<'a> Debug for CobsDecoder<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.