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
/// Generated client implementations.
pub mod worker_to_primary_client {
    #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
    use anemo::codegen::*;
    #[derive(Debug, Clone)]
    pub struct WorkerToPrimaryClient<T> {
        inner: anemo::rpc::client::Rpc<T>,
    }
    impl<T> WorkerToPrimaryClient<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::WorkerPrimaryMessage>,
        ) -> 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.WorkerToPrimary/SendMessage".into();
            self.inner.unary(request, codec).await
        }
        pub async fn worker_info(
            &mut self,
            request: impl anemo::types::request::IntoRequest<()>,
        ) -> Result<anemo::Response<crate::WorkerInfoResponse>, 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.WorkerToPrimary/WorkerInfo".into();
            self.inner.unary(request, codec).await
        }
    }
}
/// Generated server implementations.
pub mod worker_to_primary_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 WorkerToPrimaryServer.
    #[async_trait]
    pub trait WorkerToPrimary: Send + Sync + 'static {
        async fn send_message(
            &self,
            request: anemo::Request<crate::WorkerPrimaryMessage>,
        ) -> Result<anemo::Response<()>, anemo::rpc::Status>;
        async fn worker_info(
            &self,
            request: anemo::Request<()>,
        ) -> Result<anemo::Response<crate::WorkerInfoResponse>, anemo::rpc::Status>;
    }
    #[derive(Debug)]
    pub struct WorkerToPrimaryServer<T: WorkerToPrimary> {
        inner: Arc<T>,
    }
    impl<T: WorkerToPrimary> WorkerToPrimaryServer<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 WorkerToPrimaryServer<T>
    where
        T: WorkerToPrimary,
    {
        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.WorkerToPrimary/SendMessage" => {
                    #[allow(non_camel_case_types)]
                    struct SendMessageSvc<T: WorkerToPrimary>(pub Arc<T>);
                    impl<
                        T: WorkerToPrimary,
                    > anemo::rpc::server::UnaryService<crate::WorkerPrimaryMessage>
                    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::WorkerPrimaryMessage>,
                        ) -> 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.WorkerToPrimary/WorkerInfo" => {
                    #[allow(non_camel_case_types)]
                    struct WorkerInfoSvc<T: WorkerToPrimary>(pub Arc<T>);
                    impl<T: WorkerToPrimary> anemo::rpc::server::UnaryService<()>
                    for WorkerInfoSvc<T> {
                        type Response = crate::WorkerInfoResponse;
                        type Future = BoxFuture<
                            'static,
                            Result<anemo::Response<Self::Response>, anemo::rpc::Status>,
                        >;
                        fn call(&mut self, request: anemo::Request<()>) -> Self::Future {
                            let inner = self.0.clone();
                            let fut = async move { (*inner).worker_info(request).await };
                            Box::pin(fut)
                        }
                    }
                    let inner = self.inner.clone();
                    let fut = async move {
                        let method = WorkerInfoSvc(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: WorkerToPrimary> Clone for WorkerToPrimaryServer<T> {
        fn clone(&self) -> Self {
            let inner = self.inner.clone();
            Self { inner }
        }
    }
    impl<T: WorkerToPrimary> anemo::rpc::RpcService for WorkerToPrimaryServer<T> {
        const SERVICE_NAME: &'static str = "narwhal.WorkerToPrimary";
    }
}