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
impl FrameCodec
sourcepub(super) fn from_partially_read(part: Vec<u8>) -> Self
pub(super) fn from_partially_read(part: Vec<u8>) -> Self
Create a new frame codec from partially read data.
sourcepub(super) fn set_max_out_buffer_len(&mut self, max: usize)
pub(super) fn set_max_out_buffer_len(&mut self, max: usize)
Sets a maximum size for the out buffer.
sourcepub(super) fn set_out_buffer_write_len(&mut self, len: usize)
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.
sourcepub(super) fn read_frame<Stream>(
&mut self,
stream: &mut Stream,
max_size: Option<usize>,
) -> Result<Option<Frame>>where
Stream: Read,
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.
sourcepub(super) fn buffer_frame<Stream>(
&mut self,
stream: &mut Stream,
frame: Frame,
) -> Result<()>where
Stream: Write,
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.
sourcepub(super) fn write_out_buffer<Stream>(
&mut self,
stream: &mut Stream,
) -> Result<()>where
Stream: Write,
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.