ocpp/transport/json/frame
OCPP-J wire framing.
On the JSON/WebSocket transport every message is a JSON array:
CALL [2, messageId, action, payload]
CALLRESULT [3, messageId, payload]
CALLERROR [4, messageId, errorCode, errorDescription, errorDetails]
CALLRESULTERROR [5, messageId, errorCode, errorDescription, errorDetails] (2.1+)
SEND [6, messageId, action, payload] (2.1+)
CallResultError and Send are OCPP 2.1 additions: version policy (a
1.6/2.0.1 peer must never emit them) belongs to the caller, not this
grammar — the decoder accepts all five on every connection. Per part 4
§4.1.3 a receiver SHALL ignore frames with an unrecognized message type,
so UnknownMessageType is best treated as ignorable, not fatal.
Decoded payloads are kept as raw Dynamic so the caller can run the
appropriate version- and action-specific payload decoder (see the per-version
dispatch modules).
Types
pub type Frame {
Call(id: String, action: String, payload: dynamic.Dynamic)
CallResult(id: String, payload: dynamic.Dynamic)
CallError(
id: String,
code: String,
description: String,
details: dynamic.Dynamic,
)
CallResultError(
id: String,
code: String,
description: String,
details: dynamic.Dynamic,
)
Send(id: String, action: String, payload: dynamic.Dynamic)
}
Constructors
-
Call(id: String, action: String, payload: dynamic.Dynamic) -
CallResult(id: String, payload: dynamic.Dynamic) -
CallError( id: String, code: String, description: String, details: dynamic.Dynamic, ) -
CallResultError( id: String, code: String, description: String, details: dynamic.Dynamic, )(2.1) Error response to a CALLRESULT the caller could not process;
idequals the id of the CALL/CALLRESULT exchange it refers to. -
Send(id: String, action: String, payload: dynamic.Dynamic)(2.1) Unconfirmed message: no response may be sent, and it is exempt from the one-CALL-in-flight rule (e.g. NotifyPeriodicEventStream).
pub type FrameError {
MalformedJson(json.DecodeError)
UnknownMessageType(Int)
}
Constructors
-
MalformedJson(json.DecodeError) -
UnknownMessageType(Int)
Values
pub fn decode(input: String) -> Result(Frame, FrameError)
Parse an OCPP-J wire frame from its JSON string.
pub fn encode_call_error(
id: String,
code: rpc.ErrorCode,
description: String,
details: json.Json,
) -> json.Json
pub fn encode_call_result_error(
id: String,
code: rpc.ErrorCode,
description: String,
details: json.Json,
) -> json.Json
(2.1) Encode a CALLRESULTERROR: reports that the CALLRESULT received for
id could not be processed.