protocol

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package protocol defines OCPP-J versions, frame types, and payload metadata shared by the CSMS transport and version-specific message packages.

Index

Constants

View Source
const (
	MaxUniqueIDLength         = 36
	MaxActionLength           = 64
	MaxErrorCodeLength        = 64
	MaxErrorDescriptionLength = 255
)

Variables

View Source
var ErrInvalidMessage = errors.New("invalid OCPP message")

Functions

func Encode

func Encode(message Message) ([]byte, error)

func IsValidationError

func IsValidationError(err error) bool

IsValidationError reports whether err is a generated OCPP payload constraint violation.

Types

type Call

type Call struct {
	ID      string
	Action  string
	Payload json.RawMessage
}

func (Call) Type

func (m Call) Type() MessageTypeID

func (Call) UniqueID

func (m Call) UniqueID() string

type CallError

type CallError struct {
	ID          string
	Code        string
	Description string
	Details     json.RawMessage
}

func (CallError) Type

func (m CallError) Type() MessageTypeID

func (CallError) UniqueID

func (m CallError) UniqueID() string

type CallResult

type CallResult struct {
	ID      string
	Payload json.RawMessage
}

func (CallResult) Type

func (m CallResult) Type() MessageTypeID

func (CallResult) UniqueID

func (m CallResult) UniqueID() string

type Message

type Message interface {
	Type() MessageTypeID
	UniqueID() string
	// contains filtered or unexported methods
}

Message is implemented by the four OCPP-J wire frame types Call, CallResult, CallError, and Send. It is sealed because Encode cannot safely serialize arbitrary external implementations.

func Decode

func Decode(data []byte) (Message, error)

type MessageTypeID

type MessageTypeID int
const (
	CallType       MessageTypeID = 2
	CallResultType MessageTypeID = 3
	CallErrorType  MessageTypeID = 4
	SendType       MessageTypeID = 6
)

type Payload

type Payload interface {
	ActionName() string
	Version() Version
	Direction() PayloadDirection
	SchemaName() string
	Validate() error
	ValidateJSON([]byte) error
}

Payload is implemented by every generated OCPP request and confirmation. It describes the wire action and version and validates itself against the corresponding official OCPP JSON Schema.

type PayloadDirection

type PayloadDirection uint8
const (
	RequestPayload PayloadDirection = iota + 1
	ConfirmationPayload
)

type Send

type Send struct {
	ID      string
	Action  string
	Payload json.RawMessage
}

Send is an OCPP 2.1 unconfirmed message. The receiver must not return a CALLRESULT or CALLERROR.

func (Send) Type

func (m Send) Type() MessageTypeID

func (Send) UniqueID

func (m Send) UniqueID() string

type UnsupportedMessageTypeError

type UnsupportedMessageTypeError struct {
	ID   string
	Type MessageTypeID
}

func (*UnsupportedMessageTypeError) Error

func (*UnsupportedMessageTypeError) Unwrap

func (e *UnsupportedMessageTypeError) Unwrap() error

type Version

type Version string

Version is an OCPP-J WebSocket subprotocol.

const (
	OCPP16  Version = "ocpp1.6"
	OCPP201 Version = "ocpp2.0.1"
	OCPP21  Version = "ocpp2.1"
)

func ParseVersion

func ParseVersion(value string) (Version, error)

func SupportedVersions

func SupportedVersions() []Version

func (Version) Valid

func (v Version) Valid() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL