dbc_rs/
lib.rs

1//! # dbc-rs
2//!
3//! A `no_std` compatible Rust library for parsing and working with DBC (CAN database) files.
4//!
5//! ## Features
6//!
7//! - **`no_std` compatible**: Works in embedded environments without the standard library
8//! - **Minimal dependencies**: Only `heapless` when using `heapless` feature (zero dependencies with `alloc`/`std`)
9//! - **Memory efficient**: Uses `Vec` (via `alloc`) for dynamic collections
10//! - **Type-safe**: Strong typing for all DBC elements
11//!
12//! ## Usage
13//!
14//! ```rust,no_run
15//! use dbc_rs::Dbc;
16//!
17//! let dbc_content = r#"VERSION "1.0"
18//!
19//! BU_: ECM TCM
20//!
21//! BO_ 256 EngineData : 8 ECM
22//!  SG_ RPM : 0|16@0+ (0.25,0) [0|8000] "rpm" TCM
23//! "#;
24//!
25//! let dbc = Dbc::parse(dbc_content)?;
26//! # Ok::<(), dbc_rs::Error>(())
27//! ```
28
29#![cfg_attr(not(feature = "std"), no_std)]
30#![deny(unused_must_use)]
31#![forbid(unsafe_code)]
32
33#[cfg(feature = "std")]
34extern crate std;
35
36#[cfg(all(feature = "alloc", not(feature = "heapless")))]
37extern crate alloc;
38
39#[cfg(feature = "attributes")]
40mod attribute;
41mod bit_timing;
42mod byte_order;
43mod compat;
44mod dbc;
45mod error;
46mod extended_multiplexing;
47mod message;
48mod nodes;
49mod parser;
50mod receivers;
51mod signal;
52mod value_descriptions;
53mod version;
54
55// Builder infrastructure
56// Note: Macros are available in all configurations since they're compile-time only
57// and have no runtime dependencies. Builders themselves are std-only.
58mod macros;
59
60// High-performance wrapper (std-only)
61#[cfg(feature = "std")]
62mod fast_dbc;
63
64#[cfg(feature = "attributes")]
65pub use attribute::{
66    AttributeDefinition, AttributeObjectType, AttributeTarget, AttributeValue, AttributeValueType,
67};
68pub use bit_timing::BitTiming;
69pub use byte_order::ByteOrder;
70pub use dbc::{Dbc, DecodedSignal};
71pub use error::{Error, Result};
72pub use extended_multiplexing::ExtendedMultiplexing;
73pub use message::{Message, Signals};
74pub use nodes::{Node, Nodes};
75pub use receivers::Receivers;
76pub use signal::Signal;
77pub use value_descriptions::ValueDescriptions;
78pub use version::Version;
79
80/// Builders
81#[cfg(all(feature = "std", feature = "attributes"))]
82pub use attribute::AttributeDefinitionBuilder;
83#[cfg(feature = "std")]
84pub use bit_timing::BitTimingBuilder;
85#[cfg(feature = "std")]
86pub use dbc::DbcBuilder;
87#[cfg(feature = "std")]
88pub use extended_multiplexing::ExtendedMultiplexingBuilder;
89#[cfg(feature = "std")]
90pub use message::MessageBuilder;
91#[cfg(feature = "std")]
92pub use nodes::NodesBuilder;
93#[cfg(feature = "std")]
94pub use receivers::ReceiversBuilder;
95#[cfg(feature = "std")]
96pub use signal::SignalBuilder;
97#[cfg(feature = "std")]
98pub use value_descriptions::ValueDescriptionsBuilder;
99#[cfg(feature = "std")]
100pub use version::VersionBuilder;
101
102// High-performance wrapper
103#[cfg(feature = "std")]
104pub use fast_dbc::FastDbc;
105
106pub(crate) use parser::Parser;
107
108/// The version of this crate as specified in `Cargo.toml`.
109///
110/// This constant is only available when the `std` feature is enabled.
111#[cfg(feature = "std")]
112pub const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
113
114/// The DBC file format specification document.
115///
116/// This is the complete specification in Markdown format, useful for
117/// documentation and reference purposes.
118///
119/// This constant is only available when the `std` feature is enabled.
120#[cfg(feature = "std")]
121pub const SPECIFICATION: &str = include_str!("../SPECIFICATIONS.md");
122
123// Maximum limits for two-pass parsing (no alloc)
124// Note: All MAX_* constants are now defined in limits.rs (generated by build.rs)
125// and can be overridden at build time via environment variables:
126// - DBC_MAX_MESSAGES (default: 8192, must be power of 2 for heapless)
127// - DBC_MAX_SIGNALS_PER_MESSAGE (default: 64)
128// - DBC_MAX_NODES (default: 256)
129// - DBC_MAX_VALUE_DESCRIPTIONS (default: 64)
130// - DBC_MAX_NAME_SIZE (default: 32, per DBC specification)
131include!(concat!(env!("OUT_DIR"), "/limits.rs"));
132
133// DBC file format keywords
134pub(crate) const VERSION: &str = "VERSION";
135pub(crate) const CM_: &str = "CM_";
136pub(crate) const NS_: &str = "NS_";
137pub(crate) const BS_: &str = "BS_";
138pub(crate) const BU_: &str = "BU_";
139pub(crate) const BO_: &str = "BO_";
140pub(crate) const SG_: &str = "SG_";
141pub(crate) const VAL_TABLE_: &str = "VAL_TABLE_";
142pub(crate) const BA_DEF_: &str = "BA_DEF_";
143pub(crate) const BA_DEF_DEF_: &str = "BA_DEF_DEF_";
144pub(crate) const BA_: &str = "BA_";
145pub(crate) const VAL_: &str = "VAL_";
146pub(crate) const SIG_GROUP_: &str = "SIG_GROUP_";
147pub(crate) const SIG_VALTYPE_: &str = "SIG_VALTYPE_";
148pub(crate) const EV_: &str = "EV_";
149pub(crate) const BO_TX_BU_: &str = "BO_TX_BU_";
150
151// Additional keywords used in code
152pub(crate) const VECTOR_XXX: &str = "Vector__XXX";
153pub(crate) const SG_MUL_VAL_: &str = "SG_MUL_VAL_";