LogHeader

Struct LogHeader 

Source
#[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 microseconds
  • key_len (2 bytes) - Length of the key in bytes
  • val_len (4 bytes) - Length of the serialized value in bytes
  • flags (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

Fields§

§timestamp: u64

Unix timestamp in microseconds when the entry was written.

§key_len: u16

Length of the key in bytes (max 65535).

§val_len: u32

Length of the serialized value in bytes (max ~4GB).

§flags: u8

Implementations§

Source§

impl LogHeader

Source

pub fn new(key_len: u16, val_len: u32, flags: u8) -> Self

Creates a new LogHeader with the current timestamp.

§Arguments
§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);
Source

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);
Source

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);
Source

pub fn is_valid(&self) -> bool

Validates the header has reasonable values.

Returns true if:

  • key_len is less than 65535 bytes
  • val_len is less than 1GB

This is used during recovery to detect corrupted entries.

Trait Implementations§

Source§

impl Clone for LogHeader

Source§

fn clone(&self) -> LogHeader

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LogHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for LogHeader

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for LogHeader

Source§

fn eq(&self, other: &LogHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for LogHeader

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for LogHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,