1pub mod echo_service_client {
4 #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
5 use tonic::codegen::*;
6 use tonic::codegen::http::Uri;
7 #[derive(Debug, Clone)]
9 pub struct EchoServiceClient<T> {
10 inner: tonic::client::Grpc<T>,
11 }
12 impl EchoServiceClient<tonic::transport::Channel> {
13 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
15 where
16 D: TryInto<tonic::transport::Endpoint>,
17 D::Error: Into<StdError>,
18 {
19 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
20 Ok(Self::new(conn))
21 }
22 }
23 impl<T> EchoServiceClient<T>
24 where
25 T: tonic::client::GrpcService<tonic::body::BoxBody>,
26 T::Error: Into<StdError>,
27 T::ResponseBody: Body<Data = Bytes> + Send + 'static,
28 <T::ResponseBody as Body>::Error: Into<StdError> + Send,
29 {
30 pub fn new(inner: T) -> Self {
31 let inner = tonic::client::Grpc::new(inner);
32 Self { inner }
33 }
34 pub fn with_origin(inner: T, origin: Uri) -> Self {
35 let inner = tonic::client::Grpc::with_origin(inner, origin);
36 Self { inner }
37 }
38 pub fn with_interceptor<F>(
39 inner: T,
40 interceptor: F,
41 ) -> EchoServiceClient<InterceptedService<T, F>>
42 where
43 F: tonic::service::Interceptor,
44 T::ResponseBody: Default,
45 T: tonic::codegen::Service<
46 http::Request<tonic::body::BoxBody>,
47 Response = http::Response<
48 <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
49 >,
50 >,
51 <T as tonic::codegen::Service<
52 http::Request<tonic::body::BoxBody>,
53 >>::Error: Into<StdError> + Send + Sync,
54 {
55 EchoServiceClient::new(InterceptedService::new(inner, interceptor))
56 }
57 #[must_use]
62 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
63 self.inner = self.inner.send_compressed(encoding);
64 self
65 }
66 #[must_use]
68 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
69 self.inner = self.inner.accept_compressed(encoding);
70 self
71 }
72 #[must_use]
76 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
77 self.inner = self.inner.max_decoding_message_size(limit);
78 self
79 }
80 #[must_use]
84 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
85 self.inner = self.inner.max_encoding_message_size(limit);
86 self
87 }
88 pub async fn echo(
90 &mut self,
91 request: impl tonic::IntoRequest<super::EchoRequest>,
92 ) -> std::result::Result<tonic::Response<super::EchoResponse>, tonic::Status> {
93 self.inner
94 .ready()
95 .await
96 .map_err(|e| {
97 tonic::Status::new(
98 tonic::Code::Unknown,
99 format!("Service was not ready: {}", e.into()),
100 )
101 })?;
102 let codec = tonic::codec::ProstCodec::default();
103 let path = http::uri::PathAndQuery::from_static(
104 "/proto.rpc.examples.echo.v1.EchoService/Echo",
105 );
106 let mut req = request.into_request();
107 req.extensions_mut()
108 .insert(
109 GrpcMethod::new("proto.rpc.examples.echo.v1.EchoService", "Echo"),
110 );
111 self.inner.unary(req, path, codec).await
112 }
113 pub async fn echo_multiple(
115 &mut self,
116 request: impl tonic::IntoRequest<super::EchoMultipleRequest>,
117 ) -> std::result::Result<
118 tonic::Response<tonic::codec::Streaming<super::EchoMultipleResponse>>,
119 tonic::Status,
120 > {
121 self.inner
122 .ready()
123 .await
124 .map_err(|e| {
125 tonic::Status::new(
126 tonic::Code::Unknown,
127 format!("Service was not ready: {}", e.into()),
128 )
129 })?;
130 let codec = tonic::codec::ProstCodec::default();
131 let path = http::uri::PathAndQuery::from_static(
132 "/proto.rpc.examples.echo.v1.EchoService/EchoMultiple",
133 );
134 let mut req = request.into_request();
135 req.extensions_mut()
136 .insert(
137 GrpcMethod::new(
138 "proto.rpc.examples.echo.v1.EchoService",
139 "EchoMultiple",
140 ),
141 );
142 self.inner.server_streaming(req, path, codec).await
143 }
144 pub async fn echo_bi_di(
146 &mut self,
147 request: impl tonic::IntoStreamingRequest<Message = super::EchoBiDiRequest>,
148 ) -> std::result::Result<
149 tonic::Response<tonic::codec::Streaming<super::EchoBiDiResponse>>,
150 tonic::Status,
151 > {
152 self.inner
153 .ready()
154 .await
155 .map_err(|e| {
156 tonic::Status::new(
157 tonic::Code::Unknown,
158 format!("Service was not ready: {}", e.into()),
159 )
160 })?;
161 let codec = tonic::codec::ProstCodec::default();
162 let path = http::uri::PathAndQuery::from_static(
163 "/proto.rpc.examples.echo.v1.EchoService/EchoBiDi",
164 );
165 let mut req = request.into_streaming_request();
166 req.extensions_mut()
167 .insert(
168 GrpcMethod::new("proto.rpc.examples.echo.v1.EchoService", "EchoBiDi"),
169 );
170 self.inner.streaming(req, path, codec).await
171 }
172 }
173}
174pub mod echo_service_server {
176 #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
177 use tonic::codegen::*;
178 #[async_trait]
180 pub trait EchoService: Send + Sync + 'static {
181 async fn echo(
183 &self,
184 request: tonic::Request<super::EchoRequest>,
185 ) -> std::result::Result<tonic::Response<super::EchoResponse>, tonic::Status>;
186 type EchoMultipleStream: futures_core::Stream<
188 Item = std::result::Result<super::EchoMultipleResponse, tonic::Status>,
189 >
190 + Send
191 + 'static;
192 async fn echo_multiple(
194 &self,
195 request: tonic::Request<super::EchoMultipleRequest>,
196 ) -> std::result::Result<
197 tonic::Response<Self::EchoMultipleStream>,
198 tonic::Status,
199 >;
200 type EchoBiDiStream: futures_core::Stream<
202 Item = std::result::Result<super::EchoBiDiResponse, tonic::Status>,
203 >
204 + Send
205 + 'static;
206 async fn echo_bi_di(
208 &self,
209 request: tonic::Request<tonic::Streaming<super::EchoBiDiRequest>>,
210 ) -> std::result::Result<tonic::Response<Self::EchoBiDiStream>, tonic::Status>;
211 }
212 #[derive(Debug)]
214 pub struct EchoServiceServer<T: EchoService> {
215 inner: _Inner<T>,
216 accept_compression_encodings: EnabledCompressionEncodings,
217 send_compression_encodings: EnabledCompressionEncodings,
218 max_decoding_message_size: Option<usize>,
219 max_encoding_message_size: Option<usize>,
220 }
221 struct _Inner<T>(Arc<T>);
222 impl<T: EchoService> EchoServiceServer<T> {
223 pub fn new(inner: T) -> Self {
224 Self::from_arc(Arc::new(inner))
225 }
226 pub fn from_arc(inner: Arc<T>) -> Self {
227 let inner = _Inner(inner);
228 Self {
229 inner,
230 accept_compression_encodings: Default::default(),
231 send_compression_encodings: Default::default(),
232 max_decoding_message_size: None,
233 max_encoding_message_size: None,
234 }
235 }
236 pub fn with_interceptor<F>(
237 inner: T,
238 interceptor: F,
239 ) -> InterceptedService<Self, F>
240 where
241 F: tonic::service::Interceptor,
242 {
243 InterceptedService::new(Self::new(inner), interceptor)
244 }
245 #[must_use]
247 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
248 self.accept_compression_encodings.enable(encoding);
249 self
250 }
251 #[must_use]
253 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
254 self.send_compression_encodings.enable(encoding);
255 self
256 }
257 #[must_use]
261 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
262 self.max_decoding_message_size = Some(limit);
263 self
264 }
265 #[must_use]
269 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
270 self.max_encoding_message_size = Some(limit);
271 self
272 }
273 }
274 impl<T, B> tonic::codegen::Service<http::Request<B>> for EchoServiceServer<T>
275 where
276 T: EchoService,
277 B: Body + Send + 'static,
278 B::Error: Into<StdError> + Send + 'static,
279 {
280 type Response = http::Response<tonic::body::BoxBody>;
281 type Error = std::convert::Infallible;
282 type Future = BoxFuture<Self::Response, Self::Error>;
283 fn poll_ready(
284 &mut self,
285 _cx: &mut Context<'_>,
286 ) -> Poll<std::result::Result<(), Self::Error>> {
287 Poll::Ready(Ok(()))
288 }
289 fn call(&mut self, req: http::Request<B>) -> Self::Future {
290 let inner = self.inner.clone();
291 match req.uri().path() {
292 "/proto.rpc.examples.echo.v1.EchoService/Echo" => {
293 #[allow(non_camel_case_types)]
294 struct EchoSvc<T: EchoService>(pub Arc<T>);
295 impl<T: EchoService> tonic::server::UnaryService<super::EchoRequest>
296 for EchoSvc<T> {
297 type Response = super::EchoResponse;
298 type Future = BoxFuture<
299 tonic::Response<Self::Response>,
300 tonic::Status,
301 >;
302 fn call(
303 &mut self,
304 request: tonic::Request<super::EchoRequest>,
305 ) -> Self::Future {
306 let inner = Arc::clone(&self.0);
307 let fut = async move { (*inner).echo(request).await };
308 Box::pin(fut)
309 }
310 }
311 let accept_compression_encodings = self.accept_compression_encodings;
312 let send_compression_encodings = self.send_compression_encodings;
313 let max_decoding_message_size = self.max_decoding_message_size;
314 let max_encoding_message_size = self.max_encoding_message_size;
315 let inner = self.inner.clone();
316 let fut = async move {
317 let inner = inner.0;
318 let method = EchoSvc(inner);
319 let codec = tonic::codec::ProstCodec::default();
320 let mut grpc = tonic::server::Grpc::new(codec)
321 .apply_compression_config(
322 accept_compression_encodings,
323 send_compression_encodings,
324 )
325 .apply_max_message_size_config(
326 max_decoding_message_size,
327 max_encoding_message_size,
328 );
329 let res = grpc.unary(method, req).await;
330 Ok(res)
331 };
332 Box::pin(fut)
333 }
334 "/proto.rpc.examples.echo.v1.EchoService/EchoMultiple" => {
335 #[allow(non_camel_case_types)]
336 struct EchoMultipleSvc<T: EchoService>(pub Arc<T>);
337 impl<
338 T: EchoService,
339 > tonic::server::ServerStreamingService<super::EchoMultipleRequest>
340 for EchoMultipleSvc<T> {
341 type Response = super::EchoMultipleResponse;
342 type ResponseStream = T::EchoMultipleStream;
343 type Future = BoxFuture<
344 tonic::Response<Self::ResponseStream>,
345 tonic::Status,
346 >;
347 fn call(
348 &mut self,
349 request: tonic::Request<super::EchoMultipleRequest>,
350 ) -> Self::Future {
351 let inner = Arc::clone(&self.0);
352 let fut = async move {
353 (*inner).echo_multiple(request).await
354 };
355 Box::pin(fut)
356 }
357 }
358 let accept_compression_encodings = self.accept_compression_encodings;
359 let send_compression_encodings = self.send_compression_encodings;
360 let max_decoding_message_size = self.max_decoding_message_size;
361 let max_encoding_message_size = self.max_encoding_message_size;
362 let inner = self.inner.clone();
363 let fut = async move {
364 let inner = inner.0;
365 let method = EchoMultipleSvc(inner);
366 let codec = tonic::codec::ProstCodec::default();
367 let mut grpc = tonic::server::Grpc::new(codec)
368 .apply_compression_config(
369 accept_compression_encodings,
370 send_compression_encodings,
371 )
372 .apply_max_message_size_config(
373 max_decoding_message_size,
374 max_encoding_message_size,
375 );
376 let res = grpc.server_streaming(method, req).await;
377 Ok(res)
378 };
379 Box::pin(fut)
380 }
381 "/proto.rpc.examples.echo.v1.EchoService/EchoBiDi" => {
382 #[allow(non_camel_case_types)]
383 struct EchoBiDiSvc<T: EchoService>(pub Arc<T>);
384 impl<
385 T: EchoService,
386 > tonic::server::StreamingService<super::EchoBiDiRequest>
387 for EchoBiDiSvc<T> {
388 type Response = super::EchoBiDiResponse;
389 type ResponseStream = T::EchoBiDiStream;
390 type Future = BoxFuture<
391 tonic::Response<Self::ResponseStream>,
392 tonic::Status,
393 >;
394 fn call(
395 &mut self,
396 request: tonic::Request<
397 tonic::Streaming<super::EchoBiDiRequest>,
398 >,
399 ) -> Self::Future {
400 let inner = Arc::clone(&self.0);
401 let fut = async move { (*inner).echo_bi_di(request).await };
402 Box::pin(fut)
403 }
404 }
405 let accept_compression_encodings = self.accept_compression_encodings;
406 let send_compression_encodings = self.send_compression_encodings;
407 let max_decoding_message_size = self.max_decoding_message_size;
408 let max_encoding_message_size = self.max_encoding_message_size;
409 let inner = self.inner.clone();
410 let fut = async move {
411 let inner = inner.0;
412 let method = EchoBiDiSvc(inner);
413 let codec = tonic::codec::ProstCodec::default();
414 let mut grpc = tonic::server::Grpc::new(codec)
415 .apply_compression_config(
416 accept_compression_encodings,
417 send_compression_encodings,
418 )
419 .apply_max_message_size_config(
420 max_decoding_message_size,
421 max_encoding_message_size,
422 );
423 let res = grpc.streaming(method, req).await;
424 Ok(res)
425 };
426 Box::pin(fut)
427 }
428 _ => {
429 Box::pin(async move {
430 Ok(
431 http::Response::builder()
432 .status(200)
433 .header("grpc-status", "12")
434 .header("content-type", "application/grpc")
435 .body(empty_body())
436 .unwrap(),
437 )
438 })
439 }
440 }
441 }
442 }
443 impl<T: EchoService> Clone for EchoServiceServer<T> {
444 fn clone(&self) -> Self {
445 let inner = self.inner.clone();
446 Self {
447 inner,
448 accept_compression_encodings: self.accept_compression_encodings,
449 send_compression_encodings: self.send_compression_encodings,
450 max_decoding_message_size: self.max_decoding_message_size,
451 max_encoding_message_size: self.max_encoding_message_size,
452 }
453 }
454 }
455 impl<T: EchoService> Clone for _Inner<T> {
456 fn clone(&self) -> Self {
457 Self(Arc::clone(&self.0))
458 }
459 }
460 impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
461 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
462 write!(f, "{:?}", self.0)
463 }
464 }
465 impl<T: EchoService> tonic::server::NamedService for EchoServiceServer<T> {
466 const NAME: &'static str = "proto.rpc.examples.echo.v1.EchoService";
467 }
468}