pub struct DecoderReader<B, R>where
B: Buffer,
R: ByteSource,{ /* private fields */ }
Expand description
Decode transmissions read from a byte source
Implementations§
Source§impl<B, R> DecoderReader<B, R>where
B: Buffer,
R: ByteSource,
impl<B, R> DecoderReader<B, R>where
B: Buffer,
R: ByteSource,
Sourcepub fn read(&mut self) -> Result<&[u8], ReadDecodedError<R::ReadError>>
pub fn read(&mut self) -> Result<&[u8], ReadDecodedError<R::ReadError>>
Reads and decodes a transmission
On success, returns the decoded transmission (Ok(bytes)
). Otherwise, returns errors
(which can either be decoding errors or errors returned from the byte source).
When reading from a finite data source (such as a file containing a certain
number of transmissions), it’s easier to use next
instead,
which handles EOFs correctly.
See also read_nb
, which provides a convenient API for
non-blocking byte sources.
Sourcepub fn next(&mut self) -> Option<Result<&[u8], ReadDecodedError<R::ReadError>>>
pub fn next(&mut self) -> Option<Result<&[u8], ReadDecodedError<R::ReadError>>>
Tries to read and decode a transmission
On success, returns the decoded transmission (Some(Ok(bytes))
). Returns
None
if the reader returns EOF immediately. Otherwise, returns errors
(which can either be decoding errors or errors returned from the byte source).
When reading from a data source that will provide data infinitely (such
as from a serial port), it’s easier to use read
instead.
See also next_nb
, which provides a convenient API for
non-blocking byte sources.
Sourcepub fn read_nb(&mut self) -> Result<&[u8], ReadDecodedError<R::ReadError>>
Available on crate feature nb
only.
pub fn read_nb(&mut self) -> Result<&[u8], ReadDecodedError<R::ReadError>>
nb
only.Reads and decodes a transmission (non-blocking)
Same as read
except that it returns nb::Result
.
If reading from the byte source indicates that data isn’t available yet,
this method returns Err(nb::Error::WouldBlock)
.
Using nb::Result
allows this method to be awaited using the nb::block!
macro.
This function is available only if sml-rs is built with the "nb"
or "embedded_hal"
features.
Sourcepub fn next_nb(
&mut self,
) -> Result<Option<&[u8]>, ReadDecodedError<R::ReadError>>
Available on crate feature nb
only.
pub fn next_nb( &mut self, ) -> Result<Option<&[u8]>, ReadDecodedError<R::ReadError>>
nb
only.Tries to read and decode a transmission (non-blocking)
Same as next
except that it returns nb::Result
.
If reading from the byte source indicates that data isn’t available yet,
this method returns Err(nb::Error::WouldBlock)
.
Using nb::Result
allows this method to be awaited using the nb::block!
macro.
This function is available only if sml-rs is built with the "nb"
or "embedded_hal"
features.