Trait scuttlebutt::serialization::CanonicalSerialize
source · [−]pub trait CanonicalSerialize: Copy + Serialize + DeserializeOwned {
type Serializer: SequenceSerializer<Self>;
type Deserializer: SequenceDeserializer<Self>;
type ByteReprLen: ArrayLength<u8>;
type FromBytesError: Error + Send + Sync + 'static;
fn from_bytes(
bytes: &GenericArray<u8, Self::ByteReprLen>
) -> Result<Self, Self::FromBytesError>;
fn to_bytes(&self) -> GenericArray<u8, Self::ByteReprLen>;
}
Expand description
Types that implement this trait have a canonical serialization and a fixed serialization size.
Required Associated Types
sourcetype Serializer: SequenceSerializer<Self>
type Serializer: SequenceSerializer<Self>
A way to serialize field elements of this type.
See SequenceSerializer
for more info.
sourcetype Deserializer: SequenceDeserializer<Self>
type Deserializer: SequenceDeserializer<Self>
A way to deserialize field elements of this type.
See SequenceSerializer
for more info.
sourcetype ByteReprLen: ArrayLength<u8>
type ByteReprLen: ArrayLength<u8>
The number of bytes in the byte representation for this element.
sourcetype FromBytesError: Error + Send + Sync + 'static
type FromBytesError: Error + Send + Sync + 'static
The error that can result from trying to decode an invalid byte sequence.
Required Methods
sourcefn from_bytes(
bytes: &GenericArray<u8, Self::ByteReprLen>
) -> Result<Self, Self::FromBytesError>
fn from_bytes(
bytes: &GenericArray<u8, Self::ByteReprLen>
) -> Result<Self, Self::FromBytesError>
Deserialize an element from a byte array.
NOTE: for security purposes, this function will accept exactly one byte sequence for each element.
sourcefn to_bytes(&self) -> GenericArray<u8, Self::ByteReprLen>
fn to_bytes(&self) -> GenericArray<u8, Self::ByteReprLen>
Serialize an element into a byte array.
Consider using Self::Serializer
if you need to serialize several field elements.