pub struct Codec { /* private fields */ }Expand description
A pea2pea codec that constrains every frame on the wire to
a single, fixed payload size, regardless of the actual payload
contents.
§Wire format
+--------+------------+
| length | payload |
| (4 B) | (frame_size)|
+--------+------------+length: a 4-byte big-endian unsigned integer. Always equal toframe_sizefor a well-formed frame; any other value causes the connection to be torn down by the decoder.payload: exactlyframe_sizebytes of frame data. The application is free to lay them out however it likes — random padding, structured records, or anything in between — because an observer cannot tell “what” is being sent, only “when”, “to whom”, and “how big” (and the last is constant).
Implementations§
Source§impl Codec
impl Codec
Sourcepub fn new(frame_size: usize, max_frame_size: usize) -> Self
pub fn new(frame_size: usize, max_frame_size: usize) -> Self
Creates a codec that accepts frames of exactly
frame_size payload bytes and rejects any frame larger
than max_frame_size bytes (defensive DoS bound).
§Panics
Panics if frame_size == 0 (the resulting codec would
never produce a useful message).
Sourcepub fn frame_size(&self) -> usize
pub fn frame_size(&self) -> usize
Returns the on-the-wire payload size this codec expects.
Trait Implementations§
Source§impl Decoder for Codec
impl Decoder for Codec
Source§fn decode(
&mut self,
src: &mut BytesMut,
) -> Result<Option<Self::Item>, Self::Error>
fn decode( &mut self, src: &mut BytesMut, ) -> Result<Option<Self::Item>, Self::Error>
Attempts to decode a frame from the provided buffer of bytes. Read more
Auto Trait Implementations§
impl Freeze for Codec
impl RefUnwindSafe for Codec
impl Send for Codec
impl Sync for Codec
impl Unpin for Codec
impl UnsafeUnpin for Codec
impl UnwindSafe for Codec
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