ciborium_ll

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

Source§

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> Freeze for Decoder<R>
where R: Freeze,

§

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

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.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.