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§
- Borrowed
Event - 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
dataat byte offsetoff. - decode_
batch_ frame_ borrowed - Zero-copy batch frame decoder. Returns borrowed events referencing the
input
dataslice 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.dstmust 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).