diff options
author | edef <edef@unfathomable.blue> | 2022-04-25 00:00:20 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-04-25 00:00:20 +0000 |
commit | 1d7ce6b089931f48e254e9ec520de1e3e007ee8d (patch) | |
tree | 7f072a4097b6d6790b5d2768ddc09608d5eaf15e /ripple/fossil | |
parent | 31c422f86ac9a4d3b4e12a6f1a51f86315b47f0c (diff) | |
download | unf-legacy-1d7ce6b089931f48e254e9ec520de1e3e007ee8d.tar.zst |
ripple/fossil: store blob metadata as protobuf
Change-Id: I12c590d842471bf543f16fd21056224d8a7c0857
Diffstat (limited to 'ripple/fossil')
-rw-r--r-- | ripple/fossil/src/lib.rs | 22 | ||||
-rw-r--r-- | ripple/fossil/src/store.proto | 5 |
2 files changed, 12 insertions, 15 deletions
diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index 93a1a88..8c182eb 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -129,16 +129,11 @@ impl Store { // we should probably have a "blob" tree, // and reserve the default tree for DB metadata - let slice = Slice { + let blob_buf = store::Blob { offset, length: data.len() as u64, - }; - - let slice_buf = { - let mut buf = [0u8; 16]; - BigEndian::write_u64_into(&[slice.offset, slice.length], &mut buf); - buf - }; + } + .encode_to_vec(); let chunks_tail_buf = { let mut buf = [0u8; 8]; @@ -149,7 +144,7 @@ impl Store { // TODO(edef): figure out fsync for durability (&*self.db, &self.meta) .transaction(|(db, meta)| { - db.insert(&*ident.as_bytes(), &slice_buf)?; + db.insert(&*ident.as_bytes(), &*blob_buf)?; meta.insert("chunks_tail", &chunks_tail_buf)?; Ok::<_, ConflictableTransactionError>(()) }) @@ -178,20 +173,17 @@ impl Store { } fn raw_blob(&self, ident: Digest) -> RawBlob<'_> { - let slice_buf = self + let buf = self .db .get(&*ident.as_bytes()) .unwrap() .expect("blob not found"); - let slice = Slice { - offset: BigEndian::read_u64(&slice_buf[0..]), - length: BigEndian::read_u64(&slice_buf[8..]), - }; + let store::Blob { offset, length } = store::Blob::decode(&*buf).unwrap(); RawBlob { store: self, - slice, + slice: Slice { offset, length }, position: 0, } } diff --git a/ripple/fossil/src/store.proto b/ripple/fossil/src/store.proto index b2089db..cbbbbf1 100644 --- a/ripple/fossil/src/store.proto +++ b/ripple/fossil/src/store.proto @@ -28,3 +28,8 @@ message LinkNode { string name = 1; string target = 2; } + +message Blob { + uint64 offset = 1; + uint64 length = 2; +} |