parent
7fe00c6e22
commit
43c3cbd457
33 changed files with 402 additions and 450 deletions
30
pallas-codec/src/lib.rs
Normal file
30
pallas-codec/src/lib.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use minicbor::encode::Write;
|
||||
|
||||
/// Shared re-export of minicbor lib across all Pallas
|
||||
pub use minicbor;
|
||||
|
||||
/// Round-trip friendly common helper structs
|
||||
pub mod utils;
|
||||
|
||||
pub trait Fragment: Sized {
|
||||
fn read_cbor(buffer: &[u8]) -> Result<Self, minicbor::decode::Error>;
|
||||
fn write_cbor<W: Write>(&self, write: W) -> Result<(), minicbor::encode::Error<W::Error>>;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_fragment {
|
||||
($Struct:ty) => {
|
||||
impl $crate::Fragment for $Struct {
|
||||
fn read_cbor(buffer: &[u8]) -> Result<Self, decode::Error> {
|
||||
$crate::minicbor::decode(buffer)
|
||||
}
|
||||
|
||||
fn write_cbor<W: encode::Write>(
|
||||
&self,
|
||||
write: W,
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
$crate::minicbor::encode(self, write)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue