ocpp/transport/json/codec
Shared JSON-codec helpers used by every per-version codec module.
object/required/optional give a uniform way to build a JSON object where
optional fields are omitted (rather than emitted as null) when absent,
matching how OCPP peers expect optional fields to be encoded.
Values
pub fn bounded_string(max_length: Int) -> decode.Decoder(String)
Decode a string and fail if it is longer than max_length characters.
pub fn custom_data_decoder() -> decode.Decoder(
custom_data.CustomData,
)
pub fn custom_data_to_json(
value: custom_data.CustomData,
) -> json.Json
pub fn datetime_decoder() -> decode.Decoder(timestamp.Timestamp)
Decode an RFC 3339 timestamp string, failing on anything that is not one.
pub fn datetime_to_json(value: timestamp.Timestamp) -> json.Json
pub fn int_in_range(
minimum: option.Option(Int),
maximum: option.Option(Int),
) -> decode.Decoder(Int)
Decode an integer and fail if it falls outside the inclusive bounds.
pub fn json_value_decoder() -> decode.Decoder(
json_value.JsonValue,
)
pub fn json_value_to_json(
value: json_value.JsonValue,
) -> json.Json
Encode an arbitrary JSON value (for schema-less data fields).
pub fn number_decoder() -> decode.Decoder(Float)
pub fn number_in_range(
minimum: option.Option(Float),
maximum: option.Option(Float),
) -> decode.Decoder(Float)
Decode a number (float or whole-number int) and fail if it falls outside
the inclusive bounds.
pub fn number_to_json(value: Float) -> json.Json
Schema type: number maps to Float. JSON numbers without a fractional
part decode as integers, so accept both and widen to Float.
pub fn object(
entries: List(#(String, option.Option(json.Json))),
) -> json.Json
Build a JSON object, dropping any entry whose value is None.
pub fn optional(
value: option.Option(a),
encode: fn(a) -> json.Json,
) -> option.Option(json.Json)
An optional object entry: present only when the value is Some.
pub fn required(value: json.Json) -> option.Option(json.Json)
A required object entry: always present.