1
+ // This file is @generated by prost-build.
1
2
/// The request message containing the user's name.
2
3
#[ derive( Clone , PartialEq , :: prost:: Message ) ]
3
4
pub struct HelloRequest {
4
- #[ prost( string, tag= "1" ) ]
5
+ #[ prost( string, tag = "1" ) ]
5
6
pub name : :: prost:: alloc:: string:: String ,
6
7
}
7
8
/// The response message containing the greetings
8
9
#[ derive( Clone , PartialEq , :: prost:: Message ) ]
9
10
pub struct HelloReply {
10
- #[ prost( string, tag= "1" ) ]
11
+ #[ prost( string, tag = "1" ) ]
11
12
pub message : :: prost:: alloc:: string:: String ,
12
13
}
13
14
/// Generated client implementations.
14
15
pub mod greeter_client {
15
- #![ allow( unused_variables, dead_code, missing_docs, clippy:: let_unit_value) ]
16
+ #![ allow(
17
+ unused_variables,
18
+ dead_code,
19
+ missing_docs,
20
+ clippy:: wildcard_imports,
21
+ clippy:: let_unit_value,
22
+ ) ]
16
23
use tonic:: codegen:: * ;
17
24
use tonic:: codegen:: http:: Uri ;
18
25
/// The greeting service definition.
@@ -24,7 +31,7 @@ pub mod greeter_client {
24
31
/// Attempt to create a new client by connecting to a given endpoint.
25
32
pub async fn connect < D > ( dst : D ) -> Result < Self , tonic:: transport:: Error >
26
33
where
27
- D : std :: convert :: TryInto < tonic:: transport:: Endpoint > ,
34
+ D : TryInto < tonic:: transport:: Endpoint > ,
28
35
D :: Error : Into < StdError > ,
29
36
{
30
37
let conn = tonic:: transport:: Endpoint :: new ( dst) ?. connect ( ) . await ?;
@@ -35,8 +42,8 @@ pub mod greeter_client {
35
42
where
36
43
T : tonic:: client:: GrpcService < tonic:: body:: BoxBody > ,
37
44
T :: Error : Into < StdError > ,
38
- T :: ResponseBody : Body < Data = Bytes > + Send + ' static ,
39
- <T :: ResponseBody as Body >:: Error : Into < StdError > + Send ,
45
+ T :: ResponseBody : Body < Data = Bytes > + std :: marker :: Send + ' static ,
46
+ <T :: ResponseBody as Body >:: Error : Into < StdError > + std :: marker :: Send ,
40
47
{
41
48
pub fn new ( inner : T ) -> Self {
42
49
let inner = tonic:: client:: Grpc :: new ( inner) ;
@@ -61,7 +68,7 @@ pub mod greeter_client {
61
68
> ,
62
69
<T as tonic:: codegen:: Service <
63
70
http:: Request < tonic:: body:: BoxBody > ,
64
- > >:: Error : Into < StdError > + Send + Sync ,
71
+ > >:: Error : Into < StdError > + std :: marker :: Send + std :: marker :: Sync ,
65
72
{
66
73
GreeterClient :: new ( InterceptedService :: new ( inner, interceptor) )
67
74
}
@@ -80,59 +87,85 @@ pub mod greeter_client {
80
87
self . inner = self . inner . accept_compressed ( encoding) ;
81
88
self
82
89
}
90
+ /// Limits the maximum size of a decoded message.
91
+ ///
92
+ /// Default: `4MB`
93
+ #[ must_use]
94
+ pub fn max_decoding_message_size ( mut self , limit : usize ) -> Self {
95
+ self . inner = self . inner . max_decoding_message_size ( limit) ;
96
+ self
97
+ }
98
+ /// Limits the maximum size of an encoded message.
99
+ ///
100
+ /// Default: `usize::MAX`
101
+ #[ must_use]
102
+ pub fn max_encoding_message_size ( mut self , limit : usize ) -> Self {
103
+ self . inner = self . inner . max_encoding_message_size ( limit) ;
104
+ self
105
+ }
83
106
/// Sends a greeting
84
107
pub async fn say_hello (
85
108
& mut self ,
86
109
request : impl tonic:: IntoRequest < super :: HelloRequest > ,
87
- ) -> Result < tonic:: Response < super :: HelloReply > , tonic:: Status > {
110
+ ) -> std :: result :: Result < tonic:: Response < super :: HelloReply > , tonic:: Status > {
88
111
self . inner
89
112
. ready ( )
90
113
. await
91
114
. map_err ( |e| {
92
- tonic:: Status :: new (
93
- tonic:: Code :: Unknown ,
115
+ tonic:: Status :: unknown (
94
116
format ! ( "Service was not ready: {}" , e. into( ) ) ,
95
117
)
96
118
} ) ?;
97
119
let codec = tonic:: codec:: ProstCodec :: default ( ) ;
98
120
let path = http:: uri:: PathAndQuery :: from_static (
99
121
"/helloworld.Greeter/SayHello" ,
100
122
) ;
101
- self . inner . unary ( request. into_request ( ) , path, codec) . await
123
+ let mut req = request. into_request ( ) ;
124
+ req. extensions_mut ( )
125
+ . insert ( GrpcMethod :: new ( "helloworld.Greeter" , "SayHello" ) ) ;
126
+ self . inner . unary ( req, path, codec) . await
102
127
}
103
128
}
104
129
}
105
130
/// Generated server implementations.
106
131
pub mod greeter_server {
107
- #![ allow( unused_variables, dead_code, missing_docs, clippy:: let_unit_value) ]
132
+ #![ allow(
133
+ unused_variables,
134
+ dead_code,
135
+ missing_docs,
136
+ clippy:: wildcard_imports,
137
+ clippy:: let_unit_value,
138
+ ) ]
108
139
use tonic:: codegen:: * ;
109
- ///Generated trait containing gRPC methods that should be implemented for use with GreeterServer.
140
+ /// Generated trait containing gRPC methods that should be implemented for use with GreeterServer.
110
141
#[ async_trait]
111
- pub trait Greeter : Send + Sync + ' static {
142
+ pub trait Greeter : std :: marker :: Send + std :: marker :: Sync + ' static {
112
143
/// Sends a greeting
113
144
async fn say_hello (
114
145
& self ,
115
146
request : tonic:: Request < super :: HelloRequest > ,
116
- ) -> Result < tonic:: Response < super :: HelloReply > , tonic:: Status > ;
147
+ ) -> std :: result :: Result < tonic:: Response < super :: HelloReply > , tonic:: Status > ;
117
148
}
118
149
/// The greeting service definition.
119
150
#[ derive( Debug ) ]
120
- pub struct GreeterServer < T : Greeter > {
121
- inner : _Inner < T > ,
151
+ pub struct GreeterServer < T > {
152
+ inner : Arc < T > ,
122
153
accept_compression_encodings : EnabledCompressionEncodings ,
123
154
send_compression_encodings : EnabledCompressionEncodings ,
155
+ max_decoding_message_size : Option < usize > ,
156
+ max_encoding_message_size : Option < usize > ,
124
157
}
125
- struct _Inner < T > ( Arc < T > ) ;
126
- impl < T : Greeter > GreeterServer < T > {
158
+ impl < T > GreeterServer < T > {
127
159
pub fn new ( inner : T ) -> Self {
128
160
Self :: from_arc ( Arc :: new ( inner) )
129
161
}
130
162
pub fn from_arc ( inner : Arc < T > ) -> Self {
131
- let inner = _Inner ( inner) ;
132
163
Self {
133
164
inner,
134
165
accept_compression_encodings : Default :: default ( ) ,
135
166
send_compression_encodings : Default :: default ( ) ,
167
+ max_decoding_message_size : None ,
168
+ max_encoding_message_size : None ,
136
169
}
137
170
}
138
171
pub fn with_interceptor < F > (
@@ -156,24 +189,39 @@ pub mod greeter_server {
156
189
self . send_compression_encodings . enable ( encoding) ;
157
190
self
158
191
}
192
+ /// Limits the maximum size of a decoded message.
193
+ ///
194
+ /// Default: `4MB`
195
+ #[ must_use]
196
+ pub fn max_decoding_message_size ( mut self , limit : usize ) -> Self {
197
+ self . max_decoding_message_size = Some ( limit) ;
198
+ self
199
+ }
200
+ /// Limits the maximum size of an encoded message.
201
+ ///
202
+ /// Default: `usize::MAX`
203
+ #[ must_use]
204
+ pub fn max_encoding_message_size ( mut self , limit : usize ) -> Self {
205
+ self . max_encoding_message_size = Some ( limit) ;
206
+ self
207
+ }
159
208
}
160
209
impl < T , B > tonic:: codegen:: Service < http:: Request < B > > for GreeterServer < T >
161
210
where
162
211
T : Greeter ,
163
- B : Body + Send + ' static ,
164
- B :: Error : Into < StdError > + Send + ' static ,
212
+ B : Body + std :: marker :: Send + ' static ,
213
+ B :: Error : Into < StdError > + std :: marker :: Send + ' static ,
165
214
{
166
215
type Response = http:: Response < tonic:: body:: BoxBody > ;
167
216
type Error = std:: convert:: Infallible ;
168
217
type Future = BoxFuture < Self :: Response , Self :: Error > ;
169
218
fn poll_ready (
170
219
& mut self ,
171
220
_cx : & mut Context < ' _ > ,
172
- ) -> Poll < Result < ( ) , Self :: Error > > {
221
+ ) -> Poll < std :: result :: Result < ( ) , Self :: Error > > {
173
222
Poll :: Ready ( Ok ( ( ) ) )
174
223
}
175
224
fn call ( & mut self , req : http:: Request < B > ) -> Self :: Future {
176
- let inner = self . inner . clone ( ) ;
177
225
match req. uri ( ) . path ( ) {
178
226
"/helloworld.Greeter/SayHello" => {
179
227
#[ allow( non_camel_case_types) ]
@@ -189,22 +237,29 @@ pub mod greeter_server {
189
237
& mut self ,
190
238
request : tonic:: Request < super :: HelloRequest > ,
191
239
) -> Self :: Future {
192
- let inner = self . 0 . clone ( ) ;
193
- let fut = async move { ( * inner) . say_hello ( request) . await } ;
240
+ let inner = Arc :: clone ( & self . 0 ) ;
241
+ let fut = async move {
242
+ <T as Greeter >:: say_hello ( & inner, request) . await
243
+ } ;
194
244
Box :: pin ( fut)
195
245
}
196
246
}
197
247
let accept_compression_encodings = self . accept_compression_encodings ;
198
248
let send_compression_encodings = self . send_compression_encodings ;
249
+ let max_decoding_message_size = self . max_decoding_message_size ;
250
+ let max_encoding_message_size = self . max_encoding_message_size ;
199
251
let inner = self . inner . clone ( ) ;
200
252
let fut = async move {
201
- let inner = inner. 0 ;
202
253
let method = SayHelloSvc ( inner) ;
203
254
let codec = tonic:: codec:: ProstCodec :: default ( ) ;
204
255
let mut grpc = tonic:: server:: Grpc :: new ( codec)
205
256
. apply_compression_config (
206
257
accept_compression_encodings,
207
258
send_compression_encodings,
259
+ )
260
+ . apply_max_message_size_config (
261
+ max_decoding_message_size,
262
+ max_encoding_message_size,
208
263
) ;
209
264
let res = grpc. unary ( method, req) . await ;
210
265
Ok ( res)
@@ -213,40 +268,39 @@ pub mod greeter_server {
213
268
}
214
269
_ => {
215
270
Box :: pin ( async move {
216
- Ok (
217
- http:: Response :: builder ( )
218
- . status ( 200 )
219
- . header ( "grpc-status" , "12" )
220
- . header ( "content-type" , "application/grpc" )
221
- . body ( empty_body ( ) )
222
- . unwrap ( ) ,
223
- )
271
+ let mut response = http:: Response :: new ( empty_body ( ) ) ;
272
+ let headers = response. headers_mut ( ) ;
273
+ headers
274
+ . insert (
275
+ tonic:: Status :: GRPC_STATUS ,
276
+ ( tonic:: Code :: Unimplemented as i32 ) . into ( ) ,
277
+ ) ;
278
+ headers
279
+ . insert (
280
+ http:: header:: CONTENT_TYPE ,
281
+ tonic:: metadata:: GRPC_CONTENT_TYPE ,
282
+ ) ;
283
+ Ok ( response)
224
284
} )
225
285
}
226
286
}
227
287
}
228
288
}
229
- impl < T : Greeter > Clone for GreeterServer < T > {
289
+ impl < T > Clone for GreeterServer < T > {
230
290
fn clone ( & self ) -> Self {
231
291
let inner = self . inner . clone ( ) ;
232
292
Self {
233
293
inner,
234
294
accept_compression_encodings : self . accept_compression_encodings ,
235
295
send_compression_encodings : self . send_compression_encodings ,
296
+ max_decoding_message_size : self . max_decoding_message_size ,
297
+ max_encoding_message_size : self . max_encoding_message_size ,
236
298
}
237
299
}
238
300
}
239
- impl < T : Greeter > Clone for _Inner < T > {
240
- fn clone ( & self ) -> Self {
241
- Self ( self . 0 . clone ( ) )
242
- }
243
- }
244
- impl < T : std:: fmt:: Debug > std:: fmt:: Debug for _Inner < T > {
245
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
246
- write ! ( f, "{:?}" , self . 0 )
247
- }
248
- }
249
- impl < T : Greeter > tonic:: server:: NamedService for GreeterServer < T > {
250
- const NAME : & ' static str = "helloworld.Greeter" ;
301
+ /// Generated gRPC service name
302
+ pub const SERVICE_NAME : & str = "helloworld.Greeter" ;
303
+ impl < T > tonic:: server:: NamedService for GreeterServer < T > {
304
+ const NAME : & ' static str = SERVICE_NAME ;
251
305
}
252
306
}
0 commit comments