Struct savefile::Deserializer

source ·
pub struct Deserializer<'a, R: Read> {
    pub reader: &'a mut R,
    pub file_version: u32,
    pub ephemeral_state: HashMap<TypeId, Box<dyn Any>>,
}
Expand description

Object from which bytes to be deserialized are read. This is basically just a wrapped std::io::Read object, the version number of the file being read, and the current version number of the data structures in memory.

Fields§

§reader: &'a mut R

The wrapped reader

§file_version: u32

The version of the input file

§ephemeral_state: HashMap<TypeId, Box<dyn Any>>

This contains ephemeral state that can be used to implement de-duplication of strings or possibly other situations where it is desired to deserialize DAGs.

Implementations§

source§

impl<'a, TR: Read> Deserializer<'a, TR>

source

pub fn get_state<T: 'static, R: Default + 'static>(&mut self) -> &mut R

This function constructs a temporary state object of type R, and returns a mutable reference to it. This object can be used to store data that needs to live for the entire deserialization session. An example is de-duplicating Arc and other reference counted objects. Out of the box, Arc<str> has this deduplication done for it. The type T must be set to the type being deserialized, and is used as a key in a hashmap separating the state for different types.

source§

impl<'a, TR: Read> Deserializer<'a, TR>

source

pub fn read_bool(&mut self) -> Result<bool, SavefileError>

Reads a u8 and return true if equal to 1

source

pub fn read_u8(&mut self) -> Result<u8, SavefileError>

Reads an u8

source

pub fn read_u16(&mut self) -> Result<u16, SavefileError>

Reads a little endian u16

source

pub fn read_u32(&mut self) -> Result<u32, SavefileError>

Reads a little endian u32

source

pub fn read_u64(&mut self) -> Result<u64, SavefileError>

Reads a little endian u64

source

pub unsafe fn read_raw_ptr<T: ?Sized>( &mut self ) -> Result<*const T, SavefileError>

Reads the raw bit pattern of a pointer

§Safety

The stream must contain a valid pointer to T.

source

pub unsafe fn read_raw_ptr_mut<T: ?Sized>( &mut self ) -> Result<*mut T, SavefileError>

Reads the raw bit pattern of a pointer

§Safety

The stream must contain a valid pointer to T.

source

pub fn read_ptr(&mut self) -> Result<*const (), SavefileError>

Reads a pointer

source

pub fn read_u128(&mut self) -> Result<u128, SavefileError>

Reads a little endian u128

source

pub fn read_i8(&mut self) -> Result<i8, SavefileError>

Reads an i8

source

pub fn read_i16(&mut self) -> Result<i16, SavefileError>

Reads a little endian i16

source

pub fn read_i32(&mut self) -> Result<i32, SavefileError>

Reads a little endian i32

source

pub fn read_i64(&mut self) -> Result<i64, SavefileError>

Reads a little endian i64

source

pub fn read_i128(&mut self) -> Result<i128, SavefileError>

Reads a little endian i128

source

pub fn read_f32(&mut self) -> Result<f32, SavefileError>

Reads a little endian f32

source

pub fn read_f64(&mut self) -> Result<f64, SavefileError>

Reads a little endian f64

source

pub fn read_isize(&mut self) -> Result<isize, SavefileError>

Reads an i64 into an isize. For 32 bit architectures, the function fails on overflow.

source

pub fn read_usize(&mut self) -> Result<usize, SavefileError>

Reads an u64 into an usize. For 32 bit architectures, the function fails on overflow.

source

pub fn read_string(&mut self) -> Result<String, SavefileError>

Reads a 64 bit length followed by an utf8 encoded string. Fails if data is not valid utf8

source

pub fn read_bytes(&mut self, len: usize) -> Result<Vec<u8>, SavefileError>

Reads ‘len’ raw u8 bytes as a Vec<u8>

source

pub fn read_bytes_to_buf(&mut self, buf: &mut [u8]) -> Result<(), SavefileError>

Reads raw u8 bytes into the given buffer. The buffer size must be equal to the number of bytes desired to be read.

source

pub fn load<T: WithSchema + Deserialize>( reader: &mut TR, version: u32 ) -> Result<T, SavefileError>

Deserialize an object of type T from the given reader. Don’t use this method directly, use the crate::load function instead.

source

pub fn load_noschema<T: Deserialize>( reader: &mut TR, version: u32 ) -> Result<T, SavefileError>

Deserialize an object of type T from the given reader. Don’t use this method directly, use the crate::load_noschema function instead.

source

pub fn bare_deserialize<T: Deserialize>( reader: &mut TR, file_version: u32 ) -> Result<T, SavefileError>

Deserialize data which was serialized using ‘bare_serialize’

Auto Trait Implementations§

§

impl<'a, R> Freeze for Deserializer<'a, R>

§

impl<'a, R> !RefUnwindSafe for Deserializer<'a, R>

§

impl<'a, R> !Send for Deserializer<'a, R>

§

impl<'a, R> !Sync for Deserializer<'a, R>

§

impl<'a, R> Unpin for Deserializer<'a, R>

§

impl<'a, R> !UnwindSafe for Deserializer<'a, R>

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

§

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

§

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.