Allow retrieving WriteBatch serialized size

master
Roman Zeyde 6 years ago
parent 0475bbeaea
commit d035454d9e
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
  1. 17
      src/db.rs

@ -1106,6 +1106,15 @@ impl WriteBatch {
unsafe { ffi::rocksdb_writebatch_count(self.inner) as usize }
}
/// Return WriteBatch serialized size (in bytes).
pub fn size_in_bytes(&self) -> usize {
unsafe {
let mut batch_size: size_t = 0;
ffi::rocksdb_writebatch_data(self.inner, &mut batch_size);
batch_size as usize
}
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
@ -1403,6 +1412,14 @@ fn writebatch_works() {
assert!(p.is_ok());
assert!(db.get(b"k1").unwrap().is_none());
}
{
// test size_in_bytes
let mut batch = WriteBatch::default();
let before = batch.size_in_bytes();
let _ = batch.put(b"k1", b"v1234567890");
let after = batch.size_in_bytes();
assert!(before + 10 <= after);
}
}
let opts = Options::default();
assert!(DB::destroy(&opts, path).is_ok());

Loading…
Cancel
Save