Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<'a> { /* private fields */ }
Available on crate feature cbor only.
Expand description

The low level implementation of the CBOR decoder with only the handful of desired types supported.

Implementations§

Source§

impl<'a> Decoder<'a>

Source

pub fn new(data: &'a [u8]) -> Self

Creates a decoder around a data blob.

Source

pub fn finish(self) -> Result<(), Error>

Terminates decoding and returns an error if trailing bytes remain.

Source

pub fn decode_uint(&mut self) -> Result<u64, Error>

Decodes a positive integer, enforcing minimal canonicalness.

Source

pub fn decode_int(&mut self) -> Result<i64, Error>

Decodes a signed integer (major type 0 or 1).

Source

pub fn decode_bytes(&mut self) -> Result<Vec<u8>, Error>

Decodes a byte string.

Source

pub fn decode_bytes_fixed<const N: usize>(&mut self) -> Result<[u8; N], Error>

Decodes a byte string into a fixed-size array.

Source

pub fn decode_text(&mut self) -> Result<String, Error>

Decodes a UTF-8 text string.

Source

pub fn decode_array_header(&mut self) -> Result<u64, Error>

Decodes an array header, returning its length.

Source

pub fn decode_map_header(&mut self) -> Result<u64, Error>

Decodes a map header, returning the number of key-value pairs.

Source

pub fn decode_bool(&mut self) -> Result<bool, Error>

Decodes a CBOR boolean value.

Source

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

Decodes a CBOR null value.

Source

pub fn peek_null(&self) -> bool

Checks if the next value is null without consuming it.

Source

pub fn peek_int(&self) -> Result<i64, Error>

Returns the next signed integer value without consuming it.

Source

pub fn peek_uint(&self) -> Result<u64, Error>

Returns the next unsigned integer value without consuming it. Unlike peek_int, this only matches CBOR major type 0 (positive integers).

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. 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> UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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