Struct Serializer

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

Serializer struct containing a serialization buffer. Please note that this struct expects to have a sufficiently large buffer to perform the ongoing serialization.

Implementations§

Source§

impl Serializer

Source

pub fn new(len: usize) -> Serializer

Create a new Serializer struct with len byte buffer

Source

pub fn len(&self) -> usize

Returns the current byte length of the ongoing serialization (cursor position)

Source

pub fn to_vec(&self) -> Vec<u8>

Returns Vec<u8> of the currently serialized data

Source

pub fn as_slice<'slice>(&'slice self) -> &'slice [u8]

Returns a slice &[u8] of the currently serialized data

Source

pub fn offset(&mut self, offset: usize) -> &mut Self

Advance the cursor by offset bytes. Since the underlying buffer is zero-initialized, skipped bytes will remain as zero.

Source

pub fn try_offset(&mut self, offset: usize) -> Result<&mut Self>

Try advance the cursor by offset bytes. Since the underlying buffer is zero-initialized, skipped bytes will remain as zero.

Source

pub fn offset_with_zeros(&mut self, offset: usize) -> &mut Self

Advance the cursor by offset bytes while explicitly setting skipped bytes to zero. This can be useful if manually positioning cursor within the buffer and the repositioning can result in the buffer containing previously serialized data.

Source

pub fn try_offset_with_zeros(&mut self, offset: usize) -> Result<&mut Self>

Try advance the cursor by offset bytes while explicitly setting skipped bytes to zero. This can be useful if manually positioning cursor within the buffer and the repositioning can result in the buffer containing previously serialized data.

Source

pub fn align_u32(&mut self) -> &mut Self

Advance the cursor to ensure that the current cursor position is on the 32-bit alignment boundary.

Source

pub fn try_align_u32(&mut self) -> Result<&mut Self>

Try advance the cursor to ensure that the current cursor position is on the 32-bit alignment boundary.

Source

pub fn align_u64(&mut self) -> &mut Self

Advance the cursor to ensure that the current cursor position is on the 64-bit alignment boundary.

Source

pub fn try_align_u64(&mut self) -> Result<&mut Self>

Try advance the cursor to ensure that the current cursor position is on the 64-bit alignment boundary.

Source

pub fn store_u8(&mut self, v: u8) -> &mut Self

Store a single u8 value, advancing the cursor by 1 byte.

Source

pub fn try_store_u8(&mut self, v: u8) -> Result<&mut Self>

Try store a single u8 value, advancing the cursor by 1 byte.

Source

pub fn store_u16le(&mut self, v: u16) -> &mut Self

Store a u16 value using little-endian encoding, advancing the cursor by 2 bytes.

Source

pub fn try_store_u16le(&mut self, v: u16) -> Result<&mut Self>

Try to store a u16 value using little-endian encoding, advancing the cursor by 2 bytes.

Source

pub fn store_u32le(&mut self, v: u32) -> &mut Self

Store a u32 value using little-endian encoding, advancing the cursor by 4 bytes.

Source

pub fn try_store_u32le(&mut self, v: u32) -> Result<&mut Self>

Try to store a u32 value using little-endian encoding, advancing the cursor by 4 bytes.

Source

pub fn store_u64le(&mut self, v: u64) -> &mut Self

Store a u64 value using little-endian encoding, advancing the cursor by 8 bytes.

Source

pub fn try_store_u64le(&mut self, v: u64) -> Result<&mut Self>

Try to store a u64 value using little-endian encoding, advancing the cursor by 8 bytes.

Source

pub fn try_store_utf16le_sz(&mut self, text: &String) -> Result<&mut Self>

Try to store a Rust String as a zero-terminated sequence of u16 little-endian encoded bytes. This is useful to serialize windows PCWSTR zero-terminated strings.

Source

pub fn try_store_u8_slice(&mut self, vec: &[u8]) -> Result<&mut Self>

Try to store a u8 slice

Source

pub fn try_store_u16le_slice(&mut self, vec: &[u16]) -> Result<&mut Self>

Try to store a u16 slice as a sequence of little-endian encoded u16 values.

Source

pub fn store<S: Serialize>(&mut self, s: &S) -> &mut Self

Store a primitive implementing a Serialize trait

Source

pub fn try_store<S: TrySerialize>( &mut self, s: &S, ) -> Result<&mut Self, S::Error>

Try store a primitive implementing a TrySerialize trait

Trait Implementations§

Source§

impl Default for Serializer

Default implementation for Serializer that allocates 4096 byte buffer.

Source§

fn default() -> Serializer

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