Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeAs ¶ added in v0.1.0
DecodeAs attempts to cast a value of type any to a specific target type T.
Returns the value and true if successful, or the zero value of T and false otherwise.
func MustRaw ¶
func MustRaw(v any) cbor.RawMessage
MustRaw serializes the given value into CBOR format and returns it as a RawMessage.
This function panics if marshaling fails. Suitable for internal use where inputs are trusted.
func WrapHandler ¶ added in v0.1.0
WrapHandler adapts a strongly-typed handler function into a generic handler that can be registered in PlugKit's message system.
It expects input in the form of an `any` value, typically representing CBOR-decoded data. If the input is not in the expected strongly-typed form, it is re-encoded to CBOR and then decoded into the expected type. This provides compatibility with inputs that were decoded generically (e.g., into map[interface{}]interface{} or map[string]any).
This pattern ensures type safety on the handler side, while remaining flexible for various decoding strategies used within the runtime.
This function performs an indirect CBOR remarshal to transform dynamically-typed data into a statically typed value. While effective and safe, the mechanism is not idiomatic Go. It is recommended for internal use in PlugKit only, to simplify handler registration. Example:
func HandlePing(p shared.Ping) (bool, error) { ... }
client.HandleMessageType("ping", WrapHandler(HandlePing))
Types ¶
This section is empty.