common/linked_data/
ipld.rs1pub use ipld_core::cid::multihash::Multihash;
2pub use ipld_core::cid::{multibase, Cid, Error as CidError};
3pub use ipld_core::codec::Codec;
4pub use ipld_core::ipld::Ipld as LinkedData;
5
6pub const LD_RAW_CODEC: u64 = 0x55;
8pub const LD_CBOR_CODEC: u64 = 0x71;
9
10pub const BLAKE3_HASH_CODE: u64 = 0x1e;
11
12#[derive(Debug, thiserror::Error)]
13pub enum CodecError {
14 #[error("encoding error")]
15 EncodeError,
16 #[error("decoding error")]
17 DecodeError,
18}
19
20pub trait BlockEncoded<C>: serde::Serialize + serde::de::DeserializeOwned
23where
24 C: Codec<Self>,
25{
26 fn encode(&self) -> Result<Vec<u8>, CodecError> {
27 C::encode_to_vec(self).map_err(|_| CodecError::EncodeError)
28 }
29 fn decode(data: &[u8]) -> Result<Self, CodecError> {
30 C::decode_from_slice(data).map_err(|_e| CodecError::DecodeError)
31 }
32 fn codec(&self) -> u64 {
33 C::CODE
34 }
35}