Skip to main content

Module registry

Module registry 

Source
Expand description

Extensible Document Registry for app-layer CRDT types.

This module enables external crates to register custom document types that sync through peat-btle’s delta mechanism.

§Overview

The registry uses marker bytes in the 0xC0-0xCF range for app-layer types. Each registered type must implement the DocumentType trait, providing encode/decode/merge methods.

§Example

use peat_btle::registry::{DocumentType, DocumentRegistry, AppOperation};

#[derive(Clone)]
struct MyMessage {
    source_node: u32,
    timestamp: u64,
    content: String,
}

impl DocumentType for MyMessage {
    const TYPE_ID: u8 = 0xC0;
    const TYPE_NAME: &'static str = "MyMessage";

    fn identity(&self) -> (u32, u64) {
        (self.source_node, self.timestamp)
    }

    fn encode(&self) -> Vec<u8> {
        // ... encoding logic
        vec![]
    }

    fn decode(data: &[u8]) -> Option<Self> {
        // ... decoding logic
        None
    }

    fn merge(&mut self, other: &Self) -> bool {
        // ... CRDT merge logic
        false
    }
}

// Register and use
let registry = DocumentRegistry::new();
registry.register::<MyMessage>();

Structs§

AppOperation
App-layer delta operation.
DocumentRegistry
Registry for document type handlers.

Constants§

APP_OP_BASE
Base operation type for app-layer delta operations. Operations are encoded as 0x10 + (type_id - 0xC0), giving range 0x10-0x1F.
APP_TYPE_MAX
Maximum marker byte for app-layer document types.
APP_TYPE_MIN
Minimum marker byte for app-layer document types.

Traits§

DocumentType
A registered document type that can be synced through the mesh.

Functions§

decode_header
Decode header and extract type_id and payload.
decode_typed
Decode a typed document directly (when the type is known at compile time).
encode_with_header
Encode a document with its type header.