pub struct Decoder<'a> { /* private fields */ }Expand description
Parser for decoding values from a byte stream.
Decoder provides a cursor-based API for deserializing values encoded
by Encoder. All integers are decoded from little-endian format.
§Example
ⓘ
let mut dec = Decoder::new(&bytes);
let num = dec.read_u64()?;
let text = dec.read_string()?;
let flag = dec.read_bool()?;
dec.finish()?; // Verify all bytes consumedImplementations§
Source§impl<'a> Decoder<'a>
impl<'a> Decoder<'a>
Sourcepub fn read_bool(&mut self) -> Result<bool>
pub fn read_bool(&mut self) -> Result<bool>
Reads a boolean value (0 = false, 1 = true).
Returns an error if the byte is neither 0 nor 1.
Sourcepub fn read_raw(&mut self, len: usize) -> Result<&'a [u8]>
pub fn read_raw(&mut self, len: usize) -> Result<&'a [u8]>
Reads exactly len raw bytes without a length prefix.
Sourcepub fn read_bytes(&mut self) -> Result<&'a [u8]>
pub fn read_bytes(&mut self) -> Result<&'a [u8]>
Reads a byte slice with a u32 length prefix.
Format: [length: u32][data: bytes]
Sourcepub fn read_string(&mut self) -> Result<String>
pub fn read_string(&mut self) -> Result<String>
Reads a UTF-8 string with a u32 length prefix.
Returns an error if the bytes are not valid UTF-8.
Sourcepub fn read_codec<T: BytesCodec>(&mut self) -> Result<T>
pub fn read_codec<T: BytesCodec>(&mut self) -> Result<T>
Reads a value that implements BytesCodec with a length prefix.
Auto Trait Implementations§
impl<'a> Freeze for Decoder<'a>
impl<'a> RefUnwindSafe for Decoder<'a>
impl<'a> Send for Decoder<'a>
impl<'a> Sync for Decoder<'a>
impl<'a> Unpin for Decoder<'a>
impl<'a> UnsafeUnpin for Decoder<'a>
impl<'a> UnwindSafe for Decoder<'a>
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