pub struct Decoder<'de> { /* private fields */ }Expand description
The Decoder wraps a byte slice with necessary info to progressively
deserialize the bytes into a sequence of tokens.
§Usage Note
While the Decoder contains the necessary info, the actual deserialization
is done in the crate::SolType trait.
Implementations§
Source§impl<'de> Decoder<'de>
impl<'de> Decoder<'de>
Sourcepub const fn new(buf: &'de [u8]) -> Self
pub const fn new(buf: &'de [u8]) -> Self
Instantiate a new decoder from a byte slice and a validation flag.
Sourcepub const fn remaining(&self) -> Option<usize>
pub const fn remaining(&self) -> Option<usize>
Returns the number of bytes in the remaining buffer.
Sourcepub const fn remaining_words(&self) -> usize
pub const fn remaining_words(&self) -> usize
Returns the number of words in the remaining buffer.
Sourcepub fn remaining_buf(&self) -> Option<&'de [u8]>
pub fn remaining_buf(&self) -> Option<&'de [u8]>
Returns a reference to the remaining bytes in the buffer.
Sourcepub fn raw_child(&self) -> Result<Self>
pub fn raw_child(&self) -> Result<Self>
Create a child decoder, starting at offset bytes from the current
decoder’s offset.
See child.
Sourcepub fn child(&self, offset: usize) -> Result<Self, Error>
pub fn child(&self, offset: usize) -> Result<Self, Error>
Create a child decoder, starting at offset bytes from the current
decoder’s offset.
The child decoder shares the buffer.
Sourcepub fn peek<I: SliceIndex<[u8]>>(
&self,
index: I,
) -> Result<&'de I::Output, Error>
pub fn peek<I: SliceIndex<[u8]>>( &self, index: I, ) -> Result<&'de I::Output, Error>
Peek into the buffer.
Sourcepub fn peek_len_at(&self, offset: usize, len: usize) -> Result<&'de [u8], Error>
pub fn peek_len_at(&self, offset: usize, len: usize) -> Result<&'de [u8], Error>
Peek a slice of size len from the buffer at a specific offset, without
advancing the offset.
Sourcepub fn peek_len(&self, len: usize) -> Result<&'de [u8], Error>
pub fn peek_len(&self, len: usize) -> Result<&'de [u8], Error>
Peek a slice of size len from the buffer without advancing the offset.
Sourcepub fn peek_word_at(&self, offset: usize) -> Result<&'de Word, Error>
pub fn peek_word_at(&self, offset: usize) -> Result<&'de Word, Error>
Peek a word from the buffer at a specific offset, without advancing the offset.
Sourcepub fn peek_word(&self) -> Result<&'de Word, Error>
pub fn peek_word(&self) -> Result<&'de Word, Error>
Peek the next word from the buffer without advancing the offset.
Sourcepub fn peek_offset_at(&self, offset: usize) -> Result<usize>
pub fn peek_offset_at(&self, offset: usize) -> Result<usize>
Peek a usize from the buffer at a specific offset, without advancing
the offset.
Sourcepub fn peek_offset(&self) -> Result<usize>
pub fn peek_offset(&self) -> Result<usize>
Peek a usize from the buffer, without advancing the offset.
Sourcepub fn take_word(&mut self) -> Result<&'de Word, Error>
pub fn take_word(&mut self) -> Result<&'de Word, Error>
Take a word from the buffer, advancing the offset.
Sourcepub fn take_indirection(&mut self) -> Result<Self, Error>
pub fn take_indirection(&mut self) -> Result<Self, Error>
Return a child decoder by consuming a word, interpreting it as a pointer, and following it.
Sourcepub fn take_offset(&mut self) -> Result<usize>
pub fn take_offset(&mut self) -> Result<usize>
Takes a usize offset from the buffer by consuming a word.
Sourcepub fn take_slice(&mut self, len: usize) -> Result<&'de [u8]>
pub fn take_slice(&mut self, len: usize) -> Result<&'de [u8]>
Takes a slice of bytes of the given length.
Sourcepub const fn take_offset_from(&mut self, child: &Self)
pub const fn take_offset_from(&mut self, child: &Self)
Takes the offset from the child decoder and sets it as the current offset.
Sourcepub const fn set_offset(&mut self, offset: usize)
pub const fn set_offset(&mut self, offset: usize)
Sets the current offset in the buffer.
Sourcepub fn decode<T: Token<'de>>(&mut self) -> Result<T>
pub fn decode<T: Token<'de>>(&mut self) -> Result<T>
Decodes a single token from the underlying buffer.
Sourcepub fn decode_sequence<T: Token<'de> + TokenSeq<'de>>(&mut self) -> Result<T>
pub fn decode_sequence<T: Token<'de> + TokenSeq<'de>>(&mut self) -> Result<T>
Decodes a sequence of tokens from the underlying buffer.
Trait Implementations§
impl<'de> Copy for Decoder<'de>
Auto Trait Implementations§
impl<'de> Freeze for Decoder<'de>
impl<'de> RefUnwindSafe for Decoder<'de>
impl<'de> Send for Decoder<'de>
impl<'de> Sync for Decoder<'de>
impl<'de> Unpin for Decoder<'de>
impl<'de> UnwindSafe for Decoder<'de>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes