codec-json

May 6, 2026 ยท View on GitHub

Go Reference GoReportCard codecov

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.

How To

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)
)

Example

See the calc_json example for a full demonstration of codec-json.

Fuzz Testing

To run fuzz tests:

./fuzz.sh 1m