BufferCursor

Struct BufferCursor 

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

Retains the current index state into a serialization buffer.

Typically used by a BufferState to keep track of which bytes still require processing.

Implementations§

Source§

impl BufferCursor

Source

pub fn new(buf: &[u8]) -> BufferCursor

Instantiate a new cursor over the beginning of the provided buf.

Source

pub fn with_len(len: usize) -> BufferCursor

Instantiate a new cursor representing the beginning of a buffer with a specified len.

Source

pub fn len(&self) -> usize

Return the number of bytes the cursor has processed so far.

Source

pub fn is_empty(&self) -> bool

Return whether or not any bytes have been processed yet.

Source

pub fn is_pending(&self) -> bool

Return whether or not more data is expected to be processed.

Source

pub fn start_write<W>( &mut self, writer: &mut W, data: &[u8], cx: &mut Context<'_>, ) -> PollEncodeStatus<Error>
where W: AsyncWrite + Unpin,

Source

pub fn write_remaining<W>( &mut self, writer: &mut W, data: &[u8], cx: &mut Context<'_>, ) -> PollEncodeStatus<Error>
where W: AsyncWrite + Unpin,

Attempt to write all of the bytes in data, starting from the current offset of the cursor.

This implementation differs from a typical AsyncWrite operation in that the contents of data are expected to be unchanging from one call to the next, despite progress being made. The expectation is that the caller does not need to retain any information about the progress of the write, and simply needs to pass in the same references for each call.

Source

pub fn start_read<R>( &mut self, reader: &mut R, data: &mut [u8], cx: &mut Context<'_>, ) -> PollDecodeStatus<(), Error>
where R: AsyncRead + Unpin,

Source

pub fn read_remaining<R>( &mut self, reader: &mut R, data: &mut [u8], cx: &mut Context<'_>, ) -> PollDecodeStatus<(), Error>
where R: AsyncRead + Unpin,

Attempt to read all remaining bytes that are expected into data, starting from the current offset of the cursor.

This implementation differs from a typical AsyncRead operation in that the contents of data are expected to be unchanging from one call to the next, despite progress being made. The expectation is that the caller does not need to retain any information about the progress of the read, and simply needs to pass in the same references for each call.

Source

pub fn fill_vec<R>( &mut self, reader: &mut R, data: &mut Vec<u8>, cx: &mut Context<'_>, ) -> PollDecodeStatus<(), Error>
where R: AsyncBufRead + Unpin,

Semantically equivalent to read_remaining, only this method takes advantage of the AsyncBufRead trait to minimize the number of copies required to transfer the bytes into a pre-allocated Vec.

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