pub trait Value<'a> {
// Required methods
fn serialize_into(
&self,
buffer: &mut [u8],
) -> Result<usize, SerializationError>;
fn deserialize_from(buffer: &'a [u8]) -> Result<Self, SerializationError>
where Self: Sized;
}
Expand description
The trait that defines how map values are serialized and deserialized.
It also carries a lifetime so that zero-copy deserialization is supported. Zero-copy serialization is not supported due to technical restrictions.
Required Methods§
Sourcefn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, SerializationError>
fn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, SerializationError>
Serialize the value into the given buffer. If everything went ok, this function returns the length of the used part of the buffer.
Sourcefn deserialize_from(buffer: &'a [u8]) -> Result<Self, SerializationError>where
Self: Sized,
fn deserialize_from(buffer: &'a [u8]) -> Result<Self, SerializationError>where
Self: Sized,
Deserialize the value from the buffer. Because of the added lifetime, the implementation can borrow from the buffer which opens up some zero-copy possibilities.
The buffer will be the same length as the serialize function returned for this value. Though note that the length is written from flash, so bitflips can affect that (though the length is separately crc-protected) and the key deserialization might return a wrong length.