Struct MidWriter

Source
pub struct MidWriter<W, C> { /* private fields */ }
Expand description

Write side of the Middleware protocol

Implementations§

Source§

impl<W, C> MidWriter<W, C>

Source

pub async fn write_forward( &mut self, client_id: u16, buffer: &[u8], compression: ForwardCompression, ) -> Result<CompressionStatus>

Write forward packet to the destination socket.

Source§

impl<W, C> MidWriter<W, C>
where W: AsyncWriteExt + Unpin,

Source

pub fn write_disconnected( &mut self, id: u16, ) -> impl Future<Output = Result<()>> + '_

Write disconnect packet to the destination socket

Source

pub async fn write_two_bufs( &mut self, before: &[u8], after: &[u8], ) -> Result<bool>

Write two buffers to the socket in vectored mode.

Returns

  • Ok(true) if buffer was wrote using efficient implementation (without allocating buffer with size before.len() + after.len())
  • Ok(false) if buffer was wrote using the fallback way (allocating buffer with size before.len() + after.len() and copying data to it)
Source

pub fn write_all<'a>( &'a mut self, buf: &'a [u8], ) -> impl Future<Output = Result<()>> + 'a

Writes entire buffer into the socket

Source

pub fn write_u32(&mut self, v: u32) -> impl Future<Output = Result<()>> + '_

Same as MidWriter::write_u32 but writes u32 (little endian)

Source

pub fn write_u16(&mut self, v: u16) -> impl Future<Output = Result<()>> + '_

Same as MidWriter::write_u8 but writes u16 (little endian)

Source

pub fn write_u8(&mut self, v: u8) -> impl Future<Output = Result<()>> + '_

Write u8 to the destination socket (or possibly to buffer)

Source§

impl<W, C> MidWriter<BufWriter<W>, C>
where W: AsyncWrite + Unpin,

Source

pub fn flush(&mut self) -> impl Future<Output = Result<()>> + '_

Flush underlying write buffer, so remote side will receive buffered bytes immediately

Source§

impl<W, C> MidWriter<BufWriter<W>, C>
where W: AsyncWrite,

Source

pub fn new_buffered(socket: W, compressor: C, buffer_size: usize) -> Self

Create buffered writer.

Source

pub fn unbuffer(self) -> MidWriter<W, C>

Remove bufferization from the writer.

WARNING: it is neccessary to call MidWriter::flush before the unbuffering so you’re sure that previously buffered data was wrote

Source§

impl<W, C> MidWriter<W, C>
where W: AsyncWrite,

Source

pub fn make_buffered(self, buffer_size: usize) -> MidWriter<BufWriter<W>, C>

Make writer buffered

Source§

impl<W, C> MidWriter<W, C>

Source

pub fn client(&mut self) -> MidClientWriter<'_, W, C>

Create client packets writer. Used mainly to incapsulate client and server packets

Source

pub fn server(&mut self) -> MidServerWriter<'_, W, C>

Same as MidWriter::client but for server packets

Source

pub const fn socket(&self) -> &W

Get shared access to the underlying socket.

Source

pub fn socket_mut(&mut self) -> &mut W

Get exclusive access to the underlying socket.

Source

pub const fn new(socket: W, compressor: C) -> Self

Simply create writer from the underlying socket

Auto Trait Implementations§

§

impl<W, C> Freeze for MidWriter<W, C>
where W: Freeze, C: Freeze,

§

impl<W, C> RefUnwindSafe for MidWriter<W, C>

§

impl<W, C> Send for MidWriter<W, C>
where W: Send, C: Send,

§

impl<W, C> Sync for MidWriter<W, C>
where W: Sync, C: Sync,

§

impl<W, C> Unpin for MidWriter<W, C>
where W: Unpin, C: Unpin,

§

impl<W, C> UnwindSafe for MidWriter<W, C>
where W: UnwindSafe, C: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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