Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<'de, 'state> { /* 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, 'static>

Source

pub const fn new(buf: &'de [u8]) -> Self

Instantiates a new decoder from a byte slice.

Source§

impl<'de, 'state> Decoder<'de, 'state>

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 fn raw_child<'child>(&'child self) -> Result<Decoder<'de, 'child>>

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

See child.

Source

pub fn child<'child>( &'child self, offset: usize, ) -> Result<Decoder<'de, 'child>, Error>

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

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<'child>( &'child mut self, ) -> Result<Decoder<'de, 'child>, 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.

Source

pub const 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 const fn offset_from_child(&self, child: &Decoder<'de, '_>) -> usize

Returns the parent-relative offset from a child decoder.

Source

pub const 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 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 Drop for Decoder<'_, '_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'de, 'state> !Freeze for Decoder<'de, 'state>

§

impl<'de, 'state> !RefUnwindSafe for Decoder<'de, 'state>

§

impl<'de, 'state> !Send for Decoder<'de, 'state>

§

impl<'de, 'state> !Sync for Decoder<'de, 'state>

§

impl<'de, 'state> !UnwindSafe for Decoder<'de, 'state>

§

impl<'de, 'state> Unpin for Decoder<'de, 'state>

§

impl<'de, 'state> UnsafeUnpin for Decoder<'de, 'state>

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> 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> Same for T

Source§

type Output = T

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

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

fn try_from(value: U) -> Result<T, !>

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: 88 bytes