feat: Introduce shared codec lib (#71)

closes #65
This commit is contained in:
Santiago Carmuega 2022-03-13 09:37:08 -03:00 committed by GitHub
parent 7fe00c6e22
commit 43c3cbd457
33 changed files with 402 additions and 450 deletions

View file

@ -1,5 +1,7 @@
pub type Error = Box<dyn std::error::Error>;
use pallas_codec::minicbor::{decode, to_vec, Decode, Encode};
pub trait Fragment<'a>
where
Self: Sized,
@ -10,14 +12,14 @@ where
impl<'a, T> Fragment<'a> for T
where
T: minicbor::Encode + minicbor::Decode<'a> + Sized,
T: Encode + Decode<'a> + Sized,
{
fn encode_fragment(&self) -> Result<Vec<u8>, Error> {
minicbor::to_vec(self).map_err(|e| e.into())
to_vec(self).map_err(|e| e.into())
}
fn decode_fragment(bytes: &'a [u8]) -> Result<Self, Error> {
minicbor::decode(bytes).map_err(|e| e.into())
decode(bytes).map_err(|e| e.into())
}
}