1pub mod node_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)]
9 pub struct NodeClient<T> {
10 inner: tonic::client::Grpc<T>,
11 }
12 impl NodeClient<tonic::transport::Channel> {
13 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
15 where
16 D: std::convert::TryInto<tonic::transport::Endpoint>,
17 D::Error: Into<StdError>,
18 {
19 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
20 Ok(Self::new(conn))
21 }
22 }
23 impl<T> NodeClient<T>
24 where
25 T: tonic::client::GrpcService<tonic::body::BoxBody>,
26 T::Error: Into<StdError>,
27 T::ResponseBody: Body<Data = Bytes> + Send + 'static,
28 <T::ResponseBody as Body>::Error: Into<StdError> + Send,
29 {
30 pub fn new(inner: T) -> Self {
31 let inner = tonic::client::Grpc::new(inner);
32 Self { inner }
33 }
34 pub fn with_origin(inner: T, origin: Uri) -> Self {
35 let inner = tonic::client::Grpc::with_origin(inner, origin);
36 Self { inner }
37 }
38 pub fn with_interceptor<F>(
39 inner: T,
40 interceptor: F,
41 ) -> NodeClient<InterceptedService<T, F>>
42 where
43 F: tonic::service::Interceptor,
44 T::ResponseBody: Default,
45 T: tonic::codegen::Service<
46 http::Request<tonic::body::BoxBody>,
47 Response = http::Response<
48 <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
49 >,
50 >,
51 <T as tonic::codegen::Service<
52 http::Request<tonic::body::BoxBody>,
53 >>::Error: Into<StdError> + Send + Sync,
54 {
55 NodeClient::new(InterceptedService::new(inner, interceptor))
56 }
57 #[must_use]
62 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
63 self.inner = self.inner.send_compressed(encoding);
64 self
65 }
66 #[must_use]
68 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
69 self.inner = self.inner.accept_compressed(encoding);
70 self
71 }
72 pub async fn start(
74 &mut self,
75 request: impl tonic::IntoRequest<super::super::google::protobuf::Empty>,
76 ) -> Result<
77 tonic::Response<super::super::google::protobuf::Empty>,
78 tonic::Status,
79 > {
80 self.inner
81 .ready()
82 .await
83 .map_err(|e| {
84 tonic::Status::new(
85 tonic::Code::Unknown,
86 format!("Service was not ready: {}", e.into()),
87 )
88 })?;
89 let codec = tonic::codec::ProstCodec::default();
90 let path = http::uri::PathAndQuery::from_static("/plugin.Node/Start");
91 self.inner.unary(request.into_request(), path, codec).await
92 }
93 pub async fn exit_code(
95 &mut self,
96 request: impl tonic::IntoRequest<super::super::google::protobuf::Empty>,
97 ) -> Result<tonic::Response<super::ExitCodeResponse>, tonic::Status> {
98 self.inner
99 .ready()
100 .await
101 .map_err(|e| {
102 tonic::Status::new(
103 tonic::Code::Unknown,
104 format!("Service was not ready: {}", e.into()),
105 )
106 })?;
107 let codec = tonic::codec::ProstCodec::default();
108 let path = http::uri::PathAndQuery::from_static("/plugin.Node/ExitCode");
109 self.inner.unary(request.into_request(), path, codec).await
110 }
111 pub async fn stop(
112 &mut self,
113 request: impl tonic::IntoRequest<super::super::google::protobuf::Empty>,
114 ) -> Result<
115 tonic::Response<super::super::google::protobuf::Empty>,
116 tonic::Status,
117 > {
118 self.inner
119 .ready()
120 .await
121 .map_err(|e| {
122 tonic::Status::new(
123 tonic::Code::Unknown,
124 format!("Service was not ready: {}", e.into()),
125 )
126 })?;
127 let codec = tonic::codec::ProstCodec::default();
128 let path = http::uri::PathAndQuery::from_static("/plugin.Node/Stop");
129 self.inner.unary(request.into_request(), path, codec).await
130 }
131 }
132}
133pub mod node_server {
135 #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
136 use tonic::codegen::*;
137 #[async_trait]
139 pub trait Node: Send + Sync + 'static {
140 async fn start(
142 &self,
143 request: tonic::Request<super::super::google::protobuf::Empty>,
144 ) -> Result<
145 tonic::Response<super::super::google::protobuf::Empty>,
146 tonic::Status,
147 >;
148 async fn exit_code(
150 &self,
151 request: tonic::Request<super::super::google::protobuf::Empty>,
152 ) -> Result<tonic::Response<super::ExitCodeResponse>, tonic::Status>;
153 async fn stop(
154 &self,
155 request: tonic::Request<super::super::google::protobuf::Empty>,
156 ) -> Result<
157 tonic::Response<super::super::google::protobuf::Empty>,
158 tonic::Status,
159 >;
160 }
161 #[derive(Debug)]
163 pub struct NodeServer<T: Node> {
164 inner: _Inner<T>,
165 accept_compression_encodings: EnabledCompressionEncodings,
166 send_compression_encodings: EnabledCompressionEncodings,
167 }
168 struct _Inner<T>(Arc<T>);
169 impl<T: Node> NodeServer<T> {
170 pub fn new(inner: T) -> Self {
171 Self::from_arc(Arc::new(inner))
172 }
173 pub fn from_arc(inner: Arc<T>) -> Self {
174 let inner = _Inner(inner);
175 Self {
176 inner,
177 accept_compression_encodings: Default::default(),
178 send_compression_encodings: Default::default(),
179 }
180 }
181 pub fn with_interceptor<F>(
182 inner: T,
183 interceptor: F,
184 ) -> InterceptedService<Self, F>
185 where
186 F: tonic::service::Interceptor,
187 {
188 InterceptedService::new(Self::new(inner), interceptor)
189 }
190 #[must_use]
192 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
193 self.accept_compression_encodings.enable(encoding);
194 self
195 }
196 #[must_use]
198 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
199 self.send_compression_encodings.enable(encoding);
200 self
201 }
202 }
203 impl<T, B> tonic::codegen::Service<http::Request<B>> for NodeServer<T>
204 where
205 T: Node,
206 B: Body + Send + 'static,
207 B::Error: Into<StdError> + Send + 'static,
208 {
209 type Response = http::Response<tonic::body::BoxBody>;
210 type Error = std::convert::Infallible;
211 type Future = BoxFuture<Self::Response, Self::Error>;
212 fn poll_ready(
213 &mut self,
214 _cx: &mut Context<'_>,
215 ) -> Poll<Result<(), Self::Error>> {
216 Poll::Ready(Ok(()))
217 }
218 fn call(&mut self, req: http::Request<B>) -> Self::Future {
219 let inner = self.inner.clone();
220 match req.uri().path() {
221 "/plugin.Node/Start" => {
222 #[allow(non_camel_case_types)]
223 struct StartSvc<T: Node>(pub Arc<T>);
224 impl<
225 T: Node,
226 > tonic::server::UnaryService<super::super::google::protobuf::Empty>
227 for StartSvc<T> {
228 type Response = super::super::google::protobuf::Empty;
229 type Future = BoxFuture<
230 tonic::Response<Self::Response>,
231 tonic::Status,
232 >;
233 fn call(
234 &mut self,
235 request: tonic::Request<
236 super::super::google::protobuf::Empty,
237 >,
238 ) -> Self::Future {
239 let inner = self.0.clone();
240 let fut = async move { (*inner).start(request).await };
241 Box::pin(fut)
242 }
243 }
244 let accept_compression_encodings = self.accept_compression_encodings;
245 let send_compression_encodings = self.send_compression_encodings;
246 let inner = self.inner.clone();
247 let fut = async move {
248 let inner = inner.0;
249 let method = StartSvc(inner);
250 let codec = tonic::codec::ProstCodec::default();
251 let mut grpc = tonic::server::Grpc::new(codec)
252 .apply_compression_config(
253 accept_compression_encodings,
254 send_compression_encodings,
255 );
256 let res = grpc.unary(method, req).await;
257 Ok(res)
258 };
259 Box::pin(fut)
260 }
261 "/plugin.Node/ExitCode" => {
262 #[allow(non_camel_case_types)]
263 struct ExitCodeSvc<T: Node>(pub Arc<T>);
264 impl<
265 T: Node,
266 > tonic::server::UnaryService<super::super::google::protobuf::Empty>
267 for ExitCodeSvc<T> {
268 type Response = super::ExitCodeResponse;
269 type Future = BoxFuture<
270 tonic::Response<Self::Response>,
271 tonic::Status,
272 >;
273 fn call(
274 &mut self,
275 request: tonic::Request<
276 super::super::google::protobuf::Empty,
277 >,
278 ) -> Self::Future {
279 let inner = self.0.clone();
280 let fut = async move { (*inner).exit_code(request).await };
281 Box::pin(fut)
282 }
283 }
284 let accept_compression_encodings = self.accept_compression_encodings;
285 let send_compression_encodings = self.send_compression_encodings;
286 let inner = self.inner.clone();
287 let fut = async move {
288 let inner = inner.0;
289 let method = ExitCodeSvc(inner);
290 let codec = tonic::codec::ProstCodec::default();
291 let mut grpc = tonic::server::Grpc::new(codec)
292 .apply_compression_config(
293 accept_compression_encodings,
294 send_compression_encodings,
295 );
296 let res = grpc.unary(method, req).await;
297 Ok(res)
298 };
299 Box::pin(fut)
300 }
301 "/plugin.Node/Stop" => {
302 #[allow(non_camel_case_types)]
303 struct StopSvc<T: Node>(pub Arc<T>);
304 impl<
305 T: Node,
306 > tonic::server::UnaryService<super::super::google::protobuf::Empty>
307 for StopSvc<T> {
308 type Response = super::super::google::protobuf::Empty;
309 type Future = BoxFuture<
310 tonic::Response<Self::Response>,
311 tonic::Status,
312 >;
313 fn call(
314 &mut self,
315 request: tonic::Request<
316 super::super::google::protobuf::Empty,
317 >,
318 ) -> Self::Future {
319 let inner = self.0.clone();
320 let fut = async move { (*inner).stop(request).await };
321 Box::pin(fut)
322 }
323 }
324 let accept_compression_encodings = self.accept_compression_encodings;
325 let send_compression_encodings = self.send_compression_encodings;
326 let inner = self.inner.clone();
327 let fut = async move {
328 let inner = inner.0;
329 let method = StopSvc(inner);
330 let codec = tonic::codec::ProstCodec::default();
331 let mut grpc = tonic::server::Grpc::new(codec)
332 .apply_compression_config(
333 accept_compression_encodings,
334 send_compression_encodings,
335 );
336 let res = grpc.unary(method, req).await;
337 Ok(res)
338 };
339 Box::pin(fut)
340 }
341 _ => {
342 Box::pin(async move {
343 Ok(
344 http::Response::builder()
345 .status(200)
346 .header("grpc-status", "12")
347 .header("content-type", "application/grpc")
348 .body(empty_body())
349 .unwrap(),
350 )
351 })
352 }
353 }
354 }
355 }
356 impl<T: Node> Clone for NodeServer<T> {
357 fn clone(&self) -> Self {
358 let inner = self.inner.clone();
359 Self {
360 inner,
361 accept_compression_encodings: self.accept_compression_encodings,
362 send_compression_encodings: self.send_compression_encodings,
363 }
364 }
365 }
366 impl<T: Node> Clone for _Inner<T> {
367 fn clone(&self) -> Self {
368 Self(self.0.clone())
369 }
370 }
371 impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
372 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
373 write!(f, "{:?}", self.0)
374 }
375 }
376 impl<T: Node> tonic::server::NamedService for NodeServer<T> {
377 const NAME: &'static str = "plugin.Node";
378 }
379}