Skip to main content

bacnet_encoding/
lib.rs

1//! BACnet ASN.1/BER encoding and APDU/NPDU codecs per ASHRAE 135-2020.
2//!
3//! This crate provides the wire-format encoding and decoding for BACnet:
4//! - ASN.1 tag encode/decode (Clause 20.2.1)
5//! - Application-tagged primitive codecs (Clause 20.2)
6//! - APDU encode/decode (Clause 20.1)
7//! - NPDU encode/decode (Clause 6)
8//!
9//! # Features
10//!
11//! The codecs need an allocator, and one of these features to say so:
12//!
13//! - `std` (default): hosted builds. Also logs, through `tracing`, an NPDU
14//!   whose reserved control bits are set.
15//! - `alloc`: `no_std` with a global allocator, for bare-metal targets:
16//!   `default-features = false, features = ["alloc"]`. `bytes` must build for
17//!   the target; on one without atomic compare-and-swap, such as ARMv6-M,
18//!   that means its `extra-platforms` feature and a `portable-atomic` backend
19//!   the firmware picks.
20//!
21//! A build with neither fails; that combination is reserved for a future
22//! allocation-free subset.
23
24// Tests always build with std, so feature-off test runs need no imports of
25// their own.
26#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
27
28#[cfg(not(any(feature = "std", feature = "alloc")))]
29compile_error!("bacnet-encoding needs the `std` or the `alloc` feature");
30
31// `format!` and `vec!` without std's prelude.
32#[macro_use]
33extern crate alloc;
34
35pub mod apdu;
36pub mod constructed;
37pub mod npdu;
38pub mod primitives;
39pub mod segmentation;
40pub mod tags;
41
42#[cfg(test)]
43mod tags_canonical_tests;