Struct manual_serializer::Deserializer
source · pub struct Deserializer<'data> { /* private fields */ }
Expand description
Deserializer referring an existing u8
buffer
Implementations§
source§impl<'data> Deserializer<'data>
impl<'data> Deserializer<'data>
sourcepub fn new(data: &'data [u8]) -> Deserializer<'data>
pub fn new(data: &'data [u8]) -> Deserializer<'data>
Create a new Deserializer
referring the supplied u8
buffer
sourcepub fn try_offset(&mut self, offset: usize) -> Result<()>
pub fn try_offset(&mut self, offset: usize) -> Result<()>
Advance the reader by offset
bytes
sourcepub fn try_align_u32(&mut self) -> Result<()>
pub fn try_align_u32(&mut self) -> Result<()>
Advance the cursor to ensure that current cursor position is 32-bit aligned
sourcepub fn try_align_u64(&mut self) -> Result<()>
pub fn try_align_u64(&mut self) -> Result<()>
Advance the cursor to ensure that current cursor position is 64-bit aligned
sourcepub fn try_align(&mut self, align: usize) -> Result<()>
pub fn try_align(&mut self, align: usize) -> Result<()>
Advance the cursor to ensure its alignment is on the align
byte boundary.
The following ensures that the cursor is on a 128-bit alignment:
deser.try_align(16)?;
sourcepub fn try_set_cursor(&mut self, cursor: usize) -> Result<()>
pub fn try_set_cursor(&mut self, cursor: usize) -> Result<()>
Set the cursor byte position to the given cursor
value
sourcepub fn try_load_u8_vec(&mut self, len: usize) -> Result<Vec<u8>>
pub fn try_load_u8_vec(&mut self, len: usize) -> Result<Vec<u8>>
Try reading Vec<u8>
buffer of the supplied len
byte length.
sourcepub fn try_load_u16le_vec(&mut self, len: usize) -> Result<Vec<u16>>
pub fn try_load_u16le_vec(&mut self, len: usize) -> Result<Vec<u16>>
Try reading Vec<u16>
array of the supplied len
elements.
The u16
values are read as little-endian values.
sourcepub fn try_load_utf16le_sz(&mut self) -> Result<String>
pub fn try_load_utf16le_sz(&mut self) -> Result<String>
Try reading an array of u16
little-endian values from a
zero-terminated u16
array and return it as a Rust String
.
This function is useful for reading windows PCWSTR
zero-terminated
strings into Rust strings.
sourcepub fn try_load_u8(&mut self) -> Result<u8>
pub fn try_load_u8(&mut self) -> Result<u8>
Try load a u8 value
sourcepub fn load_u16le(&mut self) -> u16
pub fn load_u16le(&mut self) -> u16
Load a u16 little-endian value
sourcepub fn try_load_u16le(&mut self) -> Result<u16>
pub fn try_load_u16le(&mut self) -> Result<u16>
Try load a u16 little-endian value
Examples found in repository?
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
pub fn try_load_u16le_vec(&mut self, len: usize) -> Result<Vec<u16>> {
let mut vec: Vec<u16> = Vec::with_capacity(len);
for _ in 0..len {
vec.push(self.try_load_u16le()?)
}
Ok(vec)
}
/// Try reading an array of `u16` little-endian values from a
/// zero-terminated `u16` array and return it as a Rust `String`.
/// This function is useful for reading windows `PCWSTR` zero-terminated
/// strings into Rust strings.
pub fn try_load_utf16le_sz(&mut self) -> Result<String> {
let mut vec: Vec<u16> = Vec::new();
loop {
let v = self.try_load_u16le()?;
if v == 0 {
break;
}
vec.push(v);
}
Ok(String::from_utf16(&vec)?)
}
sourcepub fn load_u32le(&mut self) -> u32
pub fn load_u32le(&mut self) -> u32
Load a u32 little-endian value
sourcepub fn try_load_u32le(&mut self) -> Result<u32>
pub fn try_load_u32le(&mut self) -> Result<u32>
Try load a u32 little-endian value
sourcepub fn load_u64le(&mut self) -> u64
pub fn load_u64le(&mut self) -> u64
Load a u64 little-endian value
sourcepub fn try_load_u64le(&mut self) -> Result<u64>
pub fn try_load_u64le(&mut self) -> Result<u64>
Try load a u64 little-endian value
sourcepub fn load<S: Deserialize>(&mut self) -> S
pub fn load<S: Deserialize>(&mut self) -> S
Load a primitive implementing a Deserialize
trait
sourcepub fn try_load<S: TryDeserialize>(&mut self) -> Result<S, S::Error>
pub fn try_load<S: TryDeserialize>(&mut self) -> Result<S, S::Error>
Try load a primitive implementing a Deserialize
trait