pub struct Serializer<'a, W: Write> {
pub writer: &'a mut W,
pub file_version: u32,
}
Expand description
Object to which serialized data is to be written.
This is basically just a wrapped std::io::Write
object
and a file protocol version number.
In versions prior to 0.15, ‘Serializer’ did not accept a type parameter.
It now requires a type parameter with the type of writer to operate on.
Fields§
§writer: &'a mut W
The underlying writer. You should not access this.
file_version: u32
The version of the data structures which we are writing to disk. If this is < memory_version, we’re serializing into an older format. Serializing into a future format is logically impossible.
Implementations§
Source§impl<'a, W: Write + 'a> Serializer<'a, W>
impl<'a, W: Write + 'a> Serializer<'a, W>
Sourcepub fn write_bool(&mut self, v: bool) -> Result<(), SavefileError>
pub fn write_bool(&mut self, v: bool) -> Result<(), SavefileError>
Writes a binary bool to the output
Sourcepub fn write_u8(&mut self, v: u8) -> Result<(), SavefileError>
pub fn write_u8(&mut self, v: u8) -> Result<(), SavefileError>
Writes a binary u8 to the output
Sourcepub fn write_i8(&mut self, v: i8) -> Result<(), SavefileError>
pub fn write_i8(&mut self, v: i8) -> Result<(), SavefileError>
Writes a binary i8 to the output
Sourcepub fn write_u16(&mut self, v: u16) -> Result<(), SavefileError>
pub fn write_u16(&mut self, v: u16) -> Result<(), SavefileError>
Writes a binary little endian u16 to the output
Sourcepub fn write_i16(&mut self, v: i16) -> Result<(), SavefileError>
pub fn write_i16(&mut self, v: i16) -> Result<(), SavefileError>
Writes a binary little endian i16 to the output
Sourcepub fn write_u32(&mut self, v: u32) -> Result<(), SavefileError>
pub fn write_u32(&mut self, v: u32) -> Result<(), SavefileError>
Writes a binary little endian u32 to the output
Sourcepub fn write_i32(&mut self, v: i32) -> Result<(), SavefileError>
pub fn write_i32(&mut self, v: i32) -> Result<(), SavefileError>
Writes a binary little endian i32 to the output
Sourcepub fn write_f32(&mut self, v: f32) -> Result<(), SavefileError>
pub fn write_f32(&mut self, v: f32) -> Result<(), SavefileError>
Writes a binary little endian f32 to the output
Sourcepub fn write_f64(&mut self, v: f64) -> Result<(), SavefileError>
pub fn write_f64(&mut self, v: f64) -> Result<(), SavefileError>
Writes a binary little endian f64 to the output
Sourcepub fn write_u64(&mut self, v: u64) -> Result<(), SavefileError>
pub fn write_u64(&mut self, v: u64) -> Result<(), SavefileError>
Writes a binary little endian u64 to the output
Sourcepub unsafe fn write_raw_ptr<T: ?Sized>(
&mut self,
data: *const T,
) -> Result<(), SavefileError>
pub unsafe fn write_raw_ptr<T: ?Sized>( &mut self, data: *const T, ) -> Result<(), SavefileError>
Serialize the bytes of the pointer itself
§Safety
This method does not actually have any safety invariants. However, any realistic use case will involve a subsequent read_raw_ptr, and for that to have any chance of being sound, this call must have used a pointer to a valid T, or a null ptr.
Sourcepub unsafe fn write_raw_ptr_size<T>(
&mut self,
data: *const T,
len: usize,
) -> Result<(), SavefileError>
pub unsafe fn write_raw_ptr_size<T>( &mut self, data: *const T, len: usize, ) -> Result<(), SavefileError>
Write a ptr + size
Sourcepub fn write_ptr(&mut self, v: *const ()) -> Result<(), SavefileError>
pub fn write_ptr(&mut self, v: *const ()) -> Result<(), SavefileError>
Writes a binary little endian u64 to the output
Sourcepub fn write_i64(&mut self, v: i64) -> Result<(), SavefileError>
pub fn write_i64(&mut self, v: i64) -> Result<(), SavefileError>
Writes a binary little endian i64 to the output
Sourcepub fn write_u128(&mut self, v: u128) -> Result<(), SavefileError>
pub fn write_u128(&mut self, v: u128) -> Result<(), SavefileError>
Writes a binary little endian u128 to the output
Sourcepub fn write_i128(&mut self, v: i128) -> Result<(), SavefileError>
pub fn write_i128(&mut self, v: i128) -> Result<(), SavefileError>
Writes a binary little endian i128 to the output
Sourcepub fn write_usize(&mut self, v: usize) -> Result<(), SavefileError>
pub fn write_usize(&mut self, v: usize) -> Result<(), SavefileError>
Writes a binary little endian usize as u64 to the output
Sourcepub fn write_isize(&mut self, v: isize) -> Result<(), SavefileError>
pub fn write_isize(&mut self, v: isize) -> Result<(), SavefileError>
Writes a binary little endian isize as i64 to the output
Sourcepub fn write_buf(&mut self, v: &[u8]) -> Result<(), SavefileError>
pub fn write_buf(&mut self, v: &[u8]) -> Result<(), SavefileError>
Writes a binary u8 array to the output
Sourcepub fn write_string(&mut self, v: &str) -> Result<(), SavefileError>
pub fn write_string(&mut self, v: &str) -> Result<(), SavefileError>
Writes as a string as 64 bit length + utf8 data
Sourcepub fn write_bytes(&mut self, v: &[u8]) -> Result<(), SavefileError>
pub fn write_bytes(&mut self, v: &[u8]) -> Result<(), SavefileError>
Writes a binary u8 array to the output. Synonym of write_buf.
Sourcepub fn save<T: WithSchema + Serialize>(
writer: &mut W,
version: u32,
data: &T,
with_compression: bool,
) -> Result<(), SavefileError>
pub fn save<T: WithSchema + Serialize>( writer: &mut W, version: u32, data: &T, with_compression: bool, ) -> Result<(), SavefileError>
Creata a new serializer. Don’t use this function directly, use the crate::save function instead.
Sourcepub fn save_noschema<T: Serialize>(
writer: &mut W,
version: u32,
data: &T,
) -> Result<(), SavefileError>
pub fn save_noschema<T: Serialize>( writer: &mut W, version: u32, data: &T, ) -> Result<(), SavefileError>
Creata a new serializer. Don’t use this function directly, use the crate::save_noschema function instead.
Sourcepub fn bare_serialize<T: Serialize>(
writer: &mut W,
file_version: u32,
data: &T,
) -> Result<(), SavefileError>
pub fn bare_serialize<T: Serialize>( writer: &mut W, file_version: u32, data: &T, ) -> Result<(), SavefileError>
Serialize without any header. Using this means that bare_deserialize must be used to deserialize. No metadata is sent, not even version.
Sourcepub fn new_raw(
writer: &mut impl Write,
file_version: u32,
) -> Serializer<'_, impl Write>
pub fn new_raw( writer: &mut impl Write, file_version: u32, ) -> Serializer<'_, impl Write>
Create a Serializer. Don’t use this method directly, use the crate::save function instead.