rm_frame/lib.rs
1//! A lightweight binary framing protocol library.
2//!
3//! This crate provides a minimal, allocation-free framing layer
4//! designed for embedded and resource-constrained environments.
5//! It focuses on deterministic binary encoding, checksum validation,
6//! and zero-copy decoding.
7//!
8//! # Architecture Overview
9//!
10//! - **[`Validator`]**
11//! Defines CRC algorithms used to validate frames.
12//!
13//! - **[`DjiValidator`]**
14//! A concrete validator using DJI-compatible CRC8 and CRC16.
15//!
16//! - **[`Marshaler`]**
17//! Describes how a typed payload is serialized into bytes and
18//! deserialized from raw payload data.
19//!
20//! - **[`Messager`]**
21//! Implements frame packing and unpacking, combining framing,
22//! validation, and payload marshaling.
23//!
24//! - **[`RawFrame`]**
25//! A validated, zero-copy view of a decoded frame.
26//!
27//! # Typical Usage
28//!
29//! 1. Implement [`Marshaler`] for your message types
30//! 2. Create a [`Messager`] with a chosen [`Validator`]
31//! 3. Use [`pack`](Messager::pack) to encode frames
32//! 4. Use [`unpack`](Messager::unpack) to decode frames into [`RawFrame`]
33//! 5. Use [`Marshaler`] to convert [`RawFrame`] payloads to typed messages
34//!
35//! ---
36//!
37//! # Frame Layout
38//!
39//! ```text
40//! +--------+--------+--------+--------+--------+---------+--------+
41//! | SOF | LEN | SEQ | CRC8 | CMD_ID | DATA | CRC16 |
42//! +--------+--------+--------+--------+--------+---------+--------+
43//! | 1 byte | 2 byte | 1 byte | 1 byte | 2 byte | N bytes | 2 byte |
44//! +--------+--------+--------+--------+--------+---------+--------+
45//! ```
46//!
47//! # Protocol Source
48//!
49//! See RoboMaster Resources Hub for official documentation and protocol details:
50//! [RMU Communication Protocol](https://bbs.robomaster.com/wiki/20204847/811363)
51//!
52
53#![cfg_attr(not(test), no_std)]
54
55pub use crc8_dji::calculate as calc_dji8;
56pub use crc16_dji::calculate as calc_dji16;
57pub use error::{MarshalerError, PackError, UnPackError};
58pub use frame::{Messager, RawFrame};
59pub use marshaler::{ImplCommandMsg, ImplMarshal, ImplUnMarshal, Marshaler};
60pub use validator::{DjiValidator, Validator};
61
62mod crc16_dji;
63mod crc8_dji;
64mod error;
65mod frame;
66mod marshaler;
67mod validator;
68
69#[cfg(test)]
70mod tests;