Struct Decoder

Source
pub struct Decoder<B: Buffer> { /* private fields */ }
Expand description

Decoder for sml transport v1.

§Examples

let bytes = [0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01, 0x12, 0x34, 0x56, 0x78, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x00, 0xb8, 0x7b];
let expected = [0x12, 0x34, 0x56, 0x78];

let mut decoder = Decoder::<ArrayBuf<20>>::new();
for b in bytes {
    match decoder.push_byte(b) {
        Ok(None) => {},  // nothing to output currently
        Ok(Some(decoded)) => {  // complete and valid message was decoded
            assert_eq!(decoded, expected);
        }
        Err(e) => {
            panic!("Unexpected Error: {:?}", e);
        }
    }
}
assert_eq!(decoder.finalize(), None)

Implementations§

Source§

impl<B: Buffer> Decoder<B>

Source

pub fn new() -> Self

Constructs a new decoder.

Source

pub fn from_buf(buf: B) -> Self

Constructs a new decoder using an existing buffer buf.

Source

pub fn push_byte(&mut self, b: u8) -> Result<Option<&[u8]>, DecodeErr>

Pushes a byte b into the decoder, advances the parser state and possibly returns a transmission or an decoder error.

Source

pub fn finalize(&mut self) -> Option<DecodeErr>

Resets the Decoder and returns an error if it contained an incomplete message.

Source

pub fn reset(&mut self) -> usize

Resets the Decoder and returns the number of bytes that were discarded

Trait Implementations§

Source§

impl<B: Buffer> Default for Decoder<B>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<B> Freeze for Decoder<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Decoder<B>
where B: RefUnwindSafe,

§

impl<B> Send for Decoder<B>
where B: Send,

§

impl<B> Sync for Decoder<B>
where B: Sync,

§

impl<B> Unpin for Decoder<B>
where B: Unpin,

§

impl<B> UnwindSafe for Decoder<B>
where B: UnwindSafe,

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.