peat_lite/lib.rs
1// Copyright (c) 2025-2026 Defense Unicorns, Inc.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! # peat-lite
17//!
18//! Lightweight CRDT primitives for resource-constrained Peat nodes.
19//!
20//! This crate provides bounded, `no_std`-compatible data structures suitable
21//! for devices with limited memory (256KB RAM budget), such as:
22//!
23//! - WearTAK on Samsung watches
24//! - ESP32 sensor nodes
25//! - LoRa mesh devices
26//!
27//! ## Features
28//!
29//! - **`std`** (default): Enables standard library support
30//! - **`android`**: Enables UniFFI bindings for Android/Kotlin
31//! - Disable default features for `no_std`: `--no-default-features`
32//!
33//! ## Primitives
34//!
35//! | Type | Purpose | Memory |
36//! |------|---------|--------|
37//! | [`NodeId`] | 32-bit node identifier | 4 bytes |
38//! | [`CannedMessage`] | Predefined message codes | 1 byte |
39//! | [`CannedMessageEvent`] | Message with metadata | ~24 bytes |
40//! | [`LwwRegister`] | Last-writer-wins register | sizeof(T) + 12 bytes |
41//! | [`GCounter`] | Grow-only distributed counter | 4 bytes per node |
42//!
43//! ## Example
44//!
45//! ```rust
46//! use peat_lite::{NodeId, CannedMessage, CannedMessageEvent};
47//!
48//! let my_node = NodeId::new(0x12345678);
49//! let event = CannedMessageEvent::new(
50//! CannedMessage::Ack,
51//! my_node,
52//! Some(NodeId::new(0xDEADBEEF)), // target
53//! 1706234567000, // timestamp ms
54//! );
55//!
56//! // Encode for transmission
57//! let bytes = event.encode();
58//! assert_eq!(bytes[0], 0xAF); // CannedMessage marker
59//! ```
60
61#![cfg_attr(not(feature = "std"), no_std)]
62
63pub mod canned;
64pub mod counter;
65pub mod lww;
66pub mod node_id;
67pub mod protocol;
68pub mod wire;
69
70// Re-export main types at crate root
71pub use canned::{
72 CannedMessage, CannedMessageAckEvent, CannedMessageEvent, CannedMessageStore, MAX_CANNED_ACKS,
73};
74pub use counter::GCounter;
75pub use lww::LwwRegister;
76pub use node_id::NodeId;
77pub use wire::{
78 WireError, CANNED_ACK_EVENT_MAX_SIZE, CANNED_MESSAGE_MARKER, CANNED_MESSAGE_SIGNED_SIZE,
79 CANNED_MESSAGE_UNSIGNED_SIZE, SIGNATURE_SIZE,
80};
81
82// Re-export protocol types at crate root for ergonomic access
83pub use protocol::constants::*;
84pub use protocol::ota;
85pub use protocol::{
86 append_ttl, decode_header, default_ttl_for_crdt, encode_header, strip_ttl, CrdtType, Header,
87 MessageError, MessageType, NodeCapabilities,
88};