Struct Decoder

Source
pub struct Decoder<'de> { /* private fields */ }
Available on crate feature 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>

Source

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.

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<Decoder<'de>, Error>

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

See child.

Source

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.

Source

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

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 FixedBytes<32>, Error>

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

Source

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

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

Source

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.

Source

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

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

Source

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

Take a word from the buffer, advancing the offset.

Source

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.

Source

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

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

Source

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.

Source

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

Takes a slice of bytes of the given length.

Source

pub fn take_offset_from(&mut self, child: &Decoder<'de>)

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>(&mut self) -> Result<T, Error>
where T: Token<'de>,

Decodes a single token from the underlying buffer.

Source

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

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<(), Error>

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

impl Display for Decoder<'_>

Source§

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

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 u8)

🔬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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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§

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

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