4 "github.com/pkg/errors"
5 wire "github.com/tendermint/go-wire"
8 type binaryMapper struct {
10 impls []wire.ConcreteType
13 func newBinaryMapper(base interface{}) *binaryMapper {
19 // registerImplementation allows you to register multiple concrete types.
21 // We call wire.RegisterInterface with the entire (growing list) each time,
22 // as we do not know when the end is near.
23 func (m *binaryMapper) registerImplementation(data interface{}, kind string, b byte) {
24 m.impls = append(m.impls, wire.ConcreteType{O: data, Byte: b})
25 wire.RegisterInterface(m.base, m.impls...)
28 // ToWire is a convenience method to serialize with go-wire
29 // error is there to keep the same interface as json, but always nil
30 func ToWire(o interface{}) ([]byte, error) {
31 return wire.BinaryBytes(o), nil
34 // FromWire is a convenience method to deserialize with go-wire
35 func FromWire(d []byte, o interface{}) error {
36 return errors.WithStack(
37 wire.ReadBinaryBytes(d, o))