Skip to main content

Encoder

Struct Encoder 

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

A generic encoder that serializes different primitive types and collections into a byte buffer.

Implementations§

Source§

impl Encoder

Source

pub fn new() -> Self

Creates a new, empty Encoder.

Source

pub fn push_u8(&mut self, v: u8) -> AzUtilResult<()>

Appends a single u8 value to the buffer.

Source

pub fn push_raw_bytes(&mut self, bytes: Vec<u8>) -> AzUtilResult<()>

Encodes raw bytes by prefixing them with their length and appending them to the buffer.

Source

pub fn push_u16(&mut self, v: u16) -> AzUtilResult<()>

Encodes a u16 value in big-endian format.

Source

pub fn push_u32(&mut self, v: u32) -> AzUtilResult<()>

Encodes a u32 value in big-endian format.

Source

pub fn push_u64(&mut self, v: u64) -> AzUtilResult<()>

Encodes a u64 value in big-endian format.

Source

pub fn push_i64(&mut self, v: i64) -> AzUtilResult<()>

Encodes an i64 value in big-endian format.

Source

pub fn push_usize(&mut self, v: usize) -> AzUtilResult<()>

Encodes a usize value in big-endian format.

Source

pub fn push_opt<T>(&mut self, t: &Option<T>) -> AzUtilResult<()>
where T: Codec,

Encodes an Option<T> by writing a presence flag (1 or 0) followed by the value if present.

Source

pub fn push_slice<T>(&mut self, slice: &[T]) -> AzUtilResult<()>
where T: Codec,

Encodes a slice of T values by prefixing its length and encoding each element.

Source

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

Encodes a vector of T values, prefixing each element with its size before encoding it.

Source

pub fn push_string(&mut self, s: &String) -> AzUtilResult<()>

Encodes a UTF-8 string, prefixing it with its length before writing its bytes.

Source

pub fn push_bool(&mut self, b: bool) -> AzUtilResult<()>

Encodes a boolean value as 1 (true) or 0 (false).

Source

pub fn push_i8(&mut self, v: i8) -> AzUtilResult<()>

Encodes an i8 value as a single byte.

Source

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

Consumes the encoder and returns the encoded byte buffer.

Trait Implementations§

Source§

impl Clone for Encoder

Source§

fn clone(&self) -> Encoder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Encoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.