1pub mod conn_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)]
8 pub struct ConnClient<T> {
9 inner: tonic::client::Grpc<T>,
10 }
11 impl ConnClient<tonic::transport::Channel> {
12 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
14 where
15 D: std::convert::TryInto<tonic::transport::Endpoint>,
16 D::Error: Into<StdError>,
17 {
18 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
19 Ok(Self::new(conn))
20 }
21 }
22 impl<T> ConnClient<T>
23 where
24 T: tonic::client::GrpcService<tonic::body::BoxBody>,
25 T::Error: Into<StdError>,
26 T::ResponseBody: Body<Data = Bytes> + Send + 'static,
27 <T::ResponseBody as Body>::Error: Into<StdError> + Send,
28 {
29 pub fn new(inner: T) -> Self {
30 let inner = tonic::client::Grpc::new(inner);
31 Self { inner }
32 }
33 pub fn with_origin(inner: T, origin: Uri) -> Self {
34 let inner = tonic::client::Grpc::with_origin(inner, origin);
35 Self { inner }
36 }
37 pub fn with_interceptor<F>(
38 inner: T,
39 interceptor: F,
40 ) -> ConnClient<InterceptedService<T, F>>
41 where
42 F: tonic::service::Interceptor,
43 T::ResponseBody: Default,
44 T: tonic::codegen::Service<
45 http::Request<tonic::body::BoxBody>,
46 Response = http::Response<
47 <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
48 >,
49 >,
50 <T as tonic::codegen::Service<
51 http::Request<tonic::body::BoxBody>,
52 >>::Error: Into<StdError> + Send + Sync,
53 {
54 ConnClient::new(InterceptedService::new(inner, interceptor))
55 }
56 #[must_use]
61 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
62 self.inner = self.inner.send_compressed(encoding);
63 self
64 }
65 #[must_use]
67 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
68 self.inner = self.inner.accept_compressed(encoding);
69 self
70 }
71 pub async fn read(
72 &mut self,
73 request: impl tonic::IntoRequest<super::ReadRequest>,
74 ) -> Result<tonic::Response<super::ReadResponse>, tonic::Status> {
75 self.inner
76 .ready()
77 .await
78 .map_err(|e| {
79 tonic::Status::new(
80 tonic::Code::Unknown,
81 format!("Service was not ready: {}", e.into()),
82 )
83 })?;
84 let codec = tonic::codec::ProstCodec::default();
85 let path = http::uri::PathAndQuery::from_static("/net.conn.Conn/Read");
86 self.inner.unary(request.into_request(), path, codec).await
87 }
88 pub async fn write(
89 &mut self,
90 request: impl tonic::IntoRequest<super::WriteRequest>,
91 ) -> Result<tonic::Response<super::WriteResponse>, tonic::Status> {
92 self.inner
93 .ready()
94 .await
95 .map_err(|e| {
96 tonic::Status::new(
97 tonic::Code::Unknown,
98 format!("Service was not ready: {}", e.into()),
99 )
100 })?;
101 let codec = tonic::codec::ProstCodec::default();
102 let path = http::uri::PathAndQuery::from_static("/net.conn.Conn/Write");
103 self.inner.unary(request.into_request(), path, codec).await
104 }
105 pub async fn close(
106 &mut self,
107 request: impl tonic::IntoRequest<
108 super::super::super::google::protobuf::Empty,
109 >,
110 ) -> Result<
111 tonic::Response<super::super::super::google::protobuf::Empty>,
112 tonic::Status,
113 > {
114 self.inner
115 .ready()
116 .await
117 .map_err(|e| {
118 tonic::Status::new(
119 tonic::Code::Unknown,
120 format!("Service was not ready: {}", e.into()),
121 )
122 })?;
123 let codec = tonic::codec::ProstCodec::default();
124 let path = http::uri::PathAndQuery::from_static("/net.conn.Conn/Close");
125 self.inner.unary(request.into_request(), path, codec).await
126 }
127 pub async fn set_deadline(
128 &mut self,
129 request: impl tonic::IntoRequest<super::SetDeadlineRequest>,
130 ) -> Result<
131 tonic::Response<super::super::super::google::protobuf::Empty>,
132 tonic::Status,
133 > {
134 self.inner
135 .ready()
136 .await
137 .map_err(|e| {
138 tonic::Status::new(
139 tonic::Code::Unknown,
140 format!("Service was not ready: {}", e.into()),
141 )
142 })?;
143 let codec = tonic::codec::ProstCodec::default();
144 let path = http::uri::PathAndQuery::from_static(
145 "/net.conn.Conn/SetDeadline",
146 );
147 self.inner.unary(request.into_request(), path, codec).await
148 }
149 pub async fn set_read_deadline(
150 &mut self,
151 request: impl tonic::IntoRequest<super::SetDeadlineRequest>,
152 ) -> Result<
153 tonic::Response<super::super::super::google::protobuf::Empty>,
154 tonic::Status,
155 > {
156 self.inner
157 .ready()
158 .await
159 .map_err(|e| {
160 tonic::Status::new(
161 tonic::Code::Unknown,
162 format!("Service was not ready: {}", e.into()),
163 )
164 })?;
165 let codec = tonic::codec::ProstCodec::default();
166 let path = http::uri::PathAndQuery::from_static(
167 "/net.conn.Conn/SetReadDeadline",
168 );
169 self.inner.unary(request.into_request(), path, codec).await
170 }
171 pub async fn set_write_deadline(
172 &mut self,
173 request: impl tonic::IntoRequest<super::SetDeadlineRequest>,
174 ) -> Result<
175 tonic::Response<super::super::super::google::protobuf::Empty>,
176 tonic::Status,
177 > {
178 self.inner
179 .ready()
180 .await
181 .map_err(|e| {
182 tonic::Status::new(
183 tonic::Code::Unknown,
184 format!("Service was not ready: {}", e.into()),
185 )
186 })?;
187 let codec = tonic::codec::ProstCodec::default();
188 let path = http::uri::PathAndQuery::from_static(
189 "/net.conn.Conn/SetWriteDeadline",
190 );
191 self.inner.unary(request.into_request(), path, codec).await
192 }
193 }
194}
195pub mod conn_server {
197 #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
198 use tonic::codegen::*;
199 #[async_trait]
201 pub trait Conn: Send + Sync + 'static {
202 async fn read(
203 &self,
204 request: tonic::Request<super::ReadRequest>,
205 ) -> Result<tonic::Response<super::ReadResponse>, tonic::Status>;
206 async fn write(
207 &self,
208 request: tonic::Request<super::WriteRequest>,
209 ) -> Result<tonic::Response<super::WriteResponse>, tonic::Status>;
210 async fn close(
211 &self,
212 request: tonic::Request<super::super::super::google::protobuf::Empty>,
213 ) -> Result<
214 tonic::Response<super::super::super::google::protobuf::Empty>,
215 tonic::Status,
216 >;
217 async fn set_deadline(
218 &self,
219 request: tonic::Request<super::SetDeadlineRequest>,
220 ) -> Result<
221 tonic::Response<super::super::super::google::protobuf::Empty>,
222 tonic::Status,
223 >;
224 async fn set_read_deadline(
225 &self,
226 request: tonic::Request<super::SetDeadlineRequest>,
227 ) -> Result<
228 tonic::Response<super::super::super::google::protobuf::Empty>,
229 tonic::Status,
230 >;
231 async fn set_write_deadline(
232 &self,
233 request: tonic::Request<super::SetDeadlineRequest>,
234 ) -> Result<
235 tonic::Response<super::super::super::google::protobuf::Empty>,
236 tonic::Status,
237 >;
238 }
239 #[derive(Debug)]
240 pub struct ConnServer<T: Conn> {
241 inner: _Inner<T>,
242 accept_compression_encodings: EnabledCompressionEncodings,
243 send_compression_encodings: EnabledCompressionEncodings,
244 }
245 struct _Inner<T>(Arc<T>);
246 impl<T: Conn> ConnServer<T> {
247 pub fn new(inner: T) -> Self {
248 Self::from_arc(Arc::new(inner))
249 }
250 pub fn from_arc(inner: Arc<T>) -> Self {
251 let inner = _Inner(inner);
252 Self {
253 inner,
254 accept_compression_encodings: Default::default(),
255 send_compression_encodings: Default::default(),
256 }
257 }
258 pub fn with_interceptor<F>(
259 inner: T,
260 interceptor: F,
261 ) -> InterceptedService<Self, F>
262 where
263 F: tonic::service::Interceptor,
264 {
265 InterceptedService::new(Self::new(inner), interceptor)
266 }
267 #[must_use]
269 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
270 self.accept_compression_encodings.enable(encoding);
271 self
272 }
273 #[must_use]
275 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
276 self.send_compression_encodings.enable(encoding);
277 self
278 }
279 }
280 impl<T, B> tonic::codegen::Service<http::Request<B>> for ConnServer<T>
281 where
282 T: Conn,
283 B: Body + Send + 'static,
284 B::Error: Into<StdError> + Send + 'static,
285 {
286 type Response = http::Response<tonic::body::BoxBody>;
287 type Error = std::convert::Infallible;
288 type Future = BoxFuture<Self::Response, Self::Error>;
289 fn poll_ready(
290 &mut self,
291 _cx: &mut Context<'_>,
292 ) -> Poll<Result<(), Self::Error>> {
293 Poll::Ready(Ok(()))
294 }
295 fn call(&mut self, req: http::Request<B>) -> Self::Future {
296 let inner = self.inner.clone();
297 match req.uri().path() {
298 "/net.conn.Conn/Read" => {
299 #[allow(non_camel_case_types)]
300 struct ReadSvc<T: Conn>(pub Arc<T>);
301 impl<T: Conn> tonic::server::UnaryService<super::ReadRequest>
302 for ReadSvc<T> {
303 type Response = super::ReadResponse;
304 type Future = BoxFuture<
305 tonic::Response<Self::Response>,
306 tonic::Status,
307 >;
308 fn call(
309 &mut self,
310 request: tonic::Request<super::ReadRequest>,
311 ) -> Self::Future {
312 let inner = self.0.clone();
313 let fut = async move { (*inner).read(request).await };
314 Box::pin(fut)
315 }
316 }
317 let accept_compression_encodings = self.accept_compression_encodings;
318 let send_compression_encodings = self.send_compression_encodings;
319 let inner = self.inner.clone();
320 let fut = async move {
321 let inner = inner.0;
322 let method = ReadSvc(inner);
323 let codec = tonic::codec::ProstCodec::default();
324 let mut grpc = tonic::server::Grpc::new(codec)
325 .apply_compression_config(
326 accept_compression_encodings,
327 send_compression_encodings,
328 );
329 let res = grpc.unary(method, req).await;
330 Ok(res)
331 };
332 Box::pin(fut)
333 }
334 "/net.conn.Conn/Write" => {
335 #[allow(non_camel_case_types)]
336 struct WriteSvc<T: Conn>(pub Arc<T>);
337 impl<T: Conn> tonic::server::UnaryService<super::WriteRequest>
338 for WriteSvc<T> {
339 type Response = super::WriteResponse;
340 type Future = BoxFuture<
341 tonic::Response<Self::Response>,
342 tonic::Status,
343 >;
344 fn call(
345 &mut self,
346 request: tonic::Request<super::WriteRequest>,
347 ) -> Self::Future {
348 let inner = self.0.clone();
349 let fut = async move { (*inner).write(request).await };
350 Box::pin(fut)
351 }
352 }
353 let accept_compression_encodings = self.accept_compression_encodings;
354 let send_compression_encodings = self.send_compression_encodings;
355 let inner = self.inner.clone();
356 let fut = async move {
357 let inner = inner.0;
358 let method = WriteSvc(inner);
359 let codec = tonic::codec::ProstCodec::default();
360 let mut grpc = tonic::server::Grpc::new(codec)
361 .apply_compression_config(
362 accept_compression_encodings,
363 send_compression_encodings,
364 );
365 let res = grpc.unary(method, req).await;
366 Ok(res)
367 };
368 Box::pin(fut)
369 }
370 "/net.conn.Conn/Close" => {
371 #[allow(non_camel_case_types)]
372 struct CloseSvc<T: Conn>(pub Arc<T>);
373 impl<
374 T: Conn,
375 > tonic::server::UnaryService<
376 super::super::super::google::protobuf::Empty,
377 > for CloseSvc<T> {
378 type Response = super::super::super::google::protobuf::Empty;
379 type Future = BoxFuture<
380 tonic::Response<Self::Response>,
381 tonic::Status,
382 >;
383 fn call(
384 &mut self,
385 request: tonic::Request<
386 super::super::super::google::protobuf::Empty,
387 >,
388 ) -> Self::Future {
389 let inner = self.0.clone();
390 let fut = async move { (*inner).close(request).await };
391 Box::pin(fut)
392 }
393 }
394 let accept_compression_encodings = self.accept_compression_encodings;
395 let send_compression_encodings = self.send_compression_encodings;
396 let inner = self.inner.clone();
397 let fut = async move {
398 let inner = inner.0;
399 let method = CloseSvc(inner);
400 let codec = tonic::codec::ProstCodec::default();
401 let mut grpc = tonic::server::Grpc::new(codec)
402 .apply_compression_config(
403 accept_compression_encodings,
404 send_compression_encodings,
405 );
406 let res = grpc.unary(method, req).await;
407 Ok(res)
408 };
409 Box::pin(fut)
410 }
411 "/net.conn.Conn/SetDeadline" => {
412 #[allow(non_camel_case_types)]
413 struct SetDeadlineSvc<T: Conn>(pub Arc<T>);
414 impl<T: Conn> tonic::server::UnaryService<super::SetDeadlineRequest>
415 for SetDeadlineSvc<T> {
416 type Response = super::super::super::google::protobuf::Empty;
417 type Future = BoxFuture<
418 tonic::Response<Self::Response>,
419 tonic::Status,
420 >;
421 fn call(
422 &mut self,
423 request: tonic::Request<super::SetDeadlineRequest>,
424 ) -> Self::Future {
425 let inner = self.0.clone();
426 let fut = async move {
427 (*inner).set_deadline(request).await
428 };
429 Box::pin(fut)
430 }
431 }
432 let accept_compression_encodings = self.accept_compression_encodings;
433 let send_compression_encodings = self.send_compression_encodings;
434 let inner = self.inner.clone();
435 let fut = async move {
436 let inner = inner.0;
437 let method = SetDeadlineSvc(inner);
438 let codec = tonic::codec::ProstCodec::default();
439 let mut grpc = tonic::server::Grpc::new(codec)
440 .apply_compression_config(
441 accept_compression_encodings,
442 send_compression_encodings,
443 );
444 let res = grpc.unary(method, req).await;
445 Ok(res)
446 };
447 Box::pin(fut)
448 }
449 "/net.conn.Conn/SetReadDeadline" => {
450 #[allow(non_camel_case_types)]
451 struct SetReadDeadlineSvc<T: Conn>(pub Arc<T>);
452 impl<T: Conn> tonic::server::UnaryService<super::SetDeadlineRequest>
453 for SetReadDeadlineSvc<T> {
454 type Response = super::super::super::google::protobuf::Empty;
455 type Future = BoxFuture<
456 tonic::Response<Self::Response>,
457 tonic::Status,
458 >;
459 fn call(
460 &mut self,
461 request: tonic::Request<super::SetDeadlineRequest>,
462 ) -> Self::Future {
463 let inner = self.0.clone();
464 let fut = async move {
465 (*inner).set_read_deadline(request).await
466 };
467 Box::pin(fut)
468 }
469 }
470 let accept_compression_encodings = self.accept_compression_encodings;
471 let send_compression_encodings = self.send_compression_encodings;
472 let inner = self.inner.clone();
473 let fut = async move {
474 let inner = inner.0;
475 let method = SetReadDeadlineSvc(inner);
476 let codec = tonic::codec::ProstCodec::default();
477 let mut grpc = tonic::server::Grpc::new(codec)
478 .apply_compression_config(
479 accept_compression_encodings,
480 send_compression_encodings,
481 );
482 let res = grpc.unary(method, req).await;
483 Ok(res)
484 };
485 Box::pin(fut)
486 }
487 "/net.conn.Conn/SetWriteDeadline" => {
488 #[allow(non_camel_case_types)]
489 struct SetWriteDeadlineSvc<T: Conn>(pub Arc<T>);
490 impl<T: Conn> tonic::server::UnaryService<super::SetDeadlineRequest>
491 for SetWriteDeadlineSvc<T> {
492 type Response = super::super::super::google::protobuf::Empty;
493 type Future = BoxFuture<
494 tonic::Response<Self::Response>,
495 tonic::Status,
496 >;
497 fn call(
498 &mut self,
499 request: tonic::Request<super::SetDeadlineRequest>,
500 ) -> Self::Future {
501 let inner = self.0.clone();
502 let fut = async move {
503 (*inner).set_write_deadline(request).await
504 };
505 Box::pin(fut)
506 }
507 }
508 let accept_compression_encodings = self.accept_compression_encodings;
509 let send_compression_encodings = self.send_compression_encodings;
510 let inner = self.inner.clone();
511 let fut = async move {
512 let inner = inner.0;
513 let method = SetWriteDeadlineSvc(inner);
514 let codec = tonic::codec::ProstCodec::default();
515 let mut grpc = tonic::server::Grpc::new(codec)
516 .apply_compression_config(
517 accept_compression_encodings,
518 send_compression_encodings,
519 );
520 let res = grpc.unary(method, req).await;
521 Ok(res)
522 };
523 Box::pin(fut)
524 }
525 _ => {
526 Box::pin(async move {
527 Ok(
528 http::Response::builder()
529 .status(200)
530 .header("grpc-status", "12")
531 .header("content-type", "application/grpc")
532 .body(empty_body())
533 .unwrap(),
534 )
535 })
536 }
537 }
538 }
539 }
540 impl<T: Conn> Clone for ConnServer<T> {
541 fn clone(&self) -> Self {
542 let inner = self.inner.clone();
543 Self {
544 inner,
545 accept_compression_encodings: self.accept_compression_encodings,
546 send_compression_encodings: self.send_compression_encodings,
547 }
548 }
549 }
550 impl<T: Conn> Clone for _Inner<T> {
551 fn clone(&self) -> Self {
552 Self(self.0.clone())
553 }
554 }
555 impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
556 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
557 write!(f, "{:?}", self.0)
558 }
559 }
560 impl<T: Conn> tonic::server::NamedService for ConnServer<T> {
561 const NAME: &'static str = "net.conn.Conn";
562 }
563}