Module delta_document

Module delta_document 

Source
Expand description

Delta Document wire format for bandwidth-efficient sync

This module implements the v2 document format that supports delta sync - sending only changed operations instead of full state snapshots.

§Wire Format

Delta documents are identified by the DELTA_DOCUMENT_MARKER (0xB2):

[1 byte:  marker (0xB2)]
[1 byte:  flags]
  - bit 0: has_vector_clock
  - bit 1: is_response (sync response vs broadcast)
  - bits 2-7: reserved
[4 bytes: origin_node (LE)]
[8 bytes: timestamp_ms (LE)]
[variable: vector_clock (if flag set)]
  - [2 bytes: entry_count]
  - [entry_count × (4 bytes node_id + 8 bytes clock)]
[2 bytes: operation_count (LE)]
[operations...]

§Operation Format

Each operation is prefixed with a 1-byte type:

  • 0x01: IncrementCounter - counter increment
  • 0x02: UpdatePeripheral - peripheral state update
  • 0x03: SetEmergency - create emergency event
  • 0x04: AckEmergency - acknowledge emergency
  • 0x05: ClearEmergency - clear emergency

§Usage

// Check if incoming data is a delta document
if DeltaDocument::is_delta_document(&data) {
    let delta = DeltaDocument::decode(&data)?;
    for op in &delta.operations {
        apply_operation(op);
    }
}

// Build delta for a specific peer
let delta = mesh.build_delta_for_peer(&peer_id);
let data = delta.encode();

Modules§

op_type
Operation type constants

Structs§

DeltaDocument
A delta document containing only changed operations
DeltaFlags
Flags for delta document

Enums§

Operation
A CRDT operation for delta sync

Constants§

DELTA_DOCUMENT_MARKER
Marker byte for delta document format