pub struct AsyncReader<R> { /* private fields */ }Expand description
Wraps an AsyncRead and reads length-delimited CBOR values.
Requires cargo feature "async-io".
Implementations§
Source§impl<R> AsyncReader<R>
impl<R> AsyncReader<R>
Sourcepub fn with_buffer(reader: R, buffer: Vec<u8>) -> Self
pub fn with_buffer(reader: R, buffer: Vec<u8>) -> Self
Create a new reader with a max. buffer size of 512KiB.
Sourcepub fn set_max_len(&mut self, val: u32)
pub fn set_max_len(&mut self, val: u32)
Set the max. buffer size in bytes.
If length values greater than this are decoded, an
Error::InvalidLen will be returned.
Sourcepub fn reader_mut(&mut self) -> &mut R
pub fn reader_mut(&mut self) -> &mut R
Get a mutable reference to the inner reader.
Sourcepub fn into_parts(self) -> (R, Vec<u8>)
pub fn into_parts(self) -> (R, Vec<u8>)
Deconstruct this reader into the inner reader and the buffer.
Source§impl<R: AsyncRead + Unpin> AsyncReader<R>
impl<R: AsyncRead + Unpin> AsyncReader<R>
Sourcepub async fn read<'a, T: Decode<'a, ()>>(
&'a mut self,
) -> Result<Option<T>, Error>
pub async fn read<'a, T: Decode<'a, ()>>( &'a mut self, ) -> Result<Option<T>, Error>
Read the next CBOR value and decode it.
The value is assumed to be preceded by a u32 (4 bytes in network
byte order) denoting the length of the CBOR item in bytes.
Reading 0 bytes when decoding the length prefix results in Ok(None),
otherwise either Some value or an error is returned.
§Cancellation
The future returned by AsyncReader::read can be dropped while still
pending. Subsequent calls to AsyncReader::read will resume reading
where the previous future left off.