Struct Decoder
pub struct Decoder {
buf: [u8; 5],
len: u8,
state: DecoderState,
}Expand description
Incremental fixed-header decoder.
Feed bytes via Decoder::feed. Once it returns
DecodeState::Complete, read that many bytes from your transport and
pass them to Packet::decode. Then call
Decoder::reset (or create a new one) for the next packet.
Fields§
§buf: [u8; 5]Accumulator for the fixed header bytes (max 5: 1 type+flags + up to 4 VBI).
len: u8§state: DecoderStateImplementations§
§impl Decoder
impl Decoder
pub const fn new() -> Self
pub const fn new() -> Self
Creates a new decoder ready to parse the next packet.
pub const fn reset(&mut self)
pub const fn reset(&mut self)
Reset for decoding the next packet.
pub fn feed(&mut self, byte: u8) -> Result<DecodeState, DecodeError>
pub fn feed(&mut self, byte: u8) -> Result<DecodeState, DecodeError>
Feed one byte at a time and return the decode state.
Returns:
Ok(DecodeState::Incomplete)— need more bytesOk(DecodeState::Complete(header))— fixed header fully parsedErr(_)— malformed data
§Errors
Returns DecodeError on malformed input (invalid packet type,
VBI overflow, or feeding bytes after completion without reset).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Decoder
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnwindSafe for Decoder
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