Skip to main content

Decoder

Struct Decoder 

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

A generic decoder that deserializes primitive types and collections from a byte slice.

Implementations§

Source§

impl<'a> Decoder<'a>

Source

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

Creates a new Decoder for the given byte buffer.

Source

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

Reads a single u8 from the buffer.

Source

pub fn read_usize(&mut self) -> AzUtilResult<usize>

Reads a usize in big-endian format.

Source

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

Reads a u16 (2 bytes) in big-endian format.

Source

pub fn read_vec<T>(&mut self) -> AzUtilResult<Vec<T>>
where T: Codec + Sized,

Reads a vector of elements of type T by reading its length and decoding each element.

Source

pub fn read_opt<T: Codec>(&mut self) -> AzUtilResult<Option<T>>

Reads an Option<T> by checking the presence flag and decoding the value if present.

Source

pub fn read_slice<T: Codec>(&mut self) -> AzUtilResult<Vec<T>>

Reads a slice of elements of type T as a vector.

Source

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

Reads a u32 (4 bytes) in big-endian format.

Source

pub fn read_i8(&mut self) -> AzUtilResult<i8>

Reads an i8 value.

Source

pub fn read_i64(&mut self) -> AzUtilResult<i64>

Reads an i64 (8 bytes) in big-endian format.

Source

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

Reads a u64 (8 bytes) in big-endian format.

Source

pub fn read_bytes(&mut self, size: u32) -> AzUtilResult<Vec<u8>>

Reads a sequence of bytes of the specified length.

Source

pub fn read_string(&mut self) -> AzUtilResult<String>

Reads a UTF-8 string prefixed with its length.

Source

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

Reads a boolean value (1 = true, 0 = false).

Auto Trait Implementations§

§

impl<'a> Freeze for Decoder<'a>

§

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

§

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