Struct savefile::Serializer
source · pub struct Serializer<'a, W: Write> {
pub writer: &'a mut W,
pub 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.
version: u32
The version of the data structures in memory which are being serialized.
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 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: WithSchema + Serialize>(
writer: &mut W,
version: u32,
data: &T
) -> Result<(), SavefileError>
pub fn save_noschema<T: WithSchema + 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 new_raw(writer: &mut impl Write) -> Serializer<'_, impl Write>
pub fn new_raw(writer: &mut impl Write) -> Serializer<'_, impl Write>
Create a Serializer. Don’t use this method directly, use the crate::save function instead.