pub struct ObisCode<'a> { /* private fields */ }Expand description
An OBIS code from RI, keeping its original spelling.
Borrows the record’s own bytes in the ordinary case. It holds a
Cow rather than a &str for one reason: RI is a
JSON string like any other, so "1-b:1.8.\u0030" is a lawful spelling of
"1-b:1.8.0" — and a decoded escape is longer than what it denotes, so it
can never be a subslice of the source. Refusing such a record would throw
away an intact signed payload over a spelling.
Implementations§
Source§impl<'a> ObisCode<'a>
impl<'a> ObisCode<'a>
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
The code exactly as the station wrote it — decoded, when the source spelled a character as an escape.
Sourcepub fn processing(&self) -> &str
pub fn processing(&self) -> &str
The D group (processing).
Sourcepub fn billing_period(&self) -> Option<&str>
pub fn billing_period(&self) -> Option<&str>
The F group (billing period), when written.
Sourcepub fn is_register(&self) -> bool
pub fn is_register(&self) -> bool
Whether D marks this as a time-integral register (8) — the reading
a bill is computed from, as opposed to an instantaneous value.
Sourcepub fn canonical(&self) -> String
pub fn canonical(&self) -> String
The canonical [OCMF Tab. 25] spelling: two-digit upper-case groups,
* before the billing period.
Two codes are the same register exactly when their canonical forms are
equal, which is the comparison by_register uses.
Sourcepub fn is_canonical(&self) -> bool
pub fn is_canonical(&self) -> bool
Whether the code is already written in the [OCMF Tab. 25] form:
AA-BB:CC.DD.EE with two upper-case digits per group, and * before
the billing period when there is one.
Answered without building the canonical string, because this runs once per reading and the answer is “no” for every OBIS code in the reference corpus.
Sourcepub fn parse(raw: &'a str) -> Option<Self>
pub fn parse(raw: &'a str) -> Option<Self>
Parses a plain string. None when the text has no OBIS shape at all.
Sourcepub fn parse_cow(raw: Cow<'a, str>) -> Option<Self>
pub fn parse_cow(raw: Cow<'a, str>) -> Option<Self>
Parses text that may have had to be decoded from a JSON escape.
RI is a JSON string like any other, so "1-b:1.8.\u0030" is a lawful
spelling of "1-b:1.8.0" — and a decoded escape is longer than what
it denotes, so the result can never be a subslice of the record. That is
why this type holds a Cow: borrowed in every real case, owned when
it has to be. Refusing such a record instead would throw away an intact
signed payload over a spelling.