Struct dhcproto::encoder::Encoder

source ·
pub struct Encoder<'a> { /* private fields */ }
Expand description

Encoder type, holds a mut ref to a buffer that it will write data to and an offset of the next position to write

Implementations§

source§

impl<'a> Encoder<'a>

source

pub fn new(buffer: &'a mut Vec<u8>) -> Self

Create a new Encoder from a mutable buffer

source

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

Get a reference to the underlying buffer

source

pub fn write_slice(&mut self, bytes: &[u8]) -> EncodeResult<()>

write bytes to buffer Return: number of bytes written

source

pub fn write<const N: usize>(&mut self, bytes: [u8; N]) -> EncodeResult<()>

Write const number of bytes to buffer

source

pub fn write_u8(&mut self, data: u8) -> EncodeResult<()>

write a u8

source

pub fn write_u16(&mut self, data: u16) -> EncodeResult<()>

write a u16

source

pub fn write_u32(&mut self, data: u32) -> EncodeResult<()>

write a u32

source

pub fn write_u128(&mut self, data: u128) -> EncodeResult<()>

write a u128

source

pub fn write_u64(&mut self, data: u64) -> EncodeResult<()>

write a u64

source

pub fn write_i32(&mut self, data: i32) -> EncodeResult<()>

write a i32

source

pub fn write_fill_bytes( &mut self, bytes: &[u8], fill_len: usize ) -> EncodeResult<()>

Writes bytes to buffer and pads with 0 bytes up to some fill_len

Returns Err - if bytes.len() is greater then fill_len

source

pub fn write_fill<T: AsRef<[u8]>>( &mut self, s: &Option<T>, fill_len: usize ) -> EncodeResult<()>

Writes value to buffer and pads with 0 bytes up to some fill_len if String is None then write fill_len 0 bytes

Returns Err - if bytes.len() is greater then fill_len

Trait Implementations§

source§

impl<'a> Debug for Encoder<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Encoder<'a>

§

impl<'a> Send for Encoder<'a>

§

impl<'a> Sync for Encoder<'a>

§

impl<'a> Unpin for Encoder<'a>

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more