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
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>>;
}

impl<T> Fragment for T
where
    T: for<'b> minicbor::Decode<'b> + minicbor::Encode,
{
    fn read_cbor(buffer: &[u8]) -> Result<Self, minicbor::decode::Error> {
        minicbor::decode(buffer)
    }

    fn write_cbor<W: Write>(&self, write: W) -> Result<(), minicbor::encode::Error<W::Error>> {
        minicbor::encode(self, write)
    }
}