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>
impl<R: Read> Decoder<R>
Sourcepub fn push(&mut self, item: Header)
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.
Sourcepub fn offset(&mut self) -> usize
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.
Sourcepub fn bytes(&mut self, len: Option<usize>) -> Segments<'_, R, Bytes>
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.
Sourcepub fn text(&mut self, len: Option<usize>) -> Segments<'_, R, Text>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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.