1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/// Generated client implementations.
pub mod primary_to_worker_client {
    #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
    use anemo::codegen::*;
    #[derive(Debug, Clone)]
    pub struct PrimaryToWorkerClient<T> {
        inner: anemo::rpc::client::Rpc<T>,
    }
    impl<T> PrimaryToWorkerClient<T>
    where
        T: Service<Request<Bytes>, Response = Response<Bytes>>,
        T::Error: Into<BoxError>,
    {
        pub fn new(inner: T) -> Self {
            let inner = anemo::rpc::client::Rpc::new(inner);
            Self { inner }
        }
        pub async fn send_message(
            &mut self,
            request: impl anemo::types::request::IntoRequest<crate::PrimaryWorkerMessage>,
        ) -> Result<anemo::Response<()>, anemo::rpc::Status> {
            self.inner
                .ready()
                .await
                .map_err(|e| {
                    anemo::rpc::Status::unknown(
                        format!("Service was not ready: {}", e.into()),
                    )
                })?;
            let codec = anemo::rpc::codec::BincodeCodec::default();
            let mut request = request.into_request();
            *request.route_mut() = "/narwhal.PrimaryToWorker/SendMessage".into();
            self.inner.unary(request, codec).await
        }
        pub async fn synchronize(
            &mut self,
            request: impl anemo::types::request::IntoRequest<
                crate::WorkerSynchronizeMessage,
            >,
        ) -> Result<anemo::Response<()>, anemo::rpc::Status> {
            self.inner
                .ready()
                .await
                .map_err(|e| {
                    anemo::rpc::Status::unknown(
                        format!("Service was not ready: {}", e.into()),
                    )
                })?;
            let codec = anemo::rpc::codec::BincodeCodec::default();
            let mut request = request.into_request();
            *request.route_mut() = "/narwhal.PrimaryToWorker/Synchronize".into();
            self.inner.unary(request, codec).await
        }
        pub async fn request_batch(
            &mut self,
            request: impl anemo::types::request::IntoRequest<crate::RequestBatchRequest>,
        ) -> Result<anemo::Response<crate::RequestBatchResponse>, anemo::rpc::Status> {
            self.inner
                .ready()
                .await
                .map_err(|e| {
                    anemo::rpc::Status::unknown(
                        format!("Service was not ready: {}", e.into()),
                    )
                })?;
            let codec = anemo::rpc::codec::BincodeCodec::default();
            let mut request = request.into_request();
            *request.route_mut() = "/narwhal.PrimaryToWorker/RequestBatch".into();
            self.inner.unary(request, codec).await
        }
    }
}
/// Generated server implementations.
pub mod primary_to_worker_server {
    #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
    use anemo::codegen::*;
    ///Generated trait containing RPC methods that should be implemented for use with PrimaryToWorkerServer.
    #[async_trait]
    pub trait PrimaryToWorker: Send + Sync + 'static {
        async fn send_message(
            &self,
            request: anemo::Request<crate::PrimaryWorkerMessage>,
        ) -> Result<anemo::Response<()>, anemo::rpc::Status>;
        async fn synchronize(
            &self,
            request: anemo::Request<crate::WorkerSynchronizeMessage>,
        ) -> Result<anemo::Response<()>, anemo::rpc::Status>;
        async fn request_batch(
            &self,
            request: anemo::Request<crate::RequestBatchRequest>,
        ) -> Result<anemo::Response<crate::RequestBatchResponse>, anemo::rpc::Status>;
    }
    #[derive(Debug)]
    pub struct PrimaryToWorkerServer<T: PrimaryToWorker> {
        inner: Arc<T>,
    }
    impl<T: PrimaryToWorker> PrimaryToWorkerServer<T> {
        pub fn new(inner: T) -> Self {
            Self::from_arc(Arc::new(inner))
        }
        pub fn from_arc(inner: Arc<T>) -> Self {
            Self { inner }
        }
    }
    impl<T> anemo::codegen::Service<anemo::Request<Bytes>> for PrimaryToWorkerServer<T>
    where
        T: PrimaryToWorker,
    {
        type Response = anemo::Response<Bytes>;
        type Error = std::convert::Infallible;
        type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
        fn poll_ready(
            &mut self,
            _cx: &mut Context<'_>,
        ) -> Poll<Result<(), Self::Error>> {
            Poll::Ready(Ok(()))
        }
        fn call(&mut self, req: anemo::Request<Bytes>) -> Self::Future {
            let inner = self.inner.clone();
            match req.route() {
                "/narwhal.PrimaryToWorker/SendMessage" => {
                    #[allow(non_camel_case_types)]
                    struct SendMessageSvc<T: PrimaryToWorker>(pub Arc<T>);
                    impl<
                        T: PrimaryToWorker,
                    > anemo::rpc::server::UnaryService<crate::PrimaryWorkerMessage>
                    for SendMessageSvc<T> {
                        type Response = ();
                        type Future = BoxFuture<
                            'static,
                            Result<anemo::Response<Self::Response>, anemo::rpc::Status>,
                        >;
                        fn call(
                            &mut self,
                            request: anemo::Request<crate::PrimaryWorkerMessage>,
                        ) -> Self::Future {
                            let inner = self.0.clone();
                            let fut = async move {
                                (*inner).send_message(request).await
                            };
                            Box::pin(fut)
                        }
                    }
                    let inner = self.inner.clone();
                    let fut = async move {
                        let method = SendMessageSvc(inner);
                        let codec = anemo::rpc::codec::BincodeCodec::default();
                        let mut rpc = anemo::rpc::server::Rpc::new(codec);
                        let res = rpc.unary(method, req).await;
                        Ok(res)
                    };
                    Box::pin(fut)
                }
                "/narwhal.PrimaryToWorker/Synchronize" => {
                    #[allow(non_camel_case_types)]
                    struct SynchronizeSvc<T: PrimaryToWorker>(pub Arc<T>);
                    impl<
                        T: PrimaryToWorker,
                    > anemo::rpc::server::UnaryService<crate::WorkerSynchronizeMessage>
                    for SynchronizeSvc<T> {
                        type Response = ();
                        type Future = BoxFuture<
                            'static,
                            Result<anemo::Response<Self::Response>, anemo::rpc::Status>,
                        >;
                        fn call(
                            &mut self,
                            request: anemo::Request<crate::WorkerSynchronizeMessage>,
                        ) -> Self::Future {
                            let inner = self.0.clone();
                            let fut = async move { (*inner).synchronize(request).await };
                            Box::pin(fut)
                        }
                    }
                    let inner = self.inner.clone();
                    let fut = async move {
                        let method = SynchronizeSvc(inner);
                        let codec = anemo::rpc::codec::BincodeCodec::default();
                        let mut rpc = anemo::rpc::server::Rpc::new(codec);
                        let res = rpc.unary(method, req).await;
                        Ok(res)
                    };
                    Box::pin(fut)
                }
                "/narwhal.PrimaryToWorker/RequestBatch" => {
                    #[allow(non_camel_case_types)]
                    struct RequestBatchSvc<T: PrimaryToWorker>(pub Arc<T>);
                    impl<
                        T: PrimaryToWorker,
                    > anemo::rpc::server::UnaryService<crate::RequestBatchRequest>
                    for RequestBatchSvc<T> {
                        type Response = crate::RequestBatchResponse;
                        type Future = BoxFuture<
                            'static,
                            Result<anemo::Response<Self::Response>, anemo::rpc::Status>,
                        >;
                        fn call(
                            &mut self,
                            request: anemo::Request<crate::RequestBatchRequest>,
                        ) -> Self::Future {
                            let inner = self.0.clone();
                            let fut = async move {
                                (*inner).request_batch(request).await
                            };
                            Box::pin(fut)
                        }
                    }
                    let inner = self.inner.clone();
                    let fut = async move {
                        let method = RequestBatchSvc(inner);
                        let codec = anemo::rpc::codec::BincodeCodec::default();
                        let mut rpc = anemo::rpc::server::Rpc::new(codec);
                        let res = rpc.unary(method, req).await;
                        Ok(res)
                    };
                    Box::pin(fut)
                }
                _ => {
                    Box::pin(async move {
                        Ok(anemo::types::response::StatusCode::NotFound.into_response())
                    })
                }
            }
        }
    }
    impl<T: PrimaryToWorker> Clone for PrimaryToWorkerServer<T> {
        fn clone(&self) -> Self {
            let inner = self.inner.clone();
            Self { inner }
        }
    }
    impl<T: PrimaryToWorker> anemo::rpc::RpcService for PrimaryToWorkerServer<T> {
        const SERVICE_NAME: &'static str = "narwhal.PrimaryToWorker";
    }
}