avalanche_proto/gen/
http.tonic.rs

1// @generated
2/// Generated client implementations.
3pub mod http_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 HttpClient<T> {
9        inner: tonic::client::Grpc<T>,
10    }
11    impl HttpClient<tonic::transport::Channel> {
12        /// Attempt to create a new client by connecting to a given endpoint.
13        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> HttpClient<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        ) -> HttpClient<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            HttpClient::new(InterceptedService::new(inner, interceptor))
55        }
56        /// Compress requests with the given encoding.
57        ///
58        /// This requires the server to support it otherwise it might respond with an
59        /// error.
60        #[must_use]
61        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
62            self.inner = self.inner.send_compressed(encoding);
63            self
64        }
65        /// Enable decompressing responses.
66        #[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 handle(
72            &mut self,
73            request: impl tonic::IntoRequest<super::HttpRequest>,
74        ) -> Result<
75            tonic::Response<super::super::google::protobuf::Empty>,
76            tonic::Status,
77        > {
78            self.inner
79                .ready()
80                .await
81                .map_err(|e| {
82                    tonic::Status::new(
83                        tonic::Code::Unknown,
84                        format!("Service was not ready: {}", e.into()),
85                    )
86                })?;
87            let codec = tonic::codec::ProstCodec::default();
88            let path = http::uri::PathAndQuery::from_static("/http.HTTP/Handle");
89            self.inner.unary(request.into_request(), path, codec).await
90        }
91        pub async fn handle_simple(
92            &mut self,
93            request: impl tonic::IntoRequest<super::HandleSimpleHttpRequest>,
94        ) -> Result<tonic::Response<super::HandleSimpleHttpResponse>, tonic::Status> {
95            self.inner
96                .ready()
97                .await
98                .map_err(|e| {
99                    tonic::Status::new(
100                        tonic::Code::Unknown,
101                        format!("Service was not ready: {}", e.into()),
102                    )
103                })?;
104            let codec = tonic::codec::ProstCodec::default();
105            let path = http::uri::PathAndQuery::from_static("/http.HTTP/HandleSimple");
106            self.inner.unary(request.into_request(), path, codec).await
107        }
108    }
109}
110/// Generated server implementations.
111pub mod http_server {
112    #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
113    use tonic::codegen::*;
114    ///Generated trait containing gRPC methods that should be implemented for use with HttpServer.
115    #[async_trait]
116    pub trait Http: Send + Sync + 'static {
117        async fn handle(
118            &self,
119            request: tonic::Request<super::HttpRequest>,
120        ) -> Result<
121            tonic::Response<super::super::google::protobuf::Empty>,
122            tonic::Status,
123        >;
124        async fn handle_simple(
125            &self,
126            request: tonic::Request<super::HandleSimpleHttpRequest>,
127        ) -> Result<tonic::Response<super::HandleSimpleHttpResponse>, tonic::Status>;
128    }
129    #[derive(Debug)]
130    pub struct HttpServer<T: Http> {
131        inner: _Inner<T>,
132        accept_compression_encodings: EnabledCompressionEncodings,
133        send_compression_encodings: EnabledCompressionEncodings,
134    }
135    struct _Inner<T>(Arc<T>);
136    impl<T: Http> HttpServer<T> {
137        pub fn new(inner: T) -> Self {
138            Self::from_arc(Arc::new(inner))
139        }
140        pub fn from_arc(inner: Arc<T>) -> Self {
141            let inner = _Inner(inner);
142            Self {
143                inner,
144                accept_compression_encodings: Default::default(),
145                send_compression_encodings: Default::default(),
146            }
147        }
148        pub fn with_interceptor<F>(
149            inner: T,
150            interceptor: F,
151        ) -> InterceptedService<Self, F>
152        where
153            F: tonic::service::Interceptor,
154        {
155            InterceptedService::new(Self::new(inner), interceptor)
156        }
157        /// Enable decompressing requests with the given encoding.
158        #[must_use]
159        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
160            self.accept_compression_encodings.enable(encoding);
161            self
162        }
163        /// Compress responses with the given encoding, if the client supports it.
164        #[must_use]
165        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
166            self.send_compression_encodings.enable(encoding);
167            self
168        }
169    }
170    impl<T, B> tonic::codegen::Service<http::Request<B>> for HttpServer<T>
171    where
172        T: Http,
173        B: Body + Send + 'static,
174        B::Error: Into<StdError> + Send + 'static,
175    {
176        type Response = http::Response<tonic::body::BoxBody>;
177        type Error = std::convert::Infallible;
178        type Future = BoxFuture<Self::Response, Self::Error>;
179        fn poll_ready(
180            &mut self,
181            _cx: &mut Context<'_>,
182        ) -> Poll<Result<(), Self::Error>> {
183            Poll::Ready(Ok(()))
184        }
185        fn call(&mut self, req: http::Request<B>) -> Self::Future {
186            let inner = self.inner.clone();
187            match req.uri().path() {
188                "/http.HTTP/Handle" => {
189                    #[allow(non_camel_case_types)]
190                    struct HandleSvc<T: Http>(pub Arc<T>);
191                    impl<T: Http> tonic::server::UnaryService<super::HttpRequest>
192                    for HandleSvc<T> {
193                        type Response = super::super::google::protobuf::Empty;
194                        type Future = BoxFuture<
195                            tonic::Response<Self::Response>,
196                            tonic::Status,
197                        >;
198                        fn call(
199                            &mut self,
200                            request: tonic::Request<super::HttpRequest>,
201                        ) -> Self::Future {
202                            let inner = self.0.clone();
203                            let fut = async move { (*inner).handle(request).await };
204                            Box::pin(fut)
205                        }
206                    }
207                    let accept_compression_encodings = self.accept_compression_encodings;
208                    let send_compression_encodings = self.send_compression_encodings;
209                    let inner = self.inner.clone();
210                    let fut = async move {
211                        let inner = inner.0;
212                        let method = HandleSvc(inner);
213                        let codec = tonic::codec::ProstCodec::default();
214                        let mut grpc = tonic::server::Grpc::new(codec)
215                            .apply_compression_config(
216                                accept_compression_encodings,
217                                send_compression_encodings,
218                            );
219                        let res = grpc.unary(method, req).await;
220                        Ok(res)
221                    };
222                    Box::pin(fut)
223                }
224                "/http.HTTP/HandleSimple" => {
225                    #[allow(non_camel_case_types)]
226                    struct HandleSimpleSvc<T: Http>(pub Arc<T>);
227                    impl<
228                        T: Http,
229                    > tonic::server::UnaryService<super::HandleSimpleHttpRequest>
230                    for HandleSimpleSvc<T> {
231                        type Response = super::HandleSimpleHttpResponse;
232                        type Future = BoxFuture<
233                            tonic::Response<Self::Response>,
234                            tonic::Status,
235                        >;
236                        fn call(
237                            &mut self,
238                            request: tonic::Request<super::HandleSimpleHttpRequest>,
239                        ) -> Self::Future {
240                            let inner = self.0.clone();
241                            let fut = async move {
242                                (*inner).handle_simple(request).await
243                            };
244                            Box::pin(fut)
245                        }
246                    }
247                    let accept_compression_encodings = self.accept_compression_encodings;
248                    let send_compression_encodings = self.send_compression_encodings;
249                    let inner = self.inner.clone();
250                    let fut = async move {
251                        let inner = inner.0;
252                        let method = HandleSimpleSvc(inner);
253                        let codec = tonic::codec::ProstCodec::default();
254                        let mut grpc = tonic::server::Grpc::new(codec)
255                            .apply_compression_config(
256                                accept_compression_encodings,
257                                send_compression_encodings,
258                            );
259                        let res = grpc.unary(method, req).await;
260                        Ok(res)
261                    };
262                    Box::pin(fut)
263                }
264                _ => {
265                    Box::pin(async move {
266                        Ok(
267                            http::Response::builder()
268                                .status(200)
269                                .header("grpc-status", "12")
270                                .header("content-type", "application/grpc")
271                                .body(empty_body())
272                                .unwrap(),
273                        )
274                    })
275                }
276            }
277        }
278    }
279    impl<T: Http> Clone for HttpServer<T> {
280        fn clone(&self) -> Self {
281            let inner = self.inner.clone();
282            Self {
283                inner,
284                accept_compression_encodings: self.accept_compression_encodings,
285                send_compression_encodings: self.send_compression_encodings,
286            }
287        }
288    }
289    impl<T: Http> Clone for _Inner<T> {
290        fn clone(&self) -> Self {
291            Self(self.0.clone())
292        }
293    }
294    impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
295        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
296            write!(f, "{:?}", self.0)
297        }
298    }
299    impl<T: Http> tonic::server::NamedService for HttpServer<T> {
300        const NAME: &'static str = "http.HTTP";
301    }
302}