From ebe5c4530075f0ce3fa71f5ceb391f58beb02b9a Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 11:33:04 +0200 Subject: [PATCH 01/17] define a proto message for tests: amino should encode registered types as this protobuf message Signed-off-by: Ismail Khoffi --- tests/proto3/proto/compat.pb.go | 111 +++++++++++++++++++++++--------- tests/proto3/proto/compat.proto | 7 ++ 2 files changed, 89 insertions(+), 29 deletions(-) diff --git a/tests/proto3/proto/compat.pb.go b/tests/proto3/proto/compat.pb.go index 8c54fd07..a23d0d90 100644 --- a/tests/proto3/proto/compat.pb.go +++ b/tests/proto3/proto/compat.pb.go @@ -632,6 +632,55 @@ func (m *PrimitivesStructSl) GetStructs() []*PrimitivesStruct { return nil } +type AminoRegisteredAny struct { + // Prefix or Disfix (Prefix + Disamb) bytes + AminoPreOrDisfix []byte `protobuf:"bytes,1,opt,name=AminoPreOrDisfix,proto3" json:"AminoPreOrDisfix,omitempty"` + // Must be a valid serialized protocol buffer with the above specified amino pre-/disfix. + Value []byte `protobuf:"bytes,2,opt,name=Value,proto3" json:"Value,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *AminoRegisteredAny) Reset() { *m = AminoRegisteredAny{} } +func (m *AminoRegisteredAny) String() string { return proto.CompactTextString(m) } +func (*AminoRegisteredAny) ProtoMessage() {} +func (*AminoRegisteredAny) Descriptor() ([]byte, []int) { + return fileDescriptor_bced3ff93dcaa7f8, []int{14} +} + +func (m *AminoRegisteredAny) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_AminoRegisteredAny.Unmarshal(m, b) +} +func (m *AminoRegisteredAny) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_AminoRegisteredAny.Marshal(b, m, deterministic) +} +func (m *AminoRegisteredAny) XXX_Merge(src proto.Message) { + xxx_messageInfo_AminoRegisteredAny.Merge(m, src) +} +func (m *AminoRegisteredAny) XXX_Size() int { + return xxx_messageInfo_AminoRegisteredAny.Size(m) +} +func (m *AminoRegisteredAny) XXX_DiscardUnknown() { + xxx_messageInfo_AminoRegisteredAny.DiscardUnknown(m) +} + +var xxx_messageInfo_AminoRegisteredAny proto.InternalMessageInfo + +func (m *AminoRegisteredAny) GetAminoPreOrDisfix() []byte { + if m != nil { + return m.AminoPreOrDisfix + } + return nil +} + +func (m *AminoRegisteredAny) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + func init() { proto.RegisterType((*TestInt32Varint)(nil), "proto3tests.TestInt32Varint") proto.RegisterType((*TestInt32Fixed)(nil), "proto3tests.TestInt32Fixed") @@ -647,38 +696,42 @@ func init() { proto.RegisterType((*IntArr)(nil), "proto3tests.IntArr") proto.RegisterType((*PrimitivesStruct)(nil), "proto3tests.PrimitivesStruct") proto.RegisterType((*PrimitivesStructSl)(nil), "proto3tests.PrimitivesStructSl") + proto.RegisterType((*AminoRegisteredAny)(nil), "proto3tests.AminoRegisteredAny") } func init() { proto.RegisterFile("compat.proto", fileDescriptor_bced3ff93dcaa7f8) } var fileDescriptor_bced3ff93dcaa7f8 = []byte{ - // 445 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x6f, 0x6b, 0x13, 0x41, - 0x10, 0xc6, 0x39, 0xaf, 0xb9, 0xd8, 0x49, 0x48, 0xaf, 0x8b, 0xc8, 0x11, 0x11, 0xe3, 0xbe, 0xd0, - 0x50, 0xea, 0x15, 0x92, 0x12, 0x05, 0x41, 0x50, 0xfc, 0x43, 0x40, 0xa1, 0xec, 0x1d, 0xbe, 0xbf, - 0x6b, 0x36, 0x71, 0x21, 0x7b, 0x1b, 0x76, 0xa7, 0x45, 0xbf, 0x97, 0x1f, 0x50, 0xf6, 0xcf, 0x25, - 0x4d, 0x0d, 0xf4, 0x55, 0xe6, 0xd9, 0xf9, 0xcd, 0xce,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 0x3c, 0xc6, 0x27, 0x6b, 0x03, 0x00, 0x00, + // 489 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0xef, 0x6b, 0x1a, 0x41, + 0x10, 0xe5, 0x7a, 0x89, 0x36, 0xa3, 0x98, 0xcb, 0x52, 0xca, 0x61, 0x29, 0xb5, 0xfb, 0xa1, 0x15, + 0x49, 0x2f, 0xa0, 0xc1, 0x16, 0x0a, 0x05, 0x4b, 0xda, 0x22, 0xb4, 0x54, 0xf6, 0xc4, 0xef, 0x67, + 0x1c, 0xed, 0x82, 0x7b, 0x2b, 0xbb, 0x6b, 0x48, 0xfe, 0xaf, 0xfe, 0x81, 0x65, 0x7f, 0x9c, 0xc6, + 0x24, 0xd0, 0x4f, 0xce, 0x9b, 0x79, 0x6f, 0xe6, 0xf6, 0x3d, 0xa1, 0x79, 0x2d, 0xc5, 0xa6, 0x30, + 0xd9, 0x46, 0x49, 0x23, 0x49, 0xc3, 0xfd, 0x0c, 0x0c, 0x6a, 0xa3, 0xdb, 0x6f, 0x56, 0x52, 0xae, + 0xd6, 0x78, 0xe1, 0x7a, 0xf3, 0xed, 0xf2, 0xc2, 0x70, 0x81, 0xda, 0x14, 0x62, 0xe3, 0xd9, 0xf4, + 0x3d, 0x9c, 0x4e, 0x51, 0x9b, 0x71, 0x69, 0x06, 0xfd, 0x59, 0xa1, 0x78, 0x69, 0xc8, 0x0b, 0x38, + 0x76, 0x30, 0x8d, 0x3a, 0x51, 0xf7, 0x8c, 0x79, 0x40, 0x7b, 0xd0, 0xda, 0x11, 0xbf, 0xf3, 0x5b, + 0x5c, 0x90, 0x14, 0xea, 0xae, 0x08, 0xcc, 0x3a, 0xab, 0x20, 0x3d, 0x87, 0x9a, 0xe5, 0x0e, 0xfa, + 0x24, 0x81, 0x78, 0x29, 0x65, 0x98, 0xdb, 0xd2, 0x76, 0xe6, 0x85, 0x4a, 0x9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, 0xe1, 0xa3, 0x7b, 0x87, 0x6d, 0x44, 0xfe, 0x8f, 0x95, 0x1e, 0xbb, 0x76, + 0x40, 0x2e, 0x3a, 0xa3, 0x78, 0xb9, 0x4a, 0x5b, 0x9d, 0xa8, 0x7b, 0xc2, 0x02, 0xb2, 0x5b, 0xbe, + 0xde, 0x19, 0xd4, 0xe9, 0x69, 0x27, 0xea, 0x36, 0x99, 0x07, 0x24, 0x83, 0x23, 0xeb, 0x54, 0x9a, + 0xfc, 0xd7, 0x46, 0xc7, 0xa3, 0xbf, 0x80, 0x3c, 0xfc, 0xea, 0x7c, 0x4d, 0x3e, 0x42, 0xdd, 0xd7, + 0xda, 0x3d, 0xb1, 0xd1, 0x7f, 0x7d, 0x10, 0xe6, 0x43, 0x05, 0xab, 0xd8, 0x74, 0x06, 0x64, 0x24, + 0x78, 0x29, 0x19, 0xae, 0xb8, 0x36, 0xa8, 0x70, 0x31, 0x2a, 0xef, 0x48, 0x0f, 0x12, 0xd7, 0x9d, + 0x28, 0xfc, 0xad, 0xae, 0xb8, 0x5e, 0xf2, 0x5b, 0x67, 0x6b, 0x93, 0x3d, 0xea, 0xdb, 0x67, 0xcd, + 0x8a, 0xf5, 0x16, 0x5d, 0x2a, 0x4d, 0xe6, 0xc1, 0xbc, 0xe6, 0xcf, 0xff, 0x0b, 0x00, 0x00, 0xff, + 0xff, 0xe2, 0x80, 0x7f, 0xc3, 0xc3, 0x03, 0x00, 0x00, } diff --git a/tests/proto3/proto/compat.proto b/tests/proto3/proto/compat.proto index 0b710915..46dbe0e6 100644 --- a/tests/proto3/proto/compat.proto +++ b/tests/proto3/proto/compat.proto @@ -75,4 +75,11 @@ message PrimitivesStruct { message PrimitivesStructSl { repeated PrimitivesStruct Structs = 1; +} + +message AminoRegisteredAny { + // Prefix or Disfix (Prefix + Disamb) bytes + bytes AminoPreOrDisfix = 1; + // Must be a valid serialized protocol buffer with the above specified amino pre-/disfix. + bytes Value = 2; } \ No newline at end of file From 1942a917c26ff815750b4ef4f6fedeaef3bd9454 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 11:36:36 +0200 Subject: [PATCH 02/17] delete heavily outdated and unused testfile (had _ suffix -> never called) Signed-off-by: Ismail Khoffi --- time_test.go_ | 94 --------------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 time_test.go_ diff --git a/time_test.go_ b/time_test.go_ deleted file mode 100644 index f9926bc4..00000000 --- a/time_test.go_ +++ /dev/null @@ -1,94 +0,0 @@ -package amino - -import ( - "fmt" - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -type Input struct { - Date time.Time `json:"date"` -} - -func TestJSONTimeParse(t *testing.T) { - cases := []struct { - input string - expected time.Time - encoded string - }{ - { - "2017-03-31T16:45:15Z", - time.Date(2017, 3, 31, 16, 45, 15, 0, time.UTC), - "2017-03-31T16:45:15.000Z", - }, - { - "2017-03-31T16:45:15.972Z", - time.Date(2017, 3, 31, 16, 45, 15, 972000000, time.UTC), - "2017-03-31T16:45:15.972Z", - }, - { - "2017-03-31T16:45:15.972167Z", - time.Date(2017, 3, 31, 16, 45, 15, 972167000, time.UTC), - "2017-03-31T16:45:15.972Z", - }, - } - - for _, tc := range cases { - var err error - var parsed Input - data := []byte(fmt.Sprintf(`{"date":"%s"}`, tc.input)) - ReadJSONPtr(&parsed, data, &err) - if assert.Nil(t, err, "%s: %+v", tc.input, err) { - assert.Equal(t, tc.expected, parsed.Date) - out := JSONBytes(parsed) - assert.Equal(t, fmt.Sprintf(`{"date":"%s"}`, tc.encoded), string(out)) - } - } -} - - -func TestTime(t *testing.T) { - - // panic trying to encode times before 1970 - panicCases := []time.Time{ - time.Time{}, - time.Unix(-10, 0), - time.Unix(0, -10), - } - for _, c := range panicCases { - assert.Panics(t, func() { amino.MarshalBinary(c) }, "expected MarshalBinary to panic on times before 1970") - } - - // ensure we can encode/decode a recent time - now := time.Now() - buf, err := amino.MarshalBinary(now) - - var thisTime time.Time - err = amino.UnmarshalBinary(buf, thisTime) - if !thisTime.Truncate(time.Millisecond).Equal(now.Truncate(time.Millisecond)) { - t.Fatalf("times dont match. got %v, expected %v", thisTime, now) - } - - // error trying to decode bad times - errorCases := []struct { - thisTime time.Time - err error - }{ - {time.Time{}, ErrBinaryReadInvalidTimeNegative}, - {time.Unix(-10, 0), ErrBinaryReadInvalidTimeNegative}, - {time.Unix(0, -10), ErrBinaryReadInvalidTimeNegative}, - - {time.Unix(0, 10), ErrBinaryReadInvalidTimeSubMillisecond}, - {time.Unix(1, 10), ErrBinaryReadInvalidTimeSubMillisecond}, - } - for _, c := range errorCases { - timeNano := c.thisTime.UnixNano() - buf, err := amino.EncodeInt64(timeNano) - var thisTime time.Time - err = amino.UnmarshalBinary(buf, thisTime) - assert.Equal(t, err, c.err, "expected UnmarshalBinary to throw an error") - assert.Equal(t, thisTime, time.Time{}, "expected UnmarshalBinary to return default time") - } -} From 4adb68310807f6d23b49efeeb60daf91b4b872c9 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 12:06:29 +0200 Subject: [PATCH 03/17] add first simple test-case Signed-off-by: Ismail Khoffi --- tests/proto3/proto3_compat_test.go | 42 +++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/proto3/proto3_compat_test.go b/tests/proto3/proto3_compat_test.go index 71641967..76db167e 100644 --- a/tests/proto3/proto3_compat_test.go +++ b/tests/proto3/proto3_compat_test.go @@ -334,7 +334,7 @@ func TestIntVarintCompat(t *testing.T) { assert.Error(t, err) } -// See if encoding of type def types matches the proto3 encoding +// See if encoding of def types matches the proto3 encoding func TestTypeDefCompatibility(t *testing.T) { pNow := ptypes.TimestampNow() @@ -383,3 +383,43 @@ func TestTypeDefCompatibility(t *testing.T) { assert.Equal(t, pb, ab, "Amino and protobuf encoding do not match %v", i) } } + +// See if encoding of registered types matches the proto3 encoding +func TestRegisteredTypesCompatibility(t *testing.T) { + // TODO make this table driven tests using sub-tests + type Message interface{} + + type SimpleMsg struct { + Message string + Height int + } + + type SimpleMsgUnregistered struct { + Message string + Height int + } + + var cdc = amino.NewCodec() + cdc.RegisterInterface((*Message)(nil), nil) + const name = "SimpleMsg" + cdc.RegisterConcrete(&SimpleMsg{}, name, nil) + + bm := &SimpleMsg{Message: "ABC", Height: 100} + bmUnreg := &SimpleMsgUnregistered{bm.Message, bm.Height} + + bz, err := cdc.MarshalBinaryBare(bm) + require.NoError(t, err) + + bzUnreg, err := cdc.MarshalBinaryBare(bmUnreg) + require.NoError(t, err) + + pAny := &p3.AminoRegisteredAny{} + err = proto.Unmarshal(bz, pAny) + require.NoError(t, err) + + // value matches proto encoding + assert.Equal(t, pAny.Value, bzUnreg) + _, prefix := amino.NameToDisfix(name) + assert.Equal(t, pAny.AminoPreOrDisfix, prefix) + +} From 314c84a40831aae29f9ce9e75a9c4eb508cb446c Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 12:11:03 +0200 Subject: [PATCH 04/17] simple test-case passes Signed-off-by: Ismail Khoffi --- amino.go | 20 ++++++++++---------- tests/proto3/proto3_compat_test.go | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/amino.go b/amino.go index 4d6c695b..54308136 100644 --- a/amino.go +++ b/amino.go @@ -230,21 +230,21 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { // If registered concrete, prepend prefix bytes. if info.Registered { // TODO: https://github.com/tendermint/go-amino/issues/267 - //return MarshalBinaryBare(RegisteredAny{ - // AminoPreOrDisfix: info.Prefix.Bytes(), - // Value: bz, - //}) - pb := info.Prefix.Bytes() - bz = append(pb, bz...) + return MarshalBinaryBare(RegisteredAny{ + AminoPreOrDisfix: info.Prefix.Bytes(), + Value: bz, + }) + // pb := info.Prefix.Bytes() + // bz = append(pb, bz...) } return bz, nil } -//type RegisteredAny struct { -// AminoPreOrDisfix []byte -// Value []byte -//} +type RegisteredAny struct { + AminoPreOrDisfix []byte + Value []byte +} // Panics if error. func (cdc *Codec) MustMarshalBinaryBare(o interface{}) []byte { diff --git a/tests/proto3/proto3_compat_test.go b/tests/proto3/proto3_compat_test.go index 76db167e..4aa0ed34 100644 --- a/tests/proto3/proto3_compat_test.go +++ b/tests/proto3/proto3_compat_test.go @@ -415,11 +415,11 @@ func TestRegisteredTypesCompatibility(t *testing.T) { pAny := &p3.AminoRegisteredAny{} err = proto.Unmarshal(bz, pAny) - require.NoError(t, err) + assert.NoError(t, err) // value matches proto encoding assert.Equal(t, pAny.Value, bzUnreg) - _, prefix := amino.NameToDisfix(name) - assert.Equal(t, pAny.AminoPreOrDisfix, prefix) + _, prefix := amino.NameToDisfix(name) + assert.Equal(t, pAny.AminoPreOrDisfix, prefix.Bytes()) } From f909f13a79deddeebf2abe5062a6d026d1b612e7 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 14:43:48 +0200 Subject: [PATCH 05/17] use protoc-gen-gogofaster to get rid of XXX fields and enable proto compat. tests in make file Signed-off-by: Ismail Khoffi --- Makefile | 2 +- go.mod | 1 + go.sum | 5 + tests/proto3/proto/compat.pb.go | 2557 ++++++++++++++++++++++++++-- tests/proto3/proto3_compat_test.go | 13 +- 5 files changed, 2409 insertions(+), 169 deletions(-) diff --git a/Makefile b/Makefile index 9a28db9d..7a524366 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ update_tools: ### Testing test: - go test $(shell go list ./... | grep -v vendor) + go test -tags extensive_tests $(shell go list ./... | grep -v vendor) gofuzz_binary: rm -rf tests/fuzz/binary/corpus/ diff --git a/go.mod b/go.mod index caeb9be8..a28379d8 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.12 require ( github.com/davecgh/go-spew v1.1.1 + github.com/gogo/protobuf v1.2.1 github.com/golang/protobuf v1.3.0 github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf github.com/pkg/errors v0.8.1 diff --git a/go.sum b/go.sum index dcf80a65..2af48783 100644 --- a/go.sum +++ b/go.sum @@ -2,10 +2,14 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -17,4 +21,5 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= diff --git a/tests/proto3/proto/compat.pb.go b/tests/proto3/proto/compat.pb.go index a23d0d90..1f09d5ec 100644 --- a/tests/proto3/proto/compat.pb.go +++ b/tests/proto3/proto/compat.pb.go @@ -1,12 +1,14 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. +// Code generated by protoc-gen-gogo. DO NOT EDIT. // source: compat.proto package proto3tests import ( + encoding_binary "encoding/binary" fmt "fmt" - proto "github.com/golang/protobuf/proto" - timestamp "github.com/golang/protobuf/ptypes/timestamp" + proto "github.com/gogo/protobuf/proto" + types "github.com/gogo/protobuf/types" + io "io" math "math" ) @@ -19,13 +21,10 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package type TestInt32Varint struct { - Int32 int32 `protobuf:"zigzag32,1,opt,name=Int32,proto3" json:"Int32,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Int32 int32 `protobuf:"zigzag32,1,opt,name=Int32,proto3" json:"Int32,omitempty"` } func (m *TestInt32Varint) Reset() { *m = TestInt32Varint{} } @@ -34,18 +33,26 @@ func (*TestInt32Varint) ProtoMessage() {} func (*TestInt32Varint) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{0} } - func (m *TestInt32Varint) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TestInt32Varint.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *TestInt32Varint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TestInt32Varint.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_TestInt32Varint.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *TestInt32Varint) XXX_Merge(src proto.Message) { xxx_messageInfo_TestInt32Varint.Merge(m, src) } func (m *TestInt32Varint) XXX_Size() int { - return xxx_messageInfo_TestInt32Varint.Size(m) + return m.Size() } func (m *TestInt32Varint) XXX_DiscardUnknown() { xxx_messageInfo_TestInt32Varint.DiscardUnknown(m) @@ -61,10 +68,7 @@ func (m *TestInt32Varint) GetInt32() int32 { } type TestInt32Fixed struct { - Fixed32 uint32 `protobuf:"fixed32,1,opt,name=Fixed32,proto3" json:"Fixed32,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Fixed32 uint32 `protobuf:"fixed32,1,opt,name=Fixed32,proto3" json:"Fixed32,omitempty"` } func (m *TestInt32Fixed) Reset() { *m = TestInt32Fixed{} } @@ -73,18 +77,26 @@ func (*TestInt32Fixed) ProtoMessage() {} func (*TestInt32Fixed) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{1} } - func (m *TestInt32Fixed) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TestInt32Fixed.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *TestInt32Fixed) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TestInt32Fixed.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_TestInt32Fixed.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *TestInt32Fixed) XXX_Merge(src proto.Message) { xxx_messageInfo_TestInt32Fixed.Merge(m, src) } func (m *TestInt32Fixed) XXX_Size() int { - return xxx_messageInfo_TestInt32Fixed.Size(m) + return m.Size() } func (m *TestInt32Fixed) XXX_DiscardUnknown() { xxx_messageInfo_TestInt32Fixed.DiscardUnknown(m) @@ -100,11 +112,8 @@ func (m *TestInt32Fixed) GetFixed32() uint32 { } type Test32 struct { - Foo uint32 `protobuf:"fixed32,1,opt,name=foo,proto3" json:"foo,omitempty"` - Bar int32 `protobuf:"zigzag32,2,opt,name=bar,proto3" json:"bar,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Foo uint32 `protobuf:"fixed32,1,opt,name=foo,proto3" json:"foo,omitempty"` + Bar int32 `protobuf:"zigzag32,2,opt,name=bar,proto3" json:"bar,omitempty"` } func (m *Test32) Reset() { *m = Test32{} } @@ -113,18 +122,26 @@ func (*Test32) ProtoMessage() {} func (*Test32) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{2} } - func (m *Test32) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Test32.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *Test32) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Test32.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_Test32.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *Test32) XXX_Merge(src proto.Message) { xxx_messageInfo_Test32.Merge(m, src) } func (m *Test32) XXX_Size() int { - return xxx_messageInfo_Test32.Size(m) + return m.Size() } func (m *Test32) XXX_DiscardUnknown() { xxx_messageInfo_Test32.DiscardUnknown(m) @@ -147,10 +164,7 @@ func (m *Test32) GetBar() int32 { } type TestFixedInt64 struct { - Int64 uint64 `protobuf:"fixed64,1,opt,name=Int64,proto3" json:"Int64,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Int64 uint64 `protobuf:"fixed64,1,opt,name=Int64,proto3" json:"Int64,omitempty"` } func (m *TestFixedInt64) Reset() { *m = TestFixedInt64{} } @@ -159,18 +173,26 @@ func (*TestFixedInt64) ProtoMessage() {} func (*TestFixedInt64) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{3} } - func (m *TestFixedInt64) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TestFixedInt64.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *TestFixedInt64) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TestFixedInt64.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_TestFixedInt64.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *TestFixedInt64) XXX_Merge(src proto.Message) { xxx_messageInfo_TestFixedInt64.Merge(m, src) } func (m *TestFixedInt64) XXX_Size() int { - return xxx_messageInfo_TestFixedInt64.Size(m) + return m.Size() } func (m *TestFixedInt64) XXX_DiscardUnknown() { xxx_messageInfo_TestFixedInt64.DiscardUnknown(m) @@ -186,10 +208,7 @@ func (m *TestFixedInt64) GetInt64() uint64 { } type TestSFixedSInt64 struct { - SInt64 int64 `protobuf:"fixed64,1,opt,name=SInt64,proto3" json:"SInt64,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + SInt64 int64 `protobuf:"fixed64,1,opt,name=SInt64,proto3" json:"SInt64,omitempty"` } func (m *TestSFixedSInt64) Reset() { *m = TestSFixedSInt64{} } @@ -198,18 +217,26 @@ func (*TestSFixedSInt64) ProtoMessage() {} func (*TestSFixedSInt64) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{4} } - func (m *TestSFixedSInt64) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TestSFixedSInt64.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *TestSFixedSInt64) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TestSFixedSInt64.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_TestSFixedSInt64.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *TestSFixedSInt64) XXX_Merge(src proto.Message) { xxx_messageInfo_TestSFixedSInt64.Merge(m, src) } func (m *TestSFixedSInt64) XXX_Size() int { - return xxx_messageInfo_TestSFixedSInt64.Size(m) + return m.Size() } func (m *TestSFixedSInt64) XXX_DiscardUnknown() { xxx_messageInfo_TestSFixedSInt64.DiscardUnknown(m) @@ -225,10 +252,7 @@ func (m *TestSFixedSInt64) GetSInt64() int64 { } type EmbeddedStruct struct { - SomethingFixedLen int64 `protobuf:"fixed64,1,opt,name=somethingFixedLen,proto3" json:"somethingFixedLen,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + SomethingFixedLen int64 `protobuf:"fixed64,1,opt,name=somethingFixedLen,proto3" json:"somethingFixedLen,omitempty"` } func (m *EmbeddedStruct) Reset() { *m = EmbeddedStruct{} } @@ -237,18 +261,26 @@ func (*EmbeddedStruct) ProtoMessage() {} func (*EmbeddedStruct) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{5} } - func (m *EmbeddedStruct) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_EmbeddedStruct.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *EmbeddedStruct) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_EmbeddedStruct.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_EmbeddedStruct.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *EmbeddedStruct) XXX_Merge(src proto.Message) { xxx_messageInfo_EmbeddedStruct.Merge(m, src) } func (m *EmbeddedStruct) XXX_Size() int { - return xxx_messageInfo_EmbeddedStruct.Size(m) + return m.Size() } func (m *EmbeddedStruct) XXX_DiscardUnknown() { xxx_messageInfo_EmbeddedStruct.DiscardUnknown(m) @@ -265,10 +297,7 @@ func (m *EmbeddedStruct) GetSomethingFixedLen() int64 { type SomeStruct struct { // proto3 autom. turns this into a pointer ... - Emb *EmbeddedStruct `protobuf:"bytes,1,opt,name=emb,proto3" json:"emb,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Emb *EmbeddedStruct `protobuf:"bytes,1,opt,name=emb,proto3" json:"emb,omitempty"` } func (m *SomeStruct) Reset() { *m = SomeStruct{} } @@ -277,18 +306,26 @@ func (*SomeStruct) ProtoMessage() {} func (*SomeStruct) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{6} } - func (m *SomeStruct) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_SomeStruct.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *SomeStruct) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_SomeStruct.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_SomeStruct.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *SomeStruct) XXX_Merge(src proto.Message) { xxx_messageInfo_SomeStruct.Merge(m, src) } func (m *SomeStruct) XXX_Size() int { - return xxx_messageInfo_SomeStruct.Size(m) + return m.Size() } func (m *SomeStruct) XXX_DiscardUnknown() { xxx_messageInfo_SomeStruct.DiscardUnknown(m) @@ -304,10 +341,7 @@ func (m *SomeStruct) GetEmb() *EmbeddedStruct { } type ProtoGotTime struct { - T *timestamp.Timestamp `protobuf:"bytes,1,opt,name=T,proto3" json:"T,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + T *types.Timestamp `protobuf:"bytes,1,opt,name=T,proto3" json:"T,omitempty"` } func (m *ProtoGotTime) Reset() { *m = ProtoGotTime{} } @@ -316,18 +350,26 @@ func (*ProtoGotTime) ProtoMessage() {} func (*ProtoGotTime) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{7} } - func (m *ProtoGotTime) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ProtoGotTime.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *ProtoGotTime) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ProtoGotTime.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_ProtoGotTime.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *ProtoGotTime) XXX_Merge(src proto.Message) { xxx_messageInfo_ProtoGotTime.Merge(m, src) } func (m *ProtoGotTime) XXX_Size() int { - return xxx_messageInfo_ProtoGotTime.Size(m) + return m.Size() } func (m *ProtoGotTime) XXX_DiscardUnknown() { xxx_messageInfo_ProtoGotTime.DiscardUnknown(m) @@ -335,7 +377,7 @@ func (m *ProtoGotTime) XXX_DiscardUnknown() { var xxx_messageInfo_ProtoGotTime proto.InternalMessageInfo -func (m *ProtoGotTime) GetT() *timestamp.Timestamp { +func (m *ProtoGotTime) GetT() *types.Timestamp { if m != nil { return m.T } @@ -343,10 +385,7 @@ func (m *ProtoGotTime) GetT() *timestamp.Timestamp { } type TestInt32 struct { - Int32 int32 `protobuf:"varint,1,opt,name=Int32,proto3" json:"Int32,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Int32 int32 `protobuf:"varint,1,opt,name=Int32,proto3" json:"Int32,omitempty"` } func (m *TestInt32) Reset() { *m = TestInt32{} } @@ -355,18 +394,26 @@ func (*TestInt32) ProtoMessage() {} func (*TestInt32) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{8} } - func (m *TestInt32) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TestInt32.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *TestInt32) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TestInt32.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_TestInt32.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *TestInt32) XXX_Merge(src proto.Message) { xxx_messageInfo_TestInt32.Merge(m, src) } func (m *TestInt32) XXX_Size() int { - return xxx_messageInfo_TestInt32.Size(m) + return m.Size() } func (m *TestInt32) XXX_DiscardUnknown() { xxx_messageInfo_TestInt32.DiscardUnknown(m) @@ -382,11 +429,8 @@ func (m *TestInt32) GetInt32() int32 { } type TestInts struct { - Int32 int32 `protobuf:"varint,1,opt,name=Int32,proto3" json:"Int32,omitempty"` - Int64 int64 `protobuf:"varint,2,opt,name=Int64,proto3" json:"Int64,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Int32 int32 `protobuf:"varint,1,opt,name=Int32,proto3" json:"Int32,omitempty"` + Int64 int64 `protobuf:"varint,2,opt,name=Int64,proto3" json:"Int64,omitempty"` } func (m *TestInts) Reset() { *m = TestInts{} } @@ -395,18 +439,26 @@ func (*TestInts) ProtoMessage() {} func (*TestInts) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{9} } - func (m *TestInts) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TestInts.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *TestInts) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TestInts.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_TestInts.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *TestInts) XXX_Merge(src proto.Message) { xxx_messageInfo_TestInts.Merge(m, src) } func (m *TestInts) XXX_Size() int { - return xxx_messageInfo_TestInts.Size(m) + return m.Size() } func (m *TestInts) XXX_DiscardUnknown() { xxx_messageInfo_TestInts.DiscardUnknown(m) @@ -429,10 +481,7 @@ func (m *TestInts) GetInt64() int64 { } type IntDef struct { - Val int64 `protobuf:"varint,1,opt,name=val,proto3" json:"val,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Val int64 `protobuf:"varint,1,opt,name=val,proto3" json:"val,omitempty"` } func (m *IntDef) Reset() { *m = IntDef{} } @@ -441,18 +490,26 @@ func (*IntDef) ProtoMessage() {} func (*IntDef) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{10} } - func (m *IntDef) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_IntDef.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *IntDef) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_IntDef.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_IntDef.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *IntDef) XXX_Merge(src proto.Message) { xxx_messageInfo_IntDef.Merge(m, src) } func (m *IntDef) XXX_Size() int { - return xxx_messageInfo_IntDef.Size(m) + return m.Size() } func (m *IntDef) XXX_DiscardUnknown() { xxx_messageInfo_IntDef.DiscardUnknown(m) @@ -468,10 +525,7 @@ func (m *IntDef) GetVal() int64 { } type IntArr struct { - Val []int64 `protobuf:"varint,1,rep,packed,name=val,proto3" json:"val,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Val []int64 `protobuf:"varint,1,rep,packed,name=val,proto3" json:"val,omitempty"` } func (m *IntArr) Reset() { *m = IntArr{} } @@ -480,18 +534,26 @@ func (*IntArr) ProtoMessage() {} func (*IntArr) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{11} } - func (m *IntArr) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_IntArr.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *IntArr) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_IntArr.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_IntArr.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *IntArr) XXX_Merge(src proto.Message) { xxx_messageInfo_IntArr.Merge(m, src) } func (m *IntArr) XXX_Size() int { - return xxx_messageInfo_IntArr.Size(m) + return m.Size() } func (m *IntArr) XXX_DiscardUnknown() { xxx_messageInfo_IntArr.DiscardUnknown(m) @@ -518,12 +580,9 @@ type PrimitivesStruct struct { // Uint64 uint64 // Uvarint uint64 `binary:"varint"` // Uint uint - String_ string `protobuf:"bytes,14,opt,name=String,proto3" json:"String,omitempty"` - Bytes []byte `protobuf:"bytes,15,opt,name=Bytes,proto3" json:"Bytes,omitempty"` - Time *timestamp.Timestamp `protobuf:"bytes,16,opt,name=Time,proto3" json:"Time,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + String_ string `protobuf:"bytes,14,opt,name=String,proto3" json:"String,omitempty"` + Bytes []byte `protobuf:"bytes,15,opt,name=Bytes,proto3" json:"Bytes,omitempty"` + Time *types.Timestamp `protobuf:"bytes,16,opt,name=Time,proto3" json:"Time,omitempty"` } func (m *PrimitivesStruct) Reset() { *m = PrimitivesStruct{} } @@ -532,18 +591,26 @@ func (*PrimitivesStruct) ProtoMessage() {} func (*PrimitivesStruct) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{12} } - func (m *PrimitivesStruct) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_PrimitivesStruct.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *PrimitivesStruct) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_PrimitivesStruct.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_PrimitivesStruct.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *PrimitivesStruct) XXX_Merge(src proto.Message) { xxx_messageInfo_PrimitivesStruct.Merge(m, src) } func (m *PrimitivesStruct) XXX_Size() int { - return xxx_messageInfo_PrimitivesStruct.Size(m) + return m.Size() } func (m *PrimitivesStruct) XXX_DiscardUnknown() { xxx_messageInfo_PrimitivesStruct.DiscardUnknown(m) @@ -586,7 +653,7 @@ func (m *PrimitivesStruct) GetBytes() []byte { return nil } -func (m *PrimitivesStruct) GetTime() *timestamp.Timestamp { +func (m *PrimitivesStruct) GetTime() *types.Timestamp { if m != nil { return m.Time } @@ -594,10 +661,7 @@ func (m *PrimitivesStruct) GetTime() *timestamp.Timestamp { } type PrimitivesStructSl struct { - Structs []*PrimitivesStruct `protobuf:"bytes,1,rep,name=Structs,proto3" json:"Structs,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Structs []*PrimitivesStruct `protobuf:"bytes,1,rep,name=Structs,proto3" json:"Structs,omitempty"` } func (m *PrimitivesStructSl) Reset() { *m = PrimitivesStructSl{} } @@ -606,18 +670,26 @@ func (*PrimitivesStructSl) ProtoMessage() {} func (*PrimitivesStructSl) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{13} } - func (m *PrimitivesStructSl) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_PrimitivesStructSl.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *PrimitivesStructSl) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_PrimitivesStructSl.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_PrimitivesStructSl.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *PrimitivesStructSl) XXX_Merge(src proto.Message) { xxx_messageInfo_PrimitivesStructSl.Merge(m, src) } func (m *PrimitivesStructSl) XXX_Size() int { - return xxx_messageInfo_PrimitivesStructSl.Size(m) + return m.Size() } func (m *PrimitivesStructSl) XXX_DiscardUnknown() { xxx_messageInfo_PrimitivesStructSl.DiscardUnknown(m) @@ -636,10 +708,7 @@ type AminoRegisteredAny struct { // Prefix or Disfix (Prefix + Disamb) bytes AminoPreOrDisfix []byte `protobuf:"bytes,1,opt,name=AminoPreOrDisfix,proto3" json:"AminoPreOrDisfix,omitempty"` // Must be a valid serialized protocol buffer with the above specified amino pre-/disfix. - Value []byte `protobuf:"bytes,2,opt,name=Value,proto3" json:"Value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Value []byte `protobuf:"bytes,2,opt,name=Value,proto3" json:"Value,omitempty"` } func (m *AminoRegisteredAny) Reset() { *m = AminoRegisteredAny{} } @@ -648,18 +717,26 @@ func (*AminoRegisteredAny) ProtoMessage() {} func (*AminoRegisteredAny) Descriptor() ([]byte, []int) { return fileDescriptor_bced3ff93dcaa7f8, []int{14} } - func (m *AminoRegisteredAny) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AminoRegisteredAny.Unmarshal(m, b) + return m.Unmarshal(b) } func (m *AminoRegisteredAny) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AminoRegisteredAny.Marshal(b, m, deterministic) + if deterministic { + return xxx_messageInfo_AminoRegisteredAny.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } } func (m *AminoRegisteredAny) XXX_Merge(src proto.Message) { xxx_messageInfo_AminoRegisteredAny.Merge(m, src) } func (m *AminoRegisteredAny) XXX_Size() int { - return xxx_messageInfo_AminoRegisteredAny.Size(m) + return m.Size() } func (m *AminoRegisteredAny) XXX_DiscardUnknown() { xxx_messageInfo_AminoRegisteredAny.DiscardUnknown(m) @@ -702,36 +779,2192 @@ func init() { func init() { proto.RegisterFile("compat.proto", fileDescriptor_bced3ff93dcaa7f8) } var fileDescriptor_bced3ff93dcaa7f8 = []byte{ - // 489 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0xef, 0x6b, 0x1a, 0x41, - 0x10, 0xe5, 0x7a, 0x89, 0x36, 0xa3, 0x98, 0xcb, 0x52, 0xca, 0x61, 0x29, 0xb5, 0xfb, 0x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 0x23, 0xeb, 0x54, 0x9a, - 0xfc, 0xd7, 0x46, 0xc7, 0xa3, 0xbf, 0x80, 0x3c, 0xfc, 0xea, 0x7c, 0x4d, 0x3e, 0x42, 0xdd, 0xd7, - 0xda, 0x3d, 0xb1, 0xd1, 0x7f, 0x7d, 0x10, 0xe6, 0x43, 0x05, 0xab, 0xd8, 0x74, 0x06, 0x64, 0x24, - 0x78, 0x29, 0x19, 0xae, 0xb8, 0x36, 0xa8, 0x70, 0x31, 0x2a, 0xef, 0x48, 0x0f, 0x12, 0xd7, 0x9d, - 0x28, 0xfc, 0xad, 0xae, 0xb8, 0x5e, 0xf2, 0x5b, 0x67, 0x6b, 0x93, 0x3d, 0xea, 0xdb, 0x67, 0xcd, - 0x8a, 0xf5, 0x16, 0x5d, 0x2a, 0x4d, 0xe6, 0xc1, 0xbc, 0xe6, 0xcf, 0xff, 0x0b, 0x00, 0x00, 0xff, - 0xff, 0xe2, 0x80, 0x7f, 0xc3, 0xc3, 0x03, 0x00, 0x00, + // 528 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x5f, 0x6b, 0x1a, 0x4d, + 0x14, 0xc6, 0xb3, 0xef, 0x26, 0xfa, 0xe6, 0x28, 0x66, 0x33, 0x94, 0xb2, 0x58, 0xba, 0xb5, 0x73, + 0xd1, 0x8a, 0xa4, 0x1b, 0xd0, 0x60, 0x0b, 0x85, 0x82, 0x21, 0x6d, 0x11, 0x5a, 0x2a, 0xb3, 0xe2, + 0xfd, 0x1a, 0x47, 0x3b, 0xe0, 0xee, 0xc8, 0xcc, 0x18, 0x92, 0x6f, 0xd1, 0x0f, 0xd3, 0x0f, 0xd1, + 0xcb, 0x5c, 0xf6, 0xb2, 0xe8, 0x17, 0x29, 0xf3, 0x67, 0x35, 0x26, 0x81, 0x5e, 0x79, 0x9e, 0x73, + 0x7e, 0x67, 0x66, 0xf6, 0x79, 0x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e, 0xe8, 0x8c, 0x49, 0x45, 0x05, 0x9d, 0xf4, 0xf2, 0x1b, 0xd4, 0x82, 0xc0, 0x74, 0x07, 0x82, + 0x7e, 0x13, 0x17, 0x4c, 0x4e, 0xd9, 0xb5, 0xb1, 0xb5, 0x4a, 0x1e, 0xf4, 0xf5, 0x67, 0x8d, 0xd2, + 0xf9, 0x92, 0x9a, 0x54, 0xaa, 0xc4, 0x8a, 0xf3, 0xf0, 0xd7, 0x2a, 0xf2, 0x6e, 0x57, 0x91, 0xf7, + 0x67, 0x15, 0x79, 0x3f, 0xd6, 0xd1, 0xde, 0xed, 0x3a, 0xda, 0xfb, 0xbd, 0x8e, 0xf6, 0xc6, 0x25, + 0xfb, 0xb0, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe9, 0xdc, 0x1c, 0x1e, 0xdd, 0x03, 0x00, 0x00, +} + +func (m *TestInt32Varint) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestInt32Varint) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Int32 != 0 { + dAtA[i] = 0x8 + i++ + i = encodeVarintCompat(dAtA, i, uint64((uint32(m.Int32)<<1)^uint32((m.Int32>>31)))) + } + return i, nil +} + +func (m *TestInt32Fixed) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestInt32Fixed) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Fixed32 != 0 { + dAtA[i] = 0xd + i++ + encoding_binary.LittleEndian.PutUint32(dAtA[i:], uint32(m.Fixed32)) + i += 4 + } + return i, nil +} + +func (m *Test32) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Test32) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Foo != 0 { + dAtA[i] = 0xd + i++ + encoding_binary.LittleEndian.PutUint32(dAtA[i:], uint32(m.Foo)) + i += 4 + } + if m.Bar != 0 { + dAtA[i] = 0x10 + i++ + i = encodeVarintCompat(dAtA, i, uint64((uint32(m.Bar)<<1)^uint32((m.Bar>>31)))) + } + return i, nil +} + +func (m *TestFixedInt64) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestFixedInt64) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Int64 != 0 { + dAtA[i] = 0x9 + i++ + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.Int64)) + i += 8 + } + return i, nil +} + +func (m *TestSFixedSInt64) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestSFixedSInt64) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.SInt64 != 0 { + dAtA[i] = 0x9 + i++ + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.SInt64)) + i += 8 + } + return i, nil +} + +func (m *EmbeddedStruct) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EmbeddedStruct) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.SomethingFixedLen != 0 { + dAtA[i] = 0x9 + i++ + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(m.SomethingFixedLen)) + i += 8 + } + return i, nil +} + +func (m *SomeStruct) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SomeStruct) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Emb != nil { + dAtA[i] = 0xa + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Emb.Size())) + n1, err := m.Emb.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n1 + } + return i, nil +} + +func (m *ProtoGotTime) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProtoGotTime) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.T != nil { + dAtA[i] = 0xa + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.T.Size())) + n2, err := m.T.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n2 + } + return i, nil +} + +func (m *TestInt32) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestInt32) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Int32 != 0 { + dAtA[i] = 0x8 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Int32)) + } + return i, nil +} + +func (m *TestInts) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestInts) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Int32 != 0 { + dAtA[i] = 0x8 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Int32)) + } + if m.Int64 != 0 { + dAtA[i] = 0x10 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Int64)) + } + return i, nil +} + +func (m *IntDef) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IntDef) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Val != 0 { + dAtA[i] = 0x8 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Val)) + } + return i, nil +} + +func (m *IntArr) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IntArr) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Val) > 0 { + dAtA4 := make([]byte, len(m.Val)*10) + var j3 int + for _, num1 := range m.Val { + num := uint64(num1) + for num >= 1<<7 { + dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j3++ + } + dAtA4[j3] = uint8(num) + j3++ + } + dAtA[i] = 0xa + i++ + i = encodeVarintCompat(dAtA, i, uint64(j3)) + i += copy(dAtA[i:], dAtA4[:j3]) + } + return i, nil +} + +func (m *PrimitivesStruct) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrimitivesStruct) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Int32 != 0 { + dAtA[i] = 0x18 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Int32)) + } + if m.Int64 != 0 { + dAtA[i] = 0x20 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Int64)) + } + if m.Varint != 0 { + dAtA[i] = 0x28 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Varint)) + } + if len(m.String_) > 0 { + dAtA[i] = 0x72 + i++ + i = encodeVarintCompat(dAtA, i, uint64(len(m.String_))) + i += copy(dAtA[i:], m.String_) + } + if len(m.Bytes) > 0 { + dAtA[i] = 0x7a + i++ + i = encodeVarintCompat(dAtA, i, uint64(len(m.Bytes))) + i += copy(dAtA[i:], m.Bytes) + } + if m.Time != nil { + dAtA[i] = 0x82 + i++ + dAtA[i] = 0x1 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Time.Size())) + n5, err := m.Time.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n5 + } + return i, nil +} + +func (m *PrimitivesStructSl) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PrimitivesStructSl) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Structs) > 0 { + for _, msg := range m.Structs { + dAtA[i] = 0xa + i++ + i = encodeVarintCompat(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + return i, nil +} + +func (m *AminoRegisteredAny) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AminoRegisteredAny) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.AminoPreOrDisfix) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintCompat(dAtA, i, uint64(len(m.AminoPreOrDisfix))) + i += copy(dAtA[i:], m.AminoPreOrDisfix) + } + if len(m.Value) > 0 { + dAtA[i] = 0x12 + i++ + i = encodeVarintCompat(dAtA, i, uint64(len(m.Value))) + i += copy(dAtA[i:], m.Value) + } + return i, nil +} + +func encodeVarintCompat(dAtA []byte, offset int, v uint64) int { + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return offset + 1 +} +func (m *TestInt32Varint) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Int32 != 0 { + n += 1 + sozCompat(uint64(m.Int32)) + } + return n +} + +func (m *TestInt32Fixed) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Fixed32 != 0 { + n += 5 + } + return n } + +func (m *Test32) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Foo != 0 { + n += 5 + } + if m.Bar != 0 { + n += 1 + sozCompat(uint64(m.Bar)) + } + return n +} + +func (m *TestFixedInt64) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Int64 != 0 { + n += 9 + } + return n +} + +func (m *TestSFixedSInt64) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SInt64 != 0 { + n += 9 + } + return n +} + +func (m *EmbeddedStruct) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SomethingFixedLen != 0 { + n += 9 + } + return n +} + +func (m *SomeStruct) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Emb != nil { + l = m.Emb.Size() + n += 1 + l + sovCompat(uint64(l)) + } + return n +} + +func (m *ProtoGotTime) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.T != nil { + l = m.T.Size() + n += 1 + l + sovCompat(uint64(l)) + } + return n +} + +func (m *TestInt32) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Int32 != 0 { + n += 1 + sovCompat(uint64(m.Int32)) + } + return n +} + +func (m *TestInts) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Int32 != 0 { + n += 1 + sovCompat(uint64(m.Int32)) + } + if m.Int64 != 0 { + n += 1 + sovCompat(uint64(m.Int64)) + } + return n +} + +func (m *IntDef) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Val != 0 { + n += 1 + sovCompat(uint64(m.Val)) + } + return n +} + +func (m *IntArr) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Val) > 0 { + l = 0 + for _, e := range m.Val { + l += sovCompat(uint64(e)) + } + n += 1 + sovCompat(uint64(l)) + l + } + return n +} + +func (m *PrimitivesStruct) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Int32 != 0 { + n += 1 + sovCompat(uint64(m.Int32)) + } + if m.Int64 != 0 { + n += 1 + sovCompat(uint64(m.Int64)) + } + if m.Varint != 0 { + n += 1 + sovCompat(uint64(m.Varint)) + } + l = len(m.String_) + if l > 0 { + n += 1 + l + sovCompat(uint64(l)) + } + l = len(m.Bytes) + if l > 0 { + n += 1 + l + sovCompat(uint64(l)) + } + if m.Time != nil { + l = m.Time.Size() + n += 2 + l + sovCompat(uint64(l)) + } + return n +} + +func (m *PrimitivesStructSl) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Structs) > 0 { + for _, e := range m.Structs { + l = e.Size() + n += 1 + l + sovCompat(uint64(l)) + } + } + return n +} + +func (m *AminoRegisteredAny) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.AminoPreOrDisfix) + if l > 0 { + n += 1 + l + sovCompat(uint64(l)) + } + l = len(m.Value) + if l > 0 { + n += 1 + l + sovCompat(uint64(l)) + } + return n +} + +func sovCompat(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozCompat(x uint64) (n int) { + return sovCompat(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *TestInt32Varint) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TestInt32Varint: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestInt32Varint: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Int32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31)) + m.Int32 = v + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestInt32Fixed) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TestInt32Fixed: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestInt32Fixed: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 5 { + return fmt.Errorf("proto: wrong wireType = %d for field Fixed32", wireType) + } + m.Fixed32 = 0 + if (iNdEx + 4) > l { + return io.ErrUnexpectedEOF + } + m.Fixed32 = uint32(encoding_binary.LittleEndian.Uint32(dAtA[iNdEx:])) + iNdEx += 4 + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Test32) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Test32: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Test32: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 5 { + return fmt.Errorf("proto: wrong wireType = %d for field Foo", wireType) + } + m.Foo = 0 + if (iNdEx + 4) > l { + return io.ErrUnexpectedEOF + } + m.Foo = uint32(encoding_binary.LittleEndian.Uint32(dAtA[iNdEx:])) + iNdEx += 4 + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Bar", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31)) + m.Bar = v + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestFixedInt64) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TestFixedInt64: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestFixedInt64: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field Int64", wireType) + } + m.Int64 = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.Int64 = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestSFixedSInt64) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TestSFixedSInt64: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestSFixedSInt64: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field SInt64", wireType) + } + m.SInt64 = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.SInt64 = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EmbeddedStruct) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EmbeddedStruct: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EmbeddedStruct: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field SomethingFixedLen", wireType) + } + m.SomethingFixedLen = 0 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + m.SomethingFixedLen = int64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SomeStruct) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SomeStruct: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SomeStruct: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Emb", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Emb == nil { + m.Emb = &EmbeddedStruct{} + } + if err := m.Emb.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ProtoGotTime) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProtoGotTime: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProtoGotTime: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field T", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.T == nil { + m.T = &types.Timestamp{} + } + if err := m.T.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestInt32) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TestInt32: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestInt32: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Int32", wireType) + } + m.Int32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Int32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestInts) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TestInts: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestInts: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Int32", wireType) + } + m.Int32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Int32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Int64", wireType) + } + m.Int64 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Int64 |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IntDef) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IntDef: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IntDef: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Val", wireType) + } + m.Val = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Val |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IntArr) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IntArr: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IntArr: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType == 0 { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Val = append(m.Val, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.Val) == 0 { + m.Val = make([]int64, 0, elementCount) + } + for iNdEx < postIndex { + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Val = append(m.Val, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field Val", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PrimitivesStruct) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrimitivesStruct: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrimitivesStruct: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Int32", wireType) + } + m.Int32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Int32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Int64", wireType) + } + m.Int64 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Int64 |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Varint", wireType) + } + m.Varint = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Varint |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 14: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field String_", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.String_ = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 15: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bytes = append(m.Bytes[:0], dAtA[iNdEx:postIndex]...) + if m.Bytes == nil { + m.Bytes = []byte{} + } + iNdEx = postIndex + case 16: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Time", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Time == nil { + m.Time = &types.Timestamp{} + } + if err := m.Time.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PrimitivesStructSl) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PrimitivesStructSl: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrimitivesStructSl: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Structs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Structs = append(m.Structs, &PrimitivesStruct{}) + if err := m.Structs[len(m.Structs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AminoRegisteredAny) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AminoRegisteredAny: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AminoRegisteredAny: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AminoPreOrDisfix", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AminoPreOrDisfix = append(m.AminoPreOrDisfix[:0], dAtA[iNdEx:postIndex]...) + if m.AminoPreOrDisfix == nil { + m.AminoPreOrDisfix = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) + if m.Value == nil { + m.Value = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCompat(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCompat + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCompat + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCompat + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCompat + } + iNdEx += length + if iNdEx < 0 { + return 0, ErrInvalidLengthCompat + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCompat + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipCompat(dAtA[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + if iNdEx < 0 { + return 0, ErrInvalidLengthCompat + } + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthCompat = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCompat = fmt.Errorf("proto: integer overflow") +) diff --git a/tests/proto3/proto3_compat_test.go b/tests/proto3/proto3_compat_test.go index 4aa0ed34..8a53d39f 100644 --- a/tests/proto3/proto3_compat_test.go +++ b/tests/proto3/proto3_compat_test.go @@ -7,6 +7,7 @@ import ( "bufio" "bytes" "encoding/binary" + "math" "testing" "time" @@ -14,8 +15,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + ptypes "github.com/gogo/protobuf/types" "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" p3 "github.com/tendermint/go-amino/tests/proto3/proto" @@ -208,14 +209,14 @@ func TestProto3CompatTimestampNow(t *testing.T) { pbRes := p3.ProtoGotTime{} err = proto.Unmarshal(ab1, &pbRes) assert.NoError(t, err) - got, err := ptypes.Timestamp(pbRes.T) + got, err := ptypes.TimestampFromProto(pbRes.T) assert.NoError(t, err) _, err = ptypes.TimestampProto(now) assert.NoError(t, err) err = proto.Unmarshal(pb, &pbRes) assert.NoError(t, err) // create time.Time from timestamp.Timestamp and check if they are the same: - got, err = ptypes.Timestamp(pbRes.T) + got, err = ptypes.TimestampFromProto(pbRes.T) assert.Equal(t, got.UTC(), now.UTC()) } @@ -226,7 +227,7 @@ func TestProto3EpochTime(t *testing.T) { assert.NoError(t, err) err = proto.Unmarshal(ab, &pbRes) assert.NoError(t, err) - ts, err := ptypes.Timestamp(pbRes.T) + ts, err := ptypes.TimestampFromProto(pbRes.T) assert.NoError(t, err) assert.EqualValues(t, ts, epoch) } @@ -243,7 +244,7 @@ func TestProtoNegativeSeconds(t *testing.T) { assert.EqualValues(t, ntm, *res.T) err = proto.Unmarshal(ab, &pbRes) assert.NoError(t, err) - got, err := ptypes.Timestamp(pbRes.T) + got, err := ptypes.TimestampFromProto(pbRes.T) assert.NoError(t, err) assert.Equal(t, got, ntm) } @@ -338,7 +339,7 @@ func TestIntVarintCompat(t *testing.T) { func TestTypeDefCompatibility(t *testing.T) { pNow := ptypes.TimestampNow() - now, err := ptypes.Timestamp(pNow) + now, err := ptypes.TimestampFromProto(pNow) require.NoError(t, err) strSl := tests.PrimitivesStructSl{ From 94e09b2481bd3ebdc3f7f93d9dcd5cba1e57e8e2 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 15:11:28 +0200 Subject: [PATCH 06/17] locate places on decoding that need to adapt to using the RegisteredAny struct instead of operating directly on the disfix bytes Signed-off-by: Ismail Khoffi --- amino.go | 3 ++- binary-decode.go | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/amino.go b/amino.go index 54308136..a9a1a210 100644 --- a/amino.go +++ b/amino.go @@ -229,7 +229,6 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { } // If registered concrete, prepend prefix bytes. if info.Registered { - // TODO: https://github.com/tendermint/go-amino/issues/267 return MarshalBinaryBare(RegisteredAny{ AminoPreOrDisfix: info.Prefix.Bytes(), Value: bz, @@ -241,6 +240,8 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { return bz, nil } +// TODO: https://github.com/tendermint/go-amino/issues/267 +// properly document this type RegisteredAny struct { AminoPreOrDisfix []byte Value []byte diff --git a/binary-decode.go b/binary-decode.go index b9b25dac..dd4b4147 100644 --- a/binary-decode.go +++ b/binary-decode.go @@ -339,6 +339,9 @@ func (cdc *Codec) decodeReflectBinaryInterface(bz []byte, iinfo *TypeInfo, rv re } // Consume disambiguation / prefix bytes. + // TODO: https://github.com/tendermint/go-amino/issues/267 + // extract below info from RegisteredAny struct and + // continue with the value instead disamb, hasDisamb, prefix, hasPrefix, _n, err := DecodeDisambPrefixBytes(bz) if slide(&bz, &n, _n) && err != nil { return From f531e2ec319f882dcfa38224dee7540cc2d910b3 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 15:29:01 +0200 Subject: [PATCH 07/17] TestCodecRoundtripNonNilRegisteredTypeDef passes Signed-off-by: Ismail Khoffi --- binary-decode.go | 22 ++++++++++++++++++++-- reflect_test.go | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/binary-decode.go b/binary-decode.go index dd4b4147..abce91fa 100644 --- a/binary-decode.go +++ b/binary-decode.go @@ -342,10 +342,28 @@ func (cdc *Codec) decodeReflectBinaryInterface(bz []byte, iinfo *TypeInfo, rv re // TODO: https://github.com/tendermint/go-amino/issues/267 // extract below info from RegisteredAny struct and // continue with the value instead - disamb, hasDisamb, prefix, hasPrefix, _n, err := DecodeDisambPrefixBytes(bz) + aminoAny := &RegisteredAny{} + if bare { + if err = cdc.UnmarshalBinaryBare(bz, aminoAny); err != nil { + return + } + } else { + if err = cdc.UnmarshalBinaryLengthPrefixed(bz, aminoAny); err != nil { + return + } + } + disamb, hasDisamb, prefix, hasPrefix, _n, err := DecodeDisambPrefixBytes(aminoAny.AminoPreOrDisfix) if slide(&bz, &n, _n) && err != nil { return } + overhead := len(bz) - len(aminoAny.Value) + if overhead < 0 { + // we could as well panic here + err = errors.New("encoded value in RegisteredAny larger than original buffer") + return + } + slide(&bz, &n, overhead) + bz = aminoAny.Value // Get concrete type info from disfix/prefix. var cinfo *TypeInfo @@ -354,7 +372,7 @@ func (cdc *Codec) decodeReflectBinaryInterface(bz []byte, iinfo *TypeInfo, rv re } else if hasPrefix { cinfo, err = cdc.getTypeInfoFromPrefix_rlock(iinfo, prefix) } else { - err = errors.New("Expected disambiguation or prefix bytes.") + err = errors.New("expected disambiguation or prefix bytes") } if err != nil { return diff --git a/reflect_test.go b/reflect_test.go index 10a92a59..148d8595 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -242,7 +242,7 @@ func TestCodecRoundtripNonNilRegisteredTypeDef(t *testing.T) { bz, err := cdc.MarshalBinaryBare(c3) assert.Nil(t, err) - assert.Equal(t, []byte{0x11, 0x1e, 0x93, 0x82, 0xa, 0x4, 0x30, 0x31, 0x32, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0x4, 0x11, 0x1e, 0x93, 0x82, 0x12, 0x6, 0xa, 0x4, 0x30, 0x31, 0x32, 0x33}, bz, "ConcreteTypeDef incorrectly serialized") var i1 tests.Interface1 From ae255df461934bb9d1ccca2cd854b1d110b51e49 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 15:38:22 +0200 Subject: [PATCH 08/17] Following tests pass: TestCodecRoundtripUnarshalOnConcreteNonNilRegisteredTypeDef TestCodecRoundtripMarshalOnConcreteNonNilRegisteredTypeDef TestCodecRoundtripUnarshalOnConcreteNonNilRegisteredTypeDef TestCodecRoundtripMarshalOnConcreteNonNilRegisteredTypeDef Example Signed-off-by: Ismail Khoffi --- amino.go | 15 +++++++++------ example_test.go | 2 +- reflect_test.go | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/amino.go b/amino.go index a9a1a210..a086ecac 100644 --- a/amino.go +++ b/amino.go @@ -362,14 +362,17 @@ func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}) error { // If registered concrete, consume and verify prefix bytes. if info.Registered { - // TODO: https://github.com/tendermint/go-amino/issues/267 + aminoAny := &RegisteredAny{} + if err := cdc.UnmarshalBinaryBare(bz, aminoAny); err != nil { + return err + } pb := info.Prefix.Bytes() - if len(bz) < 4 { - return fmt.Errorf("UnmarshalBinaryBare expected to read prefix bytes %X (since it is registered concrete) but got %X", pb, bz) - } else if !bytes.Equal(bz[:4], pb) { - return fmt.Errorf("UnmarshalBinaryBare expected to read prefix bytes %X (since it is registered concrete) but got %X...", pb, bz[:4]) + if len(aminoAny.AminoPreOrDisfix) < 4 { + return fmt.Errorf("UnmarshalBinaryBare expected to read prefix bytes %X (since it is registered concrete) but got %X", pb, aminoAny.AminoPreOrDisfix) + } else if !bytes.Equal(aminoAny.AminoPreOrDisfix[:4], pb) { + return fmt.Errorf("UnmarshalBinaryBare expected to read prefix bytes %X (since it is registered concrete) but got %X...", pb, aminoAny.AminoPreOrDisfix[:4]) } - bz = bz[4:] + bz = aminoAny.Value } // Only add length prefix if we have another typ3 then Typ3_ByteLength. // Default is non-length prefixed: diff --git a/example_test.go b/example_test.go index 68ba611e..11eda01d 100644 --- a/example_test.go +++ b/example_test.go @@ -65,7 +65,7 @@ func Example() { fmt.Printf("Decoded successfully: %v\n", *bm == *bm2) // Output: - // Encoded: 0B740613650A034142431064 (err: ) + // Encoded: 0F0A047406136512070A034142431064 (err: ) // Decoded: &{ABC 100} (err: ) // Decoded successfully: true } diff --git a/reflect_test.go b/reflect_test.go index 148d8595..16907cb1 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -266,7 +266,7 @@ func TestCodecRoundtripNonNilRegisteredWrappedValue(t *testing.T) { bz, err := cdc.MarshalBinaryBare(c3) assert.Nil(t, err) - assert.Equal(t, []byte{0x49, 0x3f, 0xa0, 0x4b, 0xa, 0x4, 0x30, 0x31, 0x32, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0x4, 0x49, 0x3f, 0xa0, 0x4b, 0x12, 0x6, 0xa, 0x4, 0x30, 0x31, 0x32, 0x33}, bz, "ConcreteWrappedBytes incorrectly serialized") var i1 tests.Interface1 @@ -312,7 +312,7 @@ func TestCodecRoundtripMarshalOnConcreteNonNilRegisteredTypeDef(t *testing.T) { bz, err := cdc.MarshalBinaryBare(c3) assert.Nil(t, err) - assert.Equal(t, []byte{0x11, 0x1e, 0x93, 0x82, 0xa, 0x4, 0x30, 0x31, 0x32, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0x4, 0x11, 0x1e, 0x93, 0x82, 0x12, 0x6, 0xa, 0x4, 0x30, 0x31, 0x32, 0x33}, bz, "ConcreteTypeDef incorrectly serialized") var i1 tests.Interface1 @@ -332,12 +332,12 @@ func TestCodecRoundtripUnarshalOnConcreteNonNilRegisteredTypeDef(t *testing.T) { bz, err := cdc.MarshalBinaryBare(c3a) assert.Nil(t, err) - assert.Equal(t, []byte{0x11, 0x1e, 0x93, 0x82, 0xa, 0x4, 0x30, 0x31, 0x32, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0x4, 0x11, 0x1e, 0x93, 0x82, 0x12, 0x6, 0xa, 0x4, 0x30, 0x31, 0x32, 0x33}, bz, "ConcreteTypeDef incorrectly serialized") var c3b tests.ConcreteTypeDef err = cdc.UnmarshalBinaryBare(bz, &c3b) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, c3a, c3b) } From ba504bdfe70855e6b75b821c7e3cc2a807c803bd Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 16:32:09 +0200 Subject: [PATCH 09/17] All tests pass \o/ Still need much more testing though Signed-off-by: Ismail Khoffi --- binary-decode.go | 10 ++-------- binary-encode.go | 17 +++++++++-------- reflect_test.go | 14 +++++++------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/binary-decode.go b/binary-decode.go index abce91fa..7d1a85c9 100644 --- a/binary-decode.go +++ b/binary-decode.go @@ -343,14 +343,8 @@ func (cdc *Codec) decodeReflectBinaryInterface(bz []byte, iinfo *TypeInfo, rv re // extract below info from RegisteredAny struct and // continue with the value instead aminoAny := &RegisteredAny{} - if bare { - if err = cdc.UnmarshalBinaryBare(bz, aminoAny); err != nil { - return - } - } else { - if err = cdc.UnmarshalBinaryLengthPrefixed(bz, aminoAny); err != nil { - return - } + if err = cdc.UnmarshalBinaryBare(bz, aminoAny); err != nil { + return } disamb, hasDisamb, prefix, hasPrefix, _n, err := DecodeDisambPrefixBytes(aminoAny.AminoPreOrDisfix) if slide(&bz, &n, _n) && err != nil { diff --git a/binary-encode.go b/binary-encode.go index 2f008e1e..2d3b7816 100644 --- a/binary-encode.go +++ b/binary-encode.go @@ -217,25 +217,26 @@ func (cdc *Codec) encodeReflectBinaryInterface(w io.Writer, iinfo *TypeInfo, rv return } } - - // Write prefix bytes. - _, err = buf.Write(cinfo.Prefix.Bytes()) + // TODO: https://github.com/tendermint/go-amino/issues/267 + aminoAny := &RegisteredAny{AminoPreOrDisfix: cinfo.Prefix.Bytes()} + // Write actual concrete value. + buf.Reset() + err = cdc.encodeReflectBinary(buf, cinfo, crv, fopts, true) if err != nil { return } - - // Write actual concrete value. - err = cdc.encodeReflectBinary(buf, cinfo, crv, fopts, true) + aminoAny.Value = buf.Bytes() + bz, err := cdc.MarshalBinaryBare(aminoAny) if err != nil { return } if bare { // Write byteslice without byte-length prefixing. - _, err = w.Write(buf.Bytes()) + _, err = w.Write(bz) } else { // Write byte-length prefixed byteslice. - err = EncodeByteSlice(w, buf.Bytes()) + err = EncodeByteSlice(w, bz) } return } diff --git a/reflect_test.go b/reflect_test.go index 16907cb1..c3cf6572 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -168,7 +168,7 @@ func TestCodecMarshalBinaryBarePassesOnRegistered(t *testing.T) { bz, err := cdc.MarshalBinaryBare(struct{ tests.Interface1 }{tests.Concrete1{}}) assert.NoError(t, err, "correctly registered") - assert.Equal(t, []byte{0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0x6, 0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz, "prefix bytes did not match") } @@ -179,7 +179,7 @@ func TestCodecMarshalBinaryBareOnRegisteredMatches(t *testing.T) { bz, err := cdc.MarshalBinaryBare(struct{ tests.Interface1 }{tests.Concrete1{}}) assert.NoError(t, err, "correctly registered") - assert.Equal(t, []byte{0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0x6, 0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz, "prefix bytes did not match") } @@ -192,7 +192,7 @@ func TestCodecMarhsalBinaryBareRegisteredAndDisamb(t *testing.T) { bz, err := cdc.MarshalBinaryBare(struct{ tests.Interface1 }{tests.Concrete1{}}) assert.NoError(t, err, "correctly registered") - assert.Equal(t, []byte{0xa, 0x8, 0x0, 0x12, 0xb5, 0x86, 0xe3, 0xda, 0xb8, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0x6, 0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz, "prefix bytes did not match") } @@ -215,14 +215,14 @@ func TestCodecRegisterAndMarshalMultipleConcrete(t *testing.T) { { // test tests.Concrete1, no conflict. bz, err := cdc.MarshalBinaryBare(struct{ tests.Interface1 }{tests.Concrete1{}}) assert.NoError(t, err, "correctly registered") - assert.Equal(t, []byte{0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0x6, 0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz, "disfix bytes did not match") } { // test tests.Concrete2, no conflict bz, err := cdc.MarshalBinaryBare(struct{ tests.Interface1 }{tests.Concrete2{}}) assert.NoError(t, err, "correctly registered") - assert.Equal(t, []byte{0xa, 0x4, 0x6a, 0x9, 0xca, 0x1}, bz, + assert.Equal(t, []byte{0xa, 0x6, 0xa, 0x4, 0x6a, 0x9, 0xca, 0x1}, bz, "disfix bytes did not match") } } @@ -347,10 +347,10 @@ func TestCodecBinaryStructFieldNilInterface(t *testing.T) { cdc.RegisterConcrete((*tests.InterfaceFieldsStruct)(nil), "interfaceFields", nil) i1 := &tests.InterfaceFieldsStruct{F1: new(tests.InterfaceFieldsStruct), F2: nil} - bz, err := cdc.MarshalBinaryLengthPrefixed(i1) + bz, err := cdc.MarshalBinaryBare(i1) i2 := new(tests.InterfaceFieldsStruct) - err = cdc.UnmarshalBinaryLengthPrefixed(bz, i2) + err = cdc.UnmarshalBinaryBare(bz, i2) assert.NoError(t, err) require.Equal(t, i1, i2, "i1 and i2 should be the same after decoding") From 3c6bd986e8ae7bac2ad6498afb234b29d9eada42 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 16:38:24 +0200 Subject: [PATCH 10/17] Some cleanup (delete TODOs, slightly update comments) Signed-off-by: Ismail Khoffi --- amino.go | 20 +++++++++++++++----- binary-decode.go | 5 +---- binary-encode.go | 1 - 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/amino.go b/amino.go index a086ecac..c1d2f51a 100644 --- a/amino.go +++ b/amino.go @@ -227,21 +227,31 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { } bz = buf.Bytes() } - // If registered concrete, prepend prefix bytes. + // If registered concrete, prepend prefix bytes by wrapping + // message in RegisteredAny: if info.Registered { return MarshalBinaryBare(RegisteredAny{ AminoPreOrDisfix: info.Prefix.Bytes(), Value: bz, }) - // pb := info.Prefix.Bytes() - // bz = append(pb, bz...) } return bz, nil } -// TODO: https://github.com/tendermint/go-amino/issues/267 -// properly document this +// TODO: extensively document this! +// +// This will be compatible to the following proto3 message: +// +// message AminoRegisteredAny { +// // Prefix or Disfix (Prefix + Disamb) bytes +// bytes AminoPreOrDisfix = 1; +// // Must be a valid serialized protocol buffer with the above specified amino pre-/disfix. +// bytes Value = 2; +//} +// +// This is comparable to proto.Any but instead of a URL scheme there, we use amino's +// disfix bytes instead. type RegisteredAny struct { AminoPreOrDisfix []byte Value []byte diff --git a/binary-decode.go b/binary-decode.go index 7d1a85c9..4c4c51d4 100644 --- a/binary-decode.go +++ b/binary-decode.go @@ -338,10 +338,7 @@ func (cdc *Codec) decodeReflectBinaryInterface(bz []byte, iinfo *TypeInfo, rv re bz = buf } - // Consume disambiguation / prefix bytes. - // TODO: https://github.com/tendermint/go-amino/issues/267 - // extract below info from RegisteredAny struct and - // continue with the value instead + // Consume disambiguation / prefix bytes by reading into a RegisteredAny message: aminoAny := &RegisteredAny{} if err = cdc.UnmarshalBinaryBare(bz, aminoAny); err != nil { return diff --git a/binary-encode.go b/binary-encode.go index 2d3b7816..54d02eb4 100644 --- a/binary-encode.go +++ b/binary-encode.go @@ -217,7 +217,6 @@ func (cdc *Codec) encodeReflectBinaryInterface(w io.Writer, iinfo *TypeInfo, rv return } } - // TODO: https://github.com/tendermint/go-amino/issues/267 aminoAny := &RegisteredAny{AminoPreOrDisfix: cinfo.Prefix.Bytes()} // Write actual concrete value. buf.Reset() From 3e1fd8948aca1a0433c87844916fe488d63930ac Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 5 Jun 2019 17:31:41 +0200 Subject: [PATCH 11/17] more extensive comment for `RegisteredAny` type Signed-off-by: Ismail Khoffi --- amino.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/amino.go b/amino.go index c1d2f51a..91beee2b 100644 --- a/amino.go +++ b/amino.go @@ -253,8 +253,23 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { // This is comparable to proto.Any but instead of a URL scheme there, we use amino's // disfix bytes instead. type RegisteredAny struct { + // Amino Prefix or Disfix (Prefix + Disamb) bytes derived from + // the name while registering the type. + // You can get this values by using the NameToDisfix helper + // method. + // In most common cases you won't need the disambiguation bytes. + // + // The prefix bytes should be 4 bytes. In case disambiguation bytes are + // necessary, this field will hold 7 Disfix bytes + // (3 disambiguation and 4 prefix bytes). AminoPreOrDisfix []byte - Value []byte + // Must be a valid serialized protocol buffer that was registered + // with a name resulting in the above specified amino pre-/disfix bytes. + // + // Users directly using protobuf in their application need to switch + // over the different prefix (disfix) bytes to know which concrete + // type they are receiving (or encoding). + Value []byte } // Panics if error. From 38f9ef749473fd68ea87e5f599b32680dfa7dc4e Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Fri, 7 Jun 2019 11:57:03 +0200 Subject: [PATCH 12/17] minor improvement to test code Signed-off-by: Ismail Khoffi --- tests/proto3/proto/compat.pb.go | 272 +++++++++++++++++++++++++---- tests/proto3/proto/compat.proto | 5 + tests/proto3/proto3_compat_test.go | 38 ++-- 3 files changed, 266 insertions(+), 49 deletions(-) diff --git a/tests/proto3/proto/compat.pb.go b/tests/proto3/proto/compat.pb.go index 1f09d5ec..30541924 100644 --- a/tests/proto3/proto/compat.pb.go +++ b/tests/proto3/proto/compat.pb.go @@ -758,6 +758,58 @@ func (m *AminoRegisteredAny) GetValue() []byte { return nil } +type SimpleMsg struct { + Message string `protobuf:"bytes,1,opt,name=Message,proto3" json:"Message,omitempty"` + Height int64 `protobuf:"varint,2,opt,name=Height,proto3" json:"Height,omitempty"` +} + +func (m *SimpleMsg) Reset() { *m = SimpleMsg{} } +func (m *SimpleMsg) String() string { return proto.CompactTextString(m) } +func (*SimpleMsg) ProtoMessage() {} +func (*SimpleMsg) Descriptor() ([]byte, []int) { + return fileDescriptor_bced3ff93dcaa7f8, []int{15} +} +func (m *SimpleMsg) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SimpleMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SimpleMsg.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SimpleMsg) XXX_Merge(src proto.Message) { + xxx_messageInfo_SimpleMsg.Merge(m, src) +} +func (m *SimpleMsg) XXX_Size() int { + return m.Size() +} +func (m *SimpleMsg) XXX_DiscardUnknown() { + xxx_messageInfo_SimpleMsg.DiscardUnknown(m) +} + +var xxx_messageInfo_SimpleMsg proto.InternalMessageInfo + +func (m *SimpleMsg) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + +func (m *SimpleMsg) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + func init() { proto.RegisterType((*TestInt32Varint)(nil), "proto3tests.TestInt32Varint") proto.RegisterType((*TestInt32Fixed)(nil), "proto3tests.TestInt32Fixed") @@ -774,45 +826,48 @@ func init() { proto.RegisterType((*PrimitivesStruct)(nil), "proto3tests.PrimitivesStruct") proto.RegisterType((*PrimitivesStructSl)(nil), "proto3tests.PrimitivesStructSl") proto.RegisterType((*AminoRegisteredAny)(nil), "proto3tests.AminoRegisteredAny") + proto.RegisterType((*SimpleMsg)(nil), "proto3tests.SimpleMsg") } func init() { proto.RegisterFile("compat.proto", fileDescriptor_bced3ff93dcaa7f8) } var fileDescriptor_bced3ff93dcaa7f8 = []byte{ - // 528 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x5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0xd9, 0x3f, 0x56, 0x78, 0x60, 0xda, 0x4e, 0x99, - 0xe8, 0x94, 0x60, 0xf9, 0x2c, 0xac, 0x35, 0xbc, 0xe6, 0x21, 0x71, 0x4a, 0x9f, 0x72, 0x7e, 0xa3, - 0xa8, 0x0c, 0x8f, 0x1a, 0x5e, 0xb3, 0x4a, 0xac, 0x40, 0x31, 0xec, 0x6b, 0xa7, 0xc2, 0xe0, 0x9f, - 0x36, 0x1a, 0x0e, 0x7f, 0x05, 0x74, 0xff, 0xd5, 0xc9, 0x1c, 0xbd, 0x85, 0xb2, 0xad, 0xa5, 0xf9, - 0xc4, 0x4a, 0xfb, 0xf9, 0x4e, 0x98, 0xf7, 0x37, 0x48, 0x41, 0xe3, 0x11, 0xa0, 0x5e, 0xc6, 0x72, - 0x4e, 0xe8, 0x8c, 0x49, 0x45, 0x05, 0x9d, 0xf4, 0xf2, 0x1b, 0xd4, 0x82, 0xc0, 0x74, 0x07, 0x82, - 0x7e, 0x13, 0x17, 0x4c, 0x4e, 0xd9, 0xb5, 0xb1, 0xb5, 0x4a, 0x1e, 0xf4, 0xf5, 0x67, 0x8d, 0xd2, - 0xf9, 0x92, 0x9a, 0x54, 0xaa, 0xc4, 0x8a, 0xf3, 0xf0, 0xd7, 0x2a, 0xf2, 0x6e, 0x57, 0x91, 0xf7, - 0x67, 0x15, 0x79, 0x3f, 0xd6, 0xd1, 0xde, 0xed, 0x3a, 0xda, 0xfb, 0xbd, 0x8e, 0xf6, 0xc6, 0x25, - 0xfb, 0xb0, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe9, 0xdc, 0x1c, 0x1e, 0xdd, 0x03, 0x00, 0x00, + // 560 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x53, 0x5f, 0x6b, 0x1a, 0x4f, + 0x14, 0x75, 0x7f, 0x1b, 0xf5, 0xe7, 0x55, 0xcc, 0x66,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 0x9d, 0x7a, 0xd3, 0x68, 0x55, 0xa8, 0x46, 0x72, 0xcb, 0xd9, + 0x8d, 0x40, 0xee, 0x1c, 0x36, 0x8d, 0x56, 0x8d, 0x66, 0xc0, 0xf6, 0xe0, 0x40, 0x3a, 0xe5, 0x58, + 0xff, 0xb4, 0x51, 0xf1, 0xc8, 0x10, 0xec, 0xfb, 0xb7, 0xf6, 0x17, 0xf6, 0x5b, 0x28, 0x67, 0x35, + 0x57, 0x4f, 0xac, 0x76, 0x9e, 0xef, 0x85, 0x79, 0x5f, 0x41, 0x73, 0x36, 0x99, 0x80, 0xdd, 0x8f, + 0x58, 0x9c, 0x50, 0x0c, 0x19, 0x17, 0x98, 0xe2, 0xac, 0x1f, 0xdf, 0xd8, 0x6d, 0xb0, 0x54, 0x77, + 0x94, 0xe2, 0xf7, 0xf4, 0x9c, 0xf1, 0x39, 0xbb, 0x56, 0xb6, 0xd6, 0xe8, 0x83, 0xbe, 0x7c, 0xd6, + 0x24, 0x58, 0xac, 0x50, 0xa5, 0x52, 0xa3, 0x19, 0x20, 0x1f, 0xa0, 0xe2, 0xb3, 0x68, 0xb9, 0xc0, + 0x21, 0x0f, 0xe5, 0x07, 0x35, 0x44, 0xce, 0x83, 0x10, 0xd5, 0x96, 0x0a, 0xcd, 0xa1, 0xf4, 0xea, + 0x2b, 0xb2, 0xf0, 0x52, 0xe8, 0x4c, 0x35, 0x3a, 0x73, 0x7e, 0xad, 0x5d, 0xe3, 0x76, 0xed, 0x1a, + 0x7f, 0xd6, 0xae, 0xf1, 0x63, 0xe3, 0x16, 0x6e, 0x37, 0x6e, 0xe1, 0xf7, 0xc6, 0x2d, 0x4c, 0x4b, + 0xd9, 0xbb, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xde, 0x50, 0xd0, 0x7a, 0x1c, 0x04, 0x00, 0x00, } func (m *TestInt32Varint) Marshal() (dAtA []byte, err error) { @@ -1246,6 +1301,35 @@ func (m *AminoRegisteredAny) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *SimpleMsg) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SimpleMsg) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Message) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintCompat(dAtA, i, uint64(len(m.Message))) + i += copy(dAtA[i:], m.Message) + } + if m.Height != 0 { + dAtA[i] = 0x10 + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.Height)) + } + return i, nil +} + func encodeVarintCompat(dAtA []byte, offset int, v uint64) int { for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -1473,6 +1557,22 @@ func (m *AminoRegisteredAny) Size() (n int) { return n } +func (m *SimpleMsg) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Message) + if l > 0 { + n += 1 + l + sovCompat(uint64(l)) + } + if m.Height != 0 { + n += 1 + sovCompat(uint64(m.Height)) + } + return n +} + func sovCompat(x uint64) (n int) { for { n++ @@ -2858,6 +2958,110 @@ func (m *AminoRegisteredAny) Unmarshal(dAtA []byte) error { } return nil } +func (m *SimpleMsg) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SimpleMsg: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SimpleMsg: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Message = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipCompat(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/tests/proto3/proto/compat.proto b/tests/proto3/proto/compat.proto index 46dbe0e6..6340775b 100644 --- a/tests/proto3/proto/compat.proto +++ b/tests/proto3/proto/compat.proto @@ -82,4 +82,9 @@ message AminoRegisteredAny { bytes AminoPreOrDisfix = 1; // Must be a valid serialized protocol buffer with the above specified amino pre-/disfix. bytes Value = 2; +} + +message SimpleMsg { + string Message = 1; + int64 Height = 2; } \ No newline at end of file diff --git a/tests/proto3/proto3_compat_test.go b/tests/proto3/proto3_compat_test.go index 8a53d39f..71892d2c 100644 --- a/tests/proto3/proto3_compat_test.go +++ b/tests/proto3/proto3_compat_test.go @@ -385,28 +385,28 @@ func TestTypeDefCompatibility(t *testing.T) { } } -// See if encoding of registered types matches the proto3 encoding -func TestRegisteredTypesCompatibility(t *testing.T) { - // TODO make this table driven tests using sub-tests - type Message interface{} +// See if encoding of a registered type matches the proto3 encoding +func TestRegisteredTypesCompatibilitySimple(t *testing.T) { + type message interface{} - type SimpleMsg struct { + const name = "simpleMsg" + type simpleMsg struct { Message string Height int } - type SimpleMsgUnregistered struct { + type simpleMsgUnregistered struct { Message string Height int } - var cdc = amino.NewCodec() - cdc.RegisterInterface((*Message)(nil), nil) - const name = "SimpleMsg" - cdc.RegisterConcrete(&SimpleMsg{}, name, nil) + cdc := amino.NewCodec() + cdc.RegisterInterface((*message)(nil), nil) + cdc.RegisterConcrete(&simpleMsg{}, name, nil) - bm := &SimpleMsg{Message: "ABC", Height: 100} - bmUnreg := &SimpleMsgUnregistered{bm.Message, bm.Height} + bm := &simpleMsg{Message: "ABC", Height: 100} + pbm := &p3.SimpleMsg{Message: "ABC", Height: 100} + bmUnreg := &simpleMsgUnregistered{bm.Message, bm.Height} bz, err := cdc.MarshalBinaryBare(bm) require.NoError(t, err) @@ -414,13 +414,21 @@ func TestRegisteredTypesCompatibility(t *testing.T) { bzUnreg, err := cdc.MarshalBinaryBare(bmUnreg) require.NoError(t, err) + // encoded bytes decodeable via protobuf: pAny := &p3.AminoRegisteredAny{} err = proto.Unmarshal(bz, pAny) - assert.NoError(t, err) + require.NoError(t, err) - // value matches proto encoding + // amino encoded value / prefix matches proto encoding assert.Equal(t, pAny.Value, bzUnreg) - _, prefix := amino.NameToDisfix(name) assert.Equal(t, pAny.AminoPreOrDisfix, prefix.Bytes()) + pbz, err := proto.Marshal(pbm) + require.NoError(t, err) + assert.Equal(t, pbz, bzUnreg) } + +// TODO other tests to consider: +// compatibility of: +// - TestCodecMarhsalBinaryBareRegisteredAndDisamb +// - repl_test ala TestMarshalAminoBinary? From c774dcb5ca337748f5ed3082a182e4e9f2bbe701 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Fri, 28 Jun 2019 15:58:33 +0200 Subject: [PATCH 13/17] WIP: add disambigaution test Signed-off-by: Ismail Khoffi --- amino.go | 24 +++++++++++++++++++++- binary-encode.go | 10 ++++----- tests/proto3/proto3_compat_test.go | 33 ++++++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/amino.go b/amino.go index 91beee2b..5aea8254 100644 --- a/amino.go +++ b/amino.go @@ -230,8 +230,20 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { // If registered concrete, prepend prefix bytes by wrapping // message in RegisteredAny: if info.Registered { + fmt.Println(info.InterfaceInfo.AlwaysDisambiguate) + fmt.Println(info.Name) + fmt.Println(info.AlwaysDisambiguate) + fmt.Println(len(info.Implementers[info.Prefix]) > 1) + // if one of the interfaces this concrete type implements + // has set the AlwaysDisambiguate flag, we need to disambiguate. + isDisamb, _ := shouldDisamb(cdc, info) + disfix := make([]byte, 0) + if isDisamb { + disfix = append([]byte{0x00}, info.Disamb.Bytes()...) + } + disfix = append(disfix, info.Prefix.Bytes()...) return MarshalBinaryBare(RegisteredAny{ - AminoPreOrDisfix: info.Prefix.Bytes(), + AminoPreOrDisfix: disfix, Value: bz, }) } @@ -239,6 +251,16 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { return bz, nil } +func shouldDisamb(cdc *Codec, info *TypeInfo) (bool, *TypeInfo) { + for _, iinfo := range cdc.interfaceInfos { + if info.PtrToType.Implements(iinfo.Type) && iinfo.AlwaysDisambiguate { + fmt.Println("DISAMB", iinfo.Name) + return true, iinfo + } + } + return false, nil +} + // TODO: extensively document this! // // This will be compatible to the following proto3 message: diff --git a/binary-encode.go b/binary-encode.go index 54d02eb4..c3b1ddd3 100644 --- a/binary-encode.go +++ b/binary-encode.go @@ -211,15 +211,13 @@ func (cdc *Codec) encodeReflectBinaryInterface(w io.Writer, iinfo *TypeInfo, rv } else if len(iinfo.Implementers[cinfo.Prefix]) > 1 { needDisamb = true } + disfix := make([]byte, 0) if needDisamb { - _, err = buf.Write(append([]byte{0x00}, cinfo.Disamb[:]...)) - if err != nil { - return - } + disfix = append([]byte{0x00}, cinfo.Disamb[:]...) } - aminoAny := &RegisteredAny{AminoPreOrDisfix: cinfo.Prefix.Bytes()} + disfix = append(disfix, cinfo.Prefix.Bytes()...) + aminoAny := &RegisteredAny{AminoPreOrDisfix: disfix} // Write actual concrete value. - buf.Reset() err = cdc.encodeReflectBinary(buf, cinfo, crv, fopts, true) if err != nil { return diff --git a/tests/proto3/proto3_compat_test.go b/tests/proto3/proto3_compat_test.go index 71892d2c..b15fa8fd 100644 --- a/tests/proto3/proto3_compat_test.go +++ b/tests/proto3/proto3_compat_test.go @@ -428,7 +428,32 @@ func TestRegisteredTypesCompatibilitySimple(t *testing.T) { assert.Equal(t, pbz, bzUnreg) } -// TODO other tests to consider: -// compatibility of: -// - TestCodecMarhsalBinaryBareRegisteredAndDisamb -// - repl_test ala TestMarshalAminoBinary? +func TestDisamExample(t *testing.T) { + const name = "interfaceFields" + cdc := amino.NewCodec() + cdc.RegisterInterface((*tests.Interface1)(nil), &amino.InterfaceOptions{ + AlwaysDisambiguate: true, + }) + cdc.RegisterConcrete((*tests.InterfaceFieldsStruct)(nil), name, nil) + + i1 := &tests.InterfaceFieldsStruct{F1: new(tests.InterfaceFieldsStruct), F2: nil} + bz, err := cdc.MarshalBinaryBare(i1) + + t.Logf("%#v", bz) + + pAny := &p3.AminoRegisteredAny{} + err = proto.Unmarshal(bz, pAny) + require.NoError(t, err) + + disamb, prefix := amino.NameToDisfix(name) + t.Logf("%#v", disamb[:]) + disfix := bytes.Join([][]byte{disamb[:], prefix[:]}, []byte("")) + assert.Equal(t, disfix, pAny.AminoPreOrDisfix) + + i2 := new(tests.InterfaceFieldsStruct) + err = cdc.UnmarshalBinaryBare(bz, i2) + + assert.NoError(t, err) + require.Equal(t, i1, i2, "i1 and i2 should be the same after decoding") + +} From 035b43f8d79449aa6e529c2bf76a883e8ec95b9b Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 7 Aug 2019 10:37:27 +0200 Subject: [PATCH 14/17] WIP: committing feature complete code with debug output & a bunch of comments & todos for @marbar3778 to catch up Signed-off-by: Ismail Khoffi --- amino.go | 29 +--- binary-encode.go | 2 + reflect_test.go | 2 +- tests/proto3/proto/compat.pb.go | 251 ++++++++++++++++++++++++----- tests/proto3/proto/compat.proto | 4 + tests/proto3/proto3_compat_test.go | 41 ++++- 6 files changed, 260 insertions(+), 69 deletions(-) diff --git a/amino.go b/amino.go index 5aea8254..a3deab60 100644 --- a/amino.go +++ b/amino.go @@ -230,37 +230,16 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { // If registered concrete, prepend prefix bytes by wrapping // message in RegisteredAny: if info.Registered { - fmt.Println(info.InterfaceInfo.AlwaysDisambiguate) - fmt.Println(info.Name) - fmt.Println(info.AlwaysDisambiguate) - fmt.Println(len(info.Implementers[info.Prefix]) > 1) - // if one of the interfaces this concrete type implements - // has set the AlwaysDisambiguate flag, we need to disambiguate. - isDisamb, _ := shouldDisamb(cdc, info) - disfix := make([]byte, 0) - if isDisamb { - disfix = append([]byte{0x00}, info.Disamb.Bytes()...) - } - disfix = append(disfix, info.Prefix.Bytes()...) - return MarshalBinaryBare(RegisteredAny{ - AminoPreOrDisfix: disfix, + rAny := RegisteredAny{ + AminoPreOrDisfix: info.Prefix.Bytes(), Value: bz, - }) + } + return MarshalBinaryBare(rAny) } return bz, nil } -func shouldDisamb(cdc *Codec, info *TypeInfo) (bool, *TypeInfo) { - for _, iinfo := range cdc.interfaceInfos { - if info.PtrToType.Implements(iinfo.Type) && iinfo.AlwaysDisambiguate { - fmt.Println("DISAMB", iinfo.Name) - return true, iinfo - } - } - return false, nil -} - // TODO: extensively document this! // // This will be compatible to the following proto3 message: diff --git a/binary-encode.go b/binary-encode.go index c3b1ddd3..9505eea8 100644 --- a/binary-encode.go +++ b/binary-encode.go @@ -213,10 +213,12 @@ func (cdc *Codec) encodeReflectBinaryInterface(w io.Writer, iinfo *TypeInfo, rv } disfix := make([]byte, 0) if needDisamb { + // 0x00 indicates that these are disfix bytes disfix = append([]byte{0x00}, cinfo.Disamb[:]...) } disfix = append(disfix, cinfo.Prefix.Bytes()...) aminoAny := &RegisteredAny{AminoPreOrDisfix: disfix} + fmt.Printf("disfix = %#v\n", disfix) // Write actual concrete value. err = cdc.encodeReflectBinary(buf, cinfo, crv, fopts, true) if err != nil { diff --git a/reflect_test.go b/reflect_test.go index c3cf6572..3c957ded 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -192,7 +192,7 @@ func TestCodecMarhsalBinaryBareRegisteredAndDisamb(t *testing.T) { bz, err := cdc.MarshalBinaryBare(struct{ tests.Interface1 }{tests.Concrete1{}}) assert.NoError(t, err, "correctly registered") - assert.Equal(t, []byte{0xa, 0x6, 0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz, + assert.Equal(t, []byte{0xa, 0xa, 0xa, 0x8, 0x0, 0x12, 0xb5, 0x86, 0xe3, 0xda, 0xb8, 0x33}, bz, "prefix bytes did not match") } diff --git a/tests/proto3/proto/compat.pb.go b/tests/proto3/proto/compat.pb.go index 30541924..ebe70218 100644 --- a/tests/proto3/proto/compat.pb.go +++ b/tests/proto3/proto/compat.pb.go @@ -758,6 +758,50 @@ func (m *AminoRegisteredAny) GetValue() []byte { return nil } +type EmbeddedRegisteredAny struct { + F1 *AminoRegisteredAny `protobuf:"bytes,1,opt,name=F1,proto3" json:"F1,omitempty"` +} + +func (m *EmbeddedRegisteredAny) Reset() { *m = EmbeddedRegisteredAny{} } +func (m *EmbeddedRegisteredAny) String() string { return proto.CompactTextString(m) } +func (*EmbeddedRegisteredAny) ProtoMessage() {} +func (*EmbeddedRegisteredAny) Descriptor() ([]byte, []int) { + return fileDescriptor_bced3ff93dcaa7f8, []int{15} +} +func (m *EmbeddedRegisteredAny) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EmbeddedRegisteredAny) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EmbeddedRegisteredAny.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EmbeddedRegisteredAny) XXX_Merge(src proto.Message) { + xxx_messageInfo_EmbeddedRegisteredAny.Merge(m, src) +} +func (m *EmbeddedRegisteredAny) XXX_Size() int { + return m.Size() +} +func (m *EmbeddedRegisteredAny) XXX_DiscardUnknown() { + xxx_messageInfo_EmbeddedRegisteredAny.DiscardUnknown(m) +} + +var xxx_messageInfo_EmbeddedRegisteredAny proto.InternalMessageInfo + +func (m *EmbeddedRegisteredAny) GetF1() *AminoRegisteredAny { + if m != nil { + return m.F1 + } + return nil +} + type SimpleMsg struct { Message string `protobuf:"bytes,1,opt,name=Message,proto3" json:"Message,omitempty"` Height int64 `protobuf:"varint,2,opt,name=Height,proto3" json:"Height,omitempty"` @@ -767,7 +811,7 @@ func (m *SimpleMsg) Reset() { *m = SimpleMsg{} } func (m *SimpleMsg) String() string { return proto.CompactTextString(m) } func (*SimpleMsg) ProtoMessage() {} func (*SimpleMsg) Descriptor() ([]byte, []int) { - return fileDescriptor_bced3ff93dcaa7f8, []int{15} + return fileDescriptor_bced3ff93dcaa7f8, []int{16} } func (m *SimpleMsg) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -826,48 +870,51 @@ func init() { proto.RegisterType((*PrimitivesStruct)(nil), "proto3tests.PrimitivesStruct") proto.RegisterType((*PrimitivesStructSl)(nil), "proto3tests.PrimitivesStructSl") proto.RegisterType((*AminoRegisteredAny)(nil), "proto3tests.AminoRegisteredAny") + proto.RegisterType((*EmbeddedRegisteredAny)(nil), "proto3tests.EmbeddedRegisteredAny") proto.RegisterType((*SimpleMsg)(nil), "proto3tests.SimpleMsg") } func init() { proto.RegisterFile("compat.proto", fileDescriptor_bced3ff93dcaa7f8) } var fileDescriptor_bced3ff93dcaa7f8 = []byte{ - // 560 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x53, 0x5f, 0x6b, 0x1a, 0x4f, - 0x14, 0x75, 0x7f, 0x1b, 0xf5, 0xe7, 0x55, 0xcc, 0x66, 0x29, 0x65, 0xb1, 0x74, 0x6b, 0xe7, 0xa1, - 0x15, 0x49, 0x37, 0xa0, 0xc1, 0x16, 0x4a, 0x0b, 0x86, 0xf4, 0x8f, 0x50, 0xa9, 0xcc, 0x8a, 0xef, - 0x6b, 0xbc, 0x6e, 0x06, 0xdc, 0x5d, 0xd9, 0x19, 0x43, 0xf2, 0x2d, 0xfa, 0x61, 0xfa, 0x21, 0xfa, - 0x98, 0xc7, 0x3e, 0x16, 0xfd, 0x22, 0x65, 0x66, 0x67, 0x35, 0x26, 0x81, 0x3e, 0x79, 0xcf, 0xbd, - 0xe7, 0xdc, 0x99, 0x39, 0xc7, 0x85, 0xda, 0x45, 0x12, 0x2d, 0x03, 0xe1, 0x2d, 0xd3, 0x44, 0x24, - 0x76, 0x55, 0xfd, 0x74, 0x05, 0x72, 0xc1, 0x1b, 0x2f, 0xc2, 0x24, 0x09, 0x17, 0x78, 0xa2, 0x7a, - 0xd3, 0xd5, 0xfc, 0x44, 0xb0, 0x08, 0xb9, 0x08, 0xa2, 0x65, 0xc6, 0x26, 0xaf, 0xe1, 0x70, 0x8c, - 0x5c, 0x0c, 0x62, 0xd1, 0xed, 0x4c, 0x82, 0x94, 0xc5, 0xc2, 0x7e, 0x02, 0x45, 0x05, 0x1d, 0xa3, - 0x69, 0xb4, 0x8e, 0x68, 0x06, 0x48, 0x1b, 0xea, 0x5b, 0xe2, 0x67, 0x76, 0x8d, 0x33, 0xdb, 0x81, - 0xb2, 0x2a, 0x34, 0xb3,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, 0xd6, 0xae, 0xf1, 0x63, 0xe3, 0x16, 0x6e, 0x37, 0x6e, 0xe1, 0xf7, 0xc6, 0x2d, 0x4c, 0x4b, - 0xd9, 0xbb, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xde, 0x50, 0xd0, 0x7a, 0x1c, 0x04, 0x00, 0x00, + // 584 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x53, 0xc1, 0x6e, 0xda, 0x40, + 0x10, 0x8d, 0xe3, 0x84, 0x94, 0x09, 0x4a, 0x1c, 0xab, 0xad, 0xac, 0x54, 0x75, 0xd2, 0x3d, 0xb4, + 0x08, 0xa5, 0x46, 0x81, 0x88, 0x56, 0xaa, 0x5a, 0x89, 0x28, 0xa5, 0x41, 0x2a, 0x2a, 0x5a, 0x23, + 0xee, 0x26, 0x0c, 0xce, 0x4a, 0xd8, 0x46, 0xde, 0x25, 0x4a, 0xfe, 0xa2, 0x1f, 0xd3, 0x8f, 0xe8, + 0x31, 0xc7, 0x1e, 0x2b, 0xf8, 0x91, 0x6a, 0xd7, 0x6b, 0x08, 0x21, 0x52, 0x4f, 0xcc, 0x9b, 0x79, + 0x33, 0xb3, 0x7e, 0x6f, 0x80, 0xd2, 0x55, 0x12, 0x4d, 0x02, 0xe1, 0x4d, 0xd2, 0x44, 0x24, 0xf6, + 0xae, 0xfa, 0xa9, 0x0b, 0xe4, 0x82, 0x1f, 0x1e, 0x85, 0x49, 0x12, 0x8e, 0xb1, 0xaa, 0x72, 0x83, + 0xe9, 0xa8, 0x2a, 0x58, 0x84, 0x5c, 0x04, 0xd1, 0x24, 0x63, 0x93, 0x77, 0xb0, 0xdf, 0x43, 0x2e, + 0xda, 0xb1, 0xa8, 0xd7, 0xfa, 0x41, 0xca, 0x62, 0x61, 0x3f, 0x87, 0x6d, 0x05, 0x1d, 0xe3, 0xd8, + 0x28, 0x1f, 0xd0, 0x0c, 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8a, 0x3e, 0x8b, 0x26, 0x63, 0xec, 0xf0, 0x50, 0xfe, 0x35, 0x3b, 0xc8, 0x79, 0x10, + 0xa2, 0x1a, 0x51, 0xa4, 0x39, 0x94, 0xaa, 0x5f, 0x22, 0x0b, 0xaf, 0x85, 0xbe, 0x0e, 0x8d, 0xce, + 0x9d, 0xdf, 0x33, 0xd7, 0xb8, 0x9f, 0xb9, 0xc6, 0xdf, 0x99, 0x6b, 0xfc, 0x9c, 0xbb, 0x1b, 0xf7, + 0x73, 0x77, 0xe3, 0xcf, 0xdc, 0xdd, 0x18, 0x14, 0xb2, 0xe5, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, + 0xc1, 0xfc, 0x5f, 0x2c, 0x66, 0x04, 0x00, 0x00, } func (m *TestInt32Varint) Marshal() (dAtA []byte, err error) { @@ -1301,6 +1348,34 @@ func (m *AminoRegisteredAny) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *EmbeddedRegisteredAny) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EmbeddedRegisteredAny) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.F1 != nil { + dAtA[i] = 0xa + i++ + i = encodeVarintCompat(dAtA, i, uint64(m.F1.Size())) + n6, err := m.F1.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n6 + } + return i, nil +} + func (m *SimpleMsg) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1557,6 +1632,19 @@ func (m *AminoRegisteredAny) Size() (n int) { return n } +func (m *EmbeddedRegisteredAny) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.F1 != nil { + l = m.F1.Size() + n += 1 + l + sovCompat(uint64(l)) + } + return n +} + func (m *SimpleMsg) Size() (n int) { if m == nil { return 0 @@ -2958,6 +3046,95 @@ func (m *AminoRegisteredAny) Unmarshal(dAtA []byte) error { } return nil } +func (m *EmbeddedRegisteredAny) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EmbeddedRegisteredAny: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EmbeddedRegisteredAny: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field F1", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCompat + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCompat + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCompat + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.F1 == nil { + m.F1 = &AminoRegisteredAny{} + } + if err := m.F1.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCompat(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthCompat + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *SimpleMsg) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/tests/proto3/proto/compat.proto b/tests/proto3/proto/compat.proto index 6340775b..c402d86b 100644 --- a/tests/proto3/proto/compat.proto +++ b/tests/proto3/proto/compat.proto @@ -84,6 +84,10 @@ message AminoRegisteredAny { bytes Value = 2; } +message EmbeddedRegisteredAny { + AminoRegisteredAny F1 = 1; +} + message SimpleMsg { string Message = 1; int64 Height = 2; diff --git a/tests/proto3/proto3_compat_test.go b/tests/proto3/proto3_compat_test.go index b15fa8fd..5bacb502 100644 --- a/tests/proto3/proto3_compat_test.go +++ b/tests/proto3/proto3_compat_test.go @@ -428,7 +428,7 @@ func TestRegisteredTypesCompatibilitySimple(t *testing.T) { assert.Equal(t, pbz, bzUnreg) } -func TestDisamExample(t *testing.T) { +func TestDisambExample(t *testing.T) { const name = "interfaceFields" cdc := amino.NewCodec() cdc.RegisterInterface((*tests.Interface1)(nil), &amino.InterfaceOptions{ @@ -438,7 +438,13 @@ func TestDisamExample(t *testing.T) { i1 := &tests.InterfaceFieldsStruct{F1: new(tests.InterfaceFieldsStruct), F2: nil} bz, err := cdc.MarshalBinaryBare(i1) + type fieldStructUnreg struct { + F1 tests.Interface1 + } + concrete1 := &fieldStructUnreg{F1: new(tests.InterfaceFieldsStruct)} + bc, err := cdc.MarshalBinaryBare(concrete1) + require.NoError(t, err) t.Logf("%#v", bz) pAny := &p3.AminoRegisteredAny{} @@ -447,13 +453,36 @@ func TestDisamExample(t *testing.T) { disamb, prefix := amino.NameToDisfix(name) t.Logf("%#v", disamb[:]) - disfix := bytes.Join([][]byte{disamb[:], prefix[:]}, []byte("")) - assert.Equal(t, disfix, pAny.AminoPreOrDisfix) + // + //t.Logf("%v",disfix[:]) + // TODO: apparently the disamb bytes are only used for the fields + // and not for the outer interface. Not sure why this makes sense. + // assert.Equal(t, disfix, pAny.AminoPreOrDisfix) + assert.Equal(t, prefix.Bytes(), pAny.AminoPreOrDisfix) + assert.Equal(t, bc, pAny.Value) + + embeddedAny := &p3.EmbeddedRegisteredAny{} + err = proto.Unmarshal(pAny.Value, embeddedAny) + t.Logf("embeddedAny = %#v", embeddedAny) + + require.NoError(t, err) + pAnyInner := &p3.AminoRegisteredAny{} + + t.Logf("pAny.Value = %#v", pAny.Value) + err = proto.Unmarshal(pAny.Value, pAnyInner) + require.NoError(t, err) + + //disfix := bytes.Join([][]byte{disamb[:], prefix[:]}, []byte("")) + //assert.Equal(t, disfix, pAnyInner.AminoPreOrDisfix) + t.Logf("aminoInner %#v", pAnyInner.AminoPreOrDisfix) + + aminoAnyInner := &amino.RegisteredAny{} + err = cdc.UnmarshalBinaryBare(pAny.Value, aminoAnyInner) + require.NoError(t, err) + //assert.Equal(t, disfix, aminoAnyInner.AminoPreOrDisfix) i2 := new(tests.InterfaceFieldsStruct) err = cdc.UnmarshalBinaryBare(bz, i2) - - assert.NoError(t, err) + require.NoError(t, err) require.Equal(t, i1, i2, "i1 and i2 should be the same after decoding") - } From 63cc0133636150436f121a21e3e64143f2ead611 Mon Sep 17 00:00:00 2001 From: Tess Rinearson Date: Mon, 11 Nov 2019 15:19:50 +0100 Subject: [PATCH 15/17] remove debugging line --- binary-encode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binary-encode.go b/binary-encode.go index de1b1f18..61ac529b 100644 --- a/binary-encode.go +++ b/binary-encode.go @@ -252,7 +252,7 @@ func (cdc *Codec) encodeReflectBinaryInterface(w io.Writer, iinfo *TypeInfo, rv } disfix = append(disfix, cinfo.Prefix.Bytes()...) aminoAny := &RegisteredAny{AminoPreOrDisfix: disfix} - fmt.Printf("disfix = %#v\n", disfix) + // Write actual concrete value. err = cdc.encodeReflectBinary(buf, cinfo, crv, fopts, true) if err != nil { From 2e366c2cb6c28d1e4804c1b97a0d1d267ced0f91 Mon Sep 17 00:00:00 2001 From: Tess Rinearson Date: Tue, 12 Nov 2019 13:25:00 +0100 Subject: [PATCH 16/17] tidy go.mod --- go.sum | 7 ------- 1 file changed, 7 deletions(-) diff --git a/go.sum b/go.sum index 9696f1ec..6de9d1c7 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk= -github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= @@ -20,12 +18,7 @@ github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= From 96625993f14189f91441d282b8d2edce16cc4766 Mon Sep 17 00:00:00 2001 From: Tess Rinearson Date: Tue, 12 Nov 2019 13:28:36 +0100 Subject: [PATCH 17/17] golint fix --- amino.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amino.go b/amino.go index cb1a34cd..4f33d681 100644 --- a/amino.go +++ b/amino.go @@ -401,7 +401,7 @@ func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}) error { // If registered concrete, consume and verify prefix bytes. if info.Registered { aminoAny := &RegisteredAny{} - if err := cdc.UnmarshalBinaryBare(bz, aminoAny); err != nil { + if err = cdc.UnmarshalBinaryBare(bz, aminoAny); err != nil { return err } pb := info.Prefix.Bytes()