use cid::Cid;
use std::io::{BufRead, Write};
pub trait Codec<T>: Links {
const CODE: u64;
type Error;
fn decode<R: BufRead>(reader: R) -> Result<T, Self::Error>;
fn encode<W: Write>(writer: W, data: &T) -> Result<(), Self::Error>;
fn decode_from_slice(bytes: &[u8]) -> Result<T, Self::Error> {
Self::decode(bytes)
}
fn encode_to_vec(data: &T) -> Result<Vec<u8>, Self::Error> {
let mut output = Vec::new();
Self::encode(&mut output, data)?;
Ok(output)
}
}
pub trait Links {
type LinksError;
fn links(bytes: &[u8]) -> Result<impl Iterator<Item = Cid>, Self::LinksError>;
}