diff options
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/client.rs b/src/client.rs index d6caf68..e2d5d84 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::net::SocketAddr; use std::sync::atomic::{self, AtomicU32}; use std::sync::{Arc, Mutex}; +use std::borrow::Borrow; use arc_swap::ArcSwapOption; use log::{debug, error, trace}; @@ -29,6 +30,7 @@ use crate::endpoint::*; use crate::error::*; use crate::netapp::*; use crate::proto::*; +use crate::proto2::*; use crate::util::*; pub(crate) struct ClientConn { @@ -118,14 +120,15 @@ impl ClientConn { self.query_send.store(None); } - pub(crate) async fn call<T>( + pub(crate) async fn call<'a, T, B>( self: Arc<Self>, - rq: &T, - path: &str, + rq: B, + path: &'a str, prio: RequestPriority, ) -> Result<<T as Message>::Response, Error> where T: Message, + B: Borrow<T>, { let query_send = self.query_send.load_full().ok_or(Error::ConnectionClosed)?; @@ -147,19 +150,17 @@ impl ClientConn { }; // Encode request - let mut bytes = vec![]; - - bytes.extend_from_slice(&[prio, path.as_bytes().len() as u8]); - bytes.extend_from_slice(path.as_bytes()); - - if let Some(by) = telemetry_id { - bytes.push(by.len() as u8); - bytes.extend(by); - } else { - bytes.push(0); - } - - bytes.extend_from_slice(&rmp_to_vec_all_named(rq)?[..]); + let body = rmp_to_vec_all_named(rq.borrow())?; + drop(rq); + + let request = QueryMessage { + prio, + path: path.as_bytes(), + telemetry_id, + body: &body[..], + }; + let bytes = request.encode(); + drop(body); // Send request through let (resp_send, resp_recv) = oneshot::channel(); |