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.
- Document
Registry - 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§
- Document
Type - 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.