#[repr(C, packed(1))]pub struct LogHeader {
pub timestamp: u64,
pub key_len: u16,
pub val_len: u32,
pub flags: u8,
}Expand description
Fixed-size metadata preceding each log entry.
Each entry in the database file starts with a 15-byte header containing:
timestamp(8 bytes) - Unix timestamp in microsecondskey_len(2 bytes) - Length of the key in bytesval_len(4 bytes) - Length of the serialized value in bytesflags(1 byte) - Bit flags for compression and deletion
§Binary Layout
Offset Size Field
0 8 timestamp (u64 little-endian)
8 2 key_len (u16 little-endian)
10 4 val_len (u32 little-endian)
14 1 flags (u8)§Flag Bits
- Bit 0 (
IS_DELTA): Value is delta-encoded - Bit 1 (
IS_COMPRESSED): Value is LZ4 compressed - Bit 2 (
IS_TOMBSTONE): Entry is a deletion marker
Fields§
§timestamp: u64Unix timestamp in microseconds when the entry was written.
key_len: u16Length of the key in bytes (max 65535).
val_len: u32Length of the serialized value in bytes (max ~4GB).
flags: u8Bit flags: IS_DELTA | IS_COMPRESSED | IS_TOMBSTONE.
Implementations§
Source§impl LogHeader
impl LogHeader
Sourcepub fn new(key_len: u16, val_len: u32, flags: u8) -> Self
pub fn new(key_len: u16, val_len: u32, flags: u8) -> Self
Creates a new LogHeader with the current timestamp.
§Arguments
key_len- Length of the key in bytesval_len- Length of the serialized value in bytesflags- Bit flags (seeIS_DELTA,IS_COMPRESSED,IS_TOMBSTONE)
§Examples
use synadb::{LogHeader, IS_COMPRESSED};
let header = LogHeader::new(5, 100, IS_COMPRESSED);
// Copy fields to avoid unaligned access on packed struct
let key_len = header.key_len;
let val_len = header.val_len;
let flags = header.flags;
assert_eq!(key_len, 5);
assert_eq!(val_len, 100);
assert!(flags & IS_COMPRESSED != 0);Sourcepub fn to_bytes(&self) -> [u8; 15]
pub fn to_bytes(&self) -> [u8; 15]
Serializes the header to a fixed-size byte array.
The bytes are written in little-endian format for cross-platform compatibility.
§Examples
use synadb::{LogHeader, HEADER_SIZE};
let header = LogHeader::new(5, 100, 0);
let bytes = header.to_bytes();
assert_eq!(bytes.len(), HEADER_SIZE);Sourcepub fn from_bytes(buf: &[u8; 15]) -> Self
pub fn from_bytes(buf: &[u8; 15]) -> Self
Deserializes a header from a fixed-size byte array.
§Arguments
buf- A 15-byte array containing the serialized header
§Examples
use synadb::{LogHeader, HEADER_SIZE};
let original = LogHeader::new(5, 100, 0);
let bytes = original.to_bytes();
let restored = LogHeader::from_bytes(&bytes);
// Copy fields to avoid unaligned access on packed struct
let orig_key_len = original.key_len;
let orig_val_len = original.val_len;
let rest_key_len = restored.key_len;
let rest_val_len = restored.val_len;
assert_eq!(orig_key_len, rest_key_len);
assert_eq!(orig_val_len, rest_val_len);Trait Implementations§
Source§impl<'de> Deserialize<'de> for LogHeader
impl<'de> Deserialize<'de> for LogHeader
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for LogHeader
Auto Trait Implementations§
impl Freeze for LogHeader
impl RefUnwindSafe for LogHeader
impl Send for LogHeader
impl Sync for LogHeader
impl Unpin for LogHeader
impl UnwindSafe for LogHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more