use std::marker::PhantomData;
use serde::{Deserialize, Serialize};
use crate::error::BoxDynError;
pub trait Codec {
type Compact;
type Error: Into<BoxDynError>;
fn encode<I>(input: I) -> Result<Self::Compact, Self::Error>
where
I: Serialize;
fn decode<O>(input: Self::Compact) -> Result<O, Self::Error>
where
O: for<'de> Deserialize<'de>;
}
#[derive(Debug, Clone)]
pub struct NoopCodec<Compact> {
compact: PhantomData<Compact>,
}
impl<Compact> Codec for NoopCodec<Compact> {
type Compact = Compact;
type Error = BoxDynError;
fn decode<O>(_: Self::Compact) -> Result<O, Self::Error>
where
O: for<'de> Deserialize<'de>,
{
unreachable!("NoopCodec doesn't have decoding functionality")
}
fn encode<I>(_: I) -> Result<Self::Compact, Self::Error>
where
I: Serialize,
{
unreachable!("NoopCodec doesn't have decoding functionality")
}
}
#[cfg(feature = "json")]
pub mod json;