wire

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package wire defines the JSON envelopes exchanged on the AmpliFi control WebSocket. They mirror MethodRequest/AllJoynRequest and WSMessage in the decompiled app.

Index

Constants

View Source
const (
	IfaceAuth        = IfacePrefix + "Auth"
	IfaceFingerprint = IfacePrefix + "ClusterNode.fingerprint"
)

Interface names used internally, as sent in the "iface" field. The public set is amplifi.Iface*.

View Source
const IfacePrefix = "com.ubnt.UnifiHome."

IfacePrefix is the common prefix of the AllJoyn interface names.

Variables

View Source
var (
	// MsgpackNull is a msgpack nil, the argument the app passes to getters
	// such as GetWifiClientCount.
	MsgpackNull = []byte{0xc0}

	// MsgpackTwoNulls is a msgpack [nil, nil], the app's packArrayOfTwoNulls.
	MsgpackTwoNulls = []byte{0x92, 0xc0, 0xc0}
)

Functions

func ClusterNodeArg

func ClusterNodeArg(payload any) ([]byte, error)

ClusterNodeArg wraps a ClusterNode setter payload the way the app's packClusterNode does: [{LastUpdateTimestamp: now in µs}, payload].

func ClusterNodePayload

func ClusterNodePayload(v any) (map[string]any, error)

ClusterNodePayload extracts the payload map from a ClusterNode getter result, which is [cluster metadata, payload] (ClusterNodeArray).

func DecodeMsgpack

func DecodeMsgpack(b []byte) (any, error)

DecodeMsgpack decodes a msgpack payload into plain Go values. Maps become map[string]any whatever their key type: integer option codes become their decimal string ("1"), and binary keys (such as the 6 byte MACs keying a peer list) become a string of the raw bytes. This mirrors the app, which looks up option codes as strings, and avoids []byte keys that Go maps cannot hold.

func EncodeMsgpack

func EncodeMsgpack(v any) ([]byte, error)

EncodeMsgpack encodes v the way the app's MsgPackBase.serializeToMsgPack does, as the inverse of DecodeMsgpack: map keys that are decimal numbers are packed as integers (option codes), other keys as strings; []byte is packed as binary and integers in their most compact form.

func ToInt64

func ToInt64(v any) (int64, bool)

ToInt64 coerces the integer types msgpack decodes into. It reports false for non-integers and for uint64 values above math.MaxInt64.

Types

type Request

type Request struct {
	Type     string         `json:"type"`
	Iface    string         `json:"iface"`
	SeqID    int            `json:"seqId"`
	Method   string         `json:"method,omitempty"`
	Property string         `json:"property,omitempty"`
	Payload  map[string]any `json:"payload,omitempty"`
}

Request is the JSON envelope for a method call (Type "call") or a property access (Type "getProperty" or "setProperty").

type Response

type Response struct {
	Type    string         `json:"type"`
	Iface   string         `json:"iface"`
	SeqID   int            `json:"seqId"`
	Signal  string         `json:"signal"`
	Payload map[string]any `json:"payload"`
}

Response is the JSON envelope the router returns, either a reply to a call or an unsolicited signal.

func (Response) DecodeMsgpack

func (r Response) DecodeMsgpack() (any, error)

DecodeMsgpack decodes payload.msgpack (see DecodeMsgpack). It returns nil when the payload carries no msgpack or an empty one.

func (Response) Fault

func (r Response) Fault() (code int, msg string, ok bool)

Fault returns the router error carried in payload.error, if any.

func (Response) IsResponse

func (r Response) IsResponse() bool

IsResponse reports whether r is a reply to a call.

func (Response) IsSignal

func (r Response) IsSignal() bool

IsSignal reports whether r is an unsolicited event.

func (Response) Msgpack

func (r Response) Msgpack() (string, bool)

Msgpack returns the base64 string under payload.msgpack, if present.

func (Response) Value

func (r Response) Value() map[string]any

Value returns the decoded payload.value object, if present.

Jump to

Keyboard shortcuts

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