d_engine/generated/
raft.election.rs

1// This file is @generated by prost-build.
2#[derive(serde::Serialize, serde::Deserialize)]
3#[derive(Clone, Copy, PartialEq, ::prost::Message)]
4pub struct VoteRequest {
5    #[prost(uint64, tag = "1")]
6    pub term: u64,
7    #[prost(uint32, tag = "2")]
8    pub candidate_id: u32,
9    #[prost(uint64, tag = "3")]
10    pub last_log_index: u64,
11    #[prost(uint64, tag = "4")]
12    pub last_log_term: u64,
13}
14#[derive(serde::Serialize, serde::Deserialize)]
15#[derive(Clone, Copy, PartialEq, ::prost::Message)]
16pub struct VoteResponse {
17    #[prost(uint64, tag = "1")]
18    pub term: u64,
19    #[prost(bool, tag = "2")]
20    pub vote_granted: bool,
21    #[prost(uint64, tag = "3")]
22    pub last_log_index: u64,
23    #[prost(uint64, tag = "4")]
24    pub last_log_term: u64,
25}
26#[derive(serde::Serialize, serde::Deserialize)]
27#[derive(Clone, Copy, PartialEq, ::prost::Message)]
28pub struct VotedFor {
29    #[prost(uint32, tag = "1")]
30    pub voted_for_id: u32,
31    #[prost(uint64, tag = "2")]
32    pub voted_for_term: u64,
33}
34/// Generated client implementations.
35pub mod raft_election_service_client {
36    #![allow(
37        unused_variables,
38        dead_code,
39        missing_docs,
40        clippy::wildcard_imports,
41        clippy::let_unit_value,
42    )]
43    use tonic::codegen::*;
44    use tonic::codegen::http::Uri;
45    #[derive(Debug, Clone)]
46    pub struct RaftElectionServiceClient<T> {
47        inner: tonic::client::Grpc<T>,
48    }
49    impl RaftElectionServiceClient<tonic::transport::Channel> {
50        /// Attempt to create a new client by connecting to a given endpoint.
51        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
52        where
53            D: TryInto<tonic::transport::Endpoint>,
54            D::Error: Into<StdError>,
55        {
56            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
57            Ok(Self::new(conn))
58        }
59    }
60    impl<T> RaftElectionServiceClient<T>
61    where
62        T: tonic::client::GrpcService<tonic::body::BoxBody>,
63        T::Error: Into<StdError>,
64        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
65        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
66    {
67        pub fn new(inner: T) -> Self {
68            let inner = tonic::client::Grpc::new(inner);
69            Self { inner }
70        }
71        pub fn with_origin(inner: T, origin: Uri) -> Self {
72            let inner = tonic::client::Grpc::with_origin(inner, origin);
73            Self { inner }
74        }
75        pub fn with_interceptor<F>(
76            inner: T,
77            interceptor: F,
78        ) -> RaftElectionServiceClient<InterceptedService<T, F>>
79        where
80            F: tonic::service::Interceptor,
81            T::ResponseBody: Default,
82            T: tonic::codegen::Service<
83                http::Request<tonic::body::BoxBody>,
84                Response = http::Response<
85                    <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
86                >,
87            >,
88            <T as tonic::codegen::Service<
89                http::Request<tonic::body::BoxBody>,
90            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
91        {
92            RaftElectionServiceClient::new(InterceptedService::new(inner, interceptor))
93        }
94        /// Compress requests with the given encoding.
95        ///
96        /// This requires the server to support it otherwise it might respond with an
97        /// error.
98        #[must_use]
99        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
100            self.inner = self.inner.send_compressed(encoding);
101            self
102        }
103        /// Enable decompressing responses.
104        #[must_use]
105        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
106            self.inner = self.inner.accept_compressed(encoding);
107            self
108        }
109        /// Limits the maximum size of a decoded message.
110        ///
111        /// Default: `4MB`
112        #[must_use]
113        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
114            self.inner = self.inner.max_decoding_message_size(limit);
115            self
116        }
117        /// Limits the maximum size of an encoded message.
118        ///
119        /// Default: `usize::MAX`
120        #[must_use]
121        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
122            self.inner = self.inner.max_encoding_message_size(limit);
123            self
124        }
125        pub async fn request_vote(
126            &mut self,
127            request: impl tonic::IntoRequest<super::VoteRequest>,
128        ) -> std::result::Result<tonic::Response<super::VoteResponse>, tonic::Status> {
129            self.inner
130                .ready()
131                .await
132                .map_err(|e| {
133                    tonic::Status::unknown(
134                        format!("Service was not ready: {}", e.into()),
135                    )
136                })?;
137            let codec = tonic::codec::ProstCodec::default();
138            let path = http::uri::PathAndQuery::from_static(
139                "/raft.election.RaftElectionService/RequestVote",
140            );
141            let mut req = request.into_request();
142            req.extensions_mut()
143                .insert(
144                    GrpcMethod::new("raft.election.RaftElectionService", "RequestVote"),
145                );
146            self.inner.unary(req, path, codec).await
147        }
148    }
149}
150/// Generated server implementations.
151pub mod raft_election_service_server {
152    #![allow(
153        unused_variables,
154        dead_code,
155        missing_docs,
156        clippy::wildcard_imports,
157        clippy::let_unit_value,
158    )]
159    use tonic::codegen::*;
160    /// Generated trait containing gRPC methods that should be implemented for use with RaftElectionServiceServer.
161    #[async_trait]
162    pub trait RaftElectionService: std::marker::Send + std::marker::Sync + 'static {
163        async fn request_vote(
164            &self,
165            request: tonic::Request<super::VoteRequest>,
166        ) -> std::result::Result<tonic::Response<super::VoteResponse>, tonic::Status>;
167    }
168    #[derive(Debug)]
169    pub struct RaftElectionServiceServer<T> {
170        inner: Arc<T>,
171        accept_compression_encodings: EnabledCompressionEncodings,
172        send_compression_encodings: EnabledCompressionEncodings,
173        max_decoding_message_size: Option<usize>,
174        max_encoding_message_size: Option<usize>,
175    }
176    impl<T> RaftElectionServiceServer<T> {
177        pub fn new(inner: T) -> Self {
178            Self::from_arc(Arc::new(inner))
179        }
180        pub fn from_arc(inner: Arc<T>) -> Self {
181            Self {
182                inner,
183                accept_compression_encodings: Default::default(),
184                send_compression_encodings: Default::default(),
185                max_decoding_message_size: None,
186                max_encoding_message_size: None,
187            }
188        }
189        pub fn with_interceptor<F>(
190            inner: T,
191            interceptor: F,
192        ) -> InterceptedService<Self, F>
193        where
194            F: tonic::service::Interceptor,
195        {
196            InterceptedService::new(Self::new(inner), interceptor)
197        }
198        /// Enable decompressing requests with the given encoding.
199        #[must_use]
200        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
201            self.accept_compression_encodings.enable(encoding);
202            self
203        }
204        /// Compress responses with the given encoding, if the client supports it.
205        #[must_use]
206        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
207            self.send_compression_encodings.enable(encoding);
208            self
209        }
210        /// Limits the maximum size of a decoded message.
211        ///
212        /// Default: `4MB`
213        #[must_use]
214        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
215            self.max_decoding_message_size = Some(limit);
216            self
217        }
218        /// Limits the maximum size of an encoded message.
219        ///
220        /// Default: `usize::MAX`
221        #[must_use]
222        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
223            self.max_encoding_message_size = Some(limit);
224            self
225        }
226    }
227    impl<T, B> tonic::codegen::Service<http::Request<B>> for RaftElectionServiceServer<T>
228    where
229        T: RaftElectionService,
230        B: Body + std::marker::Send + 'static,
231        B::Error: Into<StdError> + std::marker::Send + 'static,
232    {
233        type Response = http::Response<tonic::body::BoxBody>;
234        type Error = std::convert::Infallible;
235        type Future = BoxFuture<Self::Response, Self::Error>;
236        fn poll_ready(
237            &mut self,
238            _cx: &mut Context<'_>,
239        ) -> Poll<std::result::Result<(), Self::Error>> {
240            Poll::Ready(Ok(()))
241        }
242        fn call(&mut self, req: http::Request<B>) -> Self::Future {
243            match req.uri().path() {
244                "/raft.election.RaftElectionService/RequestVote" => {
245                    #[allow(non_camel_case_types)]
246                    struct RequestVoteSvc<T: RaftElectionService>(pub Arc<T>);
247                    impl<
248                        T: RaftElectionService,
249                    > tonic::server::UnaryService<super::VoteRequest>
250                    for RequestVoteSvc<T> {
251                        type Response = super::VoteResponse;
252                        type Future = BoxFuture<
253                            tonic::Response<Self::Response>,
254                            tonic::Status,
255                        >;
256                        fn call(
257                            &mut self,
258                            request: tonic::Request<super::VoteRequest>,
259                        ) -> Self::Future {
260                            let inner = Arc::clone(&self.0);
261                            let fut = async move {
262                                <T as RaftElectionService>::request_vote(&inner, request)
263                                    .await
264                            };
265                            Box::pin(fut)
266                        }
267                    }
268                    let accept_compression_encodings = self.accept_compression_encodings;
269                    let send_compression_encodings = self.send_compression_encodings;
270                    let max_decoding_message_size = self.max_decoding_message_size;
271                    let max_encoding_message_size = self.max_encoding_message_size;
272                    let inner = self.inner.clone();
273                    let fut = async move {
274                        let method = RequestVoteSvc(inner);
275                        let codec = tonic::codec::ProstCodec::default();
276                        let mut grpc = tonic::server::Grpc::new(codec)
277                            .apply_compression_config(
278                                accept_compression_encodings,
279                                send_compression_encodings,
280                            )
281                            .apply_max_message_size_config(
282                                max_decoding_message_size,
283                                max_encoding_message_size,
284                            );
285                        let res = grpc.unary(method, req).await;
286                        Ok(res)
287                    };
288                    Box::pin(fut)
289                }
290                _ => {
291                    Box::pin(async move {
292                        let mut response = http::Response::new(empty_body());
293                        let headers = response.headers_mut();
294                        headers
295                            .insert(
296                                tonic::Status::GRPC_STATUS,
297                                (tonic::Code::Unimplemented as i32).into(),
298                            );
299                        headers
300                            .insert(
301                                http::header::CONTENT_TYPE,
302                                tonic::metadata::GRPC_CONTENT_TYPE,
303                            );
304                        Ok(response)
305                    })
306                }
307            }
308        }
309    }
310    impl<T> Clone for RaftElectionServiceServer<T> {
311        fn clone(&self) -> Self {
312            let inner = self.inner.clone();
313            Self {
314                inner,
315                accept_compression_encodings: self.accept_compression_encodings,
316                send_compression_encodings: self.send_compression_encodings,
317                max_decoding_message_size: self.max_decoding_message_size,
318                max_encoding_message_size: self.max_encoding_message_size,
319            }
320        }
321    }
322    /// Generated gRPC service name
323    pub const SERVICE_NAME: &str = "raft.election.RaftElectionService";
324    impl<T> tonic::server::NamedService for RaftElectionServiceServer<T> {
325        const NAME: &'static str = SERVICE_NAME;
326    }
327}