Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports grpc+json and the curl tool #148

Merged
merged 11 commits into from
Aug 18, 2023
Merged
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ serde_yaml = "0.9.4" # yaml file parser
once_cell = "1.16.0"
itertools = "0.10.1"
bytes = "1.0"

prost-serde = "0.3.0"
prost-serde-derive = "0.1.2"


4 changes: 2 additions & 2 deletions dubbo-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ repository = "https://github.com/apache/dubbo-rust.git"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
prost = "0.11.0"
prost = "0.11.9"
prettyplease = {version = "0.1"}
proc-macro2 = "1.0"
quote = "1.0"
syn = "1.0"
prost-build = "0.11.1"
prost-build = "0.11.9"
18 changes: 0 additions & 18 deletions dubbo-build/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use crate::{Method, Service};
use proc_macro2::TokenStream;
use quote::{format_ident, quote};

pub const CODEC_PATH: &str = "dubbo::codegen::ProstCodec";

/// Generate service for client.
///
/// This takes some `Service` and will generate a `TokenStream` that contains
Expand Down Expand Up @@ -167,7 +165,6 @@ fn generate_unary<T: Method>(
compile_well_known_types: bool,
path: String,
) -> TokenStream {
let codec_name = syn::parse_str::<syn::Path>(CODEC_PATH).unwrap();
let ident = format_ident!("{}", method.name());
let (request, response) = method.request_response_name(proto_path, compile_well_known_types);
let method_name = method.identifier();
Expand All @@ -177,14 +174,12 @@ fn generate_unary<T: Method>(
&mut self,
request: Request<#request>,
) -> Result<Response<#response>, dubbo::status::Status> {
let codec = #codec_name::<#request, #response>::default();
let invocation = RpcInvocation::default()
.with_service_unique_name(String::from(#service_unique_name))
.with_method_name(String::from(#method_name));
let path = http::uri::PathAndQuery::from_static(#path);
self.inner.unary(
request,
codec,
path,
invocation,
).await
Expand All @@ -199,9 +194,7 @@ fn generate_server_streaming<T: Method>(
compile_well_known_types: bool,
path: String,
) -> TokenStream {
let codec_name = syn::parse_str::<syn::Path>(CODEC_PATH).unwrap();
let ident = format_ident!("{}", method.name());

let (request, response) = method.request_response_name(proto_path, compile_well_known_types);
let method_name = method.identifier();

Expand All @@ -210,15 +203,12 @@ fn generate_server_streaming<T: Method>(
&mut self,
request: Request<#request>,
) -> Result<Response<Decoding<#response>>, dubbo::status::Status> {

let codec = #codec_name::<#request, #response>::default();
let invocation = RpcInvocation::default()
.with_service_unique_name(String::from(#service_unique_name))
.with_method_name(String::from(#method_name));
let path = http::uri::PathAndQuery::from_static(#path);
self.inner.server_streaming(
request,
codec,
path,
invocation,
).await
Expand All @@ -233,9 +223,7 @@ fn generate_client_streaming<T: Method>(
compile_well_known_types: bool,
path: String,
) -> TokenStream {
let codec_name = syn::parse_str::<syn::Path>(CODEC_PATH).unwrap();
let ident = format_ident!("{}", method.name());

let (request, response) = method.request_response_name(proto_path, compile_well_known_types);
let method_name = method.identifier();

Expand All @@ -244,14 +232,12 @@ fn generate_client_streaming<T: Method>(
&mut self,
request: impl IntoStreamingRequest<Message = #request>
) -> Result<Response<#response>, dubbo::status::Status> {
let codec = #codec_name::<#request, #response>::default();
let invocation = RpcInvocation::default()
.with_service_unique_name(String::from(#service_unique_name))
.with_method_name(String::from(#method_name));
let path = http::uri::PathAndQuery::from_static(#path);
self.inner.client_streaming(
request,
codec,
path,
invocation,
).await
Expand All @@ -266,9 +252,7 @@ fn generate_streaming<T: Method>(
compile_well_known_types: bool,
path: String,
) -> TokenStream {
let codec_name = syn::parse_str::<syn::Path>(CODEC_PATH).unwrap();
let ident = format_ident!("{}", method.name());

let (request, response) = method.request_response_name(proto_path, compile_well_known_types);
let method_name = method.identifier();

Expand All @@ -277,14 +261,12 @@ fn generate_streaming<T: Method>(
&mut self,
request: impl IntoStreamingRequest<Message = #request>
) -> Result<Response<Decoding<#response>>, dubbo::status::Status> {
let codec = #codec_name::<#request, #response>::default();
let invocation = RpcInvocation::default()
.with_service_unique_name(String::from(#service_unique_name))
.with_method_name(String::from(#method_name));
let path = http::uri::PathAndQuery::from_static(#path);
self.inner.bidi_streaming(
request,
codec,
path,
invocation,
).await
Expand Down
2 changes: 2 additions & 0 deletions dubbo-build/src/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ impl Builder {
PathBuf::from(std::env::var("OUT_DIR").unwrap())
};
config.out_dir(out_dir);
config.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]");
config.type_attribute(".", "#[serde(default)]");

if self.compile_well_known_types {
config.compile_well_known_types();
Expand Down
32 changes: 4 additions & 28 deletions dubbo-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{Ident, Lit, LitStr};

pub const CODEC_PATH: &str = "dubbo::codegen::ProstCodec";

/// Generate service for Server.
///
/// This takes some `Service` and will generate a `TokenStream` that contains
Expand Down Expand Up @@ -330,8 +328,6 @@ fn generate_unary<T: Method>(
method_ident: Ident,
server_trait: Ident,
) -> TokenStream {
let codec_name = syn::parse_str::<syn::Path>(CODEC_PATH).unwrap();

let service_ident = quote::format_ident!("{}Server", method.identifier());

let (request, response) = method.request_response_name(proto_path, compile_well_known_types);
Expand All @@ -354,16 +350,11 @@ fn generate_unary<T: Method>(
Box::pin(fut)
}
}

let fut = async move {
let mut server = TripleServer::new(
#codec_name::<#response, #request>::default()
);

let mut server = TripleServer::<#request,#response>::new();
let res = server.unary(#service_ident { inner }, req).await;
Ok(res)
};

Box::pin(fut)
}
}
Expand All @@ -375,8 +366,6 @@ fn generate_server_streaming<T: Method>(
method_ident: Ident,
server_trait: Ident,
) -> TokenStream {
let codec_name = syn::parse_str::<syn::Path>(CODEC_PATH).unwrap();

let service_ident = quote::format_ident!("{}Server", method.identifier());

let (request, response) = method.request_response_name(proto_path, compile_well_known_types);
Expand All @@ -402,12 +391,8 @@ fn generate_server_streaming<T: Method>(
Box::pin(fut)
}
}

let fut = async move {
let mut server = TripleServer::new(
#codec_name::<#response, #request>::default()
);

let mut server = TripleServer::<#request,#response>::new();
let res = server.server_streaming(#service_ident { inner }, req).await;
Ok(res)
};
Expand All @@ -426,7 +411,6 @@ fn generate_client_streaming<T: Method>(
let service_ident = quote::format_ident!("{}Server", method.identifier());

let (request, response) = method.request_response_name(proto_path, compile_well_known_types);
let codec_name = syn::parse_str::<syn::Path>(CODEC_PATH).unwrap();

quote! {
#[allow(non_camel_case_types)]
Expand All @@ -450,10 +434,7 @@ fn generate_client_streaming<T: Method>(
}

let fut = async move {
let mut server = TripleServer::new(
#codec_name::<#response, #request>::default()
);

let mut server = TripleServer::<#request,#response>::new();
let res = server.client_streaming(#service_ident { inner }, req).await;
Ok(res)
};
Expand All @@ -469,8 +450,6 @@ fn generate_streaming<T: Method>(
method_ident: Ident,
server_trait: Ident,
) -> TokenStream {
let codec_name = syn::parse_str::<syn::Path>(CODEC_PATH).unwrap();

let service_ident = quote::format_ident!("{}Server", method.identifier());

let (request, response) = method.request_response_name(proto_path, compile_well_known_types);
Expand Down Expand Up @@ -499,10 +478,7 @@ fn generate_streaming<T: Method>(
}

let fut = async move {
let mut server = TripleServer::new(
#codec_name::<#response, #request>::default()
);

let mut server = TripleServer::<#request,#response>::new();
let res = server.bidi_streaming(#service_ident { inner }, req).await;
Ok(res)
};
Expand Down
2 changes: 1 addition & 1 deletion dubbo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ argh = "0.1"
rustls-pemfile = "1.0.0"
tokio-rustls="0.23.4"
tokio = { version = "1.0", features = [ "rt-multi-thread", "time", "fs", "macros", "net", "signal", "full" ] }
prost = "0.10.4"
prost = "0.11.9"
async-trait = "0.1.56"
tower-layer.workspace = true
bytes.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion dubbo/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use super::{
registry::{BoxRegistry, Registry},
triple::{
client::TripleClient,
codec::{prost::ProstCodec, Codec},
codec::{prost::ProstCodec, serde_codec::SerdeCodec, Codec},
decode::Decoding,
server::{
service::{ClientStreamingSvc, ServerStreamingSvc, StreamingSvc, UnarySvc},
Expand Down
2 changes: 1 addition & 1 deletion dubbo/src/triple/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl ClientBuilder {
connector: "",
directory: Some(Box::new(StaticDirectory::new(&host))),
direct: true,
host: host.clone().to_string(),
host: host.to_string(),
}
}

Expand Down
Loading
Loading