pub struct Delimited<'d> { /* private fields */ }Expand description
Byte-delimited framer.
§Example
use wire_codec::WriteBuf;
use wire_codec::framing::{Delimited, Framer};
let framer = Delimited::new(b"\n").unwrap();
let mut out = [0u8; 32];
let mut buf = WriteBuf::new(&mut out);
framer.write_frame(b"line one", &mut buf).unwrap();
framer.write_frame(b"line two", &mut buf).unwrap();
let n = buf.position();
assert_eq!(&out[..n], b"line one\nline two\n");
let first = framer.next_frame(&out[..n]).unwrap().unwrap();
assert_eq!(first.payload(), b"line one");
assert_eq!(first.consumed(), 9);Implementations§
Source§impl<'d> Delimited<'d>
impl<'d> Delimited<'d>
Sourcepub const fn new(delimiter: &'d [u8]) -> Result<Self>
pub const fn new(delimiter: &'d [u8]) -> Result<Self>
Build a framer using delimiter to separate frames.
§Errors
Returns Error::EmptyDelimiter if delimiter is empty. An empty
delimiter cannot uniquely separate frames.
Sourcepub const fn with_max_payload(self, max: usize) -> Self
pub const fn with_max_payload(self, max: usize) -> Self
Set an upper bound on payload size. Frames whose payload would exceed
this size cause Error::FrameTooLarge.
Sourcepub const fn max_payload(&self) -> usize
pub const fn max_payload(&self) -> usize
Configured maximum payload size.
Trait Implementations§
Source§impl<'d> PartialEq for Delimited<'d>
impl<'d> PartialEq for Delimited<'d>
impl<'d> Copy for Delimited<'d>
impl<'d> Eq for Delimited<'d>
impl<'d> StructuralPartialEq for Delimited<'d>
Auto Trait Implementations§
impl<'d> Freeze for Delimited<'d>
impl<'d> RefUnwindSafe for Delimited<'d>
impl<'d> Send for Delimited<'d>
impl<'d> Sync for Delimited<'d>
impl<'d> Unpin for Delimited<'d>
impl<'d> UnsafeUnpin for Delimited<'d>
impl<'d> UnwindSafe for Delimited<'d>
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