Skip to main content

Decoder

Struct Decoder 

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

Reads the binary form. The step-by-step reads (Decoder::int, Decoder::map …) answer None for anything but what crate::Schema::encode writes there — the schema then reads the slow way, which says what’s wrong.

Implementations§

Source§

impl<'b> Decoder<'b>

Source

pub fn open(bytes: &'b [u8]) -> Result<Self, DecodeError>

After the header: the root value next.

Source

pub fn at_end(&self) -> bool

Whether every byte was read.

Source

pub fn value(&mut self) -> Result<Value, DecodeError>

The next value, owned.

Source

pub fn value_ref<'a>( &mut self, arena: &'a Bump, ) -> Result<ValueRef<'a>, DecodeError>
where 'b: 'a,

The next value, borrowed: strings point into the bytes, lists and maps go in arena.

Source

pub fn null(&mut self) -> bool

Whether a null is next: read if it is.

Source

pub fn bool(&mut self) -> Option<bool>

Source

pub fn int(&mut self) -> Option<i64>

Source

pub fn float(&mut self) -> Option<f64>

A float — or an int, as a number.

Source

pub fn str(&mut self) -> Option<&'b str>

Source

pub fn bytes(&mut self) -> Option<&'b [u8]>

Source

pub fn list(&mut self) -> Option<usize>

A list next: how many values; Decoder::leave after them.

Source

pub fn ints(&mut self) -> Option<usize>

A packed list of ints next (Decoder::packed_int each): how many.

Source

pub fn stream(&mut self) -> Option<&'b [u8]>

A stream next: its body (count and values, strings its own).

Source

pub fn floats(&mut self) -> Option<Vec<f64>>

A packed list of floats next: each one. (Written narrow when they fit: widened back.)

Source

pub fn floats32(&mut self) -> Option<Vec<f32>>

A packed list of 32-bit floats next: each one.

Source

pub fn packed_int(&mut self) -> Option<i64>

One int of a packed list.

Source

pub fn map(&mut self) -> Option<usize>

A map next: how many entries, each a Decoder::key and a value; Decoder::leave after them.

Source

pub fn leave(&mut self)

The end of a list or map.

Source

pub fn key(&mut self) -> Option<&'b str>

Source

pub fn skip(&mut self) -> Option<()>

The next value, read and left (its strings still join the table).

Auto Trait Implementations§

§

impl<'b> Freeze for Decoder<'b>

§

impl<'b> RefUnwindSafe for Decoder<'b>

§

impl<'b> Send for Decoder<'b>

§

impl<'b> Sync for Decoder<'b>

§

impl<'b> Unpin for Decoder<'b>

§

impl<'b> UnsafeUnpin for Decoder<'b>

§

impl<'b> UnwindSafe for Decoder<'b>

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, 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.