summary refs log tree commit diff
path: root/ripple/fossil
diff options
context:
space:
mode:
Diffstat (limited to 'ripple/fossil')
-rw-r--r--ripple/fossil/src/lib.rs22
-rw-r--r--ripple/fossil/src/store.proto5
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;
+}