1pub mod writer_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 WriterClient<T> {
9 inner: tonic::client::Grpc<T>,
10 }
11 impl WriterClient<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> WriterClient<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 ) -> WriterClient<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 WriterClient::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 write(
72 &mut self,
73 request: impl tonic::IntoRequest<super::WriteRequest>,
74 ) -> Result<tonic::Response<super::WriteResponse>, 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 "/http.responsewriter.Writer/Write",
87 );
88 self.inner.unary(request.into_request(), path, codec).await
89 }
90 pub async fn write_header(
91 &mut self,
92 request: impl tonic::IntoRequest<super::WriteHeaderRequest>,
93 ) -> Result<
94 tonic::Response<super::super::super::google::protobuf::Empty>,
95 tonic::Status,
96 > {
97 self.inner
98 .ready()
99 .await
100 .map_err(|e| {
101 tonic::Status::new(
102 tonic::Code::Unknown,
103 format!("Service was not ready: {}", e.into()),
104 )
105 })?;
106 let codec = tonic::codec::ProstCodec::default();
107 let path = http::uri::PathAndQuery::from_static(
108 "/http.responsewriter.Writer/WriteHeader",
109 );
110 self.inner.unary(request.into_request(), path, codec).await
111 }
112 pub async fn flush(
113 &mut self,
114 request: impl tonic::IntoRequest<
115 super::super::super::google::protobuf::Empty,
116 >,
117 ) -> Result<
118 tonic::Response<super::super::super::google::protobuf::Empty>,
119 tonic::Status,
120 > {
121 self.inner
122 .ready()
123 .await
124 .map_err(|e| {
125 tonic::Status::new(
126 tonic::Code::Unknown,
127 format!("Service was not ready: {}", e.into()),
128 )
129 })?;
130 let codec = tonic::codec::ProstCodec::default();
131 let path = http::uri::PathAndQuery::from_static(
132 "/http.responsewriter.Writer/Flush",
133 );
134 self.inner.unary(request.into_request(), path, codec).await
135 }
136 pub async fn hijack(
137 &mut self,
138 request: impl tonic::IntoRequest<
139 super::super::super::google::protobuf::Empty,
140 >,
141 ) -> Result<tonic::Response<super::HijackResponse>, tonic::Status> {
142 self.inner
143 .ready()
144 .await
145 .map_err(|e| {
146 tonic::Status::new(
147 tonic::Code::Unknown,
148 format!("Service was not ready: {}", e.into()),
149 )
150 })?;
151 let codec = tonic::codec::ProstCodec::default();
152 let path = http::uri::PathAndQuery::from_static(
153 "/http.responsewriter.Writer/Hijack",
154 );
155 self.inner.unary(request.into_request(), path, codec).await
156 }
157 }
158}
159pub mod writer_server {
161 #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
162 use tonic::codegen::*;
163 #[async_trait]
165 pub trait Writer: Send + Sync + 'static {
166 async fn write(
167 &self,
168 request: tonic::Request<super::WriteRequest>,
169 ) -> Result<tonic::Response<super::WriteResponse>, tonic::Status>;
170 async fn write_header(
171 &self,
172 request: tonic::Request<super::WriteHeaderRequest>,
173 ) -> Result<
174 tonic::Response<super::super::super::google::protobuf::Empty>,
175 tonic::Status,
176 >;
177 async fn flush(
178 &self,
179 request: tonic::Request<super::super::super::google::protobuf::Empty>,
180 ) -> Result<
181 tonic::Response<super::super::super::google::protobuf::Empty>,
182 tonic::Status,
183 >;
184 async fn hijack(
185 &self,
186 request: tonic::Request<super::super::super::google::protobuf::Empty>,
187 ) -> Result<tonic::Response<super::HijackResponse>, tonic::Status>;
188 }
189 #[derive(Debug)]
190 pub struct WriterServer<T: Writer> {
191 inner: _Inner<T>,
192 accept_compression_encodings: EnabledCompressionEncodings,
193 send_compression_encodings: EnabledCompressionEncodings,
194 }
195 struct _Inner<T>(Arc<T>);
196 impl<T: Writer> WriterServer<T> {
197 pub fn new(inner: T) -> Self {
198 Self::from_arc(Arc::new(inner))
199 }
200 pub fn from_arc(inner: Arc<T>) -> Self {
201 let inner = _Inner(inner);
202 Self {
203 inner,
204 accept_compression_encodings: Default::default(),
205 send_compression_encodings: Default::default(),
206 }
207 }
208 pub fn with_interceptor<F>(
209 inner: T,
210 interceptor: F,
211 ) -> InterceptedService<Self, F>
212 where
213 F: tonic::service::Interceptor,
214 {
215 InterceptedService::new(Self::new(inner), interceptor)
216 }
217 #[must_use]
219 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
220 self.accept_compression_encodings.enable(encoding);
221 self
222 }
223 #[must_use]
225 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
226 self.send_compression_encodings.enable(encoding);
227 self
228 }
229 }
230 impl<T, B> tonic::codegen::Service<http::Request<B>> for WriterServer<T>
231 where
232 T: Writer,
233 B: Body + Send + 'static,
234 B::Error: Into<StdError> + Send + 'static,
235 {
236 type Response = http::Response<tonic::body::BoxBody>;
237 type Error = std::convert::Infallible;
238 type Future = BoxFuture<Self::Response, Self::Error>;
239 fn poll_ready(
240 &mut self,
241 _cx: &mut Context<'_>,
242 ) -> Poll<Result<(), Self::Error>> {
243 Poll::Ready(Ok(()))
244 }
245 fn call(&mut self, req: http::Request<B>) -> Self::Future {
246 let inner = self.inner.clone();
247 match req.uri().path() {
248 "/http.responsewriter.Writer/Write" => {
249 #[allow(non_camel_case_types)]
250 struct WriteSvc<T: Writer>(pub Arc<T>);
251 impl<T: Writer> tonic::server::UnaryService<super::WriteRequest>
252 for WriteSvc<T> {
253 type Response = super::WriteResponse;
254 type Future = BoxFuture<
255 tonic::Response<Self::Response>,
256 tonic::Status,
257 >;
258 fn call(
259 &mut self,
260 request: tonic::Request<super::WriteRequest>,
261 ) -> Self::Future {
262 let inner = self.0.clone();
263 let fut = async move { (*inner).write(request).await };
264 Box::pin(fut)
265 }
266 }
267 let accept_compression_encodings = self.accept_compression_encodings;
268 let send_compression_encodings = self.send_compression_encodings;
269 let inner = self.inner.clone();
270 let fut = async move {
271 let inner = inner.0;
272 let method = WriteSvc(inner);
273 let codec = tonic::codec::ProstCodec::default();
274 let mut grpc = tonic::server::Grpc::new(codec)
275 .apply_compression_config(
276 accept_compression_encodings,
277 send_compression_encodings,
278 );
279 let res = grpc.unary(method, req).await;
280 Ok(res)
281 };
282 Box::pin(fut)
283 }
284 "/http.responsewriter.Writer/WriteHeader" => {
285 #[allow(non_camel_case_types)]
286 struct WriteHeaderSvc<T: Writer>(pub Arc<T>);
287 impl<
288 T: Writer,
289 > tonic::server::UnaryService<super::WriteHeaderRequest>
290 for WriteHeaderSvc<T> {
291 type Response = super::super::super::google::protobuf::Empty;
292 type Future = BoxFuture<
293 tonic::Response<Self::Response>,
294 tonic::Status,
295 >;
296 fn call(
297 &mut self,
298 request: tonic::Request<super::WriteHeaderRequest>,
299 ) -> Self::Future {
300 let inner = self.0.clone();
301 let fut = async move {
302 (*inner).write_header(request).await
303 };
304 Box::pin(fut)
305 }
306 }
307 let accept_compression_encodings = self.accept_compression_encodings;
308 let send_compression_encodings = self.send_compression_encodings;
309 let inner = self.inner.clone();
310 let fut = async move {
311 let inner = inner.0;
312 let method = WriteHeaderSvc(inner);
313 let codec = tonic::codec::ProstCodec::default();
314 let mut grpc = tonic::server::Grpc::new(codec)
315 .apply_compression_config(
316 accept_compression_encodings,
317 send_compression_encodings,
318 );
319 let res = grpc.unary(method, req).await;
320 Ok(res)
321 };
322 Box::pin(fut)
323 }
324 "/http.responsewriter.Writer/Flush" => {
325 #[allow(non_camel_case_types)]
326 struct FlushSvc<T: Writer>(pub Arc<T>);
327 impl<
328 T: Writer,
329 > tonic::server::UnaryService<
330 super::super::super::google::protobuf::Empty,
331 > for FlushSvc<T> {
332 type Response = super::super::super::google::protobuf::Empty;
333 type Future = BoxFuture<
334 tonic::Response<Self::Response>,
335 tonic::Status,
336 >;
337 fn call(
338 &mut self,
339 request: tonic::Request<
340 super::super::super::google::protobuf::Empty,
341 >,
342 ) -> Self::Future {
343 let inner = self.0.clone();
344 let fut = async move { (*inner).flush(request).await };
345 Box::pin(fut)
346 }
347 }
348 let accept_compression_encodings = self.accept_compression_encodings;
349 let send_compression_encodings = self.send_compression_encodings;
350 let inner = self.inner.clone();
351 let fut = async move {
352 let inner = inner.0;
353 let method = FlushSvc(inner);
354 let codec = tonic::codec::ProstCodec::default();
355 let mut grpc = tonic::server::Grpc::new(codec)
356 .apply_compression_config(
357 accept_compression_encodings,
358 send_compression_encodings,
359 );
360 let res = grpc.unary(method, req).await;
361 Ok(res)
362 };
363 Box::pin(fut)
364 }
365 "/http.responsewriter.Writer/Hijack" => {
366 #[allow(non_camel_case_types)]
367 struct HijackSvc<T: Writer>(pub Arc<T>);
368 impl<
369 T: Writer,
370 > tonic::server::UnaryService<
371 super::super::super::google::protobuf::Empty,
372 > for HijackSvc<T> {
373 type Response = super::HijackResponse;
374 type Future = BoxFuture<
375 tonic::Response<Self::Response>,
376 tonic::Status,
377 >;
378 fn call(
379 &mut self,
380 request: tonic::Request<
381 super::super::super::google::protobuf::Empty,
382 >,
383 ) -> Self::Future {
384 let inner = self.0.clone();
385 let fut = async move { (*inner).hijack(request).await };
386 Box::pin(fut)
387 }
388 }
389 let accept_compression_encodings = self.accept_compression_encodings;
390 let send_compression_encodings = self.send_compression_encodings;
391 let inner = self.inner.clone();
392 let fut = async move {
393 let inner = inner.0;
394 let method = HijackSvc(inner);
395 let codec = tonic::codec::ProstCodec::default();
396 let mut grpc = tonic::server::Grpc::new(codec)
397 .apply_compression_config(
398 accept_compression_encodings,
399 send_compression_encodings,
400 );
401 let res = grpc.unary(method, req).await;
402 Ok(res)
403 };
404 Box::pin(fut)
405 }
406 _ => {
407 Box::pin(async move {
408 Ok(
409 http::Response::builder()
410 .status(200)
411 .header("grpc-status", "12")
412 .header("content-type", "application/grpc")
413 .body(empty_body())
414 .unwrap(),
415 )
416 })
417 }
418 }
419 }
420 }
421 impl<T: Writer> Clone for WriterServer<T> {
422 fn clone(&self) -> Self {
423 let inner = self.inner.clone();
424 Self {
425 inner,
426 accept_compression_encodings: self.accept_compression_encodings,
427 send_compression_encodings: self.send_compression_encodings,
428 }
429 }
430 }
431 impl<T: Writer> Clone for _Inner<T> {
432 fn clone(&self) -> Self {
433 Self(self.0.clone())
434 }
435 }
436 impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
437 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
438 write!(f, "{:?}", self.0)
439 }
440 }
441 impl<T: Writer> tonic::server::NamedService for WriterServer<T> {
442 const NAME: &'static str = "http.responsewriter.Writer";
443 }
444}