Created
July 19, 2015 17:56
-
-
Save ebuchman/f399fb11a41a895d0533 to your computer and use it in GitHub Desktop.
Tendermint binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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