Documentation
¶
Overview ¶
Package codec provides a JSON-based codec implementation for cmd-stream-go.
Index ¶
- type Codec
- func NewClientCodec[T any](cmdTypes []reflect.Type, resultTypes []reflect.Type) (codec Codec[core.Cmd[T], core.Result])
- func NewCodec[T, V any](types1 []reflect.Type, types2 []reflect.Type) Codec[T, V]
- func NewServerCodec[T any](cmdTypes []reflect.Type, resultTypes []reflect.Type) (codec Codec[core.Result, core.Cmd[T]])
- type Serializer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
Codec represents a generic type-safe codec for encoding and decoding values. T is the type used for encoding, V is the type used for decoding.
func NewClientCodec ¶
func NewClientCodec[T any](cmdTypes []reflect.Type, resultTypes []reflect.Type) ( codec Codec[core.Cmd[T], core.Result], )
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 NewCodec ¶
NewCodec constructs a JSON Codec.
Parameters:
- types1 lists the Go types that can be encoded.
- types2 lists the Go types that can be decoded.
func NewServerCodec ¶
func NewServerCodec[T any](cmdTypes []reflect.Type, resultTypes []reflect.Type) ( codec Codec[core.Result, core.Cmd[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.
type Serializer ¶
type Serializer[T, V any] struct{}
func (Serializer[T, V]) Marshal ¶
func (s Serializer[T, V]) Marshal(t T) (bs []byte, err error)
func (Serializer[T, V]) Unmarshal ¶
func (s Serializer[T, V]) Unmarshal(bs []byte, v V) (err error)