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>, DecodeError>
pub fn feed(&mut self, data: u8) -> Result<Option<usize>, DecodeError>
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(DecodeError) - Message decoding failed
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<DecodeReport>, DecodeError>
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