@@ -2,7 +2,7 @@ use crate::{generate_doc_comment, generate_doc_comments};
22use proc_macro2:: { Span , TokenStream } ;
33use prost_build:: { Method , Service } ;
44use quote:: quote;
5- use syn:: { Ident , Lit , LitStr , Path } ;
5+ use syn:: { Ident , Lit , LitStr } ;
66
77pub ( crate ) fn generate ( service : & Service , proto_path : & str ) -> TokenStream {
88 let methods = generate_methods ( & service, proto_path) ;
@@ -79,8 +79,13 @@ pub(crate) fn generate(service: &Service, proto_path: &str) -> TokenStream {
7979 match req. uri( ) . path( ) {
8080 #methods
8181
82- // TODO: implement grpc unimplemented for server
83- _ => unimplemented!( ) ,
82+ _ => Box :: pin( async move {
83+ Ok ( http:: Response :: builder( )
84+ . status( 200 )
85+ . header( "grpc-status" , "12" )
86+ . body( tonic:: body:: BoxBody :: empty( ) )
87+ . unwrap( ) )
88+ } ) ,
8489 }
8590 }
8691 }
@@ -108,10 +113,9 @@ fn generate_trait_methods(service: &Service, proto_path: &str) -> TokenStream {
108113
109114 for method in & service. methods {
110115 let name = quote:: format_ident!( "{}" , method. name) ;
111- let req_message: Path =
112- syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. input_type) ) . unwrap ( ) ;
113- let res_message: Path =
114- syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. output_type) ) . unwrap ( ) ;
116+
117+ let req_message = crate :: replace_wellknown ( proto_path, & method. input_type ) ;
118+ let res_message = crate :: replace_wellknown ( proto_path, & method. output_type ) ;
115119
116120 let method_doc = generate_doc_comments ( & method. comments . leading ) ;
117121
@@ -214,9 +218,8 @@ fn generate_unary(
214218) -> TokenStream {
215219 let service_ident = Ident :: new ( & method. proto_name , Span :: call_site ( ) ) ;
216220
217- let request: Path = syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. input_type) ) . unwrap ( ) ;
218- let response: Path =
219- syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. output_type) ) . unwrap ( ) ;
221+ let request = crate :: replace_wellknown ( proto_path, & method. input_type ) ;
222+ let response = crate :: replace_wellknown ( proto_path, & method. output_type ) ;
220223
221224 quote ! {
222225 struct #service_ident<T : #server_trait >( pub Arc <T >) ;
@@ -255,9 +258,8 @@ fn generate_server_streaming(
255258) -> TokenStream {
256259 let service_ident = Ident :: new ( & method. proto_name , Span :: call_site ( ) ) ;
257260
258- let request: Path = syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. input_type) ) . unwrap ( ) ;
259- let response: Path =
260- syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. output_type) ) . unwrap ( ) ;
261+ let request = crate :: replace_wellknown ( proto_path, & method. input_type ) ;
262+ let response = crate :: replace_wellknown ( proto_path, & method. output_type ) ;
261263
262264 let response_stream = quote:: format_ident!( "{}Stream" , method. proto_name) ;
263265
@@ -300,9 +302,8 @@ fn generate_client_streaming(
300302) -> TokenStream {
301303 let service_ident = Ident :: new ( & method. proto_name , Span :: call_site ( ) ) ;
302304
303- let request: Path = syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. input_type) ) . unwrap ( ) ;
304- let response: Path =
305- syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. output_type) ) . unwrap ( ) ;
305+ let request = crate :: replace_wellknown ( proto_path, & method. input_type ) ;
306+ let response = crate :: replace_wellknown ( proto_path, & method. output_type ) ;
306307
307308 quote ! {
308309 struct #service_ident<T : #server_trait >( pub Arc <T >) ;
@@ -343,9 +344,8 @@ fn generate_streaming(
343344) -> TokenStream {
344345 let service_ident = Ident :: new ( & method. proto_name , Span :: call_site ( ) ) ;
345346
346- let request: Path = syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. input_type) ) . unwrap ( ) ;
347- let response: Path =
348- syn:: parse_str ( & format ! ( "{}::{}" , proto_path, method. output_type) ) . unwrap ( ) ;
347+ let request = crate :: replace_wellknown ( proto_path, & method. input_type ) ;
348+ let response = crate :: replace_wellknown ( proto_path, & method. output_type ) ;
349349
350350 let response_stream = quote:: format_ident!( "{}Stream" , method. proto_name) ;
351351
0 commit comments