Documentation
¶
Overview ¶
Package msg defines the canonical message envelope that flows through queues, software-facing wire formats, and CEL filters.
Index ¶
Constants ¶
const ( MaxWireEnvelopeBytes = 256 << 10 MaxPayloadBytes = 128 << 10 MaxRawPayloadBytes = 1785 MaxPhysicalFields = 256 MaxMissingFields = 256 MaxMetadataTextBytes = 1024 )
Remote Envelope limits are deliberately generous relative to NMEA 2000's 1,785-byte ISO-TP payload maximum. They bound memory before untrusted software-facing sources can reach CEL, diagnostics, or retained storage.
Variables ¶
This section is empty.
Functions ¶
func ValidateRemote ¶ added in v1.2.6
ValidateRemote rejects an Envelope whose decoded shape exceeds the appliance-safe ingress budget. encodedBytes must be the original MQTT, WebSocket, or SSE JSON document size when known.
Types ¶
type DecodeInfo ¶
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 ¶
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
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 ¶
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 ¶
SizeBytes approximates the stored size for buffer byte-limit accounting. Envelopes are immutable after publication, so the result can be shared by every connector and statistics consumer that sees the envelope.
func (*Envelope) UnmarshalJSON ¶ added in v1.1.0
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.
func (*Envelope) WireBytes ¶ added in v1.2.6
WireBytes returns the canonical consumer JSON for the Envelope. An Envelope is immutable after publication, so the encoding is computed once and shared by statistics, every matching connector route, and every downstream Adapter. Callers must treat the returned bytes as read-only.
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.