d_engine_proto/generated/
d_engine.server.election.rs1#[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 #[prost(bool, tag = "3")]
34 pub committed: bool,
35}
36pub mod raft_election_service_client {
38 #![allow(
39 unused_variables,
40 dead_code,
41 missing_docs,
42 clippy::wildcard_imports,
43 clippy::let_unit_value,
44 )]
45 use tonic::codegen::*;
46 use tonic::codegen::http::Uri;
47 #[derive(Debug, Clone)]
48 pub struct RaftElectionServiceClient<T> {
49 inner: tonic::client::Grpc<T>,
50 }
51 impl RaftElectionServiceClient<tonic::transport::Channel> {
52 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
54 where
55 D: TryInto<tonic::transport::Endpoint>,
56 D::Error: Into<StdError>,
57 {
58 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
59 Ok(Self::new(conn))
60 }
61 }
62 impl<T> RaftElectionServiceClient<T>
63 where
64 T: tonic::client::GrpcService<tonic::body::BoxBody>,
65 T::Error: Into<StdError>,
66 T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
67 <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
68 {
69 pub fn new(inner: T) -> Self {
70 let inner = tonic::client::Grpc::new(inner);
71 Self { inner }
72 }
73 pub fn with_origin(inner: T, origin: Uri) -> Self {
74 let inner = tonic::client::Grpc::with_origin(inner, origin);
75 Self { inner }
76 }
77 pub fn with_interceptor<F>(
78 inner: T,
79 interceptor: F,
80 ) -> RaftElectionServiceClient<InterceptedService<T, F>>
81 where
82 F: tonic::service::Interceptor,
83 T::ResponseBody: Default,
84 T: tonic::codegen::Service<
85 http::Request<tonic::body::BoxBody>,
86 Response = http::Response<
87 <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
88 >,
89 >,
90 <T as tonic::codegen::Service<
91 http::Request<tonic::body::BoxBody>,
92 >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
93 {
94 RaftElectionServiceClient::new(InterceptedService::new(inner, interceptor))
95 }
96 #[must_use]
101 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
102 self.inner = self.inner.send_compressed(encoding);
103 self
104 }
105 #[must_use]
107 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
108 self.inner = self.inner.accept_compressed(encoding);
109 self
110 }
111 #[must_use]
115 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
116 self.inner = self.inner.max_decoding_message_size(limit);
117 self
118 }
119 #[must_use]
123 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
124 self.inner = self.inner.max_encoding_message_size(limit);
125 self
126 }
127 pub async fn request_vote(
128 &mut self,
129 request: impl tonic::IntoRequest<super::VoteRequest>,
130 ) -> std::result::Result<tonic::Response<super::VoteResponse>, tonic::Status> {
131 self.inner
132 .ready()
133 .await
134 .map_err(|e| {
135 tonic::Status::unknown(
136 format!("Service was not ready: {}", e.into()),
137 )
138 })?;
139 let codec = tonic::codec::ProstCodec::default();
140 let path = http::uri::PathAndQuery::from_static(
141 "/d_engine.server.election.RaftElectionService/RequestVote",
142 );
143 let mut req = request.into_request();
144 req.extensions_mut()
145 .insert(
146 GrpcMethod::new(
147 "d_engine.server.election.RaftElectionService",
148 "RequestVote",
149 ),
150 );
151 self.inner.unary(req, path, codec).await
152 }
153 }
154}
155pub mod raft_election_service_server {
157 #![allow(
158 unused_variables,
159 dead_code,
160 missing_docs,
161 clippy::wildcard_imports,
162 clippy::let_unit_value,
163 )]
164 use tonic::codegen::*;
165 #[async_trait]
167 pub trait RaftElectionService: std::marker::Send + std::marker::Sync + 'static {
168 async fn request_vote(
169 &self,
170 request: tonic::Request<super::VoteRequest>,
171 ) -> std::result::Result<tonic::Response<super::VoteResponse>, tonic::Status>;
172 }
173 #[derive(Debug)]
174 pub struct RaftElectionServiceServer<T> {
175 inner: Arc<T>,
176 accept_compression_encodings: EnabledCompressionEncodings,
177 send_compression_encodings: EnabledCompressionEncodings,
178 max_decoding_message_size: Option<usize>,
179 max_encoding_message_size: Option<usize>,
180 }
181 impl<T> RaftElectionServiceServer<T> {
182 pub fn new(inner: T) -> Self {
183 Self::from_arc(Arc::new(inner))
184 }
185 pub fn from_arc(inner: Arc<T>) -> Self {
186 Self {
187 inner,
188 accept_compression_encodings: Default::default(),
189 send_compression_encodings: Default::default(),
190 max_decoding_message_size: None,
191 max_encoding_message_size: None,
192 }
193 }
194 pub fn with_interceptor<F>(
195 inner: T,
196 interceptor: F,
197 ) -> InterceptedService<Self, F>
198 where
199 F: tonic::service::Interceptor,
200 {
201 InterceptedService::new(Self::new(inner), interceptor)
202 }
203 #[must_use]
205 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
206 self.accept_compression_encodings.enable(encoding);
207 self
208 }
209 #[must_use]
211 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
212 self.send_compression_encodings.enable(encoding);
213 self
214 }
215 #[must_use]
219 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
220 self.max_decoding_message_size = Some(limit);
221 self
222 }
223 #[must_use]
227 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
228 self.max_encoding_message_size = Some(limit);
229 self
230 }
231 }
232 impl<T, B> tonic::codegen::Service<http::Request<B>> for RaftElectionServiceServer<T>
233 where
234 T: RaftElectionService,
235 B: Body + std::marker::Send + 'static,
236 B::Error: Into<StdError> + std::marker::Send + 'static,
237 {
238 type Response = http::Response<tonic::body::BoxBody>;
239 type Error = std::convert::Infallible;
240 type Future = BoxFuture<Self::Response, Self::Error>;
241 fn poll_ready(
242 &mut self,
243 _cx: &mut Context<'_>,
244 ) -> Poll<std::result::Result<(), Self::Error>> {
245 Poll::Ready(Ok(()))
246 }
247 fn call(&mut self, req: http::Request<B>) -> Self::Future {
248 match req.uri().path() {
249 "/d_engine.server.election.RaftElectionService/RequestVote" => {
250 #[allow(non_camel_case_types)]
251 struct RequestVoteSvc<T: RaftElectionService>(pub Arc<T>);
252 impl<
253 T: RaftElectionService,
254 > tonic::server::UnaryService<super::VoteRequest>
255 for RequestVoteSvc<T> {
256 type Response = super::VoteResponse;
257 type Future = BoxFuture<
258 tonic::Response<Self::Response>,
259 tonic::Status,
260 >;
261 fn call(
262 &mut self,
263 request: tonic::Request<super::VoteRequest>,
264 ) -> Self::Future {
265 let inner = Arc::clone(&self.0);
266 let fut = async move {
267 <T as RaftElectionService>::request_vote(&inner, request)
268 .await
269 };
270 Box::pin(fut)
271 }
272 }
273 let accept_compression_encodings = self.accept_compression_encodings;
274 let send_compression_encodings = self.send_compression_encodings;
275 let max_decoding_message_size = self.max_decoding_message_size;
276 let max_encoding_message_size = self.max_encoding_message_size;
277 let inner = self.inner.clone();
278 let fut = async move {
279 let method = RequestVoteSvc(inner);
280 let codec = tonic::codec::ProstCodec::default();
281 let mut grpc = tonic::server::Grpc::new(codec)
282 .apply_compression_config(
283 accept_compression_encodings,
284 send_compression_encodings,
285 )
286 .apply_max_message_size_config(
287 max_decoding_message_size,
288 max_encoding_message_size,
289 );
290 let res = grpc.unary(method, req).await;
291 Ok(res)
292 };
293 Box::pin(fut)
294 }
295 _ => {
296 Box::pin(async move {
297 let mut response = http::Response::new(empty_body());
298 let headers = response.headers_mut();
299 headers
300 .insert(
301 tonic::Status::GRPC_STATUS,
302 (tonic::Code::Unimplemented as i32).into(),
303 );
304 headers
305 .insert(
306 http::header::CONTENT_TYPE,
307 tonic::metadata::GRPC_CONTENT_TYPE,
308 );
309 Ok(response)
310 })
311 }
312 }
313 }
314 }
315 impl<T> Clone for RaftElectionServiceServer<T> {
316 fn clone(&self) -> Self {
317 let inner = self.inner.clone();
318 Self {
319 inner,
320 accept_compression_encodings: self.accept_compression_encodings,
321 send_compression_encodings: self.send_compression_encodings,
322 max_decoding_message_size: self.max_decoding_message_size,
323 max_encoding_message_size: self.max_encoding_message_size,
324 }
325 }
326 }
327 pub const SERVICE_NAME: &str = "d_engine.server.election.RaftElectionService";
329 impl<T> tonic::server::NamedService for RaftElectionServiceServer<T> {
330 const NAME: &'static str = SERVICE_NAME;
331 }
332}