pub struct LengthPrefixed { /* private fields */ }Expand description
Length-prefixed framer.
§Example
use wire_codec::WriteBuf;
use wire_codec::framing::{Endian, Framer, LengthPrefixed, LengthWidth};
let framer = LengthPrefixed::new(LengthWidth::U16, Endian::Big);
let mut out = [0u8; 16];
let mut buf = WriteBuf::new(&mut out);
framer.write_frame(b"hello", &mut buf).unwrap();
let written = buf.position();
assert_eq!(&out[..written], &[0x00, 0x05, b'h', b'e', b'l', b'l', b'o']);
let frame = framer.next_frame(&out[..written]).unwrap().unwrap();
assert_eq!(frame.payload(), b"hello");
assert_eq!(frame.consumed(), 7);Implementations§
Source§impl LengthPrefixed
impl LengthPrefixed
Sourcepub const fn new(width: LengthWidth, endian: Endian) -> Self
pub const fn new(width: LengthWidth, endian: Endian) -> Self
Build a framer using the given prefix width and endianness.
The maximum payload size defaults to the largest value the prefix can
encode. Use LengthPrefixed::with_max_payload to tighten it.
Sourcepub const fn with_max_payload(self, max: u64) -> Self
pub const fn with_max_payload(self, max: u64) -> Self
Override the payload size limit enforced when reading and writing frames.
The limit is clamped to LengthWidth::max_payload of the configured
width.
Sourcepub const fn width(&self) -> LengthWidth
pub const fn width(&self) -> LengthWidth
Configured prefix width.
Sourcepub const fn max_payload(&self) -> u64
pub const fn max_payload(&self) -> u64
Configured maximum payload size in bytes.
Trait Implementations§
Source§impl Clone for LengthPrefixed
impl Clone for LengthPrefixed
Source§fn clone(&self) -> LengthPrefixed
fn clone(&self) -> LengthPrefixed
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LengthPrefixed
impl Debug for LengthPrefixed
Source§impl Framer for LengthPrefixed
impl Framer for LengthPrefixed
impl Copy for LengthPrefixed
Auto Trait Implementations§
impl Freeze for LengthPrefixed
impl RefUnwindSafe for LengthPrefixed
impl Send for LengthPrefixed
impl Sync for LengthPrefixed
impl Unpin for LengthPrefixed
impl UnsafeUnpin for LengthPrefixed
impl UnwindSafe for LengthPrefixed
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