1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::lib::Vec;
use crate::Result;
use serde::{de::DeserializeOwned, Serialize};
pub type Encoded = Vec<u8>;
pub trait Message: Serialize + DeserializeOwned + Send + 'static {
fn encode(&self) -> Result<Encoded> {
Ok(bincode::serialize(self)?)
}
#[allow(clippy::ptr_arg)]
fn decode(e: &Encoded) -> Result<Self> {
Ok(bincode::deserialize(e)?)
}
}
impl<T> Message for T where T: Serialize + DeserializeOwned + Send + 'static {}
impl From<bincode::Error> for crate::Error {
fn from(_: bincode::Error) -> Self {
Self::new(1, "bincode")
}
}