Documentation
¶
Overview ¶
Package xmlrpc implements just enough of the XML-RPC protocol to act as a HomeMatic CCU server. It is a tightened, server-side port of the gohomematic transport package.
All public surfaces are exported as Value types plus encode/decode helpers. Higher levels (the ccu package) translate Value trees into the loosely-typed map[string]any values that mirror the Python source.
Index ¶
- Constants
- func AsBool(v Value) (bool, bool)
- func AsInt(v Value) (int, bool)
- func AsString(v Value) (string, bool)
- func EncodeCall(w io.Writer, mc *MethodCall) error
- func EncodeResponse(w io.Writer, mr *MethodResponse) error
- func IsTransport(err error) bool
- func MarshalCallBytes(mc *MethodCall) ([]byte, error)
- func MarshalResponseBytes(mr *MethodResponse) ([]byte, error)
- func Stringify(v Value) string
- func ToAny(v Value) any
- type ArrayValue
- type Base64Value
- type BoolValue
- type Client
- type DateTimeValue
- type DoubleValue
- type Fault
- type Handler
- type IntValue
- type Kind
- type Member
- type MethodCall
- type MethodHandler
- type MethodResponse
- type Mux
- type NilValue
- type StringValue
- type StructValue
- type Value
Constants ¶
const DefaultClientTimeout = 10 * time.Second
DefaultClientTimeout applies when the caller's context has no deadline.
const DefaultRequestLimit = 10 * 1024 * 1024
DefaultRequestLimit bounds the body of an incoming XML-RPC request.
const ISO8601CompactLayout = "20060102T15:04:05"
ISO8601CompactLayout is the CCU's canonical dateTime.iso8601 format.
Variables ¶
This section is empty.
Functions ¶
func AsString ¶
AsString extracts a Go string from v, accepting either StringValue or chardata that the decoder surfaced as such.
func EncodeCall ¶
func EncodeCall(w io.Writer, mc *MethodCall) error
EncodeCall writes mc to w using UTF-8 (sufficient for pydevccu clients; the original CCU emits ISO-8859-1 but accepts UTF-8 too).
func EncodeResponse ¶
func EncodeResponse(w io.Writer, mr *MethodResponse) error
EncodeResponse writes mr to w. If Fault is set, Params is ignored.
func IsTransport ¶
IsTransport returns true when err looks like a recoverable network problem rather than a CCU-level fault.
func MarshalCallBytes ¶
func MarshalCallBytes(mc *MethodCall) ([]byte, error)
MarshalCallBytes is a convenience around EncodeCall.
func MarshalResponseBytes ¶
func MarshalResponseBytes(mr *MethodResponse) ([]byte, error)
MarshalResponseBytes is a convenience around EncodeResponse.
Types ¶
type ArrayValue ¶
type ArrayValue []Value
ArrayValue maps to <array><data>…</data></array>.
func (ArrayValue) Kind ¶
func (ArrayValue) Kind() Kind
func (ArrayValue) MarshalXML ¶
func (a ArrayValue) MarshalXML(e *xml.Encoder, _ xml.StartElement) error
type Base64Value ¶
type Base64Value []byte
Base64Value maps to <base64>.
func (Base64Value) Kind ¶
func (Base64Value) Kind() Kind
func (Base64Value) MarshalXML ¶
func (v Base64Value) MarshalXML(e *xml.Encoder, _ xml.StartElement) error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a tiny XML-RPC client used by the simulator to push events back to registered callback endpoints (newDevices, deleteDevices, event, …). It is not exported through the public API.
type DateTimeValue ¶
DateTimeValue maps to <dateTime.iso8601>.
func (DateTimeValue) Kind ¶
func (DateTimeValue) Kind() Kind
func (DateTimeValue) MarshalXML ¶
func (v DateTimeValue) MarshalXML(e *xml.Encoder, _ xml.StartElement) error
func (DateTimeValue) Time ¶
func (v DateTimeValue) Time() time.Time
Time returns the wrapped Go time.
type DoubleValue ¶
type DoubleValue float64
DoubleValue maps to <double>.
func (DoubleValue) Kind ¶
func (DoubleValue) Kind() Kind
func (DoubleValue) MarshalXML ¶
func (v DoubleValue) MarshalXML(e *xml.Encoder, _ xml.StartElement) error
type Fault ¶
Fault is the data carried by an XML-RPC <fault> response. It also implements error so handlers can return it directly.
type Handler ¶
type Handler struct {
Mux *Mux
Logger *slog.Logger
// RequestLimit bounds the body in bytes. Zero means
// [DefaultRequestLimit].
RequestLimit int64
}
Handler is the http.Handler exposing a Mux over HTTP.
type Kind ¶
type Kind int
Kind identifies the concrete XML-RPC value carried by Value.
type MethodCall ¶
MethodCall is a deserialised <methodCall>.
func DecodeCall ¶
func DecodeCall(r io.Reader) (*MethodCall, error)
DecodeCall reads a <methodCall> from r.
type MethodHandler ¶
MethodHandler processes one XML-RPC method invocation.
type MethodResponse ¶
MethodResponse is a deserialised <methodResponse>. Exactly one of Params / Fault is populated.
func DecodeResponse ¶
func DecodeResponse(r io.Reader) (*MethodResponse, error)
DecodeResponse reads a <methodResponse> from r.
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux routes XML-RPC method names to handlers. Safe for concurrent use.
func (*Mux) Handle ¶
func (m *Mux) Handle(method string, fn MethodHandler)
Handle registers fn for method, replacing any prior registration.
func (*Mux) HandleFallback ¶
func (m *Mux) HandleFallback(fn MethodHandler)
HandleFallback registers a catch-all handler.
func (*Mux) RegisterSystemMethods ¶
func (m *Mux) RegisterSystemMethods()
RegisterSystemMethods wires system.listMethods, system.methodHelp and system.multicall, matching what HomeMatic clients expect.
type NilValue ¶
type NilValue struct{}
NilValue serialises as <value><nil/></value>.
func (NilValue) MarshalXML ¶
type StringValue ¶
type StringValue string
StringValue maps to <string>.
func (StringValue) Kind ¶
func (StringValue) Kind() Kind
func (StringValue) MarshalXML ¶
func (v StringValue) MarshalXML(e *xml.Encoder, _ xml.StartElement) error
type StructValue ¶
type StructValue struct {
Members []Member
}
StructValue is an ordered list of named members.
func (StructValue) Get ¶
func (s StructValue) Get(name string) (Value, bool)
Get returns the named member or (nil, false) if absent.
func (StructValue) Kind ¶
func (StructValue) Kind() Kind
func (StructValue) MarshalXML ¶
func (s StructValue) MarshalXML(e *xml.Encoder, _ xml.StartElement) error
type Value ¶
Value is the sum type covering every XML-RPC value. Implementations serialise themselves including the wrapping <value>…</value>.
func DecodeValue ¶
DecodeValue reads a single <value>…</value> from d.
CCU clients emit two equivalent string forms; both are accepted:
- <value><string>abc</string></value>
- <value>abc</value>
func FromAny ¶
FromAny converts an arbitrary Go value (typically the result of json.Unmarshal into any) to its XML-RPC equivalent. Nil yields NilValue. Numeric types collapse to IntValue or DoubleValue; maps become StructValue sorted by key (deterministic output); slices become ArrayValue.