Struct ciborium_ll::Decoder

source ·
pub struct Decoder<R: Read> { /* private fields */ }
Expand description

A decoder for deserializing CBOR items

This decoder manages the low-level decoding of CBOR items into Header objects. It also contains utility functions for parsing segmented bytes and text inputs.

Implementations§

source§

impl<R: Read> Decoder<R>

source

pub fn pull(&mut self) -> Result<Header, Error<R::Error>>

Pulls the next header from the input

source

pub fn push(&mut self, item: Header)

Push a single header into the input buffer

§Panics

This function panics if called while there is already a header in the input buffer. You should take care to call this function only after pulling a header to ensure there is nothing in the input buffer.

source

pub fn offset(&mut self) -> usize

Gets the current byte offset into the stream

The offset starts at zero when the decoder is created. Therefore, if bytes were already read from the reader before the decoder was created, you must account for this.

source

pub fn bytes(&mut self, len: Option<usize>) -> Segments<'_, R, Bytes>

Process an incoming bytes item

In CBOR, bytes can be segmented. The logic for this can be a bit tricky, so we encapsulate that logic using this function. This function MUST be called immediately after first pulling a Header::Bytes(len) from the wire and len must be provided to this function from that value.

The buf parameter provides a buffer used when reading in the segmented bytes. A large buffer will result in fewer calls to read incoming bytes at the cost of memory usage. You should consider this trade off when deciding the size of your buffer.

source

pub fn text(&mut self, len: Option<usize>) -> Segments<'_, R, Text>

Process an incoming text item

In CBOR, text can be segmented. The logic for this can be a bit tricky, so we encapsulate that logic using this function. This function MUST be called immediately after first pulling a Header::Text(len) from the wire and len must be provided to this function from that value.

The buf parameter provides a buffer used when reading in the segmented text. A large buffer will result in fewer calls to read incoming bytes at the cost of memory usage. You should consider this trade off when deciding the size of your buffer.

Trait Implementations§

source§

impl<R: Read> From<R> for Decoder<R>

source§

fn from(value: R) -> Self

Converts to this type from the input type.
source§

impl<R: Read> Read for Decoder<R>

§

type Error = <R as Read>::Error

The error type
source§

fn read_exact(&mut self, data: &mut [u8]) -> Result<(), Self::Error>

Reads exactly data.len() bytes or fails

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for Decoder<R>
where R: RefUnwindSafe,

§

impl<R> Send for Decoder<R>
where R: Send,

§

impl<R> Sync for Decoder<R>
where R: Sync,

§

impl<R> Unpin for Decoder<R>
where R: Unpin,

§

impl<R> UnwindSafe for Decoder<R>
where R: UnwindSafe,

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

§

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

§

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.