Trait sequential_storage::StorageItem
source · pub trait StorageItem {
type Key: Eq;
type Error: StorageItemError;
fn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, Self::Error>;
fn deserialize_from(buffer: &[u8]) -> Result<(Self, usize), Self::Error>
where
Self: Sized;
fn key(&self) -> Self::Key;
}
Expand description
A way of serializing and deserializing items in the storage.
A serialized byte pattern of all 0xFF
is invalid and must never be the result of the serialize_into
function
and deserialize_from
must always return an error for it.
The given buffer to serialize in and deserialize from is never bigger than MAX_STORAGE_ITEM_SIZE bytes, so make sure the item is smaller than that.
Required Associated Types§
sourcetype Error: StorageItemError
type Error: StorageItemError
The error type for serialization and deserialization
Required Methods§
sourcefn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, Self::Error>
fn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, Self::Error>
Serialize the key-value item into the given buffer. Returns the number of bytes the buffer was filled with or an error.
The serialized bytes must not all be 0xFF
. One way to prevent this is to serialize an extra 0 byte at the end if that is the case.