Struct dhcproto::decoder::Decoder

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

Decoder type. Wraps a buffer which only contains bytes that have not been read yet

Implementations§

source§

impl<'a> Decoder<'a>

source

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

Create a new Decoder

source

pub fn peek_u8(&self) -> DecodeResult<u8>

peek at the next byte without advancing the internal pointer

source

pub fn read_u8(&mut self) -> DecodeResult<u8>

read a u8

source

pub fn read_u32(&mut self) -> DecodeResult<u32>

read a u32

source

pub fn read_i32(&mut self) -> DecodeResult<i32>

read a i32

source

pub fn read_u16(&mut self) -> DecodeResult<u16>

read a u16

source

pub fn read_u64(&mut self) -> DecodeResult<u64>

read a u64

source

pub fn read<const N: usize>(&mut self) -> DecodeResult<[u8; N]>

read a N bytes into slice

source

pub fn peek<const N: usize>(&self) -> DecodeResult<[u8; N]>

peek a N bytes into slice

source

pub fn read_cstring<const MAX: usize>( &mut self ) -> DecodeResult<Option<CString>>

read a MAX length bytes into nul terminated CString

source

pub fn read_nul_bytes<const MAX: usize>( &mut self ) -> DecodeResult<Option<Vec<u8>>>

source

pub fn read_nul_string<const MAX: usize>( &mut self ) -> DecodeResult<Option<String>>

read MAX length bytes and read into utf-8 encoded String

source

pub fn read_slice(&mut self, len: usize) -> DecodeResult<&'a [u8]>

read a slice of bytes determined at runtime

source

pub fn read_string(&mut self, len: usize) -> DecodeResult<String>

Read a utf-8 encoded String

source

pub fn read_str(&mut self, len: usize) -> DecodeResult<&str>

Read a utf-8 encoded String

source

pub fn read_ipv4(&mut self, length: usize) -> DecodeResult<Ipv4Addr>

Read an ipv4 addr

source

pub fn read_ipv4s(&mut self, length: usize) -> DecodeResult<Vec<Ipv4Addr>>

Read a list of ipv4 addrs

source

pub fn read_ipv6s(&mut self, length: usize) -> DecodeResult<Vec<Ipv6Addr>>

Read a list of ipv6 addrs

source

pub fn read_pair_ipv4s( &mut self, length: usize ) -> DecodeResult<Vec<(Ipv4Addr, Ipv4Addr)>>

Read a list of ipv4 pairs

source

pub fn read_domains(&mut self, length: usize) -> DecodeResult<Vec<Name>>

Read a list of domain Names

source

pub fn read_bool(&mut self) -> DecodeResult<bool>

Read a bool

source

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

return slice of buffer start at index of unread data

Trait Implementations§

source§

impl<'a> Debug for Decoder<'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 Decoder<'a>

§

impl<'a> Send for Decoder<'a>

§

impl<'a> Sync for Decoder<'a>

§

impl<'a> Unpin for Decoder<'a>

§

impl<'a> UnwindSafe for Decoder<'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