wire

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package wire implements the NT4 protocol wire format: the JSON control messages exchanged as WebSocket text frames and the MessagePack value frames exchanged as binary frames.

It is deliberately free of any client state so that the encoding can be tested in isolation from connection handling.

Index

Constants

View Source
const (
	MethodPublish       = "publish"
	MethodUnpublish     = "unpublish"
	MethodSetProperties = "setproperties"
	MethodSubscribe     = "subscribe"
	MethodUnsubscribe   = "unsubscribe"
	MethodAnnounce      = "announce"
	MethodUnannounce    = "unannounce"
	MethodProperties    = "properties"
)

NT4 protocol methods.

View Source
const (
	DataTypeBoolean      = 0
	DataTypeDouble       = 1
	DataTypeInt          = 2
	DataTypeFloat        = 3
	DataTypeString       = 4
	DataTypeBinary       = 5
	DataTypeBooleanArray = 16
	DataTypeDoubleArray  = 17
	DataTypeIntArray     = 18
	DataTypeFloatArray   = 19
	DataTypeStringArray  = 20
)

NT4 binary type IDs.

View Source
const TimeSyncTopicID = -1

TimeSyncTopicID is the reserved topic ID used for time synchronization frames.

Variables

This section is empty.

Functions

func DecodeFrames

func DecodeFrames(data []byte) ([][]any, error)

DecodeFrames retains the original tuple ABI and returns complete frames preceding a malformed suffix. New code should use WalkFrames.

func EncodeTimeSyncRequest

func EncodeTimeSyncRequest(clientTime int64) ([]byte, error)

func EncodeValue

func EncodeValue(topicID int32, timestamp int64, typeID int, value any) ([]byte, error)

EncodeValue encodes a single validated NT4 value frame: [topicID, timestamp, typeID, value].

func NormalizeValue

func NormalizeValue(typeID int, value any) (any, error)

NormalizeValue validates an NT value for typeID and returns an owned, canonical Go representation suitable for encoding or delivery.

func WalkFrames

func WalkFrames(data []byte, visit func(Frame) error) error

WalkFrames visits complete tuples in wire order. A malformed suffix returns an error after visits for all preceding complete tuples; visit errors stop traversal immediately. Callers must bound their input WebSocket message.

Types

type Frame

type Frame struct {
	TopicID   int32
	Timestamp int64
	TypeID    int
	Value     any
}

DecodeFrames decodes and validates concatenated MessagePack frames. Frames decoded before a malformed frame are returned with the error. Frame is a validated binary NT tuple. Value is owned by the decoder.

type Message

type Message struct {
	Method string `json:"method"`
	Params any    `json:"params"`
}

Message is a text-based NT4 protocol message.

func Publish

func Publish(name string, pubUID int32, typeStr string, props map[string]any) Message

func SetProperties

func SetProperties(name string, update map[string]any) Message

func Subscribe

func Subscribe(topics []string, subUID int32, options map[string]any) Message

func Unpublish

func Unpublish(pubUID int32) Message

func Unsubscribe

func Unsubscribe(subUID int32) Message

type PublishParams

type PublishParams struct {
	Name       string         `json:"name"`
	PubUID     int32          `json:"pubuid"`
	Type       string         `json:"type"`
	Properties map[string]any `json:"properties"`
}

type SetPropertiesParams

type SetPropertiesParams struct {
	Name   string         `json:"name"`
	Update map[string]any `json:"update"`
}

type SubscribeParams

type SubscribeParams struct {
	Topics  []string       `json:"topics"`
	SubUID  int32          `json:"subuid"`
	Options map[string]any `json:"options"`
}

type UnpublishParams

type UnpublishParams struct {
	PubUID int32 `json:"pubuid"`
}

type UnsubscribeParams

type UnsubscribeParams struct {
	SubUID int32 `json:"subuid"`
}

Jump to

Keyboard shortcuts

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