avalanche_types/proto/pb/
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: 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        /// Limits the maximum size of a decoded message.
72        ///
73        /// Default: `4MB`
74        #[must_use]
75        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
76            self.inner = self.inner.max_decoding_message_size(limit);
77            self
78        }
79        /// Limits the maximum size of an encoded message.
80        ///
81        /// Default: `usize::MAX`
82        #[must_use]
83        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
84            self.inner = self.inner.max_encoding_message_size(limit);
85            self
86        }
87        pub async fn handle(
88            &mut self,
89            request: impl tonic::IntoRequest<super::HttpRequest>,
90        ) -> std::result::Result<
91            tonic::Response<super::super::google::protobuf::Empty>,
92            tonic::Status,
93        > {
94            self.inner
95                .ready()
96                .await
97                .map_err(|e| {
98                    tonic::Status::new(
99                        tonic::Code::Unknown,
100                        format!("Service was not ready: {}", e.into()),
101                    )
102                })?;
103            let codec = tonic::codec::ProstCodec::default();
104            let path = http::uri::PathAndQuery::from_static("/http.HTTP/Handle");
105            let mut req = request.into_request();
106            req.extensions_mut().insert(GrpcMethod::new("http.HTTP", "Handle"));
107            self.inner.unary(req, path, codec).await
108        }
109        pub async fn handle_simple(
110            &mut self,
111            request: impl tonic::IntoRequest<super::HandleSimpleHttpRequest>,
112        ) -> std::result::Result<
113            tonic::Response<super::HandleSimpleHttpResponse>,
114            tonic::Status,
115        > {
116            self.inner
117                .ready()
118                .await
119                .map_err(|e| {
120                    tonic::Status::new(
121                        tonic::Code::Unknown,
122                        format!("Service was not ready: {}", e.into()),
123                    )
124                })?;
125            let codec = tonic::codec::ProstCodec::default();
126            let path = http::uri::PathAndQuery::from_static("/http.HTTP/HandleSimple");
127            let mut req = request.into_request();
128            req.extensions_mut().insert(GrpcMethod::new("http.HTTP", "HandleSimple"));
129            self.inner.unary(req, path, codec).await
130        }
131    }
132}
133/// Generated server implementations.
134pub mod http_server {
135    #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
136    use tonic::codegen::*;
137    /// Generated trait containing gRPC methods that should be implemented for use with HttpServer.
138    #[async_trait]
139    pub trait Http: Send + Sync + 'static {
140        async fn handle(
141            &self,
142            request: tonic::Request<super::HttpRequest>,
143        ) -> std::result::Result<
144            tonic::Response<super::super::google::protobuf::Empty>,
145            tonic::Status,
146        >;
147        async fn handle_simple(
148            &self,
149            request: tonic::Request<super::HandleSimpleHttpRequest>,
150        ) -> std::result::Result<
151            tonic::Response<super::HandleSimpleHttpResponse>,
152            tonic::Status,
153        >;
154    }
155    #[derive(Debug)]
156    pub struct HttpServer<T: Http> {
157        inner: _Inner<T>,
158        accept_compression_encodings: EnabledCompressionEncodings,
159        send_compression_encodings: EnabledCompressionEncodings,
160        max_decoding_message_size: Option<usize>,
161        max_encoding_message_size: Option<usize>,
162    }
163    struct _Inner<T>(Arc<T>);
164    impl<T: Http> HttpServer<T> {
165        pub fn new(inner: T) -> Self {
166            Self::from_arc(Arc::new(inner))
167        }
168        pub fn from_arc(inner: Arc<T>) -> Self {
169            let inner = _Inner(inner);
170            Self {
171                inner,
172                accept_compression_encodings: Default::default(),
173                send_compression_encodings: Default::default(),
174                max_decoding_message_size: None,
175                max_encoding_message_size: None,
176            }
177        }
178        pub fn with_interceptor<F>(
179            inner: T,
180            interceptor: F,
181        ) -> InterceptedService<Self, F>
182        where
183            F: tonic::service::Interceptor,
184        {
185            InterceptedService::new(Self::new(inner), interceptor)
186        }
187        /// Enable decompressing requests with the given encoding.
188        #[must_use]
189        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
190            self.accept_compression_encodings.enable(encoding);
191            self
192        }
193        /// Compress responses with the given encoding, if the client supports it.
194        #[must_use]
195        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
196            self.send_compression_encodings.enable(encoding);
197            self
198        }
199        /// Limits the maximum size of a decoded message.
200        ///
201        /// Default: `4MB`
202        #[must_use]
203        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
204            self.max_decoding_message_size = Some(limit);
205            self
206        }
207        /// Limits the maximum size of an encoded message.
208        ///
209        /// Default: `usize::MAX`
210        #[must_use]
211        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
212            self.max_encoding_message_size = Some(limit);
213            self
214        }
215    }
216    impl<T, B> tonic::codegen::Service<http::Request<B>> for HttpServer<T>
217    where
218        T: Http,
219        B: Body + Send + 'static,
220        B::Error: Into<StdError> + Send + 'static,
221    {
222        type Response = http::Response<tonic::body::BoxBody>;
223        type Error = std::convert::Infallible;
224        type Future = BoxFuture<Self::Response, Self::Error>;
225        fn poll_ready(
226            &mut self,
227            _cx: &mut Context<'_>,
228        ) -> Poll<std::result::Result<(), Self::Error>> {
229            Poll::Ready(Ok(()))
230        }
231        fn call(&mut self, req: http::Request<B>) -> Self::Future {
232            let inner = self.inner.clone();
233            match req.uri().path() {
234                "/http.HTTP/Handle" => {
235                    #[allow(non_camel_case_types)]
236                    struct HandleSvc<T: Http>(pub Arc<T>);
237                    impl<T: Http> tonic::server::UnaryService<super::HttpRequest>
238                    for HandleSvc<T> {
239                        type Response = super::super::google::protobuf::Empty;
240                        type Future = BoxFuture<
241                            tonic::Response<Self::Response>,
242                            tonic::Status,
243                        >;
244                        fn call(
245                            &mut self,
246                            request: tonic::Request<super::HttpRequest>,
247                        ) -> Self::Future {
248                            let inner = Arc::clone(&self.0);
249                            let fut = async move { (*inner).handle(request).await };
250                            Box::pin(fut)
251                        }
252                    }
253                    let accept_compression_encodings = self.accept_compression_encodings;
254                    let send_compression_encodings = self.send_compression_encodings;
255                    let max_decoding_message_size = self.max_decoding_message_size;
256                    let max_encoding_message_size = self.max_encoding_message_size;
257                    let inner = self.inner.clone();
258                    let fut = async move {
259                        let inner = inner.0;
260                        let method = HandleSvc(inner);
261                        let codec = tonic::codec::ProstCodec::default();
262                        let mut grpc = tonic::server::Grpc::new(codec)
263                            .apply_compression_config(
264                                accept_compression_encodings,
265                                send_compression_encodings,
266                            )
267                            .apply_max_message_size_config(
268                                max_decoding_message_size,
269                                max_encoding_message_size,
270                            );
271                        let res = grpc.unary(method, req).await;
272                        Ok(res)
273                    };
274                    Box::pin(fut)
275                }
276                "/http.HTTP/HandleSimple" => {
277                    #[allow(non_camel_case_types)]
278                    struct HandleSimpleSvc<T: Http>(pub Arc<T>);
279                    impl<
280                        T: Http,
281                    > tonic::server::UnaryService<super::HandleSimpleHttpRequest>
282                    for HandleSimpleSvc<T> {
283                        type Response = super::HandleSimpleHttpResponse;
284                        type Future = BoxFuture<
285                            tonic::Response<Self::Response>,
286                            tonic::Status,
287                        >;
288                        fn call(
289                            &mut self,
290                            request: tonic::Request<super::HandleSimpleHttpRequest>,
291                        ) -> Self::Future {
292                            let inner = Arc::clone(&self.0);
293                            let fut = async move {
294                                (*inner).handle_simple(request).await
295                            };
296                            Box::pin(fut)
297                        }
298                    }
299                    let accept_compression_encodings = self.accept_compression_encodings;
300                    let send_compression_encodings = self.send_compression_encodings;
301                    let max_decoding_message_size = self.max_decoding_message_size;
302                    let max_encoding_message_size = self.max_encoding_message_size;
303                    let inner = self.inner.clone();
304                    let fut = async move {
305                        let inner = inner.0;
306                        let method = HandleSimpleSvc(inner);
307                        let codec = tonic::codec::ProstCodec::default();
308                        let mut grpc = tonic::server::Grpc::new(codec)
309                            .apply_compression_config(
310                                accept_compression_encodings,
311                                send_compression_encodings,
312                            )
313                            .apply_max_message_size_config(
314                                max_decoding_message_size,
315                                max_encoding_message_size,
316                            );
317                        let res = grpc.unary(method, req).await;
318                        Ok(res)
319                    };
320                    Box::pin(fut)
321                }
322                _ => {
323                    Box::pin(async move {
324                        Ok(
325                            http::Response::builder()
326                                .status(200)
327                                .header("grpc-status", "12")
328                                .header("content-type", "application/grpc")
329                                .body(empty_body())
330                                .unwrap(),
331                        )
332                    })
333                }
334            }
335        }
336    }
337    impl<T: Http> Clone for HttpServer<T> {
338        fn clone(&self) -> Self {
339            let inner = self.inner.clone();
340            Self {
341                inner,
342                accept_compression_encodings: self.accept_compression_encodings,
343                send_compression_encodings: self.send_compression_encodings,
344                max_decoding_message_size: self.max_decoding_message_size,
345                max_encoding_message_size: self.max_encoding_message_size,
346            }
347        }
348    }
349    impl<T: Http> Clone for _Inner<T> {
350        fn clone(&self) -> Self {
351            Self(Arc::clone(&self.0))
352        }
353    }
354    impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
355        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
356            write!(f, "{:?}", self.0)
357        }
358    }
359    impl<T: Http> tonic::server::NamedService for HttpServer<T> {
360        const NAME: &'static str = "http.HTTP";
361    }
362}