Struct Encoder

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

Data type used to encode data efficient

This structure has been built from the ground up to avoid branching while encoding.

Implementations§

Source§

impl Encoder

Source

pub fn new<P: PacketVal>(msg: &P) -> Encoder

Pass an already constructed packet in. This will allocate a buffer the size of that packet

Source

pub fn from_vec<P: PacketVal>(msg: &P, x: Vec<u8>) -> Encoder

To avoid allocations this method allows for a pre-allocated vector be passed in. The Vector’s size will be checked, and it MAY be resized if too small. If it’s capacity is sufficient no allocations will be done.

Source

pub fn get_vec(self) -> Vec<u8>

Consumes this type (destroying it) but returns the underlying vector as to not dellocator it’s memory (be used again).

Source

pub unsafe fn with_capacity(size: usize) -> Self

Used internally for testing, maybe useful to the developer reading this this allows for the input value to set the len/capacity of the internal memory

#Unsafe

This method is unsafe. If you encode a packet LARGER then the method your program may seg fault as there is no bounds checking when encoding.

Source

pub fn as_slice<'a>(&'a self) -> &'a [u8]

While the underlying vec is fully populated this returns only the data written to it. So if with::capacity is used to create a buffer larger then a packet this can be used to read only the packet data.

Source

pub fn len(&self) -> usize

Get length of data written to the encoder

Source

pub fn encode_u8(&mut self, x: u8)

Encode a u8 used internally.

Source

pub fn encode_u16(&mut self, x: u16)

Encode a u16 used internally.

Source

pub fn encode_u32(&mut self, x: u32)

Encode a u32 used internally.

Source

pub fn encode_u64(&mut self, x: u64)

Encode a u64 used internally.

Source

pub fn encode_slice(&mut self, x: &[u8])

Encode a u8 used internally.

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.