alloy_sol_types::abi

Struct Decoder

Source
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>

Source

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.

Source

pub const fn offset(&self) -> usize

Returns the current offset in the buffer.

Source

pub const fn remaining(&self) -> Option<usize>

Returns the number of bytes in the remaining buffer.

Source

pub const fn remaining_words(&self) -> usize

Returns the number of words in the remaining buffer.

Source

pub fn remaining_buf(&self) -> Option<&'de [u8]>

Returns a reference to the remaining bytes in the buffer.

Source

pub const fn is_empty(&self) -> bool

Returns whether the remaining buffer is empty.

Source

pub const fn validate(&self) -> bool

Returns true if this decoder is validating type correctness.

Source

pub fn set_validate(&mut self, validate: bool)

Set whether to validate type correctness.

Source

pub fn raw_child(&self) -> Result<Self>

Create a child decoder, starting at offset bytes from the current decoder’s offset.

See child.

Source

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.

Source

pub fn peek<I: SliceIndex<[u8]>>( &self, index: I, ) -> Result<&'de I::Output, Error>

Peek into the buffer.

Source

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.

Source

pub fn peek_len(&self, len: usize) -> Result<&'de [u8], Error>

Peek a slice of size len from the buffer without advancing the offset.

Source

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.

Source

pub fn peek_word(&self) -> Result<&'de Word, Error>

Peek the next word from the buffer without advancing the offset.

Source

pub fn peek_offset_at(&self, offset: usize) -> Result<usize>

Peek a usize from the buffer at a specific offset, without advancing the offset.

Source

pub fn peek_offset(&self) -> Result<usize>

Peek a usize from the buffer, without advancing the offset.

Source

pub fn take_word(&mut self) -> Result<&'de Word, Error>

Take a word from the buffer, advancing the offset.

Source

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.

Source

pub fn take_offset(&mut self) -> Result<usize>

Takes a usize offset from the buffer by consuming a word.

Source

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.

Source

pub fn take_slice_unchecked(&mut self, len: usize) -> Result<&'de [u8]>

Takes a slice of bytes of the given length.

Source

pub fn take_offset_from(&mut self, child: &Self)

Takes the offset from the child decoder and sets it as the current offset.

Source

pub fn set_offset(&mut self, offset: usize)

Sets the current offset in the buffer.

Source

pub fn decode<T: Token<'de>>(&mut self) -> Result<T>

Decodes a single token from the underlying buffer.

Source

pub fn decode_sequence<T: Token<'de> + TokenSeq<'de>>(&mut self) -> Result<T>

Decodes a sequence of tokens from the underlying buffer.

Trait Implementations§

Source§

impl<'de> Clone for Decoder<'de>

Source§

fn clone(&self) -> Decoder<'de>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Decoder<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Decoder<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V