OSDN Git Service

Hulk did something
[bytom/vapor.git] / vendor / github.com / tendermint / go-wire / data / binary.go
diff --git a/vendor/github.com/tendermint/go-wire/data/binary.go b/vendor/github.com/tendermint/go-wire/data/binary.go
new file mode 100644 (file)
index 0000000..1e221a4
--- /dev/null
@@ -0,0 +1,38 @@
+package data
+
+import (
+       "github.com/pkg/errors"
+       wire "github.com/tendermint/go-wire"
+)
+
+type binaryMapper struct {
+       base  interface{}
+       impls []wire.ConcreteType
+}
+
+func newBinaryMapper(base interface{}) *binaryMapper {
+       return &binaryMapper{
+               base: base,
+       }
+}
+
+// registerImplementation allows you to register multiple concrete types.
+//
+// We call wire.RegisterInterface with the entire (growing list) each time,
+// as we do not know when the end is near.
+func (m *binaryMapper) registerImplementation(data interface{}, kind string, b byte) {
+       m.impls = append(m.impls, wire.ConcreteType{O: data, Byte: b})
+       wire.RegisterInterface(m.base, m.impls...)
+}
+
+// ToWire is a convenience method to serialize with go-wire
+// error is there to keep the same interface as json, but always nil
+func ToWire(o interface{}) ([]byte, error) {
+       return wire.BinaryBytes(o), nil
+}
+
+// FromWire is a convenience method to deserialize with go-wire
+func FromWire(d []byte, o interface{}) error {
+       return errors.WithStack(
+               wire.ReadBinaryBytes(d, o))
+}