@@ -7,10 +7,15 @@ use quote::{format_ident, quote};
7
7
///
8
8
/// This takes some `Service` and will generate a `TokenStream` that contains
9
9
/// a public module with the generated client.
10
- pub fn generate < T : Service > ( service : & T , emit_package : bool , proto_path : & str ) -> TokenStream {
10
+ pub fn generate < T : Service > (
11
+ service : & T ,
12
+ emit_package : bool ,
13
+ proto_path : & str ,
14
+ compile_well_known_types : bool ,
15
+ ) -> TokenStream {
11
16
let service_ident = quote:: format_ident!( "{}Client" , service. name( ) ) ;
12
17
let client_mod = quote:: format_ident!( "{}_client" , naive_snake_case( & service. name( ) ) ) ;
13
- let methods = generate_methods ( service, emit_package, proto_path) ;
18
+ let methods = generate_methods ( service, emit_package, proto_path, compile_well_known_types ) ;
14
19
15
20
let connect = generate_connect ( & service_ident) ;
16
21
let service_doc = generate_doc_comments ( service. comment ( ) ) ;
@@ -87,7 +92,12 @@ fn generate_connect(_service_ident: &syn::Ident) -> TokenStream {
87
92
TokenStream :: new ( )
88
93
}
89
94
90
- fn generate_methods < T : Service > ( service : & T , emit_package : bool , proto_path : & str ) -> TokenStream {
95
+ fn generate_methods < T : Service > (
96
+ service : & T ,
97
+ emit_package : bool ,
98
+ proto_path : & str ,
99
+ compile_well_known_types : bool ,
100
+ ) -> TokenStream {
91
101
let mut stream = TokenStream :: new ( ) ;
92
102
let package = if emit_package { service. package ( ) } else { "" } ;
93
103
@@ -103,10 +113,14 @@ fn generate_methods<T: Service>(service: &T, emit_package: bool, proto_path: &st
103
113
stream. extend ( generate_doc_comments ( method. comment ( ) ) ) ;
104
114
105
115
let method = match ( method. client_streaming ( ) , method. server_streaming ( ) ) {
106
- ( false , false ) => generate_unary ( method, proto_path, path) ,
107
- ( false , true ) => generate_server_streaming ( method, proto_path, path) ,
108
- ( true , false ) => generate_client_streaming ( method, proto_path, path) ,
109
- ( true , true ) => generate_streaming ( method, proto_path, path) ,
116
+ ( false , false ) => generate_unary ( method, proto_path, compile_well_known_types, path) ,
117
+ ( false , true ) => {
118
+ generate_server_streaming ( method, proto_path, compile_well_known_types, path)
119
+ }
120
+ ( true , false ) => {
121
+ generate_client_streaming ( method, proto_path, compile_well_known_types, path)
122
+ }
123
+ ( true , true ) => generate_streaming ( method, proto_path, compile_well_known_types, path) ,
110
124
} ;
111
125
112
126
stream. extend ( method) ;
@@ -115,10 +129,15 @@ fn generate_methods<T: Service>(service: &T, emit_package: bool, proto_path: &st
115
129
stream
116
130
}
117
131
118
- fn generate_unary < T : Method > ( method : & T , proto_path : & str , path : String ) -> TokenStream {
132
+ fn generate_unary < T : Method > (
133
+ method : & T ,
134
+ proto_path : & str ,
135
+ compile_well_known_types : bool ,
136
+ path : String ,
137
+ ) -> TokenStream {
119
138
let codec_name = syn:: parse_str :: < syn:: Path > ( T :: CODEC_PATH ) . unwrap ( ) ;
120
139
let ident = format_ident ! ( "{}" , method. name( ) ) ;
121
- let ( request, response) = method. request_response_name ( proto_path) ;
140
+ let ( request, response) = method. request_response_name ( proto_path, compile_well_known_types ) ;
122
141
123
142
quote ! {
124
143
pub async fn #ident(
@@ -135,11 +154,16 @@ fn generate_unary<T: Method>(method: &T, proto_path: &str, path: String) -> Toke
135
154
}
136
155
}
137
156
138
- fn generate_server_streaming < T : Method > ( method : & T , proto_path : & str , path : String ) -> TokenStream {
157
+ fn generate_server_streaming < T : Method > (
158
+ method : & T ,
159
+ proto_path : & str ,
160
+ compile_well_known_types : bool ,
161
+ path : String ,
162
+ ) -> TokenStream {
139
163
let codec_name = syn:: parse_str :: < syn:: Path > ( T :: CODEC_PATH ) . unwrap ( ) ;
140
164
let ident = format_ident ! ( "{}" , method. name( ) ) ;
141
165
142
- let ( request, response) = method. request_response_name ( proto_path) ;
166
+ let ( request, response) = method. request_response_name ( proto_path, compile_well_known_types ) ;
143
167
144
168
quote ! {
145
169
pub async fn #ident(
@@ -156,11 +180,16 @@ fn generate_server_streaming<T: Method>(method: &T, proto_path: &str, path: Stri
156
180
}
157
181
}
158
182
159
- fn generate_client_streaming < T : Method > ( method : & T , proto_path : & str , path : String ) -> TokenStream {
183
+ fn generate_client_streaming < T : Method > (
184
+ method : & T ,
185
+ proto_path : & str ,
186
+ compile_well_known_types : bool ,
187
+ path : String ,
188
+ ) -> TokenStream {
160
189
let codec_name = syn:: parse_str :: < syn:: Path > ( T :: CODEC_PATH ) . unwrap ( ) ;
161
190
let ident = format_ident ! ( "{}" , method. name( ) ) ;
162
191
163
- let ( request, response) = method. request_response_name ( proto_path) ;
192
+ let ( request, response) = method. request_response_name ( proto_path, compile_well_known_types ) ;
164
193
165
194
quote ! {
166
195
pub async fn #ident(
@@ -177,11 +206,16 @@ fn generate_client_streaming<T: Method>(method: &T, proto_path: &str, path: Stri
177
206
}
178
207
}
179
208
180
- fn generate_streaming < T : Method > ( method : & T , proto_path : & str , path : String ) -> TokenStream {
209
+ fn generate_streaming < T : Method > (
210
+ method : & T ,
211
+ proto_path : & str ,
212
+ compile_well_known_types : bool ,
213
+ path : String ,
214
+ ) -> TokenStream {
181
215
let codec_name = syn:: parse_str :: < syn:: Path > ( T :: CODEC_PATH ) . unwrap ( ) ;
182
216
let ident = format_ident ! ( "{}" , method. name( ) ) ;
183
217
184
- let ( request, response) = method. request_response_name ( proto_path) ;
218
+ let ( request, response) = method. request_response_name ( proto_path, compile_well_known_types ) ;
185
219
186
220
quote ! {
187
221
pub async fn #ident(
0 commit comments