msg

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package msg defines the canonical message envelope that flows through queues, software-facing wire formats, and CEL filters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecodeInfo

type DecodeInfo struct {
	Status   string   `json:"status"`
	Complete bool     `json:"complete"`
	Fallback bool     `json:"fallback,omitempty"`
	Missing  []string `json:"missing,omitempty"`
}

type Envelope

type Envelope struct {
	Seq              int64                               `json:"id,omitempty"`
	ConnectorID      string                              `json:"connector,omitempty"`
	PGN              uint32                              `json:"pgn"`
	Source           uint8                               `json:"source"`
	Dest             uint8                               `json:"dest"`
	Priority         uint8                               `json:"priority"`
	Timestamp        time.Time                           `json:"timestamp"`
	ObservedAt       time.Time                           `json:"observed_at"`
	Ingress          string                              `json:"ingress,omitempty"`
	OriginIngress    string                              `json:"origin_ingress,omitempty"`
	DeviceName       *uint64                             `json:"device_name,omitempty"`
	DeviceNameHex    string                              `json:"device_name_hex,omitempty"`
	PGNName          string                              `json:"pgn_name,omitempty"`
	Variant          string                              `json:"variant,omitempty"`
	Transport        string                              `json:"transport,omitempty"`
	ManufacturerCode *uint16                             `json:"manufacturer_code,omitempty"`
	Decode           DecodeInfo                          `json:"decode"`
	Physical         map[string]n2kcatalog.PhysicalField `json:"physical,omitempty"`
	Payload          json.RawMessage                     `json:"payload"`
	Raw              []byte                              `json:"raw,omitempty"`
	// contains filtered or unexported fields
}

func FromPGN

func FromPGN(m pgn.Message) (*Envelope, error)

FromPGN converts a decoded n2k message into an Envelope. Payload is the complete native JSON representation of the n2k Go struct, including every exported MessageInfo field. Known PGNs get Raw set to the canonical re-encoding; UnknownPGN keeps its original bytes.

func (*Envelope) Info

func (e *Envelope) Info() pgn.MessageInfo

Info rebuilds the MessageInfo for encoding this envelope back onto a CAN bus.

func (*Envelope) MarshalJSON added in v1.1.0

func (e *Envelope) MarshalJSON() ([]byte, error)

MarshalJSON emits the consumer contract shared by MQTT, SSE, WebSocket, TCP, NDJSON files, and persisted route buffers. Only payload and metadata plus the raw CAN bytes exist at the top level. Payload is the verbatim JSON representation of the native n2k struct.

func (*Envelope) PayloadMap

func (e *Envelope) PayloadMap() map[string]any

PayloadMap returns the payload as a map for CEL evaluation, decoded once and cached. Callers must treat the returned map as read-only — it is shared across all subscribers of this envelope.

func (*Envelope) SizeBytes

func (e *Envelope) SizeBytes() int

SizeBytes approximates the stored size for buffer byte-limit accounting.

func (*Envelope) UnmarshalJSON added in v1.1.0

func (e *Envelope) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts the same three-key consumer contract. CAN identity is restored from payload.info, so an upstream Beacon can ingest the document without duplicating N2K fields into Beacon metadata.

type Metadata added in v1.1.0

type Metadata struct {
	Seq              int64                               `json:"id,omitempty"`
	ConnectorID      string                              `json:"connector,omitempty"`
	ObservedAt       time.Time                           `json:"observed_at"`
	Ingress          string                              `json:"ingress,omitempty"`
	OriginIngress    string                              `json:"origin_ingress,omitempty"`
	DeviceName       *uint64                             `json:"device_name,omitempty"`
	DeviceNameHex    string                              `json:"device_name_hex,omitempty"`
	PGNName          string                              `json:"pgn_name,omitempty"`
	Variant          string                              `json:"variant,omitempty"`
	Transport        string                              `json:"transport,omitempty"`
	ManufacturerCode *uint16                             `json:"manufacturer_code,omitempty"`
	Decode           DecodeInfo                          `json:"decode"`
	Physical         map[string]n2kcatalog.PhysicalField `json:"physical,omitempty"`
}

Metadata holds everything Beacon adds to an N2K message. The native n2k struct and raw CAN bytes are separate siblings.

Jump to

Keyboard shortcuts

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