pub trait Encode: Clone {
const SIZE: DataSize;
const ALIGNMENT: PageOffset;
// Required methods
fn encode(&self) -> Cow<'_, [u8]>;
fn decode(data: Cow<'_, [u8]>) -> MemoryResult<Self>
where Self: Sized;
fn size(&self) -> MSize;
}Expand description
This trait defines the encoding and decoding behaviour for data types used in the DBMS canister.
Required Associated Constants§
Sourceconst SIZE: DataSize
const SIZE: DataSize
The size characteristic of the data type.
The DataSize can either be a fixed size in bytes or dynamic.
Sourceconst ALIGNMENT: PageOffset
const ALIGNMENT: PageOffset
The alignment requirement in bytes for the data type.
If Self::SIZE is DataSize::Fixed, the alignment must be equal to the size,
otherwise it can be any value.
This value should never be less than 8 for DataSize::Dynamic types to ensure proper memory alignment.
We should set a default value (probably 32) for dynamic types to avoid misalignment issues, but letting an expert user to override it if necessary.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.