aboutsummaryrefslogtreecommitdiff
path: root/src/client.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-02-21 12:01:04 +0100
committerAlex Auvolat <alex@adnab.me>2022-02-21 12:01:04 +0100
commit3b8bff634198c5ae17ab16d5c85c30b3201ae593 (patch)
tree8f3545c230c08c3a3100faf1293345e88a43d3dd /src/client.rs
parent109d6c143d01b2d59027d45738692fa8ef6253ee (diff)
downloadnetapp-3b8bff634198c5ae17ab16d5c85c30b3201ae593.tar.gz
netapp-3b8bff634198c5ae17ab16d5c85c30b3201ae593.zip
Refactoring
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs33
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();