codec-json provides a JSON-based codec for cmd-stream.
It maps concrete Command and Result types to internal identifiers, allowing type-safe serialization across network boundaries.
import (
"reflect"
cdcjson "github.com/cmd-stream/codec-json-go"
)
var (
// Note: The order of types matters — two codecs created with the same types
// in a different order are not considered equal.
cmdTypes = []reflect.Type{
reflect.TypeFor[YourCmd](),
// ...
}
resultTypes = []reflect.Type{
reflect.TypeFor[YourResult](),
// ...
}
serverCodec = cdcjson.NewServerCodec(cmdTypes, resultTypes)
clientCodec = cdcjson.NewClientCodec(cmdTypes, resultTypes)
)See the calc_json
example for a full demonstration of codec-json.
To run fuzz tests:
./fuzz.sh 1m