2025-01-26 23:21:35 +01:00
|
|
|
pub mod auth;
|
|
|
|
|
pub mod server;
|
|
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! define_protocol {
|
2025-02-01 19:42:45 +01:00
|
|
|
($id:literal $( <$lifetime:lifetime> )?($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => {
|
2025-02-01 20:59:21 +01:00
|
|
|
fn protocol $( <$lifetime> )? (rmcmessage: &RMCMessage, $($varname : $ty),*) -> Option<RMCResponse>{
|
2025-01-26 23:21:35 +01:00
|
|
|
if rmcmessage.protocol_id != $id{
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-01 20:59:21 +01:00
|
|
|
let response_function = match rmcmessage.method_id{
|
2025-01-26 23:21:35 +01:00
|
|
|
$(
|
2025-02-01 20:59:21 +01:00
|
|
|
$func_id => $func,
|
|
|
|
|
)*
|
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
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-01 20:59:21 +01:00
|
|
|
let response_result = response_function(rmcmessage, $($varname),*);
|
|
|
|
|
|
2025-01-26 23:21:35 +01:00
|
|
|
Some(RMCResponse{
|
|
|
|
|
protocol_id: $id,
|
|
|
|
|
response_result
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-02-01 19:42:45 +01:00
|
|
|
|
|
|
|
|
pub fn bound_protocol$(<$lifetime>)?($($varname : $ty,)*) -> Box<dyn Fn(&RMCMessage) -> Option<RMCResponse> + Send + Sync $( + $lifetime)?>{
|
|
|
|
|
Box::new(
|
|
|
|
|
move |v| {
|
|
|
|
|
$(
|
|
|
|
|
let $varname = $varname.clone();
|
|
|
|
|
)*
|
|
|
|
|
protocol(v, $($varname,)*)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-01-26 23:21:35 +01:00
|
|
|
};
|
|
|
|
|
}
|