pub struct BinarySerdeBuf<'a> { /* private fields */ }Expand description
a binary serializer and deserializes which serializes and deserializes values to or from a buffer.
Implementations§
Source§impl<'a> BinarySerdeBuf<'a>
impl<'a> BinarySerdeBuf<'a>
Sourcepub fn new(buf: &'a mut [u8], endianness: Endianness) -> Self
pub fn new(buf: &'a mut [u8], endianness: Endianness) -> Self
creates a new binary serializer/deserializer which serializes/deserializer values to/from the given buffer using the given endianness.
Sourcepub fn serialize<T: BinarySerde>(&mut self, value: &T)
pub fn serialize<T: BinarySerde>(&mut self, value: &T)
serializes a value of type T into the current position in the buffer, and advances the position accordingly.
§Panics
this function panics if the serialization exceeds the bounds of the buffer.
Sourcepub fn consume_bytes(&mut self, amount: usize) -> &[u8]
pub fn consume_bytes(&mut self, amount: usize) -> &[u8]
consumes and returns the next amount bytes from the current position in the buffer, and advances the position accordingly.
§Panics
this function panics if the requested amount of bytes exceeds the bounds of the buffer.
Sourcepub fn deserialize<T: BinarySerde>(&mut self) -> Result<T, DeserializeError>
pub fn deserialize<T: BinarySerde>(&mut self) -> Result<T, DeserializeError>
deserializes a value of type T from the current position in the buffer, and advances the position accordingly.
§Panics
this function panics if the deserialization exceeds the bounds of the buffer.
Sourcepub fn position(&self) -> usize
pub fn position(&self) -> usize
returns the current position of this deserializer in the buffer.
Sourcepub fn set_position(&mut self, new_position: usize)
pub fn set_position(&mut self, new_position: usize)
sets the position of this deserializer in the buffer.
Sourcepub fn move_forwards(&mut self, amount: usize)
pub fn move_forwards(&mut self, amount: usize)
moves this deserializer’s position forwards according to the given amount.
Sourcepub fn move_backwards(&mut self, amount: usize)
pub fn move_backwards(&mut self, amount: usize)
moves this deserializer’s position backwards according to the given amount.
Sourcepub fn set_endianness(&mut self, new_endianness: Endianness)
pub fn set_endianness(&mut self, new_endianness: Endianness)
sets the endianness of this serializer/deserializer
Sourcepub fn endianness(&self) -> Endianness
pub fn endianness(&self) -> Endianness
returns the endianness of this serializer/deserializer.