Skip to main content

Module frame

Module frame 

Source
Expand description

WAL frame encode / decode helpers.

Byte layout is documented in docs/format.md § Write-ahead log. This module is the single place that knows it; the parent super::Wal only calls into the helpers exposed here.

Structs§

FrameHeader
In-memory representation of a WAL frame header.

Enums§

FrameDecode
Classified outcome of decoding a single WAL frame. Pass-2 of recovery distinguishes “torn tail / stale generation” (silently discarded) from “CRC mismatch in a frame that should have been valid” (which surfaces as Error::WalCorruption). See docs/format.md § Recovery semantics.

Constants§

FRAME_AEAD_SUFFIX_SIZE
Phase 4 (issue #9): per-frame AEAD suffix length for encrypted WALs (24-byte XChaCha20-Poly1305 nonce + 16-byte Poly1305 tag = 40 bytes). Frames in encrypted WALs are FRAME_SIZE + FRAME_AEAD_SUFFIX_SIZE = 4200 bytes on disk; the extra bytes sit AFTER the ciphertext body.
FRAME_HEADER_SIZE
Fixed size of a per-frame header (preceding the page body).
FRAME_SIZE
Per-frame size on disk for a plaintext WAL: header + page body. Equal to 4160 bytes.
FRAME_SIZE_ENCRYPTED
Phase 4 (issue #9): per-frame size on disk for an encrypted WAL.
WAL_HEADER_SIZE
Fixed size of the WAL file header. See docs/format.md § Write- ahead log → WAL header.
WAL_MAGIC
File magic for the WAL header. ASCII OBJW.

Functions§

decode_frame_header
Decode and validate a frame from buf. Returns None if the CRC does not validate, if the salt does not match expected_salt, or if reserved bytes are non-zero.
decode_frame_header_classified
Classify a single frame buffer. The buffer length must equal FRAME_SIZE; otherwise FrameDecode::Malformed is returned.
encode_frame_header
Encode header into the first FRAME_HEADER_SIZE bytes of buf AND compute the per-frame CRC32C covering the frame header (with the CRC field zeroed) plus the page body that follows.
frame_offset
Byte offset of the frame at index frame_index (0-based, where 0 is the first frame after the WAL header).
frame_size_for
Phase 4 (issue #9): pick the right per-frame size given the encrypted flag.