pub trait SimpleDataSerializer {
// Required methods
fn write(&mut self, v: &[u8]) -> Result<()>;
fn write_u8(&mut self, v: u8) -> Result<()>;
// Provided methods
fn write_u16(&mut self, v: u16) -> Result<()> { ... }
fn write_u32(&mut self, v: u32) -> Result<()> { ... }
fn write_u64(&mut self, v: u64) -> Result<()> { ... }
fn write_i8(&mut self, v: i8) -> Result<()> { ... }
fn write_i16(&mut self, v: i16) -> Result<()> { ... }
fn write_i32(&mut self, v: i32) -> Result<()> { ... }
fn write_i64(&mut self, v: i64) -> Result<()> { ... }
fn write_f32(&mut self, v: f32) -> Result<()> { ... }
fn write_f64(&mut self, v: f64) -> Result<()> { ... }
fn write_byte_array(&mut self, v: &[u8]) -> Result<()> { ... }
}
Expand description
This trait implements a simple serializer for basic data types.
It follows the format used by Java’s java.io.DataOutputStream
and write
all values using the big endian format.
This trait also allows the definition of a custom Result type thar will
allow its methods to be used with the operatior ?
.
Required Methods§
Provided Methods§
Sourcefn write_u16(&mut self, v: u16) -> Result<()>
fn write_u16(&mut self, v: u16) -> Result<()>
Writes an u16 value.
Arguments:
v
: The value to write;
Sourcefn write_u32(&mut self, v: u32) -> Result<()>
fn write_u32(&mut self, v: u32) -> Result<()>
Writes an u32 value.
Arguments:
v
: The value to write;
Sourcefn write_u64(&mut self, v: u64) -> Result<()>
fn write_u64(&mut self, v: u64) -> Result<()>
Writes an u64 value.
Arguments:
v
: The value to write;
Sourcefn write_i8(&mut self, v: i8) -> Result<()>
fn write_i8(&mut self, v: i8) -> Result<()>
Writes an i8 value.
Arguments:
v
: The value to write;
Sourcefn write_i16(&mut self, v: i16) -> Result<()>
fn write_i16(&mut self, v: i16) -> Result<()>
Writes an i16 value.
Arguments:
v
: The value to write;
Sourcefn write_i32(&mut self, v: i32) -> Result<()>
fn write_i32(&mut self, v: i32) -> Result<()>
Writes an i32 value.
Arguments:
v
: The value to write;
Sourcefn write_i64(&mut self, v: i64) -> Result<()>
fn write_i64(&mut self, v: i64) -> Result<()>
Writes an i64 value.
Arguments:
v
: The value to write;
Sourcefn write_f32(&mut self, v: f32) -> Result<()>
fn write_f32(&mut self, v: f32) -> Result<()>
Writes a f32 value.
Arguments:
v
: The value to write;
Sourcefn write_f64(&mut self, v: f64) -> Result<()>
fn write_f64(&mut self, v: f64) -> Result<()>
Writes a f64 value.
Arguments:
v
: The value to write;
Sourcefn write_byte_array(&mut self, v: &[u8]) -> Result<()>
fn write_byte_array(&mut self, v: &[u8]) -> Result<()>
Writes a byte array. The size of the byte array is encoded as an u16 value followed by the bytes of the array.
Arguments:
v
: The value to write;