HiveDocument

Struct HiveDocument 

Source
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: u32

Document version (incremented on each change)

§node_id: NodeId

Source node ID that created/last modified this document

§counter: GCounter

CRDT 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

Source

pub fn new(node_id: NodeId) -> Self

Create a new document for the given node

Source

pub fn with_peripheral(self, peripheral: Peripheral) -> Self

Create with an initial peripheral

Source

pub fn with_emergency(self, emergency: EmergencyEvent) -> Self

Create with an initial emergency event

Source

pub fn increment_version(&mut self)

Increment the document version

Source

pub fn increment_counter(&mut self)

Increment the counter for this node

Source

pub fn set_event(&mut self, event_type: EventType, timestamp: u64)

Set an event on the peripheral

Source

pub fn clear_event(&mut self)

Clear the event from the peripheral

Source

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.

Source

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)

Source

pub fn clear_emergency(&mut self)

Clear the emergency event

Source

pub fn get_emergency(&self) -> Option<&EmergencyEvent>

Get the current emergency event (if any)

Source

pub fn has_emergency(&self) -> bool

Check if there’s an active emergency

Source

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)

Source

pub fn current_event(&self) -> Option<EventType>

Get the current event type (if any)

Source

pub fn encode(&self) -> Vec<u8>

Encode to bytes for BLE transmission

Source

pub fn decode(data: &[u8]) -> Option<Self>

Decode from bytes received over BLE

Source

pub fn total_count(&self) -> u64

Get the total counter value

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> HiveDocument

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HiveDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HiveDocument

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.