pub struct IoDecoder<R: Read> { /* private fields */ }Available on crate feature
std only.Expand description
Streaming decoder that reads directly from any Read-shaped source.
Each IoDecoder::read call may issue many small reads against the
underlying source. Wrap raw sockets / files in std::io::BufReader
first if read-syscall amplification is a concern.
§Examples
use pack_io::{IoEncoder, IoDecoder};
use std::io::Cursor;
let mut buf: Vec<u8> = Vec::new();
{
let mut enc = IoEncoder::new(&mut buf);
enc.write(&42_u64).unwrap();
enc.write(&"hi").unwrap();
}
let mut dec = IoDecoder::new(Cursor::new(buf));
let n: u64 = dec.read().unwrap();
let s: String = dec.read().unwrap();
assert_eq!((n, s.as_str()), (42, "hi"));Implementations§
Source§impl<R: Read> IoDecoder<R>
impl<R: Read> IoDecoder<R>
Sourcepub fn with_config(reader: R, config: Config) -> Result<Self>
pub fn with_config(reader: R, config: Config) -> Result<Self>
Wrap reader with the supplied configuration.
§Errors
Returns SerialError::InvalidLength if config.max_alloc == 0.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Consume the decoder and return the underlying reader.
Sourcepub fn read<T: Deserialize>(&mut self) -> Result<T>
pub fn read<T: Deserialize>(&mut self) -> Result<T>
Decode the next value from the underlying reader.
§Errors
- Propagates any
crate::SerialErrorfrom the type’sDeserialize. - Maps any
std::io::Errorfrom the reader intoSerialError::Io.
Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for IoDecoder<R>where
R: Freeze,
impl<R> RefUnwindSafe for IoDecoder<R>where
R: RefUnwindSafe,
impl<R> Send for IoDecoder<R>where
R: Send,
impl<R> Sync for IoDecoder<R>where
R: Sync,
impl<R> Unpin for IoDecoder<R>where
R: Unpin,
impl<R> UnsafeUnpin for IoDecoder<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for IoDecoder<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
Mutably borrows from an owned value. Read more