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], validate: bool) -> Self
pub const fn new(buf: &'de [u8], validate: bool) -> Self
Instantiate a new decoder from a byte slice and a validation flag.
If validate
is true, the decoder will check that the bytes conform to
expected type limitations, and that the decoded values can be re-encoded
to an identical bytestring.
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 const fn validate(&self) -> bool
pub const fn validate(&self) -> bool
Returns true
if this decoder is validating type correctness.
Sourcepub fn set_validate(&mut self, validate: bool)
pub fn set_validate(&mut self, validate: bool)
Set whether to validate type correctness.
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 and validation flag.
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 by consuming up to the next word boundary.
Sourcepub fn take_slice_unchecked(&mut self, len: usize) -> Result<&'de [u8]>
pub fn take_slice_unchecked(&mut self, len: usize) -> Result<&'de [u8]>
Takes a slice of bytes of the given length.
Sourcepub fn take_offset_from(&mut self, child: &Self)
pub fn take_offset_from(&mut self, child: &Self)
Takes the offset from the child decoder and sets it as the current offset.
Sourcepub fn set_offset(&mut self, offset: usize)
pub 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,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)