codec-protobuf-go provides a Protobuf-based codec for cmd-stream-go.
It maps concrete Command and Result types to internal identifiers, allowing type-safe serialization across network boundaries.
Important: This Protobuf codec expects all Command and Result types
to implement proto.Message. If a type does not implement proto.Message,
the codec will panic at runtime.
import (
"reflect"
codec "github.com/cmd-stream/codec-protobuf-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 = codec.NewServerCodec(cmdTypes, resultTypes)
clientCodec = codec.NewClientCodec(cmdTypes, resultTypes)
)