pub struct Decoder<'de> { /* private fields */ }dyn-abi only.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) -> Decoder<'de>
pub const fn new(buf: &'de [u8], validate: bool) -> Decoder<'de>
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<Decoder<'de>, Error>
pub fn raw_child(&self) -> Result<Decoder<'de>, Error>
Create a child decoder, starting at offset bytes from the current
decoder’s offset.
See child.
Sourcepub fn child(&self, offset: usize) -> Result<Decoder<'de>, Error>
pub fn child(&self, offset: usize) -> Result<Decoder<'de>, 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>(
&self,
index: I,
) -> Result<&'de <I as SliceIndex<[u8]>>::Output, Error>where
I: SliceIndex<[u8]>,
pub fn peek<I>(
&self,
index: I,
) -> Result<&'de <I as SliceIndex<[u8]>>::Output, Error>where
I: SliceIndex<[u8]>,
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 FixedBytes<32>, Error>
pub fn peek_word_at(&self, offset: usize) -> Result<&'de FixedBytes<32>, Error>
Peek a word from the buffer at a specific offset, without advancing the offset.
Sourcepub fn peek_word(&self) -> Result<&'de FixedBytes<32>, Error>
pub fn peek_word(&self) -> Result<&'de FixedBytes<32>, Error>
Peek the next word from the buffer without advancing the offset.
Sourcepub fn peek_offset_at(&self, offset: usize) -> Result<usize, Error>
pub fn peek_offset_at(&self, offset: usize) -> Result<usize, Error>
Peek a usize from the buffer at a specific offset, without advancing
the offset.
Sourcepub fn peek_offset(&self) -> Result<usize, Error>
pub fn peek_offset(&self) -> Result<usize, Error>
Peek a usize from the buffer, without advancing the offset.
Sourcepub fn take_word(&mut self) -> Result<&'de FixedBytes<32>, Error>
pub fn take_word(&mut self) -> Result<&'de FixedBytes<32>, Error>
Take a word from the buffer, advancing the offset.
Sourcepub fn take_indirection(&mut self) -> Result<Decoder<'de>, Error>
pub fn take_indirection(&mut self) -> Result<Decoder<'de>, 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, Error>
pub fn take_offset(&mut self) -> Result<usize, Error>
Takes a usize offset from the buffer by consuming a word.
Sourcepub fn take_slice(&mut self, len: usize) -> Result<&'de [u8], Error>
pub fn take_slice(&mut self, len: usize) -> Result<&'de [u8], Error>
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], Error>
pub fn take_slice_unchecked(&mut self, len: usize) -> Result<&'de [u8], Error>
Takes a slice of bytes of the given length.
Sourcepub fn take_offset_from(&mut self, child: &Decoder<'de>)
pub fn take_offset_from(&mut self, child: &Decoder<'de>)
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.
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§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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