oi4_dnp_encoding/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
2//! OI4 / DIN SPEC 91406 Digital Nameplate (DNP) encoding / decoding / validation.
3//!
4//! Features:
5//! - std (default): Enables std::error::Error integration; implies `alloc`.
6//! - alloc: Provides heap-backed APIs (e.g. `encode` -> String, `decode`).
7//! - strict: Enforces uppercase hex escapes and forbids unescaped reserved ASCII.
8//!
9//! Encoding rules summary:
10//! * Unreserved characters (ALPHA / DIGIT / '-' / '.' / '_' / '~') stay literal.
11//! * Every other ASCII byte (including the comma itself) MUST be represented as `,XX` (uppercase hex) when produced by the encoder.
12//! * Non-ASCII Unicode stays verbatim (its UTF-8 bytes are not individually re-escaped), unless future spec revisions say otherwise.
13//! * Decoder (default mode) accepts lowercase hex in escape triplets; encoder always outputs uppercase.
14//! * Strict mode tightens validation (see feature `strict`).
15//!
16//! No panics on valid usage; no unsafe in production code.
17//!
18//! ```rust
19//! use oi4_dnp_encoding::encode;
20//! # #[cfg(feature="alloc")]
21//! # {
22//! let s = "Hello World!"; // space & exclamation must be escaped
23//! let enc = encode(s);
24//! assert_eq!(enc, "Hello,20World,21");
25//! # }
26//! ```
27
28#[cfg(feature = "alloc")]
29extern crate alloc;
30
31pub mod decode;
32pub mod encode;
33mod error;
34mod hex; // internal hex helpers
35pub mod validate;
36
37#[cfg(feature = "alloc")]
38pub use crate::decode::decode;
39#[cfg(feature = "alloc")]
40pub use crate::encode::encode;
41pub use crate::encode::{encode_into, encoded_len};
42pub use crate::error::{Error, ErrorKind};
43pub use crate::validate::{validate_dnp, Rules};