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
- func DecodeFrames(data []byte) ([][]any, error)
- func EncodeTimeSyncRequest(clientTime int64) ([]byte, error)
- func EncodeValue(topicID int32, timestamp int64, typeID int, value any) ([]byte, error)
- func NormalizeValue(typeID int, value any) (any, error)
- func WalkFrames(data []byte, visit func(Frame) error) error
- type Frame
- type Message
- func Publish(name string, pubUID int32, typeStr string, props map[string]any) Message
- func SetProperties(name string, update map[string]any) Message
- func Subscribe(topics []string, subUID int32, options map[string]any) Message
- func Unpublish(pubUID int32) Message
- func Unsubscribe(subUID int32) Message
- type PublishParams
- type SetPropertiesParams
- type SubscribeParams
- type UnpublishParams
- type UnsubscribeParams
Constants ¶
const ( MethodPublish = "publish" MethodUnpublish = "unpublish" MethodSetProperties = "setproperties" MethodSubscribe = "subscribe" MethodUnsubscribe = "unsubscribe" MethodAnnounce = "announce" MethodUnannounce = "unannounce" MethodProperties = "properties" )
NT4 protocol methods.
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.
const TimeSyncTopicID = -1
TimeSyncTopicID is the reserved topic ID used for time synchronization frames.
Variables ¶
This section is empty.
Functions ¶
func DecodeFrames ¶
DecodeFrames retains the original tuple ABI and returns complete frames preceding a malformed suffix. New code should use WalkFrames.
func EncodeTimeSyncRequest ¶
func EncodeValue ¶
EncodeValue encodes a single validated NT4 value frame: [topicID, timestamp, typeID, value].
func NormalizeValue ¶
NormalizeValue validates an NT value for typeID and returns an owned, canonical Go representation suitable for encoding or delivery.
func WalkFrames ¶
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 ¶
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 PublishParams ¶
type SetPropertiesParams ¶
type SubscribeParams ¶
type UnpublishParams ¶
type UnpublishParams struct {
PubUID int32 `json:"pubuid"`
}
type UnsubscribeParams ¶
type UnsubscribeParams struct {
SubUID int32 `json:"subuid"`
}