#[derive(Debug, Clone, Copy)]
pub enum Cbor {}
#[cfg(feature = "minicbor")]
#[derive(Debug, Clone)]
pub struct CborEncodeError(alloc::string::String);
#[cfg(feature = "minicbor")]
impl core::fmt::Display for CborEncodeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "CBOR encode error: {}", self.0)
}
}
#[cfg(feature = "minicbor")]
impl<T: minicbor::Encode<()>> super::Encode<T> for Cbor {
type Error = CborEncodeError;
fn encode(value: &T) -> Result<alloc::vec::Vec<u8>, Self::Error> {
minicbor::to_vec(value).map_err(|e| CborEncodeError(alloc::string::ToString::to_string(&e)))
}
}
#[cfg(feature = "minicbor")]
#[derive(Debug, Clone)]
pub struct CborDecodeError(alloc::string::String);
#[cfg(feature = "minicbor")]
impl core::fmt::Display for CborDecodeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "CBOR decode error: {}", self.0)
}
}
#[cfg(feature = "minicbor")]
impl<T: for<'a> minicbor::Decode<'a, ()>> super::Decode<T> for Cbor {
type Error = CborDecodeError;
fn decode(bytes: &[u8]) -> Result<T, Self::Error> {
minicbor::decode(bytes).map_err(|e| CborDecodeError(alloc::string::ToString::to_string(&e)))
}
}