-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_codec.go
More file actions
30 lines (24 loc) · 993 Bytes
/
client_codec.go
File metadata and controls
30 lines (24 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package codec
import (
"reflect"
"github.com/cmd-stream/cmd-stream-go/core"
)
// ClientCodec defines a JSON codec for the client side.
type ClientCodec[T any] = 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 NewClientCodec[T any](cmdTypes []reflect.Type, resultTypes []reflect.Type,
opts ...SetOption,
) (c ClientCodec[T]) {
return newCodec[core.Cmd[T], core.Result](cmdTypes, resultTypes, opts...)
}
// NewClientCodecWith creates a JSON codec for the client side using the
// provided Registry.
func NewClientCodecWith[T any](registry *Registry[T], opts ...SetOption) ClientCodec[T] {
return NewClientCodec[T](registry.Cmds(), registry.Results(), opts...)
}