From 1d7ce6b089931f48e254e9ec520de1e3e007ee8d Mon Sep 17 00:00:00 2001 From: edef Date: Mon, 25 Apr 2022 00:00:20 +0000 Subject: ripple/fossil: store blob metadata as protobuf Change-Id: I12c590d842471bf543f16fd21056224d8a7c0857 --- ripple/fossil/src/lib.rs | 22 +++++++--------------- ripple/fossil/src/store.proto | 5 +++++ 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'ripple/fossil') 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; +} -- cgit 1.4.1