Expand description
Payload decoding with spec-exact failure classification.
OCPP does not have one “bad payload” error. It has five, and answering with the wrong one
is a conformance failure that most implementations make because they collapse every
serde error into a single code. This module keeps them apart:
| What went wrong | DecodeErrorKind |
|---|---|
| The payload is not a JSON object, or the JSON is malformed | Format |
| A required member is missing, or an array is too short/long | Occurrence |
| A member has the wrong JSON type | Type |
| A value is too long, out of range, or an undefined enum value | Property |
| A member the schema does not define was present (strict mode) | UnknownField |
| Cross-field rules broken | Protocol |
DecodeOptions additionally carries the leniency knobs that make it possible to talk to
the substantial share of field devices that do not follow the schemas. Leniency is
implemented as a bounded repair loop: the strict parse runs first, and only when it
fails is the offending member — identified by path — rewritten and the parse retried. A
conforming payload therefore costs exactly one strict parse.
Structs§
- Decode
Error - A decoding failure, carrying enough detail to fill an OCPP
CALLERROR. - Decode
Options - Decoding policy. The strict default is exactly what the specification requires.
- Decoded
- A decoded payload, and what had to be forgiven to decode it.
- Repair
- One thing a lenient decode forgave, and where.
Enums§
- Date
Time Leniency - How much to forgive in
dateTimemembers. - Decode
Error Kind - The category of a decoding failure, which decides the OCPP error code.
- Numeric
Strings - How to treat numbers sent as JSON strings (
"42"). - Repair
Kind - The kinds of non-conformance leniency forgives.
- Unknown
Enum Values - How to treat enumeration values the schema does not define.
- Unknown
Fields - How to treat members the schema does not define.
- Whole
Floats - How to treat a whole number written with a fraction (
20000.0) where the schema saysintegerand the schema’s own draft does not count it as one.
Functions§
- decode_
payload - Decodes and validates one payload according to
options. - decode_
payload_ reporting decode_payload, also returning everyRepairthe lenient options applied.- from_
str - Decodes and validates one payload from JSON text, strictly: what a test, a fixture or a replayed log line needs, without a transport handler around it.
- transcode
- Decodes a payload and serializes the typed value straight back.