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>
impl<B: Buffer> Decoder<B>
Sourcepub fn push_byte(&mut self, b: u8) -> Result<Option<&[u8]>, DecodeErr>
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.
Trait Implementations§
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> 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