1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use anyhow::Error; use meio_protocol::{ProtocolCodec, ProtocolData}; // TODO: Consider to move it to `meio-protocol` pub struct JsonCodec; impl ProtocolCodec for JsonCodec { fn decode<T: ProtocolData>(data: &[u8]) -> Result<T, Error> { serde_json::from_slice(data).map_err(Error::from) } fn encode<T: ProtocolData>(value: &T) -> Result<Vec<u8>, Error> { serde_json::to_vec(value).map_err(Error::from) } }