1pub mod shared_memory_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 SharedMemoryClient<T> {
9 inner: tonic::client::Grpc<T>,
10 }
11 impl SharedMemoryClient<tonic::transport::Channel> {
12 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> SharedMemoryClient<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 ) -> SharedMemoryClient<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 SharedMemoryClient::new(InterceptedService::new(inner, interceptor))
55 }
56 #[must_use]
61 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
62 self.inner = self.inner.send_compressed(encoding);
63 self
64 }
65 #[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 get(
72 &mut self,
73 request: impl tonic::IntoRequest<super::GetRequest>,
74 ) -> Result<tonic::Response<super::GetResponse>, tonic::Status> {
75 self.inner
76 .ready()
77 .await
78 .map_err(|e| {
79 tonic::Status::new(
80 tonic::Code::Unknown,
81 format!("Service was not ready: {}", e.into()),
82 )
83 })?;
84 let codec = tonic::codec::ProstCodec::default();
85 let path = http::uri::PathAndQuery::from_static(
86 "/sharedmemory.SharedMemory/Get",
87 );
88 self.inner.unary(request.into_request(), path, codec).await
89 }
90 pub async fn indexed(
91 &mut self,
92 request: impl tonic::IntoRequest<super::IndexedRequest>,
93 ) -> Result<tonic::Response<super::IndexedResponse>, tonic::Status> {
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 "/sharedmemory.SharedMemory/Indexed",
106 );
107 self.inner.unary(request.into_request(), path, codec).await
108 }
109 pub async fn apply(
110 &mut self,
111 request: impl tonic::IntoRequest<super::ApplyRequest>,
112 ) -> Result<tonic::Response<super::ApplyResponse>, tonic::Status> {
113 self.inner
114 .ready()
115 .await
116 .map_err(|e| {
117 tonic::Status::new(
118 tonic::Code::Unknown,
119 format!("Service was not ready: {}", e.into()),
120 )
121 })?;
122 let codec = tonic::codec::ProstCodec::default();
123 let path = http::uri::PathAndQuery::from_static(
124 "/sharedmemory.SharedMemory/Apply",
125 );
126 self.inner.unary(request.into_request(), path, codec).await
127 }
128 }
129}
130pub mod shared_memory_server {
132 #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
133 use tonic::codegen::*;
134 #[async_trait]
136 pub trait SharedMemory: Send + Sync + 'static {
137 async fn get(
138 &self,
139 request: tonic::Request<super::GetRequest>,
140 ) -> Result<tonic::Response<super::GetResponse>, tonic::Status>;
141 async fn indexed(
142 &self,
143 request: tonic::Request<super::IndexedRequest>,
144 ) -> Result<tonic::Response<super::IndexedResponse>, tonic::Status>;
145 async fn apply(
146 &self,
147 request: tonic::Request<super::ApplyRequest>,
148 ) -> Result<tonic::Response<super::ApplyResponse>, tonic::Status>;
149 }
150 #[derive(Debug)]
151 pub struct SharedMemoryServer<T: SharedMemory> {
152 inner: _Inner<T>,
153 accept_compression_encodings: EnabledCompressionEncodings,
154 send_compression_encodings: EnabledCompressionEncodings,
155 }
156 struct _Inner<T>(Arc<T>);
157 impl<T: SharedMemory> SharedMemoryServer<T> {
158 pub fn new(inner: T) -> Self {
159 Self::from_arc(Arc::new(inner))
160 }
161 pub fn from_arc(inner: Arc<T>) -> Self {
162 let inner = _Inner(inner);
163 Self {
164 inner,
165 accept_compression_encodings: Default::default(),
166 send_compression_encodings: Default::default(),
167 }
168 }
169 pub fn with_interceptor<F>(
170 inner: T,
171 interceptor: F,
172 ) -> InterceptedService<Self, F>
173 where
174 F: tonic::service::Interceptor,
175 {
176 InterceptedService::new(Self::new(inner), interceptor)
177 }
178 #[must_use]
180 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
181 self.accept_compression_encodings.enable(encoding);
182 self
183 }
184 #[must_use]
186 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
187 self.send_compression_encodings.enable(encoding);
188 self
189 }
190 }
191 impl<T, B> tonic::codegen::Service<http::Request<B>> for SharedMemoryServer<T>
192 where
193 T: SharedMemory,
194 B: Body + Send + 'static,
195 B::Error: Into<StdError> + Send + 'static,
196 {
197 type Response = http::Response<tonic::body::BoxBody>;
198 type Error = std::convert::Infallible;
199 type Future = BoxFuture<Self::Response, Self::Error>;
200 fn poll_ready(
201 &mut self,
202 _cx: &mut Context<'_>,
203 ) -> Poll<Result<(), Self::Error>> {
204 Poll::Ready(Ok(()))
205 }
206 fn call(&mut self, req: http::Request<B>) -> Self::Future {
207 let inner = self.inner.clone();
208 match req.uri().path() {
209 "/sharedmemory.SharedMemory/Get" => {
210 #[allow(non_camel_case_types)]
211 struct GetSvc<T: SharedMemory>(pub Arc<T>);
212 impl<T: SharedMemory> tonic::server::UnaryService<super::GetRequest>
213 for GetSvc<T> {
214 type Response = super::GetResponse;
215 type Future = BoxFuture<
216 tonic::Response<Self::Response>,
217 tonic::Status,
218 >;
219 fn call(
220 &mut self,
221 request: tonic::Request<super::GetRequest>,
222 ) -> Self::Future {
223 let inner = self.0.clone();
224 let fut = async move { (*inner).get(request).await };
225 Box::pin(fut)
226 }
227 }
228 let accept_compression_encodings = self.accept_compression_encodings;
229 let send_compression_encodings = self.send_compression_encodings;
230 let inner = self.inner.clone();
231 let fut = async move {
232 let inner = inner.0;
233 let method = GetSvc(inner);
234 let codec = tonic::codec::ProstCodec::default();
235 let mut grpc = tonic::server::Grpc::new(codec)
236 .apply_compression_config(
237 accept_compression_encodings,
238 send_compression_encodings,
239 );
240 let res = grpc.unary(method, req).await;
241 Ok(res)
242 };
243 Box::pin(fut)
244 }
245 "/sharedmemory.SharedMemory/Indexed" => {
246 #[allow(non_camel_case_types)]
247 struct IndexedSvc<T: SharedMemory>(pub Arc<T>);
248 impl<
249 T: SharedMemory,
250 > tonic::server::UnaryService<super::IndexedRequest>
251 for IndexedSvc<T> {
252 type Response = super::IndexedResponse;
253 type Future = BoxFuture<
254 tonic::Response<Self::Response>,
255 tonic::Status,
256 >;
257 fn call(
258 &mut self,
259 request: tonic::Request<super::IndexedRequest>,
260 ) -> Self::Future {
261 let inner = self.0.clone();
262 let fut = async move { (*inner).indexed(request).await };
263 Box::pin(fut)
264 }
265 }
266 let accept_compression_encodings = self.accept_compression_encodings;
267 let send_compression_encodings = self.send_compression_encodings;
268 let inner = self.inner.clone();
269 let fut = async move {
270 let inner = inner.0;
271 let method = IndexedSvc(inner);
272 let codec = tonic::codec::ProstCodec::default();
273 let mut grpc = tonic::server::Grpc::new(codec)
274 .apply_compression_config(
275 accept_compression_encodings,
276 send_compression_encodings,
277 );
278 let res = grpc.unary(method, req).await;
279 Ok(res)
280 };
281 Box::pin(fut)
282 }
283 "/sharedmemory.SharedMemory/Apply" => {
284 #[allow(non_camel_case_types)]
285 struct ApplySvc<T: SharedMemory>(pub Arc<T>);
286 impl<
287 T: SharedMemory,
288 > tonic::server::UnaryService<super::ApplyRequest> for ApplySvc<T> {
289 type Response = super::ApplyResponse;
290 type Future = BoxFuture<
291 tonic::Response<Self::Response>,
292 tonic::Status,
293 >;
294 fn call(
295 &mut self,
296 request: tonic::Request<super::ApplyRequest>,
297 ) -> Self::Future {
298 let inner = self.0.clone();
299 let fut = async move { (*inner).apply(request).await };
300 Box::pin(fut)
301 }
302 }
303 let accept_compression_encodings = self.accept_compression_encodings;
304 let send_compression_encodings = self.send_compression_encodings;
305 let inner = self.inner.clone();
306 let fut = async move {
307 let inner = inner.0;
308 let method = ApplySvc(inner);
309 let codec = tonic::codec::ProstCodec::default();
310 let mut grpc = tonic::server::Grpc::new(codec)
311 .apply_compression_config(
312 accept_compression_encodings,
313 send_compression_encodings,
314 );
315 let res = grpc.unary(method, req).await;
316 Ok(res)
317 };
318 Box::pin(fut)
319 }
320 _ => {
321 Box::pin(async move {
322 Ok(
323 http::Response::builder()
324 .status(200)
325 .header("grpc-status", "12")
326 .header("content-type", "application/grpc")
327 .body(empty_body())
328 .unwrap(),
329 )
330 })
331 }
332 }
333 }
334 }
335 impl<T: SharedMemory> Clone for SharedMemoryServer<T> {
336 fn clone(&self) -> Self {
337 let inner = self.inner.clone();
338 Self {
339 inner,
340 accept_compression_encodings: self.accept_compression_encodings,
341 send_compression_encodings: self.send_compression_encodings,
342 }
343 }
344 }
345 impl<T: SharedMemory> Clone for _Inner<T> {
346 fn clone(&self) -> Self {
347 Self(self.0.clone())
348 }
349 }
350 impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
351 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
352 write!(f, "{:?}", self.0)
353 }
354 }
355 impl<T: SharedMemory> tonic::server::NamedService for SharedMemoryServer<T> {
356 const NAME: &'static str = "sharedmemory.SharedMemory";
357 }
358}