[go: up one dir, main page]

CobsDecoderHeapless

Struct CobsDecoderHeapless 

Source
pub struct CobsDecoderHeapless<const N: usize> { /* private fields */ }
Expand description

The CobsDecoderHeapless type is used to decode a stream of bytes to a given mutable output slice. It owns the heapless decoding buffer.

This structure uses a heapless vector as the decoding buffer to avoid lifetimes.

Implementations§

Source§

impl<const N: usize> CobsDecoderHeapless<N>

Source

pub fn new() -> Self

This constructor internally creates the heapless vector.

Source

pub fn new_with_vec(vec: Vec<u8, N>) -> Self

This constructor allows passing the heapless vector to use.

This can be useful to place the heapless vector into the static BSS section instead of the stack.

Source

pub fn feed(&mut self, data: u8) -> Result<Option<usize>, DecodeError>

Feed a single byte into the streaming decoder. Return values mean:

  • Ok(None) - State machine okay, more data needed
  • Ok(Some(N)) - A message of N bytes was successfully decoded
  • Err(DecodeError) - Message decoding failed

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<DecodeReport>, DecodeError>

Push a slice of bytes into the streaming CobsDecoder. Return values mean:

  • Ok(None) - State machine okay, more data needed
  • Ok(Some(DecodeReport))) - A message was successfully decoded. The parse size of the report specifies the consumed bytes of the passed data chunk.
  • Err(DecodeError) - Message decoding failed

If the decoder is used for continuous decoding, the user must take care of feeding any undecoded bytes of the input data back into the decoder. This can be done by Self::pushing the undecoded bytes (the last X bytes of the input with X being the length of the input minus the parsed length) into the decoder after a frame was decoded.

NOTE: Sentinel value must be included in the input to this function for the decoding to complete

Source

pub fn dest(&self) -> &[u8]

Destination buffer which contains decoded frames.

Source

pub fn dest_mut(&mut self) -> &mut [u8]

Destination buffer which contains decoded frames.

This allows using the buffer for other purposes than decoding after a frame was found. Changing the buffer in any other state might corrupt a frame which might currently be decoded.

Source

pub fn reset(&mut self)

Reset the decoding state machine.

Trait Implementations§

Source§

impl<const N: usize> Debug for CobsDecoderHeapless<N>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for CobsDecoderHeapless<N>

Source§

fn default() -> CobsDecoderHeapless<N>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for CobsDecoderHeapless<N>

§

impl<const N: usize> RefUnwindSafe for CobsDecoderHeapless<N>

§

impl<const N: usize> Send for CobsDecoderHeapless<N>

§

impl<const N: usize> Sync for CobsDecoderHeapless<N>

§

impl<const N: usize> Unpin for CobsDecoderHeapless<N>

§

impl<const N: usize> UnwindSafe for CobsDecoderHeapless<N>

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>,

Source§

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>,

Source§

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.