Skip to content

Make JSON/YAML output idiomatic with structured record values - #107

Merged
maebli merged 1 commit into
mainfrom
feat/structured-record-values
Jul 23, 2026
Merged

Make JSON/YAML output idiomatic with structured record values#107
maebli merged 1 commit into
mainfrom
feat/structured-record-values

Conversation

@maebli

@maebli maebli commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Follow-up to #106, implementing the breaking cleanups it deferred. All changes are confined to the serialization layer; the parser API is untouched.

Changes

Structured record values. summary.records[].value was a table-style string like "(2850427)e-2[m³](Volume)". It is now split into structured fields derived from the processed data record header:

{
  "display": "(876543)e-3[m³](Volume)",
  "value": 876543.0,
  "exponent": -3,
  "unit": "",
  "quantity": "Volume",
  "data_information": "0,Inst,BCD 6-digit",
  "header_hex": "0B 13",
  "data_hex": "43 65 87"
}

The human-readable string is kept as display, and the table and CSV formats render from it, so their output is byte-for-byte unchanged. value, exponent, unit and quantity are omitted where they don't apply (dates, manufacturer-specific records).

Removed manufacturer_info. The top-level JSON/YAML key duplicated summary.manufacturer (code/name/website/description). Migration: read summary.manufacturer instead.

Hex strings for raw byte payloads. frame.data (wireless), data_records[].raw_bytes and manufacturer-specific record data now serialize as compact uppercase hex strings ("2F2F") instead of decimal byte arrays ([47, 47]). Implemented as serialize-only serde attributes backed by a new m_bus_core::serde_hex helper (no_std-compatible, collect_str-based), so Deserialize impls and the parser API are unchanged.

Versioning

This is a breaking change for JSON/YAML consumers: all workspace crates are bumped in lockstep from 0.1.4 to 0.2.0, and the migration is documented in CHANGELOG.md.

Verification

  • cargo test --features std,decryption — 37 passed
  • cargo test --features std — 34 passed
  • cargo build (no default features), cargo check --workspace, clippy, fmt — clean
  • Cross-format agreement test extended to assert the structured record fields match the normalized summary; new tests cover structured values, manufacturer_info removal, and hex payload serialization
  • Verified end-to-end via the CLI: JSON/YAML show the new shape; table and CSV output unchanged

Note: cargo check -p m-bus-application-layer --features serde (without std) fails, but this is pre-existing on main and unrelated.

- Replace the table-style string in summary.records[].value with
  structured fields (value, exponent, unit, quantity) derived from the
  processed data record header; keep the human-readable string as
  'display' so table and CSV output stay unchanged.
- Remove the deprecated top-level manufacturer_info key from JSON/YAML;
  summary.manufacturer carries the same information.
- Serialize raw byte payloads (wireless frame data, record raw_bytes,
  manufacturer-specific data) as compact uppercase hex strings via
  serialize-only serde changes.
- Bump workspace versions to 0.2.0 and document the migration in the
  changelog.
@maebli
maebli merged commit 7e865e7 into main Jul 23, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant