tonic_health/generated/
grpc_health_v1.rs

1// This file is @generated by prost-build.
2#[derive(Clone, PartialEq, ::prost::Message)]
3pub struct HealthCheckRequest {
4    #[prost(string, tag = "1")]
5    pub service: ::prost::alloc::string::String,
6}
7#[derive(Clone, Copy, PartialEq, ::prost::Message)]
8pub struct HealthCheckResponse {
9    #[prost(enumeration = "health_check_response::ServingStatus", tag = "1")]
10    pub status: i32,
11}
12/// Nested message and enum types in `HealthCheckResponse`.
13pub mod health_check_response {
14    #[derive(
15        Clone,
16        Copy,
17        Debug,
18        PartialEq,
19        Eq,
20        Hash,
21        PartialOrd,
22        Ord,
23        ::prost::Enumeration
24    )]
25    #[repr(i32)]
26    pub enum ServingStatus {
27        Unknown = 0,
28        Serving = 1,
29        NotServing = 2,
30        /// Used only by the Watch method.
31        ServiceUnknown = 3,
32    }
33    impl ServingStatus {
34        /// String value of the enum field names used in the ProtoBuf definition.
35        ///
36        /// The values are not transformed in any way and thus are considered stable
37        /// (if the ProtoBuf definition does not change) and safe for programmatic use.
38        pub fn as_str_name(&self) -> &'static str {
39            match self {
40                Self::Unknown => "UNKNOWN",
41                Self::Serving => "SERVING",
42                Self::NotServing => "NOT_SERVING",
43                Self::ServiceUnknown => "SERVICE_UNKNOWN",
44            }
45        }
46        /// Creates an enum from field names used in the ProtoBuf definition.
47        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
48            match value {
49                "UNKNOWN" => Some(Self::Unknown),
50                "SERVING" => Some(Self::Serving),
51                "NOT_SERVING" => Some(Self::NotServing),
52                "SERVICE_UNKNOWN" => Some(Self::ServiceUnknown),
53                _ => None,
54            }
55        }
56    }
57}
58/// Generated client implementations.
59pub mod health_client {
60    #![allow(
61        unused_variables,
62        dead_code,
63        missing_docs,
64        clippy::wildcard_imports,
65        clippy::let_unit_value,
66    )]
67    use tonic::codegen::*;
68    use tonic::codegen::http::Uri;
69    #[derive(Debug, Clone)]
70    pub struct HealthClient<T> {
71        inner: tonic::client::Grpc<T>,
72    }
73    impl<T> HealthClient<T>
74    where
75        T: tonic::client::GrpcService<tonic::body::BoxBody>,
76        T::Error: Into<StdError>,
77        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
78        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
79    {
80        pub fn new(inner: T) -> Self {
81            let inner = tonic::client::Grpc::new(inner);
82            Self { inner }
83        }
84        pub fn with_origin(inner: T, origin: Uri) -> Self {
85            let inner = tonic::client::Grpc::with_origin(inner, origin);
86            Self { inner }
87        }
88        pub fn with_interceptor<F>(
89            inner: T,
90            interceptor: F,
91        ) -> HealthClient<InterceptedService<T, F>>
92        where
93            F: tonic::service::Interceptor,
94            T::ResponseBody: Default,
95            T: tonic::codegen::Service<
96                http::Request<tonic::body::BoxBody>,
97                Response = http::Response<
98                    <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
99                >,
100            >,
101            <T as tonic::codegen::Service<
102                http::Request<tonic::body::BoxBody>,
103            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
104        {
105            HealthClient::new(InterceptedService::new(inner, interceptor))
106        }
107        /// Compress requests with the given encoding.
108        ///
109        /// This requires the server to support it otherwise it might respond with an
110        /// error.
111        #[must_use]
112        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
113            self.inner = self.inner.send_compressed(encoding);
114            self
115        }
116        /// Enable decompressing responses.
117        #[must_use]
118        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
119            self.inner = self.inner.accept_compressed(encoding);
120            self
121        }
122        /// Limits the maximum size of a decoded message.
123        ///
124        /// Default: `4MB`
125        #[must_use]
126        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
127            self.inner = self.inner.max_decoding_message_size(limit);
128            self
129        }
130        /// Limits the maximum size of an encoded message.
131        ///
132        /// Default: `usize::MAX`
133        #[must_use]
134        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
135            self.inner = self.inner.max_encoding_message_size(limit);
136            self
137        }
138        /// If the requested service is unknown, the call will fail with status
139        /// NOT_FOUND.
140        pub async fn check(
141            &mut self,
142            request: impl tonic::IntoRequest<super::HealthCheckRequest>,
143        ) -> std::result::Result<
144            tonic::Response<super::HealthCheckResponse>,
145            tonic::Status,
146        > {
147            self.inner
148                .ready()
149                .await
150                .map_err(|e| {
151                    tonic::Status::unknown(
152                        format!("Service was not ready: {}", e.into()),
153                    )
154                })?;
155            let codec = tonic::codec::ProstCodec::default();
156            let path = http::uri::PathAndQuery::from_static(
157                "/grpc.health.v1.Health/Check",
158            );
159            let mut req = request.into_request();
160            req.extensions_mut()
161                .insert(GrpcMethod::new("grpc.health.v1.Health", "Check"));
162            self.inner.unary(req, path, codec).await
163        }
164        /// Performs a watch for the serving status of the requested service.
165        /// The server will immediately send back a message indicating the current
166        /// serving status.  It will then subsequently send a new message whenever
167        /// the service's serving status changes.
168        ///
169        /// If the requested service is unknown when the call is received, the
170        /// server will send a message setting the serving status to
171        /// SERVICE_UNKNOWN but will *not* terminate the call.  If at some
172        /// future point, the serving status of the service becomes known, the
173        /// server will send a new message with the service's serving status.
174        ///
175        /// If the call terminates with status UNIMPLEMENTED, then clients
176        /// should assume this method is not supported and should not retry the
177        /// call.  If the call terminates with any other status (including OK),
178        /// clients should retry the call with appropriate exponential backoff.
179        pub async fn watch(
180            &mut self,
181            request: impl tonic::IntoRequest<super::HealthCheckRequest>,
182        ) -> std::result::Result<
183            tonic::Response<tonic::codec::Streaming<super::HealthCheckResponse>>,
184            tonic::Status,
185        > {
186            self.inner
187                .ready()
188                .await
189                .map_err(|e| {
190                    tonic::Status::unknown(
191                        format!("Service was not ready: {}", e.into()),
192                    )
193                })?;
194            let codec = tonic::codec::ProstCodec::default();
195            let path = http::uri::PathAndQuery::from_static(
196                "/grpc.health.v1.Health/Watch",
197            );
198            let mut req = request.into_request();
199            req.extensions_mut()
200                .insert(GrpcMethod::new("grpc.health.v1.Health", "Watch"));
201            self.inner.server_streaming(req, path, codec).await
202        }
203    }
204}
205/// Generated server implementations.
206pub mod health_server {
207    #![allow(
208        unused_variables,
209        dead_code,
210        missing_docs,
211        clippy::wildcard_imports,
212        clippy::let_unit_value,
213    )]
214    use tonic::codegen::*;
215    /// Generated trait containing gRPC methods that should be implemented for use with HealthServer.
216    #[async_trait]
217    pub trait Health: std::marker::Send + std::marker::Sync + 'static {
218        /// If the requested service is unknown, the call will fail with status
219        /// NOT_FOUND.
220        async fn check(
221            &self,
222            request: tonic::Request<super::HealthCheckRequest>,
223        ) -> std::result::Result<
224            tonic::Response<super::HealthCheckResponse>,
225            tonic::Status,
226        >;
227        /// Server streaming response type for the Watch method.
228        type WatchStream: tonic::codegen::tokio_stream::Stream<
229                Item = std::result::Result<super::HealthCheckResponse, tonic::Status>,
230            >
231            + std::marker::Send
232            + 'static;
233        /// Performs a watch for the serving status of the requested service.
234        /// The server will immediately send back a message indicating the current
235        /// serving status.  It will then subsequently send a new message whenever
236        /// the service's serving status changes.
237        ///
238        /// If the requested service is unknown when the call is received, the
239        /// server will send a message setting the serving status to
240        /// SERVICE_UNKNOWN but will *not* terminate the call.  If at some
241        /// future point, the serving status of the service becomes known, the
242        /// server will send a new message with the service's serving status.
243        ///
244        /// If the call terminates with status UNIMPLEMENTED, then clients
245        /// should assume this method is not supported and should not retry the
246        /// call.  If the call terminates with any other status (including OK),
247        /// clients should retry the call with appropriate exponential backoff.
248        async fn watch(
249            &self,
250            request: tonic::Request<super::HealthCheckRequest>,
251        ) -> std::result::Result<tonic::Response<Self::WatchStream>, tonic::Status>;
252    }
253    #[derive(Debug)]
254    pub struct HealthServer<T> {
255        inner: Arc<T>,
256        accept_compression_encodings: EnabledCompressionEncodings,
257        send_compression_encodings: EnabledCompressionEncodings,
258        max_decoding_message_size: Option<usize>,
259        max_encoding_message_size: Option<usize>,
260    }
261    impl<T> HealthServer<T> {
262        pub fn new(inner: T) -> Self {
263            Self::from_arc(Arc::new(inner))
264        }
265        pub fn from_arc(inner: Arc<T>) -> Self {
266            Self {
267                inner,
268                accept_compression_encodings: Default::default(),
269                send_compression_encodings: Default::default(),
270                max_decoding_message_size: None,
271                max_encoding_message_size: None,
272            }
273        }
274        pub fn with_interceptor<F>(
275            inner: T,
276            interceptor: F,
277        ) -> InterceptedService<Self, F>
278        where
279            F: tonic::service::Interceptor,
280        {
281            InterceptedService::new(Self::new(inner), interceptor)
282        }
283        /// Enable decompressing requests with the given encoding.
284        #[must_use]
285        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
286            self.accept_compression_encodings.enable(encoding);
287            self
288        }
289        /// Compress responses with the given encoding, if the client supports it.
290        #[must_use]
291        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
292            self.send_compression_encodings.enable(encoding);
293            self
294        }
295        /// Limits the maximum size of a decoded message.
296        ///
297        /// Default: `4MB`
298        #[must_use]
299        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
300            self.max_decoding_message_size = Some(limit);
301            self
302        }
303        /// Limits the maximum size of an encoded message.
304        ///
305        /// Default: `usize::MAX`
306        #[must_use]
307        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
308            self.max_encoding_message_size = Some(limit);
309            self
310        }
311    }
312    impl<T, B> tonic::codegen::Service<http::Request<B>> for HealthServer<T>
313    where
314        T: Health,
315        B: Body + std::marker::Send + 'static,
316        B::Error: Into<StdError> + std::marker::Send + 'static,
317    {
318        type Response = http::Response<tonic::body::BoxBody>;
319        type Error = std::convert::Infallible;
320        type Future = BoxFuture<Self::Response, Self::Error>;
321        fn poll_ready(
322            &mut self,
323            _cx: &mut Context<'_>,
324        ) -> Poll<std::result::Result<(), Self::Error>> {
325            Poll::Ready(Ok(()))
326        }
327        fn call(&mut self, req: http::Request<B>) -> Self::Future {
328            match req.uri().path() {
329                "/grpc.health.v1.Health/Check" => {
330                    #[allow(non_camel_case_types)]
331                    struct CheckSvc<T: Health>(pub Arc<T>);
332                    impl<
333                        T: Health,
334                    > tonic::server::UnaryService<super::HealthCheckRequest>
335                    for CheckSvc<T> {
336                        type Response = super::HealthCheckResponse;
337                        type Future = BoxFuture<
338                            tonic::Response<Self::Response>,
339                            tonic::Status,
340                        >;
341                        fn call(
342                            &mut self,
343                            request: tonic::Request<super::HealthCheckRequest>,
344                        ) -> Self::Future {
345                            let inner = Arc::clone(&self.0);
346                            let fut = async move {
347                                <T as Health>::check(&inner, request).await
348                            };
349                            Box::pin(fut)
350                        }
351                    }
352                    let accept_compression_encodings = self.accept_compression_encodings;
353                    let send_compression_encodings = self.send_compression_encodings;
354                    let max_decoding_message_size = self.max_decoding_message_size;
355                    let max_encoding_message_size = self.max_encoding_message_size;
356                    let inner = self.inner.clone();
357                    let fut = async move {
358                        let method = CheckSvc(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                            .apply_max_message_size_config(
366                                max_decoding_message_size,
367                                max_encoding_message_size,
368                            );
369                        let res = grpc.unary(method, req).await;
370                        Ok(res)
371                    };
372                    Box::pin(fut)
373                }
374                "/grpc.health.v1.Health/Watch" => {
375                    #[allow(non_camel_case_types)]
376                    struct WatchSvc<T: Health>(pub Arc<T>);
377                    impl<
378                        T: Health,
379                    > tonic::server::ServerStreamingService<super::HealthCheckRequest>
380                    for WatchSvc<T> {
381                        type Response = super::HealthCheckResponse;
382                        type ResponseStream = T::WatchStream;
383                        type Future = BoxFuture<
384                            tonic::Response<Self::ResponseStream>,
385                            tonic::Status,
386                        >;
387                        fn call(
388                            &mut self,
389                            request: tonic::Request<super::HealthCheckRequest>,
390                        ) -> Self::Future {
391                            let inner = Arc::clone(&self.0);
392                            let fut = async move {
393                                <T as Health>::watch(&inner, request).await
394                            };
395                            Box::pin(fut)
396                        }
397                    }
398                    let accept_compression_encodings = self.accept_compression_encodings;
399                    let send_compression_encodings = self.send_compression_encodings;
400                    let max_decoding_message_size = self.max_decoding_message_size;
401                    let max_encoding_message_size = self.max_encoding_message_size;
402                    let inner = self.inner.clone();
403                    let fut = async move {
404                        let method = WatchSvc(inner);
405                        let codec = tonic::codec::ProstCodec::default();
406                        let mut grpc = tonic::server::Grpc::new(codec)
407                            .apply_compression_config(
408                                accept_compression_encodings,
409                                send_compression_encodings,
410                            )
411                            .apply_max_message_size_config(
412                                max_decoding_message_size,
413                                max_encoding_message_size,
414                            );
415                        let res = grpc.server_streaming(method, req).await;
416                        Ok(res)
417                    };
418                    Box::pin(fut)
419                }
420                _ => {
421                    Box::pin(async move {
422                        let mut response = http::Response::new(empty_body());
423                        let headers = response.headers_mut();
424                        headers
425                            .insert(
426                                tonic::Status::GRPC_STATUS,
427                                (tonic::Code::Unimplemented as i32).into(),
428                            );
429                        headers
430                            .insert(
431                                http::header::CONTENT_TYPE,
432                                tonic::metadata::GRPC_CONTENT_TYPE,
433                            );
434                        Ok(response)
435                    })
436                }
437            }
438        }
439    }
440    impl<T> Clone for HealthServer<T> {
441        fn clone(&self) -> Self {
442            let inner = self.inner.clone();
443            Self {
444                inner,
445                accept_compression_encodings: self.accept_compression_encodings,
446                send_compression_encodings: self.send_compression_encodings,
447                max_decoding_message_size: self.max_decoding_message_size,
448                max_encoding_message_size: self.max_encoding_message_size,
449            }
450        }
451    }
452    /// Generated gRPC service name
453    pub const SERVICE_NAME: &str = "grpc.health.v1.Health";
454    impl<T> tonic::server::NamedService for HealthServer<T> {
455        const NAME: &'static str = SERVICE_NAME;
456    }
457}