Skip to main content

Module json

Module json 

Source
Expand description

Telegrams as JSON, without allocating: Display adapters that write one object.

use mbus_kit::{json::Json, Application};

let app = Application::parse(0x78, &[0x0C, 0x13, 0x27, 0x04, 0x85, 0x02])?;
assert_eq!(
    Json::new(&app).to_string(),
    r#"{"meter":null,"ci":"78","authenticity":"none","body":"records","records":[{"name":"volume","function":"instantaneous","storage":0,"tariff":0,"subunit":0,"modifiers":[],"value":2850.427,"unit":"m3","authenticity":"none","text":"volume — 2850.427 m³"}]}"#
);

Schema (one object per telegram; fields in this order, absent ones left out):

FieldTypeMeaning
meterobject or nullmanufacturer (3 letters), id (8 digits, or 8 hex digits when not BCD), version, medium (name), medium_code
cistringthe CI field, two hex digits
access, statusnumberfrom the transport header, if it has one
rssi_dbmnumberwhen given with Json::rssi
authenticitystringnone, encrypted (decrypted, not integrity-protected) or authenticated
counternumberthe message counter the MAC or tag covers (authenticated only)
bodystringrecords, encrypted, compact, format, fragment, application_error, alarm, empty
securitystringfor encrypted: mode5, mode7, mode10, ell, mode<n>
signaturestringfor compact and format: the format signature, four hex digits
bytesstringfor application_error and alarm: the payload in hex
recordsarrayfor records: see below
manufacturer_datastringbytes after a 0F/1F DIF, in hex
manufacturer_authenticitystringwhat protects them, like a record’s authenticity

A record is name, function, storage, tariff, subunit, modifiers (strings), then value and unit: an exact decimal number literal with an ASCII unit code (m3, Wh, degC, m3/h, …) when the record is a quantity; otherwise a string (dates and times in ISO 8601, text, hex bytes) or null (no value, NaN, invalid BCD). Then encrypted (true when the record came out of decryption) and text, the record’s one-line description. A compact profile has "value":null and a profile object: direction (forward, backward, registers), elements_are (readings, increments, decrements, differences), spacing ({"every":15,"unit":"s"}, months as "mo", or "columns") and elements, exact numbers in the record’s unit (null for the “illegal” preset). A record that does not parse is {"error": "…"}, and the list ends there. Strings are escaped per RFC 8259.

Structs§

Json
One telegram as a JSON object.
JsonAddress
A meter address as the JSON object used for meter.
JsonRecord
One record as a JSON object (the elements of records in Json), with the authenticity of its own bytes (Record::authenticity).
JsonString
A string as a JSON string literal, quotes included.