feat(account): add grpc to communicate with account server
This commit is contained in:
parent
6984a20bdd
commit
cb6a6f9028
15 changed files with 797 additions and 30 deletions
|
|
@ -2,15 +2,17 @@ pub mod auth;
|
|||
pub mod server;
|
||||
#[macro_export]
|
||||
macro_rules! define_protocol {
|
||||
($id:literal $( <$lifetime:lifetime> )?($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => {
|
||||
fn protocol $( <$lifetime> )? (rmcmessage: &RMCMessage, $($varname : $ty),*) -> Option<RMCResponse>{
|
||||
($id:literal ($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => {
|
||||
async fn protocol (rmcmessage: &RMCMessage, $($varname : $ty),*) -> Option<RMCResponse>{
|
||||
if rmcmessage.protocol_id != $id{
|
||||
return None;
|
||||
}
|
||||
|
||||
let response_function = match rmcmessage.method_id{
|
||||
let self_data: ( $( $ty ),* ) = ($( $varname ),*);
|
||||
|
||||
let response_result = match rmcmessage.method_id{
|
||||
$(
|
||||
$func_id => $func,
|
||||
$func_id => $func ( rmcmessage, self_data).await,
|
||||
)*
|
||||
_ => {
|
||||
error!("invalid method id sent to protocol {}: {:?}", $id, rmcmessage.method_id);
|
||||
|
|
@ -23,21 +25,21 @@ macro_rules! define_protocol {
|
|||
}
|
||||
};
|
||||
|
||||
let response_result = response_function(rmcmessage, $($varname),*);
|
||||
|
||||
Some(RMCResponse{
|
||||
protocol_id: $id,
|
||||
response_result
|
||||
})
|
||||
}
|
||||
|
||||
pub fn bound_protocol$(<$lifetime>)?($($varname : $ty,)*) -> Box<dyn Fn(&RMCMessage) -> Option<RMCResponse> + Send + Sync $( + $lifetime)?>{
|
||||
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>{
|
||||
Box::new(
|
||||
move |v| {
|
||||
$(
|
||||
let $varname = $varname.clone();
|
||||
)*
|
||||
protocol(v, $($varname,)*)
|
||||
Box::pin(async move {
|
||||
$(
|
||||
let $varname = $varname.clone();
|
||||
)*
|
||||
protocol(v, $($varname,)*).await
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue