pub struct HiveDocument {
pub version: u32,
pub node_id: NodeId,
pub counter: GCounter,
pub peripheral: Option<Peripheral>,
pub emergency: Option<EmergencyEvent>,
}Expand description
A HIVE document for mesh synchronization
Contains header information, a CRDT G-Counter for tracking mesh activity, optional peripheral data for events, and optional emergency event with ACK tracking.
Fields§
§version: u32Document version (incremented on each change)
node_id: NodeIdSource node ID that created/last modified this document
counter: GCounterCRDT G-Counter tracking activity across the mesh
peripheral: Option<Peripheral>Optional peripheral data (sensor info, events)
emergency: Option<EmergencyEvent>Optional active emergency event with distributed ACK tracking
Implementations§
Source§impl HiveDocument
impl HiveDocument
Sourcepub fn with_peripheral(self, peripheral: Peripheral) -> Self
pub fn with_peripheral(self, peripheral: Peripheral) -> Self
Create with an initial peripheral
Sourcepub fn with_emergency(self, emergency: EmergencyEvent) -> Self
pub fn with_emergency(self, emergency: EmergencyEvent) -> Self
Create with an initial emergency event
Sourcepub fn increment_version(&mut self)
pub fn increment_version(&mut self)
Increment the document version
Sourcepub fn increment_counter(&mut self)
pub fn increment_counter(&mut self)
Increment the counter for this node
Sourcepub fn set_event(&mut self, event_type: EventType, timestamp: u64)
pub fn set_event(&mut self, event_type: EventType, timestamp: u64)
Set an event on the peripheral
Sourcepub fn clear_event(&mut self)
pub fn clear_event(&mut self)
Clear the event from the peripheral
Sourcepub fn set_emergency(
&mut self,
source_node: u32,
timestamp: u64,
known_peers: &[u32],
)
pub fn set_emergency( &mut self, source_node: u32, timestamp: u64, known_peers: &[u32], )
Set an emergency event
Creates a new emergency event with the given source node, timestamp, and list of known peers to track for ACKs.
Sourcepub fn ack_emergency(&mut self, node_id: u32) -> bool
pub fn ack_emergency(&mut self, node_id: u32) -> bool
Record an ACK for the current emergency
Returns true if the ACK was new (state changed)
Sourcepub fn clear_emergency(&mut self)
pub fn clear_emergency(&mut self)
Clear the emergency event
Sourcepub fn get_emergency(&self) -> Option<&EmergencyEvent>
pub fn get_emergency(&self) -> Option<&EmergencyEvent>
Get the current emergency event (if any)
Sourcepub fn has_emergency(&self) -> bool
pub fn has_emergency(&self) -> bool
Check if there’s an active emergency
Sourcepub fn merge(&mut self, other: &HiveDocument) -> bool
pub fn merge(&mut self, other: &HiveDocument) -> bool
Merge with another document using CRDT semantics
Returns true if our state changed (useful for triggering re-broadcast)
Sourcepub fn current_event(&self) -> Option<EventType>
pub fn current_event(&self) -> Option<EventType>
Get the current event type (if any)
Sourcepub fn total_count(&self) -> u64
pub fn total_count(&self) -> u64
Get the total counter value
Sourcepub fn encoded_size(&self) -> usize
pub fn encoded_size(&self) -> usize
Get the encoded size of this document
Use this to check if the document fits within BLE MTU constraints.
Sourcepub fn exceeds_target_size(&self) -> bool
pub fn exceeds_target_size(&self) -> bool
Check if the document exceeds the target size for single-packet transmission
Returns true if the document is larger than TARGET_DOCUMENT_SIZE.
Sourcepub fn exceeds_max_size(&self) -> bool
pub fn exceeds_max_size(&self) -> bool
Check if the document exceeds the maximum size
Returns true if the document is larger than MAX_DOCUMENT_SIZE.
Trait Implementations§
Source§impl Clone for HiveDocument
impl Clone for HiveDocument
Source§fn clone(&self) -> HiveDocument
fn clone(&self) -> HiveDocument
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more