pub trait ByteFmt: Sized {
// Required methods
fn decode(bytes: &[u8]) -> Result<Self>;
fn encode(&self) -> Vec<u8>;
}
Expand description
Trait converting a type from/to a sparse byte format. It is roughly equivalent to serde::Serialize + serde::Deserialize, but has additional requirements:
- binary encoding should be well defined, rather than rely on the internals of the serde::Serializer implementation.
- encoding should support backward-compatibility. It will be used in building
network messages, which might get signed. Note that for signing it is nice to have
encoding uniqueness (i.e.
decode(b).encode()==b
). However it not strictly necessary, because reencoding might be avoided.
Required Methods§
Object Safety§
This trait is not object safe.