pub struct Decoder<U: UPrim> { /* private fields */ }Expand description
An incremental varint decoder for reading varints byte-by-byte from streams.
This is useful when reading from async streams where you receive one byte at a time and need to know when the varint is complete while also building up the decoded value.
§Example
use commonware_codec::varint::Decoder;
let mut decoder = Decoder::<u32>::new();
// Feed bytes one at a time (e.g., from a stream)
// 300 encodes as [0xAC, 0x02]
assert_eq!(decoder.feed(0xAC).unwrap(), None); // continuation bit set, need more
assert_eq!(decoder.feed(0x02).unwrap(), Some(300)); // complete!Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<U> Freeze for Decoder<U>where
U: Freeze,
impl<U> RefUnwindSafe for Decoder<U>where
U: RefUnwindSafe,
impl<U> Send for Decoder<U>where
U: Send,
impl<U> Sync for Decoder<U>where
U: Sync,
impl<U> Unpin for Decoder<U>where
U: Unpin,
impl<U> UnwindSafe for Decoder<U>where
U: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)