Expand description
The semantic validator: everything JSON Schema cannot say.
A message can satisfy the schema completely and still be wrong. An operation mode
whose fill-level bands leave a gap, an envelope outside the bounds the Resource
Manager published, an instruction naming an actuator that does not exist, a
percentile band below the one beneath it — all of these are schema-valid, and all of
them are what INVALID_CONTENT exists for: “Message contents is invalid (e.g.
contains a non-existing ID). Somewhat equivalent to BAD_REQUEST in HTTP.”
§Three layers, never collapsed
| Layer | Answered by | A failure becomes |
|---|---|---|
| Is it JSON, and does it match the schema? | crate::codec | INVALID_DATA / INVALID_MESSAGE |
| Is it internally consistent? | this module, with Context::empty | INVALID_CONTENT |
| Is it consistent with the session? | this module, with a full Context | INVALID_CONTENT |
The types accept whatever the schema accepts — a factor of 1.3 is representable —
because a proxy has to be able to carry a message it would refuse to send, and
because answering INVALID_CONTENT requires having decoded the message first.
§Severity
An Error is a requirement the standard states plainly. A
Warning is one it leaves ambiguous — and there are more of
those than anyone would like, each citing its [s2-json #n] issue or its E number
as errata. Warnings never refuse traffic: another conforming
implementation is entitled to read the same silence differently.
use s2_kit::prelude::*;
use s2_kit::validate::{Context, Validate, rules};
let message = decode(
r#"{"message_type":"FRBC.Instruction","message_id":"m1","id":"i1",
"actuator_id":"a1","operation_mode":"om1","operation_mode_factor":1.3,
"execution_time":"2019-08-24T14:15:22Z","abnormal_condition":false}"#,
)?;
let report = message.validate(&Context::empty());
assert!(report.has_errors());
assert_eq!(report.first_error().unwrap().rule, rules::FACTOR_RANGE);
// The rule identifier is what travels in the reception status we send back.
assert!(report.diagnostic_label().unwrap().starts_with("S2-NUM-004"));Re-exports§
Modules§
Structs§
- Context
- What the cross-message rules need to know.
- Report
- Everything wrong with one message.
- RuleId
- A stable rule identifier, such as
S2-FRBC-004. - Timer
State - When one timer of one actuator finishes.
- Violation
- One thing that is wrong with a message.
Enums§
- Severity
- Whether breaking a rule makes a message invalid, or merely suspect.
Traits§
- Validate
- Something that can be checked against the standard’s semantics.
Functions§
- rules_
markdown - The rule catalogue as Markdown, for the documentation site and
s2-kit rules.