pub(super) struct FrameCodec {
    in_buffer: ReadBuffer<READ_BUFFER_CHUNK_SIZE>,
    out_buffer: Vec<u8>,
    max_out_buffer_len: usize,
    out_buffer_write_len: usize,
    header: Option<(FrameHeader, u64)>,
}
Expand description

A codec for WebSocket frames.

Fields§

§in_buffer: ReadBuffer<READ_BUFFER_CHUNK_SIZE>

Buffer to read data from the stream.

§out_buffer: Vec<u8>

Buffer to send packets to the network.

§max_out_buffer_len: usize

Capacity limit for out_buffer.

§out_buffer_write_len: usize

Buffer target length to reach before writing to the stream on calls to buffer_frame.

Setting this to non-zero will buffer small writes from hitting the stream.

§header: Option<(FrameHeader, u64)>

Header and remaining size of the incoming packet being processed.

Implementations§

source§

impl FrameCodec

source

pub(super) fn new() -> Self

Create a new frame codec.

source

pub(super) fn from_partially_read(part: Vec<u8>) -> Self

Create a new frame codec from partially read data.

source

pub(super) fn set_max_out_buffer_len(&mut self, max: usize)

Sets a maximum size for the out buffer.

source

pub(super) fn set_out_buffer_write_len(&mut self, len: usize)

Sets Self::buffer_frame buffer target length to reach before writing to the stream.

source

pub(super) fn read_frame<Stream>( &mut self, stream: &mut Stream, max_size: Option<usize> ) -> Result<Option<Frame>>where Stream: Read,

Read a frame from the provided stream.

source

pub(super) fn buffer_frame<Stream>( &mut self, stream: &mut Stream, frame: Frame ) -> Result<()>where Stream: Write,

Writes a frame into the out_buffer. If the out buffer size is over the out_buffer_write_len will also write the out buffer into the provided stream.

To ensure buffered frames are written call Self::write_out_buffer.

May write to the stream, will not flush.

source

pub(super) fn write_out_buffer<Stream>( &mut self, stream: &mut Stream ) -> Result<()>where Stream: Write,

Writes the out_buffer to the provided stream.

Does not flush.

Trait Implementations§

source§

impl Debug for FrameCodec

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V