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.

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").
UnknownEnumValues
How to treat enumeration values the schema does not define.
UnknownFields
How to treat members the schema does not define.

Functions§

decode_payload
Decodes and validates one payload according to options.
transcode
Decodes a payload and serializes the typed value straight back.