Decoder

Struct Decoder 

Source
pub struct Decoder<'a> { /* private fields */ }
Expand description

A decoder for a twine blob.

Implementations§

Source§

impl<'a> Decoder<'a>

Source

pub fn new(bs: &'a [u8]) -> Result<Self>

Create a new decoder reading from these bytes.

Source

pub fn deref(&self, off: Offset) -> Result<Offset>

Dereference the offset.

If the value at this offset is a pointer, follow the pointer; repeat until it’s not. This is done implicitly by most other functions in this module, but it can be useful to do it by hand in case there is caching done on decoding (eg. to memoize the value decoded at a particular offset, it’s better to dereference the offset first).

Source

pub fn get_shallow_value(&self, off: Offset) -> Result<ShallowValue<'a>>

Read one value at the given offset.

This does not recurse into subvalues, so it is fairly fast. The main way of deserializing from twine is through this function. If the value at off is a pointer, it is implicitly followed. As a consequence, this never returns a Immediate::Pointer value.

Source

pub fn get_i64(&self, off: Offset) -> Result<i64>

Get an integer.

Source

pub fn get_bool(&self, off: Offset) -> Result<bool>

Source

pub fn get_null(&self, off: Offset) -> Result<()>

Source

pub fn get_float(&self, off: Offset) -> Result<f64>

Source

pub fn get_str(&self, off: Offset) -> Result<&'a str>

Source

pub fn get_bytes(&self, off: Offset) -> Result<&'a [u8]>

Source

pub fn get_array(&self, off: Offset, res: &mut Vec<Offset>) -> Result<()>

Read an array of offsets into res

Source

pub fn get_dict( &self, off: Offset, res: &mut Vec<(Offset, Offset)>, ) -> Result<()>

Read a dictionary of offsets into res.

res is cleared before reading.

Source

pub fn get_tag(&self, off: Offset) -> Result<(Tag, Offset)>

Read a tagged value.

The value itself is not read, only an offset to it is returned.

Source

pub fn get_variant( &self, off: Offset, args: &mut Vec<Offset>, ) -> Result<VariantIdx>

Read a variant value. The variant index is returned, and (the offsets of the) arguments are pushed into args.

args is cleared first.

Source

pub fn entrypoint(&self) -> Result<Offset>

Find the entrypoint.

A twine blob is terminated with a postfix (in essence, a pointer to the actual toplevel value). This reads the postfix and returns the offset of the toplevel value.

Trait Implementations§

Source§

impl<'a> Clone for Decoder<'a>

Source§

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

Returns a duplicate 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<'a> Debug for Decoder<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Decoder<'a>

§

impl<'a> RefUnwindSafe for Decoder<'a>

§

impl<'a> Send for Decoder<'a>

§

impl<'a> Sync for Decoder<'a>

§

impl<'a> Unpin for Decoder<'a>

§

impl<'a> UnwindSafe for Decoder<'a>

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, 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.