Skip to content

Commit

Permalink
Use serde_json::from_reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Jun 10, 2024
1 parent a299467 commit 2712424
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
42 changes: 12 additions & 30 deletions plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,10 @@ impl Aligner {
let mut other_intervals: HashMap<u64, u64> = HashMap::new();
// expecting sample.payload to be a vec of intervals with their checksum
for each in reply_content {
match each.payload().deserialize::<Cow<str>>() {
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;
Expand Down Expand Up @@ -268,16 +262,10 @@ impl Aligner {
let (reply_content, mut no_err) = self.perform_query(other_rep, properties).await;
let mut other_subintervals: HashMap<u64, u64> = HashMap::new();
for each in reply_content {
match each.payload().deserialize::<Cow<str>>() {
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;
Expand Down Expand Up @@ -315,16 +303,10 @@ impl Aligner {
let (reply_content, mut no_err) = self.perform_query(other_rep, properties).await;
let mut other_content: HashMap<u64, Vec<LogEntry>> = HashMap::new();
for each in reply_content {
match each.payload().deserialize::<Cow<str>>() {
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;
Expand Down
10 changes: 2 additions & 8 deletions plugins/zenoh-plugin-storage-manager/src/replica/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Cow<str>>() {
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;
Expand Down

0 comments on commit 2712424

Please sign in to comment.