use crate::Error;
pub trait Format {
type Body: crate::Body;
fn encode_message<T: ToMessage<Self>>(value: &T) -> Result<(i32, Self::Body), Box<dyn std::error::Error + Send>> {
value.to_message()
}
fn decode_message<T: FromMessage<Self>>(message: crate::Message<Self::Body>) -> Result<T, Error> {
T::from_message(message)
}
}
pub trait EncodeBody<T: ?Sized>: Format {
fn encode_body(value: &T) -> Result<Self::Body, Box<dyn std::error::Error + Send>>;
}
pub trait DecodeBody<T: Sized>: Format {
fn decode_body(body: Self::Body) -> Result<T, Box<dyn std::error::Error + Send>>;
}
pub trait ToMessage<F: Format + ?Sized> {
fn to_message(&self) -> Result<(i32, F::Body), Box<dyn std::error::Error + Send>>;
}
pub trait FromMessage<F: Format + ?Sized>: Sized {
fn from_message(message: crate::Message<F::Body>) -> Result<Self, Error>;
}