use crate::network::swarm::RequestResponseKey;
use anyhow::Result;
use serde::{Deserialize, Serialize};
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
pub(crate) enum RequestResponseError {
#[error("failed to retrieve data keyed by cid {}, tagged with {:?}, within timeout", .0.cid, .0.capsule_tag.tag())]
Timeout(RequestResponseKey),
#[error("failed to wrap {} into a Ipld capsule, tagged with {:?}", .0.cid, .0.capsule_tag.tag())]
InvalidCapsule(RequestResponseKey),
#[error("unsupported message request for tag {:?}, with cid {}", .0.capsule_tag.tag(), .0.cid)]
Unsupported(RequestResponseKey),
}
impl RequestResponseError {
pub(crate) fn encode(&self) -> Result<Vec<u8>> {
serde_ipld_dagcbor::to_vec(self).map_err(anyhow::Error::new)
}
pub(crate) fn decode(bytes: &[u8]) -> Result<(Self, usize)> {
serde_ipld_dagcbor::from_slice(bytes).map_err(anyhow::Error::new)
}
}