From 271242460108ed427229b5cf8896500f881fda93 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 10 Jun 2024 17:22:40 +0200 Subject: [PATCH] Use serde_json::from_reader --- .../src/replica/aligner.rs | 42 ++++++------------- .../src/replica/mod.rs | 10 +---- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs b/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs index 358ee2e66b..e1bac3ae49 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs @@ -216,16 +216,10 @@ impl Aligner { let mut other_intervals: HashMap = HashMap::new(); // expecting sample.payload to be a vec of intervals with their checksum for each in reply_content { - match each.payload().deserialize::>() { - Ok(s) => match serde_json::from_str(&s) { - Ok((i, c)) => { - other_intervals.insert(i, c); - } - Err(e) => { - tracing::error!("[ALIGNER] Error decoding reply: {}", e); - no_err = false; - } - }, + match serde_json::from_reader(each.payload().reader()) { + Ok((i, c)) => { + other_intervals.insert(i, c); + } Err(e) => { tracing::error!("[ALIGNER] Error decoding reply: {}", e); no_err = false; @@ -268,16 +262,10 @@ impl Aligner { let (reply_content, mut no_err) = self.perform_query(other_rep, properties).await; let mut other_subintervals: HashMap = HashMap::new(); for each in reply_content { - match each.payload().deserialize::>() { - Ok(s) => match serde_json::from_str(&s) { - Ok((i, c)) => { - other_subintervals.insert(i, c); - } - Err(e) => { - tracing::error!("[ALIGNER] Error decoding reply: {}", e); - no_err = false; - } - }, + match serde_json::from_reader(each.payload().reader()) { + Ok((i, c)) => { + other_subintervals.insert(i, c); + } Err(e) => { tracing::error!("[ALIGNER] Error decoding reply: {}", e); no_err = false; @@ -315,16 +303,10 @@ impl Aligner { let (reply_content, mut no_err) = self.perform_query(other_rep, properties).await; let mut other_content: HashMap> = HashMap::new(); for each in reply_content { - match each.payload().deserialize::>() { - Ok(s) => match serde_json::from_str(&s) { - Ok((i, c)) => { - other_content.insert(i, c); - } - Err(e) => { - tracing::error!("[ALIGNER] Error decoding reply: {}", e); - no_err = false; - } - }, + match serde_json::from_reader(each.payload().reader()) { + Ok((i, c)) => { + other_content.insert(i, c); + } Err(e) => { tracing::error!("[ALIGNER] Error decoding reply: {}", e); no_err = false; diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs b/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs index 0a6fece0a2..b2f37a07e9 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs @@ -226,14 +226,8 @@ impl Replica { let from = &sample.key_expr().as_str() [Replica::get_digest_key(&self.key_expr, ALIGN_PREFIX).len() + 1..]; - let digest: Digest = match sample.payload().deserialize::>() { - Ok(s) => match serde_json::from_str(&s) { - Ok(digest) => digest, - Err(e) => { - tracing::error!("[DIGEST_SUB] Error in decoding the digest: {}", e); - continue; - } - }, + let digest: Digest = match serde_json::from_reader(sample.payload().reader()) { + Ok(digest) => digest, Err(e) => { tracing::error!("[DIGEST_SUB] Error in decoding the digest: {}", e); continue;