Skip to content

Commit 76b5691

Browse files
committed
fix(foundationdb): make proper use of pack/unpack
1 parent 5d18008 commit 76b5691

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

foundationdb/src/directory/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::directory::error::DirectoryError;
1818
use crate::directory::node::Node;
1919
use crate::future::FdbSlice;
2020
use crate::tuple::hca::HighContentionAllocator;
21-
use crate::tuple::{pack_into, Subspace};
21+
use crate::tuple::Subspace;
2222
use crate::{FdbError, FdbResult, Transaction};
2323
use byteorder::{LittleEndian, WriteBytesExt};
2424

@@ -378,9 +378,10 @@ impl DirectoryLayer {
378378

379379
for path_name in paths {
380380
node_path.push(path_name.to_owned());
381-
let mut next_node_key = vec![DEFAULT_SUB_DIRS];
382-
pack_into(&path_name, &mut next_node_key);
383-
subspace = subspace.subspace(&next_node_key);
381+
subspace = subspace.subspace::<(&[u8], String)>(&(
382+
vec![DEFAULT_SUB_DIRS].as_slice(),
383+
path_name.to_owned(),
384+
));
384385

385386
let mut node = Node {
386387
paths: node_path.clone(),

foundationdb/src/directory/node.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,8 @@ impl Node {
9696
for fdb_value in fdb_values {
9797
let subspace = Subspace::from_bytes(fdb_value.key());
9898
// stripping from subspace
99-
let sub_directory: Vec<u8> = self.node_subspace.unpack(subspace.bytes())?;
100-
match String::from_utf8(sub_directory.to_owned()) {
101-
Ok(mut s) => {
102-
// s is like "\u{0}\u{2}node-0\u{0}"
103-
// we need to remove DEFAULT_SUB_DIRS at the beginning and the padding at the end.
104-
// maybe there is a better way to clean it? Unpack?
105-
s.remove(0);
106-
s.remove(0);
107-
s.remove(s.len() - 1);
108-
results.push(s);
109-
}
110-
Err(err) => {
111-
return Err(DirectoryError::Message(format!(
112-
"could not decode '{:?}' in utf-8: {}",
113-
sub_directory, err
114-
)))
115-
}
116-
}
99+
let sub_directory: (Vec<u8>, String) = self.node_subspace.unpack(subspace.bytes())?;
100+
results.push(sub_directory.1);
117101
}
118102
Ok(results)
119103
}

0 commit comments

Comments
 (0)