diff options
author | Alex Auvolat <alex@adnab.me> | 2022-07-21 19:05:51 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-07-21 19:05:51 +0200 |
commit | 44bbc1c00c2532e08dff0d4a547b0a707e89f32d (patch) | |
tree | a6c021ae50370b3c065e3485ef1dd06052a962c9 /src/endpoint.rs | |
parent | 26989bba1409bfc093e58ef98e75885b10ad7c1c (diff) | |
download | netapp-44bbc1c00c2532e08dff0d4a547b0a707e89f32d.tar.gz netapp-44bbc1c00c2532e08dff0d4a547b0a707e89f32d.zip |
Rename AutoSerialize into SimpleMessage and refactor a bit
Diffstat (limited to 'src/endpoint.rs')
-rw-r--r-- | src/endpoint.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/endpoint.rs b/src/endpoint.rs index e6b2236..3f292d9 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -19,7 +19,7 @@ pub trait EndpointHandler<M>: Send + Sync where M: Message, { - async fn handle(self: &Arc<Self>, m: &M, from: NodeID) -> M::Response; + async fn handle(self: &Arc<Self>, m: M, from: NodeID) -> M::Response; } /// If one simply wants to use an endpoint in a client fashion, @@ -28,7 +28,7 @@ where /// it will panic if it is ever made to handle request. #[async_trait] impl<M: Message + 'static> EndpointHandler<M> for () { - async fn handle(self: &Arc<()>, _m: &M, _from: NodeID) -> M::Response { + async fn handle(self: &Arc<()>, _m: M, _from: NodeID) -> M::Response { panic!("This endpoint should not have a local handler."); } } @@ -81,19 +81,16 @@ where /// Call this endpoint on a remote node (or on the local node, /// for that matter) - pub async fn call<B>( + pub async fn call( &self, target: &NodeID, - req: B, + req: M, prio: RequestPriority, - ) -> Result<<M as Message>::Response, Error> - where - B: Borrow<M> + Send + Sync, - { + ) -> Result<<M as Message>::Response, Error> { if *target == self.netapp.id { match self.handler.load_full() { None => Err(Error::NoHandler), - Some(h) => Ok(h.handle(req.borrow(), self.netapp.id).await), + Some(h) => Ok(h.handle(req, self.netapp.id).await), } } else { let conn = self @@ -152,10 +149,11 @@ where None => Err(Error::NoHandler), Some(h) => { let req = rmp_serde::decode::from_read_ref(buf)?; - let req = M::deserialize_msg(req, stream).await; - let res = h.handle(&req, from).await; + let req = M::from_parts(req, stream); + let res = h.handle(req, from).await; + let (res, res_stream) = res.into_parts(); let res_bytes = rmp_to_vec_all_named(&res)?; - Ok(res_bytes) + Ok((res_bytes, res_stream)) } } } |