event.Data & command.Payload are both empty interfaces. Both registries can be combined into a single implementation that uses interface{}es instead (single implementation can also make use of generics when they land).
New design:
package codec
type Encoding interface {
Encode(w io.Writer, name string, val interface{}) error
Decode(name string, r io.Reader) (interface{}, error)
}
// Encoder is the encoder for a specific event data or command payload.
type Encoder interface {
Encode(w io.Writer, interface{}) error
}
// Decoder is the decoder for a specific event data or command payload.
type Decoder interface {
Decode(io.Reader) (interface{}, error)
}
type Registry struct { ... } // implements Encoding
// Register the encoder & decoder for specific event data or command payload.
func (r *Registry) Register(name string, enc Encoder, dec Decoder)
// Gob registers the encoding for the event data or command payload with the given name.
// It uses the provided factory function to make the event data and encodes & decodes it using encoding/gob.
//
// This is basically the previous implementation.
func (r *Registry) Gob(name string, make func() interface{})
Currently, events & commands must be registered using a factory function:
event.Data
&command.Payload
are both empty interfaces. Both registries can be combined into a single implementation that usesinterface{}
es instead (single implementation can also make use of generics when they land).New design: