macro_rules! register_handlers {
(
$(
$variant:ident($handler:ty)
),* $(,)?
) => {
use crate::peer::protocol::bidirectional::BidirectionalHandler as _;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum Message {
$(
#[doc = concat!("Message variant for ", stringify!($variant))]
$variant(<$handler as crate::peer::protocol::bidirectional::BidirectionalHandler>::Message),
)*
}
impl Message {
pub async fn dispatch<L>(
self,
peer: &crate::peer::Peer<L>,
sender_node_id: &crate::crypto::PublicKey,
send: iroh::endpoint::SendStream,
) -> Result<(), iroh::protocol::AcceptError>
where
L: crate::bucket_log::BucketLogProvider,
L::Error: std::error::Error + Send + Sync + 'static,
{
match self {
$(
Message::$variant(message) => {
tracing::debug!(concat!("Dispatching ", stringify!($variant), " message"));
<$handler>::_handle_message(peer, sender_node_id, message, send).await
}
)*
}
}
}
#[allow(dead_code)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum Reply {
$(
#[doc = concat!("Reply variant for ", stringify!($variant))]
$variant(<$handler as crate::peer::protocol::bidirectional::BidirectionalHandler>::Reply),
)*
}
};
}