dragonfly_plugin/generated/
df.plugin.tonic.rs

1// @generated
2/// Generated client implementations.
3pub mod plugin_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 PluginClient<T> {
9        inner: tonic::client::Grpc<T>,
10    }
11    impl PluginClient<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> PluginClient<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        ) -> PluginClient<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            PluginClient::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 event_stream(
88            &mut self,
89            request: impl tonic::IntoStreamingRequest<Message = super::PluginToHost>,
90        ) -> std::result::Result<
91            tonic::Response<tonic::codec::Streaming<super::HostToPlugin>>,
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(
105                "/df.plugin.Plugin/EventStream",
106            );
107            let mut req = request.into_streaming_request();
108            req.extensions_mut()
109                .insert(GrpcMethod::new("df.plugin.Plugin", "EventStream"));
110            self.inner.streaming(req, path, codec).await
111        }
112    }
113}
114/// Generated server implementations.
115pub mod plugin_server {
116    #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
117    use tonic::codegen::*;
118    /// Generated trait containing gRPC methods that should be implemented for use with PluginServer.
119    #[async_trait]
120    pub trait Plugin: Send + Sync + 'static {
121        /// Server streaming response type for the EventStream method.
122        type EventStreamStream: tonic::codegen::tokio_stream::Stream<
123                Item = std::result::Result<super::HostToPlugin, tonic::Status>,
124            >
125            + Send
126            + 'static;
127        async fn event_stream(
128            &self,
129            request: tonic::Request<tonic::Streaming<super::PluginToHost>>,
130        ) -> std::result::Result<
131            tonic::Response<Self::EventStreamStream>,
132            tonic::Status,
133        >;
134    }
135    #[derive(Debug)]
136    pub struct PluginServer<T: Plugin> {
137        inner: Arc<T>,
138        accept_compression_encodings: EnabledCompressionEncodings,
139        send_compression_encodings: EnabledCompressionEncodings,
140        max_decoding_message_size: Option<usize>,
141        max_encoding_message_size: Option<usize>,
142    }
143    impl<T: Plugin> PluginServer<T> {
144        pub fn new(inner: T) -> Self {
145            Self::from_arc(Arc::new(inner))
146        }
147        pub fn from_arc(inner: Arc<T>) -> Self {
148            Self {
149                inner,
150                accept_compression_encodings: Default::default(),
151                send_compression_encodings: Default::default(),
152                max_decoding_message_size: None,
153                max_encoding_message_size: None,
154            }
155        }
156        pub fn with_interceptor<F>(
157            inner: T,
158            interceptor: F,
159        ) -> InterceptedService<Self, F>
160        where
161            F: tonic::service::Interceptor,
162        {
163            InterceptedService::new(Self::new(inner), interceptor)
164        }
165        /// Enable decompressing requests with the given encoding.
166        #[must_use]
167        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
168            self.accept_compression_encodings.enable(encoding);
169            self
170        }
171        /// Compress responses with the given encoding, if the client supports it.
172        #[must_use]
173        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
174            self.send_compression_encodings.enable(encoding);
175            self
176        }
177        /// Limits the maximum size of a decoded message.
178        ///
179        /// Default: `4MB`
180        #[must_use]
181        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
182            self.max_decoding_message_size = Some(limit);
183            self
184        }
185        /// Limits the maximum size of an encoded message.
186        ///
187        /// Default: `usize::MAX`
188        #[must_use]
189        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
190            self.max_encoding_message_size = Some(limit);
191            self
192        }
193    }
194    impl<T, B> tonic::codegen::Service<http::Request<B>> for PluginServer<T>
195    where
196        T: Plugin,
197        B: Body + Send + 'static,
198        B::Error: Into<StdError> + Send + 'static,
199    {
200        type Response = http::Response<tonic::body::BoxBody>;
201        type Error = std::convert::Infallible;
202        type Future = BoxFuture<Self::Response, Self::Error>;
203        fn poll_ready(
204            &mut self,
205            _cx: &mut Context<'_>,
206        ) -> Poll<std::result::Result<(), Self::Error>> {
207            Poll::Ready(Ok(()))
208        }
209        fn call(&mut self, req: http::Request<B>) -> Self::Future {
210            match req.uri().path() {
211                "/df.plugin.Plugin/EventStream" => {
212                    #[allow(non_camel_case_types)]
213                    struct EventStreamSvc<T: Plugin>(pub Arc<T>);
214                    impl<T: Plugin> tonic::server::StreamingService<super::PluginToHost>
215                    for EventStreamSvc<T> {
216                        type Response = super::HostToPlugin;
217                        type ResponseStream = T::EventStreamStream;
218                        type Future = BoxFuture<
219                            tonic::Response<Self::ResponseStream>,
220                            tonic::Status,
221                        >;
222                        fn call(
223                            &mut self,
224                            request: tonic::Request<
225                                tonic::Streaming<super::PluginToHost>,
226                            >,
227                        ) -> Self::Future {
228                            let inner = Arc::clone(&self.0);
229                            let fut = async move {
230                                <T as Plugin>::event_stream(&inner, request).await
231                            };
232                            Box::pin(fut)
233                        }
234                    }
235                    let accept_compression_encodings = self.accept_compression_encodings;
236                    let send_compression_encodings = self.send_compression_encodings;
237                    let max_decoding_message_size = self.max_decoding_message_size;
238                    let max_encoding_message_size = self.max_encoding_message_size;
239                    let inner = self.inner.clone();
240                    let fut = async move {
241                        let method = EventStreamSvc(inner);
242                        let codec = tonic::codec::ProstCodec::default();
243                        let mut grpc = tonic::server::Grpc::new(codec)
244                            .apply_compression_config(
245                                accept_compression_encodings,
246                                send_compression_encodings,
247                            )
248                            .apply_max_message_size_config(
249                                max_decoding_message_size,
250                                max_encoding_message_size,
251                            );
252                        let res = grpc.streaming(method, req).await;
253                        Ok(res)
254                    };
255                    Box::pin(fut)
256                }
257                _ => {
258                    Box::pin(async move {
259                        Ok(
260                            http::Response::builder()
261                                .status(200)
262                                .header("grpc-status", tonic::Code::Unimplemented as i32)
263                                .header(
264                                    http::header::CONTENT_TYPE,
265                                    tonic::metadata::GRPC_CONTENT_TYPE,
266                                )
267                                .body(empty_body())
268                                .unwrap(),
269                        )
270                    })
271                }
272            }
273        }
274    }
275    impl<T: Plugin> Clone for PluginServer<T> {
276        fn clone(&self) -> Self {
277            let inner = self.inner.clone();
278            Self {
279                inner,
280                accept_compression_encodings: self.accept_compression_encodings,
281                send_compression_encodings: self.send_compression_encodings,
282                max_decoding_message_size: self.max_decoding_message_size,
283                max_encoding_message_size: self.max_encoding_message_size,
284            }
285        }
286    }
287    impl<T: Plugin> tonic::server::NamedService for PluginServer<T> {
288        const NAME: &'static str = "df.plugin.Plugin";
289    }
290}