2025-01-26 23:21:35 +01:00
|
|
|
pub mod auth;
|
|
|
|
|
pub mod server;
|
|
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! define_protocol {
|
2025-02-02 00:46:04 +01:00
|
|
|
($id:literal ($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => {
|
2025-02-02 20:25:22 +01:00
|
|
|
#[allow(unused_parens)]
|
2025-02-02 00:46:04 +01:00
|
|
|
async fn protocol (rmcmessage: &RMCMessage, $($varname : $ty),*) -> Option<RMCResponse>{
|
2025-01-26 23:21:35 +01:00
|
|
|
if rmcmessage.protocol_id != $id{
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-02 00:46:04 +01:00
|
|
|
let self_data: ( $( $ty ),* ) = ($( $varname ),*);
|
|
|
|
|
|
|
|
|
|
let response_result = match rmcmessage.method_id{
|
2025-01-26 23:21:35 +01:00
|
|
|
$(
|
2025-02-02 00:46:04 +01:00
|
|
|
$func_id => $func ( rmcmessage, self_data).await,
|
2025-02-01 20:59:21 +01:00
|
|
|
)*
|
2025-01-26 23:21:35 +01:00
|
|
|
_ => {
|
|
|
|
|
error!("invalid method id sent to protocol {}: {:?}", $id, rmcmessage.method_id);
|
2025-02-01 20:59:21 +01:00
|
|
|
return Some(
|
|
|
|
|
RMCResponse{
|
|
|
|
|
protocol_id: $id,
|
|
|
|
|
response_result: rmcmessage.error_result_with_code(ErrorCode::Core_NotImplemented)
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-01-26 23:21:35 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Some(RMCResponse{
|
|
|
|
|
protocol_id: $id,
|
|
|
|
|
response_result
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-02-02 20:25:22 +01:00
|
|
|
#[allow(unused_parens)]
|
2025-02-02 00:46:04 +01:00
|
|
|
pub fn bound_protocol($($varname : $ty,)*) -> Box<dyn for<'message_lifetime> Fn(&'message_lifetime RMCMessage) -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = Option<RMCResponse>> + Send + 'message_lifetime>> + Send + Sync>{
|
2025-02-01 19:42:45 +01:00
|
|
|
Box::new(
|
|
|
|
|
move |v| {
|
2025-02-02 00:46:04 +01:00
|
|
|
Box::pin(async move {
|
|
|
|
|
$(
|
|
|
|
|
let $varname = $varname.clone();
|
|
|
|
|
)*
|
|
|
|
|
protocol(v, $($varname,)*).await
|
|
|
|
|
})
|
2025-02-01 19:42:45 +01:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-01-26 23:21:35 +01:00
|
|
|
};
|
|
|
|
|
}
|