Skip to main content

Module format

Module format 

Source
Expand description

Wire format for datawal records (v0.1-pre).

Each record is a self-contained framed unit:

offset  size  field
------  ----  ------------------------------------------
    0    4    magic        = b"DWAL"
    4    2    version      u16 LE = 1
    6    1    record_type  u8  (0=Raw, 1=Put, 2=Delete)
    7    1    flags        u8  reserved, must be 0
    8    8    txid         u64 LE
   16    4    key_len      u32 LE
   20    4    payload_len  u32 LE
   24    K    key          K = key_len bytes
 24+K    P    payload      P = payload_len bytes
24+K+P   4    crc32c       u32 LE = CRC32C(bytes[0 .. 24+K+P])

Total wire size: HEADER_LEN (24) + key_len + payload_len + CRC_LEN (4).

Notes:

  • CRC covers the 24-byte header AND key AND payload (everything before the CRC itself).
  • CRC algorithm is CRC32C (Castagnoli, polynomial 0x1EDC6F41), computed with the crc32c crate. There is a known-vector test in this module (see crc32c_known_vector) pinning the algorithm.
  • All multi-byte integers are little-endian.

Enums§

DecodeError
Hard errors that abort scanning regardless of position in the file.
DecodeOutcome
Outcome of attempting to decode the next record from a byte slice starting at the given offset.
RecordType
Type of a record. Encoded as a single byte in the header.

Constants§

CRC_LEN
CRC trailer length.
HEADER_LEN
Fixed-size record header (everything before key/payload/crc).
MAGIC
Magic bytes identifying a datawal record header.
MAX_KEY_LEN
Hard cap on key length. v0.1-pre rejects anything larger before allocation.
MAX_PAYLOAD_LEN
Hard cap on payload length. v0.1-pre rejects anything larger before allocation.
WIRE_VERSION
On-disk wire format version. Bumped on any incompatible header change.

Functions§

decode_next
Try to decode one record starting at buf[offset..].
encode_record
Encode a single record into a freshly-allocated Vec<u8> ready to be written to disk in one append.
record_wire_size
Total wire size of a record with the given key/payload lengths.