Documentation
¶
Overview ¶
Package rpc holds the helpers the area packages (device, wifi, clients, ...) share on top of amplifi.Client's public Call and CallJSON: typed result decoding, read-modify-write setters, and access to the integer-keyed option maps the Device and ClusterNode interfaces use.
Index ¶
- Constants
- Variables
- func Addr(v any) netip.Addr
- func Addrs(v any) []netip.Addr
- func Bool(m map[string]any, key string) bool
- func Bytes(m map[string]any, key string) []byte
- func ClusterMap(ctx context.Context, c Caller, method string) (map[string]any, error)
- func Code(kind string, names map[string]string, name string) (int64, error)
- func CodeName(names map[string]string, code int64) string
- func CompareNumeric(a, b string) int
- func Decode(method string, v, out any) error
- func ExpectOK(method string, v any) error
- func Flat(m map[string]any) map[string]any
- func Int(m map[string]any, key string) int64
- func JSON(ctx context.Context, c Caller, iface, method string, arg, out any) error
- func JSONString(v any) any
- func KeyName(names map[string]string, key string) string
- func MAC(v any) amplifi.MAC
- func Map(ctx context.Context, c Caller, iface, method string, arg any) (map[string]any, error)
- func Mask(s string) string
- func MaskFields(m map[string]any, codes ...string) map[string]any
- func Name(names map[string]string, m map[string]any, key string) string
- func PackAddr(a netip.Addr) ([]byte, error)
- func PackMAC(m amplifi.MAC) ([]byte, error)
- func PackPrefix(p netip.Prefix) ([]byte, error)
- func Prefix(v any) netip.Prefix
- func Prefixes(v any) []netip.Prefix
- func Put[T any](m map[string]any, code string, v *T)
- func PutInt[T ~int](m map[string]any, code string, v *T)
- func Role(code int64) amplifi.Role
- func Set(ctx context.Context, c Caller, iface, method string, payload any) error
- func SetCluster(ctx context.Context, c Caller, method string, payload any) error
- func String(m map[string]any, key string) string
- func Submaps(v any) iter.Seq2[string, map[string]any]
- func Update(ctx context.Context, c Caller, iface, getMethod string, getArg any, ...) error
- func UpdateCluster(ctx context.Context, c Caller, getMethod, setMethod string, ...) error
- func UpdateEntry(ctx context.Context, c Caller, iface, getMethod string, getArg any, ...) error
- func Value(ctx context.Context, c Caller, iface, method string, arg, out any) error
- type Caller
Constants ¶
const Redacted = "********"
Redacted replaces secrets in redacted output.
Variables ¶
var ( // BandNames maps WifiBand codes. BandNames = map[string]string{"1": "2.4GHz", "2": "5GHz"} // NetworkNames maps WifiInterfaceRole codes. 7 (friend) is not in the // app's enum but routers report it. NetworkNames = map[string]string{ "1": "setup", "2": "internal", "3": "main", "4": "guest", "5": "device", "6": "relay", "7": "friend", "8": "iot", } // ClientNetworks are the networks that carry clients; the others are // mesh backhaul and setup networks. ClientNetworks = map[string]bool{"3": true, "4": true, "5": true, "7": true, "8": true} )
Code tables shared by several areas. Option maps and enums use integer codes, keyed here by their decimal string as in decoded option maps.
var ( Null = amplifi.RawMsgpack(wire.MsgpackNull) TwoNulls = amplifi.RawMsgpack(wire.MsgpackTwoNulls) )
Null and TwoNulls are the msgpack nil and [nil, nil] arguments many getters expect, ready to pass to Call.
Functions ¶
func Addr ¶
Addr decodes a packed address: 4 or 16 bytes, or 5 or 17 bytes with a trailing prefix length, which is dropped. Anything else gives the zero Addr.
func Addrs ¶
Addrs decodes a list of packed addresses, skipping invalid ones. A single binary value is accepted as a list of one.
func ClusterMap ¶
ClusterMap calls a ClusterNode getter, which takes a msgpack nil and answers [metadata, payload], and returns the payload.
func Code ¶
Code returns the integer code for name in names, ignoring case. "#N" is accepted for codes without a name. kind names the enum in the error.
func CodeName ¶
CodeName returns the name for an integer code in names, or "#code" when it is not known.
func CompareNumeric ¶
CompareNumeric orders strings numerically when both are integers, numbers before other strings, and other strings lexically. It suits option codes, IDs and port names.
func Decode ¶
Decode converts a decoded result into out by way of JSON. A string holding JSON is parsed first, as some methods answer with one.
func ExpectOK ¶
ExpectOK checks a setter's result: a msgpack boolean that must be true. A nil result is accepted, as some setters return nothing.
func Flat ¶
Flat drops nested maps from an option map, which the app's serializer never sends back (MsgPackBase.serializeToMsgPack only packs scalars, binary and lists).
func JSON ¶
JSON calls a method with a JSON argument (payload.value) and decodes the result into out. A nil out discards the result.
func JSONString ¶
JSONString returns v parsed as JSON if it is a string holding JSON, and v unchanged otherwise.
func KeyName ¶
KeyName is CodeName for a code that is already a decimal string, such as an option map key.
func MAC ¶
MAC converts a binary MAC, as a []byte value or a raw-byte map key, to a MAC. Anything that is not 6 bytes yields nil.
func MaskFields ¶
MaskFields returns a copy of m with the non-empty strings under codes replaced by Redacted. A nil m gives an empty map.
func PackAddr ¶
PackAddr packs an IPv4 address as 4 bytes. The zero Addr packs as empty binary, which clears the option.
func PackMAC ¶
PackMAC packs a MAC as 6 byte binary. An empty MAC packs as empty binary, which clears a MAC override.
func PackPrefix ¶
PackPrefix packs an IPv4 address and prefix length as 5 bytes: the address followed by the length. The zero Prefix packs as empty binary.
func Prefix ¶
Prefix decodes a packed address with a prefix length: 5 or 17 bytes, the address followed by the length. A bare 4 or 16 byte address gets a full-length prefix. Anything else gives the zero Prefix.
func PutInt ¶
PutInt is Put for integer types, stored as int64. Named types need this because the msgpack encoder writes a type with a MarshalText method, such as wifi.Encryption, as text.
func Set ¶
Set calls a setter with a msgpack payload (an option map, or a list for the Add*/Delete* methods) and checks its boolean result.
func SetCluster ¶
SetCluster calls a ClusterNode setter, wrapping payload as [{timestamp}, payload].
func Submaps ¶
Submaps yields the entries of v, a map, whose values are maps. Anything else in v, or a v that is not a map, is skipped.
func Update ¶
func Update(ctx context.Context, c Caller, iface, getMethod string, getArg any, setMethod string, changes map[string]any) error
Update does a read-modify-write of an option map: it reads the map with getMethod and getArg, applies changes (option code -> value) and writes the whole map back with setMethod.
func UpdateCluster ¶
func UpdateCluster(ctx context.Context, c Caller, getMethod, setMethod string, changes map[string]any) error
UpdateCluster is Update for a ClusterNode option map.
func UpdateEntry ¶
func UpdateEntry(ctx context.Context, c Caller, iface, getMethod string, getArg any, setMethod, key string, changes map[string]any) error
UpdateEntry does a read-modify-write of a map of option maps keyed by name, such as radios or interfaces: it applies changes to the entry under key and writes every entry back flattened. Empty changes do nothing.