pub struct Deserializer<'data> { /* private fields */ }
Expand description

Deserializer referring an existing u8 buffer

Implementations§

Create a new Deserializer referring the supplied u8 buffer

Get current byte position of the reader

Get amount of bytes remaining for consumption

Advance the reader by offset bytes

Examples found in repository?
src/lib.rs (line 122)
120
121
122
123
124
    pub fn try_align(&mut self, align: usize) -> Result<()> {
        let offset = self.cursor % align;
        self.try_offset(offset)?;
        Ok(())
    }

Advance the cursor to ensure that current cursor position is 32-bit aligned

Advance the cursor to ensure that current cursor position is 64-bit aligned

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)?;
Examples found in repository?
src/lib.rs (line 105)
104
105
106
107
108
109
110
111
112
113
    pub fn try_align_u32(&mut self) -> Result<()> {
        self.try_align(4)?;
        Ok(())
    }
    
    /// Advance the cursor to ensure that current cursor position is 64-bit aligned
    pub fn try_align_u64(&mut self) -> Result<()> {
        self.try_align(8)?;
        Ok(())
    }

Set the cursor byte position to the given cursor value

Try reading Vec<u8> buffer of the supplied len byte length.

Try reading Vec<u16> array of the supplied len elements. The u16 values are read as little-endian values.

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.

Load a u8 value

Try load a u8 value

Load a u16 little-endian value

Try load a u16 little-endian value

Examples found in repository?
src/lib.rs (line 152)
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)?)
    }

Load a u32 little-endian value

Try load a u32 little-endian value

Load a u64 little-endian value

Try load a u64 little-endian value

Load a primitive implementing a Deserialize trait

Try load a primitive implementing a Deserialize trait

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.