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
impl Encoder
Sourcepub fn push_u8(&mut self, v: u8) -> AzUtilResult<()>
pub fn push_u8(&mut self, v: u8) -> AzUtilResult<()>
Appends a single u8 value to the buffer.
Sourcepub fn push_raw_bytes(&mut self, bytes: Vec<u8>) -> AzUtilResult<()>
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.
Sourcepub fn push_u16(&mut self, v: u16) -> AzUtilResult<()>
pub fn push_u16(&mut self, v: u16) -> AzUtilResult<()>
Encodes a u16 value in big-endian format.
Sourcepub fn push_u32(&mut self, v: u32) -> AzUtilResult<()>
pub fn push_u32(&mut self, v: u32) -> AzUtilResult<()>
Encodes a u32 value in big-endian format.
Sourcepub fn push_u64(&mut self, v: u64) -> AzUtilResult<()>
pub fn push_u64(&mut self, v: u64) -> AzUtilResult<()>
Encodes a u64 value in big-endian format.
Sourcepub fn push_i64(&mut self, v: i64) -> AzUtilResult<()>
pub fn push_i64(&mut self, v: i64) -> AzUtilResult<()>
Encodes an i64 value in big-endian format.
Sourcepub fn push_usize(&mut self, v: usize) -> AzUtilResult<()>
pub fn push_usize(&mut self, v: usize) -> AzUtilResult<()>
Encodes a usize value in big-endian format.
Sourcepub fn push_opt<T>(&mut self, t: &Option<T>) -> AzUtilResult<()>where
T: Codec,
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.
Sourcepub fn push_slice<T>(&mut self, slice: &[T]) -> AzUtilResult<()>where
T: Codec,
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.
Sourcepub fn push_vec<T>(&mut self, vec: Vec<T>) -> AzUtilResult<()>
pub fn push_vec<T>(&mut self, vec: Vec<T>) -> AzUtilResult<()>
Encodes a vector of T values, prefixing each element with its size before encoding it.
Sourcepub fn push_string(&mut self, s: &String) -> AzUtilResult<()>
pub fn push_string(&mut self, s: &String) -> AzUtilResult<()>
Encodes a UTF-8 string, prefixing it with its length before writing its bytes.
Sourcepub fn push_bool(&mut self, b: bool) -> AzUtilResult<()>
pub fn push_bool(&mut self, b: bool) -> AzUtilResult<()>
Encodes a boolean value as 1 (true) or 0 (false).
Sourcepub fn push_i8(&mut self, v: i8) -> AzUtilResult<()>
pub fn push_i8(&mut self, v: i8) -> AzUtilResult<()>
Encodes an i8 value as a single byte.
Sourcepub fn into_inner(self) -> Vec<u8>
pub fn into_inner(self) -> Vec<u8>
Consumes the encoder and returns the encoded byte buffer.