Skip to main content

FrameCodec

Struct FrameCodec 

Source
pub struct FrameCodec { /* private fields */ }
Expand description

A configured framing codec.

Stateless beyond the configured max_frame_bytes bound: encode and decode operate on one frame at a time and hold no connection state (handshake sequencing is crate::handshake::HandshakeGate’s job, not the codec’s).

Implementations§

Source§

impl FrameCodec

Source

pub const fn new(max_frame_bytes: usize) -> Self

A codec with the given maximum frame size (the JSON payload length, not counting the 4-byte prefix).

Source

pub const fn max_frame_bytes(&self) -> usize

Source

pub fn encode(&self, frame: &Frame) -> Result<Vec<u8>, CodecError>

Encode one frame as a complete length-prefixed wire buffer: 4-byte BE length followed by the JSON payload, guarded by this codec’s own configured maximum so encode and decode share one bound.

Source

pub fn decode(&self, buf: &[u8]) -> Result<Frame, CodecError>

Decode one complete length-prefixed frame from buf.

buf must contain at least the full frame (prefix + payload); this function does not support partial/streaming input. Bytes in buf beyond the decoded frame, if any, are ignored — a transport that reads a stream is responsible for slicing exactly one frame’s bytes (using the length prefix) before calling this, or for using decode_with_consumed to learn where the decoded frame ends.

Source

pub fn decode_with_consumed( &self, buf: &[u8], ) -> Result<(Frame, usize), CodecError>

Decode one complete length-prefixed frame from buf and report the number of bytes consumed: the 4-byte length prefix plus the declared payload length. The remainder buf[consumed..] — if any — is the next frame’s bytes, letting a transport split a buffered stream into frames without re-parsing the length prefix itself. The frame itself is decoded exactly as decode.

Trait Implementations§

Source§

impl Clone for FrameCodec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FrameCodec

Source§

impl Debug for FrameCodec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FrameCodec

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for FrameCodec

Source§

impl PartialEq for FrameCodec

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FrameCodec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.