pub struct FrameReader<'a> { /* private fields */ }Expand description
Reads length-prefixed frames from a byte stream.
Yields individual message payloads that can be decoded
with BitReader.
§Example
use vexil_runtime::{BitReader, FrameReader};
let stream: &[u8] = &[
4, 0x2A, 0x00, 0x00, 0x00, // frame 1: len=4, u32(42) LE
6, 0x05, 0x68, 0x65, 0x6C, 0x6C, 0x6F, // frame 2: len=6, string "hello"
];
let mut fr = FrameReader::new(stream);
let frame1 = fr.read_frame().unwrap().unwrap();
let mut r = BitReader::new(frame1);
assert_eq!(r.read_u32().unwrap(), 42);
let frame2 = fr.read_frame().unwrap().unwrap();
let mut r = BitReader::new(frame2);
assert_eq!(r.read_string().unwrap(), "hello");
assert!(fr.read_frame().is_none()); // EOFImplementations§
Source§impl<'a> FrameReader<'a>
impl<'a> FrameReader<'a>
Sourcepub fn read_frame(&mut self) -> Option<Result<&'a [u8], DecodeError>>
pub fn read_frame(&mut self) -> Option<Result<&'a [u8], DecodeError>>
Read the next frame. Returns the payload bytes, or None at EOF.
Auto Trait Implementations§
impl<'a> Freeze for FrameReader<'a>
impl<'a> RefUnwindSafe for FrameReader<'a>
impl<'a> Send for FrameReader<'a>
impl<'a> Sync for FrameReader<'a>
impl<'a> Unpin for FrameReader<'a>
impl<'a> UnsafeUnpin for FrameReader<'a>
impl<'a> UnwindSafe for FrameReader<'a>
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