Skip to main content

Module codec

Module codec 

Source
Expand description

Byte-level wire codec for log segments.

A segment is an app-supplied magic header plus a sequence of entries. Each entry is one op (encoded through the Op trait), a delta-encoded timestamp, an optional user id (server mode), and a truncated blake3 integrity check. The magic identifies the application and is supplied by the caller to Encoder::new / Decoder::new.

This module is generic over the op vocabulary E: Op: the framing here (header, timestamp deltas, UUID dictionary compression, blake3 trailer, expungement markers) knows nothing about any particular op. Each data domain implements Op for its own op type — for example the table op vocabulary in ubiquisync-tables.

Structs§

DecodedLogs
The result of decoding a whole segment, including the end state needed to append more entries to it.
Decoder
Streaming decoder for one segment: reads the header on construction, then yields entries one at a time, carrying the cross-entry state (timestamp base, UUID dictionary) that delta- and dictionary-decoding need.
Encoder
Streaming encoder for one segment: writes the header on construction, then appends entries, carrying the cross-entry state (timestamp base, UUID dictionary) that delta- and dictionary-encoding need.
EntryBufferReader
Decodes one log entry’s body — the read counterpart to EntryBufferWriter. Feeds bytes through the rolling hash and resolves dictionary-compressed UUIDs.
EntryBufferWriter
Encodes one log entry’s body: accumulates bytes while feeding a rolling blake3 hash, and deduplicates UUIDs against a dictionary shared across the segment’s entries.
OpIndexEntry
The indexable form of an op: its tag plus the key/value split of its body. See IndexableOp.
Reader
A thin BufRead wrapper that the codec reads a segment from, tracking position only enough to answer is_eof.

Enums§

CodecError
An error encoding or decoding the log wire format.
DecodedEntry
One decoded entry: a live log entry or an expunged-entry marker.

Constants§

FLAG_DEVICE
Segment mode flag: device mode — attribution is implicit from the peer directory, so entries carry no user id.
FLAG_SERVER
Segment mode flag: server mode — every entry carries an explicit user id.
TAG_EXPUNGED
Reserved entry tag marking an expunged entry: the tag followed by the 32-byte blake3 hash of the original entry, with no body, no timestamp delta, and no integrity-check suffix. Domain op vocabularies must not reuse this tag.

Traits§

IndexableOp
An Op that can also be split into an indexable (tag, key, value) triple for the SQL op-log. key is the indexable identity (such as table + primary key). value is the op’s remaining payload.
Op
An op vocabulary that can be encoded to / decoded from the log wire format.