viewstamped_replication/
request.rs

1use crate::viewstamp::View;
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
5pub struct ClientIdentifier(u128);
6
7impl Default for ClientIdentifier {
8    fn default() -> Self {
9        Self(uuid::Uuid::new_v4().as_u128())
10    }
11}
12
13#[derive(
14    Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize,
15)]
16pub struct RequestIdentifier(u128);
17
18impl RequestIdentifier {
19    pub fn increment(&mut self) {
20        self.0 += 1;
21    }
22
23    pub fn next(&self) -> Self {
24        Self(self.0 + 1)
25    }
26}
27
28#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
29pub struct Request<R> {
30    /// The operation (with its arguments) the client wants to run.
31    pub payload: R,
32    /// Client id
33    pub client: ClientIdentifier,
34    /// Client-assigned number for the request.
35    pub id: RequestIdentifier,
36}
37
38#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
39pub struct Reply<R> {
40    /// The current view of the replica.
41    pub view: View,
42    /// Client-assigned number for the request.
43    pub id: RequestIdentifier,
44    /// The response from the service after executing the operation.
45    pub payload: R,
46}