Skip to main content

Module encoding

Module encoding 

Source
Expand description

Batch frame codec (v2 wire format) and reusable encoder buffer.

┌──────────────────────────────────────────────────┐
│ Magic        4 bytes   "EWAL"                    │
│ Version      2 bytes   (2)                       │
│ Flags        2 bytes   (bit 0 = compressed)      │
│ RecordCount  4 bytes                             │
│ FirstLSN     8 bytes                             │
│ BatchSize    4 bytes   (total frame incl. CRC)   │
├──────────────────────────────────────────────────┤
│ Records region (possibly compressed):            │
│   PayloadLen  4B │ MetaLen 2B │ Meta │ Payload   │
├──────────────────────────────────────────────────┤
│ CRC32C       4 bytes                             │
└──────────────────────────────────────────────────┘

Structs§

BorrowedEvent
Borrowed event referencing data in a memory-mapped region. Zero-copy: payload and meta are sub-slices of the mmap’d buffer. Callers must copy if data must outlive the mmap lifetime.

Functions§

decode_all_batches
Decodes all sequential batch frames from data, stopping at the first invalid or truncated frame. Returns (events, last_valid_offset, error).
decode_batch_frame
Decodes one batch frame from data at byte offset off.
decode_batch_frame_borrowed
Zero-copy batch frame decoder. Returns borrowed events referencing the input data slice directly. No heap allocation when uncompressed.
decode_batch_header
Decode only the header of a batch frame, returning (count, first_lsn, total_size). Validates magic, version, bounds AND CRC. Used by recovery.
encode_batch_frame
Encodes a complete batch frame into dst, returning the number of bytes written. dst must be large enough to hold the frame (use [batch_frame_size] to pre-compute).
scan_batch_header
Fast header-only scan: validates magic, version, and bounds but skips CRC. Used for forward scanning where integrity was already verified, or where speed is more important than detecting corruption (e.g. index building).