Add package to client handler params
This commit is contained in:
parent
7d326ea183
commit
4f629e3421
6 changed files with 11 additions and 9 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -281,7 +281,7 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nrpc"
|
name = "nrpc"
|
||||||
version = "0.2.0"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
@ -290,7 +290,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nrpc-build"
|
name = "nrpc-build"
|
||||||
version = "0.5.0"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nrpc",
|
"nrpc",
|
||||||
"prettyplease 0.2.4",
|
"prettyplease 0.2.4",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nrpc-build"
|
name = "nrpc-build"
|
||||||
version = "0.5.0"
|
version = "0.6.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
repository = "https://github.com/NGnius/nRPC"
|
repository = "https://github.com/NGnius/nRPC"
|
||||||
|
@ -21,4 +21,4 @@ quote = "1.0"
|
||||||
syn = "2.0"
|
syn = "2.0"
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
|
|
||||||
nrpc = { version = "0.2", path = "../nrpc" }
|
nrpc = { version = "0.6", path = "../nrpc" }
|
||||||
|
|
|
@ -86,7 +86,7 @@ fn trait_methods_server(descriptors: &Vec<prost_build::Method>) -> proc_macro2::
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn struct_methods_client(service_name: &str, descriptors: &Vec<prost_build::Method>) -> proc_macro2::TokenStream {
|
fn struct_methods_client(package_name: &str, service_name: &str, descriptors: &Vec<prost_build::Method>) -> proc_macro2::TokenStream {
|
||||||
let mut gen_methods = Vec::with_capacity(descriptors.len());
|
let mut gen_methods = Vec::with_capacity(descriptors.len());
|
||||||
for descriptor in descriptors {
|
for descriptor in descriptors {
|
||||||
match (descriptor.client_streaming, descriptor.server_streaming) {
|
match (descriptor.client_streaming, descriptor.server_streaming) {
|
||||||
|
@ -101,7 +101,7 @@ fn struct_methods_client(service_name: &str, descriptors: &Vec<prost_build::Meth
|
||||||
let mut in_buf = ::nrpc::_helpers::bytes::BytesMut::new();
|
let mut in_buf = ::nrpc::_helpers::bytes::BytesMut::new();
|
||||||
input.encode(&mut in_buf)?;
|
input.encode(&mut in_buf)?;
|
||||||
let mut out_buf = ::nrpc::_helpers::bytes::BytesMut::new();
|
let mut out_buf = ::nrpc::_helpers::bytes::BytesMut::new();
|
||||||
self.inner.call(#service_name, #method_name, in_buf.into(), &mut out_buf).await?;
|
self.inner.call(#package_name, #service_name, #method_name, in_buf.into(), &mut out_buf).await?;
|
||||||
Ok(#output_ty::decode(out_buf)?)
|
Ok(#output_ty::decode(out_buf)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ impl ServiceGenerator for ProtobufServiceGenerator {
|
||||||
}
|
}
|
||||||
if self.generate_client {
|
if self.generate_client {
|
||||||
let service_mod_name = quote::format_ident!("{}_mod_client", service.name.to_lowercase());
|
let service_mod_name = quote::format_ident!("{}_mod_client", service.name.to_lowercase());
|
||||||
let service_methods = struct_methods_client(&service.name, &service.methods);
|
let service_methods = struct_methods_client(&service.package, &service.name, &service.methods);
|
||||||
let service_struct_name = quote::format_ident!("{}Service", service.name);
|
let service_struct_name = quote::format_ident!("{}Service", service.name);
|
||||||
let descriptor_str = format!("{}.{}", service.package, service.name);
|
let descriptor_str = format!("{}.{}", service.package, service.name);
|
||||||
let service_rename = quote::format_ident!("{}Client", service.name);
|
let service_rename = quote::format_ident!("{}Client", service.name);
|
||||||
|
|
|
@ -48,11 +48,12 @@ struct ClientHandler;
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl nrpc::ClientHandler for ClientHandler {
|
impl nrpc::ClientHandler for ClientHandler {
|
||||||
async fn call(&mut self,
|
async fn call(&mut self,
|
||||||
|
package: &str,
|
||||||
service: &str,
|
service: &str,
|
||||||
method: &str,
|
method: &str,
|
||||||
input: bytes::Bytes,
|
input: bytes::Bytes,
|
||||||
output: &mut bytes::BytesMut) -> Result<(), nrpc::ServiceError> {
|
output: &mut bytes::BytesMut) -> Result<(), nrpc::ServiceError> {
|
||||||
println!("call {}/{} with data {:?}", service, method, input);
|
println!("call {}.{}/{} with data {:?}", package, service, method, input);
|
||||||
// This is ok to hardcode ONLY because it's for testing
|
// This is ok to hardcode ONLY because it's for testing
|
||||||
Ok(helloworld::HelloReply {
|
Ok(helloworld::HelloReply {
|
||||||
message: "Hello World".into(),
|
message: "Hello World".into(),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nrpc"
|
name = "nrpc"
|
||||||
version = "0.2.0"
|
version = "0.6.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
repository = "https://github.com/NGnius/nRPC"
|
repository = "https://github.com/NGnius/nRPC"
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub trait ServerService {
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait ClientHandler {
|
pub trait ClientHandler {
|
||||||
async fn call(&mut self,
|
async fn call(&mut self,
|
||||||
|
package: &str,
|
||||||
service: &str,
|
service: &str,
|
||||||
method: &str,
|
method: &str,
|
||||||
input: bytes::Bytes,
|
input: bytes::Bytes,
|
||||||
|
|
Loading…
Reference in a new issue