Skip to main content

Module decode

Module decode 

Source
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 wrongDecodeErrorKind
The payload is not a JSON object, or the JSON is malformedFormat
A required member is missing, or an array is too short/longOccurrence
A member has the wrong JSON typeType
A value is too long, out of range, or an undefined enum valueProperty
A member the schema does not define was present (strict mode)UnknownField
Cross-field rules brokenProtocol

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§

DecodeError
A decoding failure, carrying enough detail to fill an OCPP CALLERROR.
DecodeOptions
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§

DateTimeLeniency
How much to forgive in dateTime members.
DecodeErrorKind
The category of a decoding failure, which decides the OCPP error code.
NumericStrings
How to treat numbers sent as JSON strings ("42").
RepairKind
The kinds of non-conformance leniency forgives.
UnknownEnumValues
How to treat enumeration values the schema does not define.
UnknownFields
How to treat members the schema does not define.
WholeFloats
How to treat a whole number written with a fraction (20000.0) where the schema says integer and 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 every Repair the lenient options applied.
transcode
Decodes a payload and serializes the typed value straight back.