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
impl Serializer
Sourcepub fn new(len: usize) -> Serializer
pub fn new(len: usize) -> Serializer
Create a new Serializer
struct with len
byte buffer
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the current byte length of the ongoing serialization (cursor position)
Sourcepub fn as_slice<'slice>(&'slice self) -> &'slice [u8] ⓘ
pub fn as_slice<'slice>(&'slice self) -> &'slice [u8] ⓘ
Returns a slice &[u8]
of the currently serialized data
Sourcepub fn offset(&mut self, offset: usize) -> &mut Self
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.
Sourcepub fn try_offset(&mut self, offset: usize) -> Result<&mut Self>
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.
Sourcepub fn offset_with_zeros(&mut self, offset: usize) -> &mut Self
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.
Sourcepub fn try_offset_with_zeros(&mut self, offset: usize) -> Result<&mut Self>
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.
Sourcepub fn align_u32(&mut self) -> &mut Self
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.
Sourcepub fn try_align_u32(&mut self) -> Result<&mut Self>
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.
Sourcepub fn align_u64(&mut self) -> &mut Self
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.
Sourcepub fn try_align_u64(&mut self) -> Result<&mut Self>
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.
Sourcepub fn store_u8(&mut self, v: u8) -> &mut Self
pub fn store_u8(&mut self, v: u8) -> &mut Self
Store a single u8
value, advancing the cursor by 1 byte.
Sourcepub fn try_store_u8(&mut self, v: u8) -> Result<&mut Self>
pub fn try_store_u8(&mut self, v: u8) -> Result<&mut Self>
Try store a single u8
value, advancing the cursor by 1 byte.
Sourcepub fn store_u16le(&mut self, v: u16) -> &mut Self
pub fn store_u16le(&mut self, v: u16) -> &mut Self
Store a u16
value using little-endian encoding, advancing the cursor by 2 bytes.
Sourcepub fn try_store_u16le(&mut self, v: u16) -> Result<&mut Self>
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.
Sourcepub fn store_u32le(&mut self, v: u32) -> &mut Self
pub fn store_u32le(&mut self, v: u32) -> &mut Self
Store a u32
value using little-endian encoding, advancing the cursor by 4 bytes.
Sourcepub fn try_store_u32le(&mut self, v: u32) -> Result<&mut Self>
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.
Sourcepub fn store_u64le(&mut self, v: u64) -> &mut Self
pub fn store_u64le(&mut self, v: u64) -> &mut Self
Store a u64
value using little-endian encoding, advancing the cursor by 8 bytes.
Sourcepub fn try_store_u64le(&mut self, v: u64) -> Result<&mut Self>
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.
Sourcepub fn try_store_utf16le_sz(&mut self, text: &String) -> Result<&mut Self>
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.
Sourcepub fn try_store_u8_slice(&mut self, vec: &[u8]) -> Result<&mut Self>
pub fn try_store_u8_slice(&mut self, vec: &[u8]) -> Result<&mut Self>
Try to store a u8
slice
Sourcepub fn try_store_u16le_slice(&mut self, vec: &[u16]) -> Result<&mut Self>
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.
Sourcepub fn store<S: Serialize>(&mut self, s: &S) -> &mut Self
pub fn store<S: Serialize>(&mut self, s: &S) -> &mut Self
Store a primitive implementing a Serialize
trait
Sourcepub fn try_store<S: TrySerialize>(
&mut self,
s: &S,
) -> Result<&mut Self, S::Error>
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.
impl Default for Serializer
Default implementation for Serializer
that allocates 4096 byte buffer.