Skip to content

Instantly share code, notes, and snippets.

@ebuchman
Created July 19, 2015 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebuchman/f399fb11a41a895d0533 to your computer and use it in GitHub Desktop.
Save ebuchman/f399fb11a41a895d0533 to your computer and use it in GitHub Desktop.
Tendermint binary
package main
import (
"bytes"
"fmt"
"github.com/tendermint/tendermint/binary"
)
type MyTypeA [3]byte
type MyTypeB []byte
// Types of PubKey implementations
const (
TypeA = byte(0x01)
TypeB = byte(0x02)
)
type AType interface{}
// for binary.readReflect
var _ = binary.RegisterInterface(
struct{ AType }{},
binary.ConcreteType{MyTypeA{}, TypeA},
// add/rm this to see the difference!
binary.ConcreteType{MyTypeB{}, TypeB},
)
func main() {
var c = MyTypeA([3]byte{1, 2, 3})
var d = MyTypeB([]byte{1, 2, 3})
n, err := new(int64), new(error)
w1, w2 := new(bytes.Buffer), new(bytes.Buffer)
binary.WriteBinary(c[:], w1, n, err)
binary.WriteBinary(d, w2, n, err)
fmt.Println(w1.Bytes())
fmt.Println(w2.Bytes())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment