Skip to content

Commit

Permalink
Minor change to make fastcdc return Bytes intead of BytesMut
Browse files Browse the repository at this point in the history
  • Loading branch information
allada committed Nov 16, 2021
1 parent a76a35f commit d5f1918
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions util/fastcdc.rs
Expand Up @@ -4,7 +4,7 @@
// This implementation is heavily based on:
// https://github.com/nlfiedler/fastcdc-rs/blob/1e804fe27444e37b2c4f93d540f861d170c8a257/src/lib.rs

use bytes::BytesMut;
use bytes::{Bytes, BytesMut};
use tokio_util::codec::Decoder;

struct State {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl FastCDC {
}

impl Decoder for FastCDC {
type Item = BytesMut;
type Item = Bytes;
type Error = std::io::Error;

fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
Expand Down Expand Up @@ -120,14 +120,14 @@ impl Decoder for FastCDC {
split_point,
self.max_size
);
return Ok(Some(buf.split_to(split_point)));
return Ok(Some(buf.split_to(split_point).freeze()));
}
self.state.position = split_point;
if self.state.position == 0 {
self.state.position = buf.len();
}

return Ok(None);
Ok(None)
}

fn decode_eof(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
Expand All @@ -140,7 +140,7 @@ impl Decoder for FastCDC {
// If our buffer is empty we don't have any more data.
return Ok(None);
}
Ok(Some(buf.split()))
Ok(Some(buf.split().freeze()))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions util/tests/fastcdc_test.rs
Expand Up @@ -6,7 +6,7 @@ use std::collections::{HashMap, HashSet};
use std::io::Cursor;
use std::marker::Unpin;

use bytes::BytesMut;
use bytes::Bytes;
use futures::stream::StreamExt;
use rand::{rngs::SmallRng, Rng, SeedableRng};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -108,7 +108,7 @@ mod fastcdc_tests {
let fast_cdc = FastCDC::new(1024, 2048, 4096);
let left_frames = {
let mut frame_reader = FramedRead::new(Cursor::new(&rand_data), fast_cdc.clone());
let frames: Vec<BytesMut> = get_frames(&mut frame_reader).await?;
let frames: Vec<Bytes> = get_frames(&mut frame_reader).await?;

let mut frames_map = HashMap::new();
let mut pos = 0;
Expand All @@ -129,7 +129,7 @@ mod fastcdc_tests {

let mut right_frames = {
let mut frame_reader = FramedRead::new(Cursor::new(&rand_data), fast_cdc.clone());
let frames: Vec<BytesMut> = get_frames(&mut frame_reader).await?;
let frames: Vec<Bytes> = get_frames(&mut frame_reader).await?;

let mut frames_map = HashMap::new();
let mut pos = 0;
Expand Down

0 comments on commit d5f1918

Please sign in to comment.