pub struct Record { /* private fields */ }Expand description
A single record in the event log.
Records are the on-disk representation of events. Each record contains an offset (logical position), a record kind, compression kind, the event payload, and is serialized with a CRC32 checksum for integrity.
§Record Kinds
RecordKind::Data: Normal application dataRecordKind::Checkpoint: Periodic verification anchorRecordKind::Tombstone: Logical deletion marker
Implementations§
Source§impl Record
impl Record
Sourcepub fn new(offset: Offset, prev_hash: Option<ChainHash>, payload: Bytes) -> Self
pub fn new(offset: Offset, prev_hash: Option<ChainHash>, payload: Bytes) -> Self
Creates a new data record with the given offset and payload (uncompressed).
Sourcepub fn with_kind(
offset: Offset,
prev_hash: Option<ChainHash>,
kind: RecordKind,
payload: Bytes,
) -> Self
pub fn with_kind( offset: Offset, prev_hash: Option<ChainHash>, kind: RecordKind, payload: Bytes, ) -> Self
Creates a new record with a specific kind (uncompressed).
Sourcepub fn with_compression(
offset: Offset,
prev_hash: Option<ChainHash>,
kind: RecordKind,
compression: CompressionKind,
payload: Bytes,
) -> Self
pub fn with_compression( offset: Offset, prev_hash: Option<ChainHash>, kind: RecordKind, compression: CompressionKind, payload: Bytes, ) -> Self
Creates a new record with a specific kind and compression.
Sourcepub fn kind(&self) -> RecordKind
pub fn kind(&self) -> RecordKind
Returns the kind of this record.
Sourcepub fn compression(&self) -> CompressionKind
pub fn compression(&self) -> CompressionKind
Returns the compression kind used for the payload.
Sourcepub fn is_checkpoint(&self) -> bool
pub fn is_checkpoint(&self) -> bool
Returns true if this is a checkpoint record.
Sourcepub fn compute_hash(&self) -> ChainHash
pub fn compute_hash(&self) -> ChainHash
Computes the hash of this record for chain linking.
The hash covers the kind byte and payload to ensure the record kind is part of the tamper-evident chain. The hash is computed over the original (uncompressed) payload.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serializes the record to bytes.
Format: [offset:u64][prev_hash:32B][kind:u8][compression:u8][length:u32][payload][crc32:u32]
All integers are little-endian.
Sourcepub fn to_bytes_into(&self, buf: &mut BytesMut)
pub fn to_bytes_into(&self, buf: &mut BytesMut)
Serializes the record into an existing BytesMut buffer (zero-copy path).
Sourcepub fn from_bytes(data: &Bytes) -> Result<(Self, usize), StorageError>
pub fn from_bytes(data: &Bytes) -> Result<(Self, usize), StorageError>
Deserializes a record from bytes.
Returns the parsed record and the number of bytes consumed.
Uses zero-copy slicing for the payload via Bytes::slice.
AUDIT-2026-03 M-8: Detects torn writes via RECORD_END sentinel check.
§Errors
StorageError::UnexpectedEofif the data is truncatedStorageError::CorruptedRecordif the CRC doesn’t matchStorageError::TornWriteif RECORD_START or RECORD_END sentinel is missingStorageError::InvalidRecordKindif the kind byte is invalidStorageError::InvalidCompressionKindif the compression byte is invalid