Skip to content

Instantly share code, notes, and snippets.

@liamsi
Last active June 3, 2018 10:44
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 liamsi/efe2c0816f686d1c631cd64dec1e3aa2 to your computer and use it in GitHub Desktop.
Save liamsi/efe2c0816f686d1c631cd64dec1e3aa2 to your computer and use it in GitHub Desktop.
// compat.proto:
//
syntax = "proto3";
package proto3tests;
message Test32 {
fixed32 foo = 1;
int32 bar = 2;
}
// test in golang:
cdc := amino.NewCodec()
// amino:
ab, err = cdc.MarshalBinaryBare(p3.Test32{Foo:42 , Bar:42})
assert.NoError(t, err, "unexpected error")
//proto3
pb, err = proto.Marshal(&p3.Test32{Foo:42, Bar: 42})
assert.NoError(t, err, "unexpected error")
// this fails and ...
assert.Equal(t, pb, ab, "encoding doesn't match")
// ... yields:
//=== RUN TestEncodeAminoDecodeProto
//--- FAIL: TestEncodeAminoDecodeProto (0.00s)
// Error Trace: proto3_compat_test.go:62
// Error: Not equal: []byte{0xd, 0x2a, 0x0, 0x0, 0x0, 0x10, 0x2a} (expected)
// != []byte{0xd, 0x0, 0x0, 0x0, 0x2a, 0x15, 0x0, 0x0, 0x0, 0x2a} (actual)
//
// Diff:
// --- Expected
// +++ Actual
// @@ -1,3 +1,3 @@
// -([]uint8) (len=7 cap=7) {
// - 00000000 0d 2a 00 00 00 10 2a |.*....*|
// +([]uint8) (len=10 cap=64) {
// + 00000000 0d 00 00 00 2a 15 00 00 00 2a |....*....*|
// }
// Messages: encoding doesn't match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment