oi4-dnp-encoding
Rust Implementation of OI4 / DIN SPEC 91406 Digital Nameplate (DNP) encoding, decoding and validation.
Features
- Zero runtime dependencies
no_stdsupport (with optionalalloc)- Strict mode (feature
strict) enforcing uppercase hex and prohibiting unescaped reserved ASCII - High performance branch-lean encoder/decoder
- Safe Rust only; no panics on valid usage
Encoding Summary
Unreserved characters: A–Z a–z 0–9 - . _ ~ stay literal. All other ASCII bytes (including comma) are escaped as ,XX (uppercase hex). Non-ASCII Unicode is passed through verbatim.
Examples:
Space (0x20) -> ,20
Comma (0x2C) -> ,2C
# -> ,23
/ -> ,2F
Basic Usage (std / alloc)
use ;
let original = "Hello World!";
let enc = encode;
assert_eq!;
let dec = decode.unwrap;
assert_eq!;
Examples
Alle Beispiele liegen im Verzeichnis examples/ und werden nicht in die Library kompiliert (kein Größen-Overhead für Nutzer).
Schnellstart:
# Einfaches Encode/Decode/Validate
# Validierung & Fehlerbehandlung
# Strict Mode Verhalten (Großbuchstaben-Hex + Pflicht Maskierung)
# Heap-freies Encoding (demonstriert no_std Pfad)
# oder wirklich ohne std:
Validation
use ;
let s = "Hello,20World,21"; // already encoded
validate_dnp.unwrap;
Enable strict feature:
Differential Test (Go Reference)
Set environment variable GO_DNP_REPO to a local clone of the Go reference repo (OI4/dnp-encoder-go) and run:
Or standalone script:
GO_DNP_REPO=/path/to/go/repo
Fallback: Wenn GO_DNP_REPO nicht gesetzt ist, klont tools/compare_go.sh automatisch den Branch development aus
https://github.com/OI4/dnp-encoder-go.git
(shallow clone, depth=1) in ein temporäres Verzeichnis und räumt danach auf. Voraussetzungen für den Fallback: git und go im PATH.
Golden File Generation
|
Fuzzing
Requires nightly and libFuzzer (cargo-fuzz style not strictly necessary here). Example using libfuzzer-sys directly:
Current discrete fuzz targets (manual): fuzz/fuzz_targets/decode.rs, validate.rs.
Coverage
no_std
- Without
std, errors do not implementstd::error::Error. - Without
alloc, onlyencode_into,encoded_len, andvalidate_dnpare available.
MSRV
Minimum Supported Rust Version: 1.74 (pinned via rust-toolchain.toml).
License
MIT
Status
Early implementation; align with authoritative PDF specification. Any deviations vs. Go reference will be documented in DESIGN.md.