Documentation
¶
Overview ¶
Package codec provides a JSON-based codec implementation for cmd-stream.
Index ¶
Constants ¶
const ErrorPrefix = "codecjson: "
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClientCodec ¶
ClientCodec defines a JSON codec for the client side.
func NewClientCodec ¶
func NewClientCodec[T any](cmdTypes []reflect.Type, resultTypes []reflect.Type, opts ...SetOption, ) (c ClientCodec[T])
NewClientCodec creates a JSON codec for the client side.
The cmdTypes slice lists Command types the client can send. The resultTypes slice lists Result types the client expects to receive.
Note: The order of types matters — two codecs created with the same types in a different order are not considered equal.
func NewClientCodecWith ¶
func NewClientCodecWith[T any](registry *Registry[T], opts ...SetOption) ClientCodec[T]
NewClientCodecWith creates a JSON codec for the client side using the provided Registry.
type Registry ¶
Registry is a collection of Command and Result types.
The order of registration matters — two registries created with the same types in a different order will produce codecs that are not compatible.
func NewRegistry ¶
NewRegistry creates a new Registry with the provided options.
type Serializer ¶
type Serializer[T, V any] struct{}
Serializer implements the gnrc.Serializer interface using JSON.
func (Serializer[T, V]) Marshal ¶
func (s Serializer[T, V]) Marshal(t T) (bs []byte, err error)
Marshal encodes the given value of type T into a JSON byte slice.
func (Serializer[T, V]) Unmarshal ¶
func (s Serializer[T, V]) Unmarshal(bs []byte, v V) (err error)
Unmarshal decodes the JSON byte slice into the given value of type V.
type ServerCodec ¶
ServerCodec defines a JSON codec for the server side.
func NewServerCodec ¶
func NewServerCodec[T any](cmdTypes []reflect.Type, resultTypes []reflect.Type, opts ...SetOption, ) (c ServerCodec[T])
NewServerCodec creates a JSON codec for the server side.
The cmdTypes slice lists Command types the server can handle. The resultTypes slice lists Result types that can be returned to the client.
Note: The order of types matters — two codecs created with the same types in a different order are not considered equal.
func NewServerCodecWith ¶
func NewServerCodecWith[T any](registry *Registry[T], opts ...SetOption) ServerCodec[T]
NewServerCodecWith creates a JSON codec for the server side using the provided Registry.