Skip to main content

FrameEncoder

Struct FrameEncoder 

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

Turns packets into wire bytes. Packets are appended to an internal output buffer; take it with FrameEncoder::take (or let crate::io::FramedWriter flush it), so several packets of one tick go out in a single write.

Implementations§

Source§

impl FrameEncoder

Source

pub fn new() -> Self

An encoder with no compression and no encryption.

Source

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

Sets the compression threshold (negative = off), as received from the server.

Source

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

Turns on encryption for everything written from now on.

Source

pub fn write_packet<P: Packet>(&mut self, p: &P) -> Result<(), EncodeError>

Encodes and frames a typed packet.

Source

pub fn write_set<S: PacketSet>(&mut self, p: &S) -> Result<(), EncodeError>

Encodes and frames a packet-set enum value.

Source

pub fn write_raw(&mut self, p: &RawPacket) -> Result<(), EncodeError>

Frames a raw packet.

Source

pub fn pending(&self) -> &[u8] ⓘ

Bytes waiting to be sent.

Source

pub fn take(&mut self) -> BytesMut

Takes the bytes waiting to be sent.

Source

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

The output buffer (for transports that consume it in place).

Trait Implementations§

Source§

impl Debug for FrameEncoder

Source§

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

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

impl Default for FrameEncoder

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.