aboutsummaryrefslogtreecommitdiffstats
path: root/log_db/src/common.rs
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2024-11-04 23:13:44 +0200
committerJan Tuomi <jan@jantuomi.fi>2024-11-05 22:08:51 +0200
commitae07cfa82a52abe007670dd52a418deaf5bf0efb (patch)
treebf14226d6af2196b8593a97879e33a9429308706 /log_db/src/common.rs
parent1086c414ebb6b8f30c3840ec73e3d48b0fd44339 (diff)
Rewrite compaction routine
Diffstat (limited to 'log_db/src/common.rs')
-rw-r--r--log_db/src/common.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/log_db/src/common.rs b/log_db/src/common.rs
index ce1a30f..cbb36a8 100644
--- a/log_db/src/common.rs
+++ b/log_db/src/common.rs
@@ -122,6 +122,30 @@ pub struct MetadataHeader {
pub uuid: Uuid,
}
+const METADATA_HEADER_PADDING: &[u8] = &[0; 7];
+impl MetadataHeader {
+ pub fn serialize(&self) -> Vec<u8> {
+ let uuid_bytes = self.uuid.as_bytes().to_vec();
+
+ let mut header = vec![self.version];
+ header.extend(METADATA_HEADER_PADDING);
+ header.extend(uuid_bytes);
+
+ assert_eq!(header.len(), METADATA_FILE_HEADER_SIZE);
+
+ header
+ }
+
+ pub fn deserialize(bytes: &[u8]) -> Self {
+ assert_eq!(bytes.len(), METADATA_FILE_HEADER_SIZE);
+
+ let version = bytes[0];
+ let uuid = Uuid::from_slice(&bytes[8..24]).expect("Failed to deserialize Uuid");
+
+ MetadataHeader { version, uuid }
+ }
+}
+
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum WriteDurability {
/// Changes are written to an application-level write buffer without flushing to the OS write buffer or syncing to disk.