refactor(proto): start replacing anyhow with thiserror
This commit is contained in:
parent
dbd0ef3970
commit
bb39d138d8
8 changed files with 57 additions and 15 deletions
|
|
@ -1,9 +1,10 @@
|
|||
use crate::message::primitive::config::pg_proto_config;
|
||||
use bincode::{Decode, Encode};
|
||||
use crate::message::errors::{ProtoDeserializeError, ProtoSerializeError};
|
||||
|
||||
pub trait MessageData: Sized {
|
||||
fn deserialize(data: &[u8]) -> anyhow::Result<Self>;
|
||||
fn serialize(&self) -> anyhow::Result<Vec<u8>>;
|
||||
fn serialize(&self) -> Result<Vec<u8>, ProtoSerializeError>;
|
||||
fn deserialize(data: &[u8]) -> Result<Self, ProtoDeserializeError>;
|
||||
}
|
||||
|
||||
impl<T> MessageData for T
|
||||
|
|
@ -11,12 +12,12 @@ where
|
|||
T: Encode + Decode,
|
||||
{
|
||||
#[inline]
|
||||
fn deserialize(data: &[u8]) -> anyhow::Result<Self> {
|
||||
Ok(bincode::decode_from_slice(data, pg_proto_config())?.0)
|
||||
fn serialize(&self) -> Result<Vec<u8>, ProtoSerializeError> {
|
||||
Ok(bincode::encode_to_vec(self, pg_proto_config())?)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize(&self) -> anyhow::Result<Vec<u8>> {
|
||||
Ok(bincode::encode_to_vec(self, pg_proto_config())?)
|
||||
fn deserialize(data: &[u8]) -> Result<Self, ProtoDeserializeError> {
|
||||
Ok(bincode::decode_from_slice(data, pg_proto_config())?.0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue