Skip to main content

EncoderBuffer

Struct EncoderBuffer 

Source
pub struct EncoderBuffer<'a> { /* private fields */ }
Expand description

Helper struct for building encoded messages.

Provides a convenient way to track the current write position and manage buffer space.

Implementations§

Source§

impl<'a> EncoderBuffer<'a>

Source

pub fn new(buffer: &'a mut [u8], offset: usize) -> Self

Creates a new encoder buffer.

§Arguments
  • buffer - Mutable byte buffer to write to
  • offset - Starting offset in the buffer
Source

pub fn buffer(&self) -> &[u8]

Returns the underlying buffer.

Source

pub fn buffer_mut(&mut self) -> &mut [u8]

Returns the mutable underlying buffer.

Source

pub const fn offset(&self) -> usize

Returns the starting offset.

Source

pub const fn position(&self) -> usize

Returns the current write position.

Source

pub const fn bytes_written(&self) -> usize

Returns the number of bytes written.

Source

pub fn remaining(&self) -> usize

Returns the remaining capacity.

Source

pub fn advance(&mut self, count: usize)

Advances the position by the given number of bytes.

§Arguments
  • count - Number of bytes to advance
Source

pub fn set_position(&mut self, pos: usize)

Sets the position to a specific offset.

§Arguments
  • pos - New position
Source

pub fn write_u8(&mut self, value: u8)

Writes a u8 at the current position and advances.

Source

pub fn write_u16_le(&mut self, value: u16)

Writes a u16 in little-endian at the current position and advances.

Source

pub fn write_u32_le(&mut self, value: u32)

Writes a u32 in little-endian at the current position and advances.

Source

pub fn write_u64_le(&mut self, value: u64)

Writes a u64 in little-endian at the current position and advances.

Source

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

Writes bytes at the current position and advances.

Source

pub fn write_zeros(&mut self, count: usize)

Writes zeros at the current position and advances.

Trait Implementations§

Source§

impl<'a> Debug for EncoderBuffer<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for EncoderBuffer<'a>

§

impl<'a> RefUnwindSafe for EncoderBuffer<'a>

§

impl<'a> Send for EncoderBuffer<'a>

§

impl<'a> Sync for EncoderBuffer<'a>

§

impl<'a> Unpin for EncoderBuffer<'a>

§

impl<'a> !UnwindSafe for EncoderBuffer<'a>

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.