Documentation
¶
Overview ¶
Package ocppj implements OCPP-J (JSON over WebSocket) framing.
Index ¶
- Variables
- func EncodeCall(msgID, action string, payload []byte) ([]byte, error)
- func EncodeCallError(msgID, code, desc string, details []byte) ([]byte, error)
- func EncodeCallResult(msgID string, payload []byte) ([]byte, error)
- func EncodeCallResultError(msgID, code, desc string, details []byte) ([]byte, error)
- func EncodeSend(msgID, action string, payload []byte) ([]byte, error)
- func EncodeSignedCall(msgID, action string, signedPayload []byte) ([]byte, error)
- func EncodeSignedSend(msgID, action string, signedPayload []byte) ([]byte, error)
- func NewMsgID() string
- type CallError
- type Direction
- type ErrorCode
- type Frame
- type Message
- type MessageType
- type ProtocolError
- type SendMessage
- type Version
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnClosed = errors.New("ocpp: connection closed") ErrConnDropped = errors.New("ocpp: connection dropped") ErrNotConnected = errors.New("ocpp: not connected") ErrAlreadyConnected = errors.New("ocpp: already connected") ErrCallTimeout = errors.New("ocpp: call timeout") ErrCallCancelled = errors.New("ocpp: call cancelled") ErrQueueFull = errors.New("ocpp: outbound queue full") ErrConcurrentCallLimit = errors.New("ocpp: concurrent call limit exceeded") ErrUnknownAction = errors.New("ocpp: unknown action") ErrHandlerNotRegistered = errors.New("ocpp: handler not registered") ErrInvalidDirection = errors.New("ocpp: invalid message direction") ErrDuplicateHandler = errors.New("ocpp: handler already registered") ErrUnsupportedVersion = errors.New("ocpp: unsupported version") ErrVersionMismatch = errors.New("ocpp: version mismatch on connection") // ErrIgnoredMessageType is returned by Parse for a well-formed frame whose // MessageTypeId is not one this implementation handles. Per OCPP 2.1 Part 4 // §4.4 the payload is ignored; the reader drops it without warning. ErrIgnoredMessageType = errors.New("ocpp: ignored message type") )
Functions ¶
func EncodeCall ¶
EncodeCall builds a [2, msgID, action, payload] frame.
func EncodeCallError ¶
EncodeCallError builds a [4, msgID, code, desc, details] frame.
func EncodeCallResult ¶
EncodeCallResult builds a [3, msgID, payload] frame.
func EncodeCallResultError ¶ added in v0.1.7
EncodeCallResultError builds a [5, msgID, code, desc, details] frame (OCPP 2.1 CALLRESULTERROR).
func EncodeSend ¶ added in v0.1.7
EncodeSend builds a [6, msgID, action, payload] frame (OCPP 2.1 SEND).
func EncodeSignedCall ¶ added in v0.1.7
EncodeSignedCall builds a [2, msgID, action+"-Signed", signedPayload] frame (OCPP 2.1 Part 4 Ch 7). signedPayload is a Flattened JWS JSON object.
func EncodeSignedSend ¶ added in v0.1.7
EncodeSignedSend builds a [6, msgID, action+"-Signed", signedPayload] frame.
Types ¶
type CallError ¶
type CallError struct {
Code ErrorCode
Description string
Details map[string]any
// IsResultError marks a CallError that arrived as a CALLRESULTERROR (type 5)
// rather than a CALLERROR (type 4). Wire content is identical; this is for
// observability only.
IsResultError bool
// contains filtered or unexported fields
}
CallError is an OCPP-J error response (MessageType 4).
func NewCallError ¶
NewCallError builds a CallError.
func WrapCallError ¶
WrapCallError builds a CallError wrapping an underlying cause.
type ErrorCode ¶
type ErrorCode string
ErrorCode is an OCPP-J CallError code.
const ( ErrorCodeNotImplemented ErrorCode = "NotImplemented" ErrorCodeNotSupported ErrorCode = "NotSupported" ErrorCodeInternalError ErrorCode = "InternalError" ErrorCodeProtocolError ErrorCode = "ProtocolError" ErrorCodeSecurityError ErrorCode = "SecurityError" ErrorCodeFormatViolation ErrorCode = "FormatViolation" // 2.x ErrorCodeFormationViolation ErrorCode = "FormationViolation" // 1.6 ErrorCodePropertyConstraintViolation ErrorCode = "PropertyConstraintViolation" ErrorCodeOccurenceConstraintViolation ErrorCode = "OccurenceConstraintViolation" //nolint:misspell // OCPP 1.6 spec wire spelling ErrorCodeOccurrenceConstraintViolation ErrorCode = "OccurrenceConstraintViolation" // 2.x ErrorCodeTypeConstraintViolation ErrorCode = "TypeConstraintViolation" ErrorCodeGenericError ErrorCode = "GenericError" ErrorCodeMessageTypeNotSupported ErrorCode = "MessageTypeNotSupported" // 2.x ErrorCodeRPCFrameworkError ErrorCode = "RpcFrameworkError" // 2.x )
type Frame ¶
type Frame struct {
Type MessageType
Signed bool // OCPP 2.1: action carried a "-Signed" suffix; Payload is a JWS object
MsgID string
Action string // Call / Send
Payload []byte // Call / CallResult / Send: raw JSON object
ErrCode string // CallError / CallResultError
ErrDesc string // CallError / CallResultError
ErrData []byte // CallError / CallResultError: raw JSON object
}
Frame is a parsed OCPP-J message.
type Message ¶
Message binds an OCPP action to its request and response types at compile time. Generated code creates package-level Message values; user code passes them to On/Call so Req/Resp are inferred.
type MessageType ¶
type MessageType int
MessageType is the OCPP-J MessageTypeId (first array element).
const ( Call MessageType = 2 CallResult MessageType = 3 MessageTypeCallError MessageType = 4 MessageTypeCallResultError MessageType = 5 // OCPP 2.1 Send MessageType = 6 // OCPP 2.1 )
func (MessageType) String ¶
func (m MessageType) String() string
type ProtocolError ¶
ProtocolError indicates an OCPP-J frame that does not conform to the wire format.
func (*ProtocolError) Error ¶
func (e *ProtocolError) Error() string
type SendMessage ¶ added in v0.1.7
SendMessage binds an OCPP 2.1 SEND action to its request type at compile time. SEND messages are unconfirmed and have no response type. Generated code creates package-level SendMessage values; user code passes them to Send/OnSend.