Skip to content

Commit

Permalink
[Fixup] entry and entry header encoding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chyezh committed Jun 22, 2024
1 parent 19c3312 commit 3c220ce
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 181 deletions.
73 changes: 0 additions & 73 deletions lib/storage/src/entry/builder.rs

This file was deleted.

27 changes: 27 additions & 0 deletions lib/storage/src/entry/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,31 @@ mod tests {
assert_eq!(n, header.binary_size());
assert_eq!(buf, b"\x03keyvalue");
}

#[test]
fn test_read_at_all() {
for i in 1..10 {
read_all(i);
}
}

fn read_all(step: usize) {
let key = Bytes::from_static(b"key");
let value = Bytes::from_static(b"value");
let header = Header::new(key.clone(), value.clone());

let mut buf = vec![0; step];
let mut all = vec![];
let mut offset = 0;
loop {
let n = header.read_at(&mut buf, offset);
offset += n;
all.extend_from_slice(&buf[..n]);
if n == 0 {
break;
}
}
assert_eq!(all, b"\x03keyvalue");
assert_eq!(offset, header.binary_size());
}
}
Loading

0 comments on commit 3c220ce

Please sign in to comment.