use crate::value::WireTypeId;
#[derive(Debug, thiserror::Error)]
pub enum CodecError {
#[error("unknown wire type id: {0}")]
UnknownTypeId(WireTypeId),
#[error(
"type mismatch for wire type id {expected}: value did not downcast to the registered type"
)]
TypeMismatch {
expected: WireTypeId,
},
#[error("encode failure: {0}")]
Encode(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("decode failure: {0}")]
Decode(#[source] Box<dyn std::error::Error + Send + Sync>),
}
impl CodecError {
pub fn encode_failure<E>(err: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::Encode(err.into())
}
pub fn decode_failure<E>(err: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::Decode(err.into())
}
}