Skip to main content

FrameDecoder

Struct FrameDecoder 

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

Splits a byte stream into packets.

Implementations§

Source§

impl FrameDecoder

Source

pub fn new() -> Self

A decoder with no compression, no encryption, default limits and no filter.

Source

pub fn set_limits(&mut self, limits: FrameLimits)

Sets the limits.

Source

pub fn set_compression(&mut self, threshold: i32)

Turns compression on or off (from the server’s Set Compression packet; a negative threshold means off). Call it right after decoding that packet.

Source

pub fn compression(&self) -> bool

Whether compression is on.

Source

pub fn enable_encryption(&mut self, secret: &[u8; 16])

Turns on decryption. Bytes already buffered but not yet split into frames are decrypted too, since the server encrypts everything after its encryption request was answered.

Source

pub fn is_encrypted(&self) -> bool

Whether decryption is on.

Source

pub fn set_filter(&mut self, filter: PacketFilter)

Sets the per-id interest filter.

Source

pub fn filter(&self) -> &PacketFilter

The current filter.

Source

pub fn stats(&self) -> DecoderStats

Counters.

Source

pub fn buffered(&self) -> usize

Number of buffered, not yet consumed bytes.

Source

pub fn push(&mut self, data: &[u8])

Appends received bytes (decrypting them if encryption is on).

Source

pub fn buffer_mut(&mut self) -> &mut BytesMut

The receive buffer, for reading directly into it. After appending n bytes call FrameDecoder::commit with the length before the read.

FrameDecoder::reserve_read also makes room for the read first.

Source

pub fn reserve_read(&mut self) -> &mut BytesMut

The receive buffer with room for the next read: at least the rest of the frame being received, at least a couple of KB otherwise. The consumed front is reused in place when no packet still shares the buffer. After appending call FrameDecoder::commit with the length before the read, as with FrameDecoder::buffer_mut.

Source

pub fn commit(&mut self, old_len: usize)

Decrypts bytes appended to FrameDecoder::buffer_mut since old_len.

Source

pub fn set_detach_frames(&mut self, on: bool)

Copies uncompressed frames out of the receive buffer instead of sharing it with the packets (off by default). A packet body that something keeps (a registry entry, a profile property) then does not keep a whole receive buffer alive. Meant for the short login and configuration states: it costs an allocation per frame.

Source

pub fn rehome(&mut self)

Moves the buffered bytes to a fresh receive buffer of the standard size. Packets split off before keep the old buffer (only) to themselves; call it at a state change (the end of the configuration) so that the packets of the new state do not share a buffer with data kept from the old one.

Source

pub fn needed(&self) -> Option<usize>

How many more bytes are needed to complete the next frame, if known.

Source

pub fn next_packet(&mut self) -> Result<Option<RawPacket>, FrameError>

Splits off the next packet that passes the filter.

Returns Ok(None) when more bytes are needed. Errors are fatal for the connection (the stream position is lost).

Trait Implementations§

Source§

impl Debug for FrameDecoder

Source§

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

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

impl Default for FrameDecoder

Source§

fn default() -> Self

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

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.