medea_control_api_proto/grpc/
callback.rs1#[derive(Clone, PartialEq, ::prost::Message)]
4pub struct Request {
5 #[prost(string, tag = "1")]
7 pub fid: ::prost::alloc::string::String,
8 #[prost(string, tag = "2")]
10 pub at: ::prost::alloc::string::String,
11 #[prost(oneof = "request::Event", tags = "3, 4")]
13 pub event: ::core::option::Option<request::Event>,
14}
15pub mod request {
17 #[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
19 pub enum Event {
20 #[prost(message, tag = "3")]
21 OnJoin(super::OnJoin),
22 #[prost(message, tag = "4")]
23 OnLeave(super::OnLeave),
24 }
25}
26#[derive(Clone, Copy, PartialEq, ::prost::Message)]
31pub struct Response {}
32#[derive(Clone, Copy, PartialEq, ::prost::Message)]
34pub struct OnJoin {}
35#[derive(Clone, Copy, PartialEq, ::prost::Message)]
37pub struct OnLeave {
38 #[prost(enumeration = "on_leave::Reason", tag = "1")]
40 pub reason: i32,
41}
42pub mod on_leave {
44 #[derive(
46 Clone,
47 Copy,
48 Debug,
49 PartialEq,
50 Eq,
51 Hash,
52 PartialOrd,
53 Ord,
54 ::prost::Enumeration
55 )]
56 #[repr(i32)]
57 pub enum Reason {
58 Disconnected = 0,
60 Lost = 1,
62 Kicked = 2,
64 Shutdown = 3,
66 }
67 impl Reason {
68 pub fn as_str_name(&self) -> &'static str {
73 match self {
74 Self::Disconnected => "DISCONNECTED",
75 Self::Lost => "LOST",
76 Self::Kicked => "KICKED",
77 Self::Shutdown => "SHUTDOWN",
78 }
79 }
80 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
82 match value {
83 "DISCONNECTED" => Some(Self::Disconnected),
84 "LOST" => Some(Self::Lost),
85 "KICKED" => Some(Self::Kicked),
86 "SHUTDOWN" => Some(Self::Shutdown),
87 _ => None,
88 }
89 }
90 }
91}
92pub mod callback_client {
94 #![allow(
95 unused_variables,
96 dead_code,
97 missing_docs,
98 clippy::wildcard_imports,
99 clippy::let_unit_value,
100 )]
101 use tonic::codegen::*;
102 use tonic::codegen::http::Uri;
103 #[derive(Debug, Clone)]
105 pub struct CallbackClient<T> {
106 inner: tonic::client::Grpc<T>,
107 }
108 impl CallbackClient<tonic::transport::Channel> {
109 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
111 where
112 D: TryInto<tonic::transport::Endpoint>,
113 D::Error: Into<StdError>,
114 {
115 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
116 Ok(Self::new(conn))
117 }
118 }
119 impl<T> CallbackClient<T>
120 where
121 T: tonic::client::GrpcService<tonic::body::Body>,
122 T::Error: Into<StdError>,
123 T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
124 <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
125 {
126 pub fn new(inner: T) -> Self {
127 let inner = tonic::client::Grpc::new(inner);
128 Self { inner }
129 }
130 pub fn with_origin(inner: T, origin: Uri) -> Self {
131 let inner = tonic::client::Grpc::with_origin(inner, origin);
132 Self { inner }
133 }
134 pub fn with_interceptor<F>(
135 inner: T,
136 interceptor: F,
137 ) -> CallbackClient<InterceptedService<T, F>>
138 where
139 F: tonic::service::Interceptor,
140 T::ResponseBody: Default,
141 T: tonic::codegen::Service<
142 http::Request<tonic::body::Body>,
143 Response = http::Response<
144 <T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
145 >,
146 >,
147 <T as tonic::codegen::Service<
148 http::Request<tonic::body::Body>,
149 >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
150 {
151 CallbackClient::new(InterceptedService::new(inner, interceptor))
152 }
153 #[must_use]
158 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
159 self.inner = self.inner.send_compressed(encoding);
160 self
161 }
162 #[must_use]
164 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
165 self.inner = self.inner.accept_compressed(encoding);
166 self
167 }
168 #[must_use]
172 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
173 self.inner = self.inner.max_decoding_message_size(limit);
174 self
175 }
176 #[must_use]
180 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
181 self.inner = self.inner.max_encoding_message_size(limit);
182 self
183 }
184 pub async fn on_event(
186 &mut self,
187 request: impl tonic::IntoRequest<super::Request>,
188 ) -> std::result::Result<tonic::Response<super::Response>, tonic::Status> {
189 self.inner
190 .ready()
191 .await
192 .map_err(|e| {
193 tonic::Status::unknown(
194 format!("Service was not ready: {}", e.into()),
195 )
196 })?;
197 let codec = tonic::codec::ProstCodec::default();
198 let path = http::uri::PathAndQuery::from_static(
199 "/callback.Callback/OnEvent",
200 );
201 let mut req = request.into_request();
202 req.extensions_mut().insert(GrpcMethod::new("callback.Callback", "OnEvent"));
203 self.inner.unary(req, path, codec).await
204 }
205 }
206}
207pub mod callback_server {
209 #![allow(
210 unused_variables,
211 dead_code,
212 missing_docs,
213 clippy::wildcard_imports,
214 clippy::let_unit_value,
215 )]
216 use tonic::codegen::*;
217 #[async_trait]
219 pub trait Callback: std::marker::Send + std::marker::Sync + 'static {
220 async fn on_event(
222 &self,
223 request: tonic::Request<super::Request>,
224 ) -> std::result::Result<tonic::Response<super::Response>, tonic::Status>;
225 }
226 #[derive(Debug)]
228 pub struct CallbackServer<T> {
229 inner: Arc<T>,
230 accept_compression_encodings: EnabledCompressionEncodings,
231 send_compression_encodings: EnabledCompressionEncodings,
232 max_decoding_message_size: Option<usize>,
233 max_encoding_message_size: Option<usize>,
234 }
235 impl<T> CallbackServer<T> {
236 pub fn new(inner: T) -> Self {
237 Self::from_arc(Arc::new(inner))
238 }
239 pub fn from_arc(inner: Arc<T>) -> Self {
240 Self {
241 inner,
242 accept_compression_encodings: Default::default(),
243 send_compression_encodings: Default::default(),
244 max_decoding_message_size: None,
245 max_encoding_message_size: None,
246 }
247 }
248 pub fn with_interceptor<F>(
249 inner: T,
250 interceptor: F,
251 ) -> InterceptedService<Self, F>
252 where
253 F: tonic::service::Interceptor,
254 {
255 InterceptedService::new(Self::new(inner), interceptor)
256 }
257 #[must_use]
259 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
260 self.accept_compression_encodings.enable(encoding);
261 self
262 }
263 #[must_use]
265 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
266 self.send_compression_encodings.enable(encoding);
267 self
268 }
269 #[must_use]
273 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
274 self.max_decoding_message_size = Some(limit);
275 self
276 }
277 #[must_use]
281 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
282 self.max_encoding_message_size = Some(limit);
283 self
284 }
285 }
286 impl<T, B> tonic::codegen::Service<http::Request<B>> for CallbackServer<T>
287 where
288 T: Callback,
289 B: Body + std::marker::Send + 'static,
290 B::Error: Into<StdError> + std::marker::Send + 'static,
291 {
292 type Response = http::Response<tonic::body::Body>;
293 type Error = std::convert::Infallible;
294 type Future = BoxFuture<Self::Response, Self::Error>;
295 fn poll_ready(
296 &mut self,
297 _cx: &mut Context<'_>,
298 ) -> Poll<std::result::Result<(), Self::Error>> {
299 Poll::Ready(Ok(()))
300 }
301 fn call(&mut self, req: http::Request<B>) -> Self::Future {
302 match req.uri().path() {
303 "/callback.Callback/OnEvent" => {
304 #[allow(non_camel_case_types)]
305 struct OnEventSvc<T: Callback>(pub Arc<T>);
306 impl<T: Callback> tonic::server::UnaryService<super::Request>
307 for OnEventSvc<T> {
308 type Response = super::Response;
309 type Future = BoxFuture<
310 tonic::Response<Self::Response>,
311 tonic::Status,
312 >;
313 fn call(
314 &mut self,
315 request: tonic::Request<super::Request>,
316 ) -> Self::Future {
317 let inner = Arc::clone(&self.0);
318 let fut = async move {
319 <T as Callback>::on_event(&inner, request).await
320 };
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 max_decoding_message_size = self.max_decoding_message_size;
327 let max_encoding_message_size = self.max_encoding_message_size;
328 let inner = self.inner.clone();
329 let fut = async move {
330 let method = OnEventSvc(inner);
331 let codec = tonic::codec::ProstCodec::default();
332 let mut grpc = tonic::server::Grpc::new(codec)
333 .apply_compression_config(
334 accept_compression_encodings,
335 send_compression_encodings,
336 )
337 .apply_max_message_size_config(
338 max_decoding_message_size,
339 max_encoding_message_size,
340 );
341 let res = grpc.unary(method, req).await;
342 Ok(res)
343 };
344 Box::pin(fut)
345 }
346 _ => {
347 Box::pin(async move {
348 let mut response = http::Response::new(
349 tonic::body::Body::default(),
350 );
351 let headers = response.headers_mut();
352 headers
353 .insert(
354 tonic::Status::GRPC_STATUS,
355 (tonic::Code::Unimplemented as i32).into(),
356 );
357 headers
358 .insert(
359 http::header::CONTENT_TYPE,
360 tonic::metadata::GRPC_CONTENT_TYPE,
361 );
362 Ok(response)
363 })
364 }
365 }
366 }
367 }
368 impl<T> Clone for CallbackServer<T> {
369 fn clone(&self) -> Self {
370 let inner = self.inner.clone();
371 Self {
372 inner,
373 accept_compression_encodings: self.accept_compression_encodings,
374 send_compression_encodings: self.send_compression_encodings,
375 max_decoding_message_size: self.max_decoding_message_size,
376 max_encoding_message_size: self.max_encoding_message_size,
377 }
378 }
379 }
380 pub const SERVICE_NAME: &str = "callback.Callback";
382 impl<T> tonic::server::NamedService for CallbackServer<T> {
383 const NAME: &'static str = SERVICE_NAME;
384 }
385}