pub struct SlipReader<R> { /* private fields */ }Expand description
Reader wrapper that decodes SLIP frames from an underlying byte stream.
A full streaming example is provided in examples/stream.rs. Use
SlipReader::take_remainder to inspect buffered data when a stream ends
mid-frame.
Implementations§
Source§impl<R> SlipReader<R>
impl<R> SlipReader<R>
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Consume the wrapper and return the inner reader.
Sourcepub fn into_inner_with_remainder(self) -> (R, FrameRemainder)
pub fn into_inner_with_remainder(self) -> (R, FrameRemainder)
Consume the wrapper and return both the inner reader and any buffered remainder.
Source§impl<R: Read> SlipReader<R>
impl<R: Read> SlipReader<R>
Sourcepub fn read_frame_into(&mut self, buffer: &mut Vec<u8>) -> Result<Option<usize>>
pub fn read_frame_into(&mut self, buffer: &mut Vec<u8>) -> Result<Option<usize>>
Read the next SLIP frame into the supplied buffer.
On success the buffer is populated with the decoded payload and the function returns the frame length.
When the end of the underlying reader is reached without another complete frame, Ok(None) is returned.
Sourcepub fn read_frame(&mut self) -> Result<Option<Vec<u8>>>
pub fn read_frame(&mut self) -> Result<Option<Vec<u8>>>
Read the next SLIP frame and return it as a freshly allocated Vec.
Sourcepub fn read_frame_length(&mut self) -> Result<Option<usize>>
pub fn read_frame_length(&mut self) -> Result<Option<usize>>
Read the next SLIP frame and return only its decoded length.
use slipstream::{SlipReader, encode_frame, Result};
use std::io::Cursor;
let encoded = [encode_frame(b"foo"), encode_frame(&[1])].concat();
let mut reader = SlipReader::new(Cursor::new(encoded));
assert_eq!(reader.read_frame_length()?, Some(3));
assert_eq!(reader.read_frame_length()?, Some(1));
assert!(reader.read_frame_length()?.is_none());Sourcepub fn take_remainder(&mut self) -> FrameRemainder
pub fn take_remainder(&mut self) -> FrameRemainder
Take ownership of any pending decoded bytes accumulated for the current, incomplete frame.
use slipstream::{SlipReader, encode_frame, SlipError, Result};
use std::io::Cursor;
let mut encoded = encode_frame(b"data");
encoded.pop(); // remove END terminator
let mut reader = SlipReader::new(Cursor::new(encoded));
let mut frame = Vec::new();
assert!(matches!(
reader.read_frame_into(&mut frame),
Err(SlipError::UnexpectedEndOfFrame)
));
let remainder = reader.take_remainder();
assert_eq!(remainder.decoded, b"data");
assert!(!remainder.escape_pending);Sourcepub fn has_remainder(&self) -> bool
pub fn has_remainder(&self) -> bool
Check if an incomplete frame is currently buffered.