Trait request_response::Serializable

source ·
pub trait Serializable: Sized {
    // Required methods
    fn to_bytes(&self) -> Result<Vec<u8>>;
    fn from_bytes(bytes: &[u8]) -> Result<Self>;
}
Expand description

A trait for serializing and deserializing a type to and from a byte array. Request types and Response types will need to implement this trait

Required Methods§

source

fn to_bytes(&self) -> Result<Vec<u8>>

Serialize the type to a byte array. If this is for a Request and your Request type is represented as an enum, please make sure that you serialize it with a unique type ID. Otherwise, you may end up with collisions as the request hash is used as a unique identifier

§Errors
  • If the type cannot be serialized to a byte array
source

fn from_bytes(bytes: &[u8]) -> Result<Self>

Deserialize the type from a byte array

§Errors
  • If the byte array is not a valid representation of the type

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<R: Request> Serializable for ResponseMessage<R>

source§

impl<R: Request, K: SignatureKey> Serializable for Message<R, K>

A blanket implementation of the Serializable trait for any Message

source§

impl<R: Request, K: SignatureKey> Serializable for RequestMessage<R, K>