diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml index 2d529690..c9549323 100644 --- a/.github/workflows/ci-workflow.yml +++ b/.github/workflows/ci-workflow.yml @@ -30,5 +30,6 @@ jobs: - name: Protoc version run: PATH=$HOME/bin:$PATH protoc --version - - name: Build server all + - name: Build server allgo version + run: PATH=$HOME/bin:$PATH make buildserverall diff --git a/.gitignore b/.gitignore index 82f4de4a..9d9124c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ ._* *.js *.js.map +.idea # Conformance test output and transient files. conformance/failing_tests.txt \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ac943637..b62c6194 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- [#115](https://github.com/cosmos/gogoproto/pull/115) Move any type from `cosmos-sdk/codec/types` to `types/any`. + ## [v1.4.11](https://github.com/cosmos/gogoproto/releases/tag/v1.4.10) - 2023-05-11 ### Improvements diff --git a/Makefile b/Makefile index b4bdcddb..639f4425 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,7 @@ regenerate: install make -C test/issue620 regenerate make -C test/protobuffer regenerate make -C test/issue630 regenerate + make -C test/test regenerate make gofmt diff --git a/go.mod b/go.mod index 66b6e8cf..07f6a84a 100644 --- a/go.mod +++ b/go.mod @@ -4,17 +4,26 @@ go 1.19 require ( github.com/google/go-cmp v0.6.0 - golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb - google.golang.org/grpc v1.62.1 + github.com/stretchr/testify v1.8.4 + github.com/tendermint/go-amino v0.16.0 + golang.org/x/exp v0.0.0-20231006140011-7918f672742d + google.golang.org/grpc v1.61.1 google.golang.org/protobuf v1.32.0 ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/google/gofuzz v1.2.0 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect golang.org/x/net v0.20.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) // API changed in an incompatible way diff --git a/go.sum b/go.sum index 1677b3c0..b7d41469 100644 --- a/go.sum +++ b/go.sum @@ -1,23 +1,59 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +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/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= -golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= +github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s= -google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= -google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 h1:/jFB8jK5R3Sq3i/lmeZO0cATSzFfZaJq1J2Euan3XKU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0/go.mod h1:FUoWkonphQm3RhTS+kOEhF8h0iDpm4tdXolVCeZ9KKA= +google.golang.org/grpc v1.61.1 h1:kLAiWrZs7YeDM6MumDe7m3y4aM6wacLzM1Y/wiLP9XY= +google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/test/test/Makefile b/test/test/Makefile new file mode 100644 index 00000000..dc15c6b8 --- /dev/null +++ b/test/test/Makefile @@ -0,0 +1,38 @@ +# Protocol Buffers for Go with Gadgets +# +# Copyright (c) 2013, The GoGo Authors. All rights reserved. +# http://github.com/cosmos/gogoproto +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +regenerate: + cd .. && \ + protoc-min-version --version="3.0.0" --proto_path=../:../protobuf/:. --gogo_out=\ + Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types/any,\ + Mgoogle/protobuf/duration.proto=github.com/cosmos/gogoproto/types,\ + Mgoogle/protobuf/struct.proto=github.com/cosmos/gogoproto/types,\ + Mgoogle/protobuf/timestamp.proto=github.com/cosmos/gogoproto/types,\ + Mgoogle/protobuf/wrappers.proto=github.com/cosmos/gogoproto/types,\ + Mgoogle/protobuf/field_mask.proto=github.com/cosmos/gogoproto/types\ + :../types/any test/test.proto \ No newline at end of file diff --git a/test/test/test.proto b/test/test/test.proto new file mode 100644 index 00000000..02544fff --- /dev/null +++ b/test/test/test.proto @@ -0,0 +1,51 @@ +syntax = "proto3"; +package test; + +import "gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; + +option (gogoproto.marshaler_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.sizer_all) = true; + +message Dog { + string size = 1; + string name = 2; +} + +message Cat { + string moniker = 1; + int32 lives = 2; +} + +message Bird { + string species = 1; + int32 color = 2; +} + +message HasAnimal { + google.protobuf.Any animal = 1; + int64 x = 2; +} + +message HasHasAnimal { + google.protobuf.Any has_animal = 1; +} + +message HasHasHasAnimal { + google.protobuf.Any has_has_animal = 1; +} + +// bad MultiSignature with extra fields +message BadMultiSignature { + option (gogoproto.goproto_unrecognized) = true; + repeated bytes signatures = 1; + bytes malicious_field = 5; +} + +message TableModel { + uint64 id = 1; + string name = 2; + uint64 number = 3; + bytes metadata = 4; +} diff --git a/types/any/any.pb.go b/types/any/any.pb.go new file mode 100644 index 00000000..8dc80f39 --- /dev/null +++ b/types/any/any.pb.go @@ -0,0 +1,535 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: google/protobuf/any.proto + +package types + +import ( + bytes "bytes" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +func (m *Any) Reset() { *m = Any{} } +func (*Any) ProtoMessage() {} +func (*Any) Descriptor() ([]byte, []int) { + return fileDescriptor_b53526c13ae22eb4, []int{0} +} +func (*Any) XXX_WellKnownType() string { return "Any" } +func (m *Any) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Any) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Any.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Any) XXX_Merge(src proto.Message) { + xxx_messageInfo_Any.Merge(m, src) +} +func (m *Any) XXX_Size() int { + return m.Size() +} +func (m *Any) XXX_DiscardUnknown() { + xxx_messageInfo_Any.DiscardUnknown(m) +} + +var xxx_messageInfo_Any proto.InternalMessageInfo + +func (m *Any) GetTypeUrl() string { + if m != nil { + return m.TypeUrl + } + return "" +} + +func (m *Any) GetValue() []byte { + if m != nil { + return m.Value + } + return nil +} + +func (*Any) XXX_MessageName() string { + return "google.protobuf.Any" +} +func init() { +} + +func init() { proto.RegisterFile("google/protobuf/any.proto", fileDescriptor_b53526c13ae22eb4) } + +var fileDescriptor_b53526c13ae22eb4 = []byte{ + // 248 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4c, 0xcf, 0xcf, 0x4f, + 0xcf, 0x49, 0xd5, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0x4f, 0xcc, 0xab, 0xd4, + 0x03, 0x73, 0x84, 0xf8, 0x21, 0x52, 0x7a, 0x30, 0x29, 0x29, 0x91, 0xf4, 0xfc, 0xf4, 0x7c, 0x30, + 0x4f, 0x1f, 0xc4, 0x82, 0x48, 0x28, 0x79, 0x70, 0x31, 0x3b, 0xe6, 0x55, 0x0a, 0x49, 0x72, 0x71, + 0x94, 0x54, 0x16, 0xa4, 0xc6, 0x97, 0x16, 0xe5, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xb1, + 0x83, 0xf8, 0xa1, 0x45, 0x39, 0x42, 0x22, 0x5c, 0xac, 0x65, 0x89, 0x39, 0xa5, 0xa9, 0x12, 0x4c, + 0x0a, 0x8c, 0x1a, 0x3c, 0x41, 0x10, 0x8e, 0x95, 0xc0, 0x8c, 0x05, 0xf2, 0x0c, 0x1b, 0x16, 0xc8, + 0x33, 0x7c, 0x58, 0x28, 0xcf, 0xd0, 0x70, 0x47, 0x81, 0xc1, 0xa9, 0x99, 0xf1, 0xc6, 0x43, 0x39, + 0x86, 0x0f, 0x0f, 0xe5, 0x18, 0x7f, 0x3c, 0x94, 0x63, 0x6c, 0x78, 0x24, 0xc7, 0xb8, 0xe2, 0x91, + 0x1c, 0xe3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0xf8, 0xe2, + 0x91, 0x1c, 0xc3, 0x07, 0x90, 0xf8, 0x63, 0x39, 0xc6, 0x03, 0x8f, 0xe5, 0x18, 0x4e, 0x3c, 0x96, + 0x63, 0xe4, 0x12, 0x4e, 0xce, 0xcf, 0xd5, 0x43, 0x73, 0xab, 0x13, 0x87, 0x63, 0x5e, 0x65, 0x00, + 0x88, 0x13, 0xc0, 0x18, 0xc5, 0x0a, 0x72, 0x48, 0xf1, 0x22, 0x26, 0x66, 0xf7, 0x00, 0xa7, 0x55, + 0x4c, 0x72, 0xee, 0x10, 0xa5, 0x01, 0x50, 0xa5, 0x7a, 0xe1, 0xa9, 0x39, 0x39, 0xde, 0x79, 0xf9, + 0xe5, 0x79, 0x21, 0x20, 0x65, 0x49, 0x6c, 0x60, 0x33, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x4d, 0x91, 0x00, 0xa0, 0x1a, 0x01, 0x00, 0x00, +} + +func (this *Any) Compare(that interface{}) int { + if that == nil { + if this == nil { + return 0 + } + return 1 + } + + that1, ok := that.(*Any) + if !ok { + that2, ok := that.(Any) + if ok { + that1 = &that2 + } else { + return 1 + } + } + if that1 == nil { + if this == nil { + return 0 + } + return 1 + } else if this == nil { + return -1 + } + if this.TypeUrl != that1.TypeUrl { + if this.TypeUrl < that1.TypeUrl { + return -1 + } + return 1 + } + if c := bytes.Compare(this.Value, that1.Value); c != 0 { + return c + } + if c := bytes.Compare(this.XXX_unrecognized, that1.XXX_unrecognized); c != 0 { + return c + } + return 0 +} +func (this *Any) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Any) + if !ok { + that2, ok := that.(Any) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.TypeUrl != that1.TypeUrl { + return false + } + if !bytes.Equal(this.Value, that1.Value) { + return false + } + if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { + return false + } + return true +} +func (m *Any) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Any) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Any) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintAny(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x12 + } + if len(m.TypeUrl) > 0 { + i -= len(m.TypeUrl) + copy(dAtA[i:], m.TypeUrl) + i = encodeVarintAny(dAtA, i, uint64(len(m.TypeUrl))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintAny(dAtA []byte, offset int, v uint64) int { + offset -= sovAny(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func NewPopulatedAny(r randyAny, easy bool) *Any { + this := &Any{} + this.TypeUrl = string(randStringAny(r)) + v1 := r.Intn(100) + this.Value = make([]byte, v1) + for i := 0; i < v1; i++ { + this.Value[i] = byte(r.Intn(256)) + } + if !easy && r.Intn(10) != 0 { + this.XXX_unrecognized = randUnrecognizedAny(r, 3) + } + return this +} + +type randyAny interface { + Float32() float32 + Float64() float64 + Int63() int64 + Int31() int32 + Uint32() uint32 + Intn(n int) int +} + +func randUTF8RuneAny(r randyAny) rune { + ru := r.Intn(62) + if ru < 10 { + return rune(ru + 48) + } else if ru < 36 { + return rune(ru + 55) + } + return rune(ru + 61) +} +func randStringAny(r randyAny) string { + v2 := r.Intn(100) + tmps := make([]rune, v2) + for i := 0; i < v2; i++ { + tmps[i] = randUTF8RuneAny(r) + } + return string(tmps) +} +func randUnrecognizedAny(r randyAny, maxFieldNumber int) (dAtA []byte) { + l := r.Intn(5) + for i := 0; i < l; i++ { + wire := r.Intn(4) + if wire == 3 { + wire = 5 + } + fieldNumber := maxFieldNumber + r.Intn(100) + dAtA = randFieldAny(dAtA, r, fieldNumber, wire) + } + return dAtA +} +func randFieldAny(dAtA []byte, r randyAny, fieldNumber int, wire int) []byte { + key := uint32(fieldNumber)<<3 | uint32(wire) + switch wire { + case 0: + dAtA = encodeVarintPopulateAny(dAtA, uint64(key)) + v3 := r.Int63() + if r.Intn(2) == 0 { + v3 *= -1 + } + dAtA = encodeVarintPopulateAny(dAtA, uint64(v3)) + case 1: + dAtA = encodeVarintPopulateAny(dAtA, uint64(key)) + dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) + case 2: + dAtA = encodeVarintPopulateAny(dAtA, uint64(key)) + ll := r.Intn(100) + dAtA = encodeVarintPopulateAny(dAtA, uint64(ll)) + for j := 0; j < ll; j++ { + dAtA = append(dAtA, byte(r.Intn(256))) + } + default: + dAtA = encodeVarintPopulateAny(dAtA, uint64(key)) + dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) + } + return dAtA +} +func encodeVarintPopulateAny(dAtA []byte, v uint64) []byte { + for v >= 1<<7 { + dAtA = append(dAtA, uint8(uint64(v)&0x7f|0x80)) + v >>= 7 + } + dAtA = append(dAtA, uint8(v)) + return dAtA +} +func (m *Any) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.TypeUrl) + if l > 0 { + n += 1 + l + sovAny(uint64(l)) + } + l = len(m.Value) + if l > 0 { + n += 1 + l + sovAny(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func sovAny(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAny(x uint64) (n int) { + return sovAny(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Any) 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 ErrIntOverflowAny + } + 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: Any: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Any: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TypeUrl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAny + } + 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 ErrInvalidLengthAny + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAny + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TypeUrl = string(dAtA[iNdEx:postIndex]) + 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 ErrIntOverflowAny + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAny + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAny + } + 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 := skipAny(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAny + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAny(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAny + } + 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, ErrIntOverflowAny + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAny + } + 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, ErrInvalidLengthAny + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAny + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAny + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAny = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAny = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAny = fmt.Errorf("proto: unexpected end of group") +) diff --git a/types/any/any_with_cache.go b/types/any/any_with_cache.go new file mode 100644 index 00000000..c050250f --- /dev/null +++ b/types/any/any_with_cache.go @@ -0,0 +1,156 @@ +package types + +import ( + "errors" + fmt "fmt" + + "github.com/cosmos/gogoproto/proto" + protov2 "google.golang.org/protobuf/proto" +) + +type Any struct { + // A URL/resource name that uniquely identifies the type of the serialized + // protocol buffer message. This string must contain at least + // one "/" character. The last segment of the URL's path must represent + // the fully qualified name of the type (as in + // `path/google.protobuf.Duration`). The name should be in a canonical form + // (e.g., leading "." is not accepted). + // + // In practice, teams usually precompile into the binary all types that they + // expect it to use in the context of Any. However, for URLs which use the + // scheme `http`, `https`, or no scheme, one can optionally set up a type + // server that maps type URLs to message definitions as follows: + // + // * If no scheme is provided, `https` is assumed. + // * An HTTP GET on the URL must yield a [google.protobuf.Type][] + // value in binary format, or produce an error. + // * Applications are allowed to cache lookup results based on the + // URL, or have them precompiled into a binary to avoid any + // lookup. Therefore, binary compatibility needs to be preserved + // on changes to types. (Use versioned type names to manage + // breaking changes.) + // + // Note: this functionality is not currently available in the official + // protobuf release, and it is not used for type URLs beginning with + // type.googleapis.com. + // + // Schemes other than `http`, `https` (or the empty scheme) might be + // used with implementation specific semantics. + + TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"` + + // Must be a valid serialized protocol buffer of the above specified type. + Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` + + cachedValue interface{} + + compat *anyCompat +} + +// NewAnyWithCacheWithValue constructs a new Any packed with the value provided or +// returns an error if that value couldn't be packed. This also caches +// the packed value so that it can be retrieved from GetCachedValue without +// unmarshalling +func NewAnyWithCacheWithValue(v proto.Message) (*Any, error) { + if v == nil { + return nil, errors.New("Expecting non nil value to create a new Any, failed packing protobuf message to Any") + } + + var ( + bz []byte + err error + ) + if msg, ok := v.(protov2.Message); ok { + protov2MarshalOpts := protov2.MarshalOptions{Deterministic: true} + bz, err = protov2MarshalOpts.Marshal(msg) + } else { + bz, err = proto.Marshal(v) + } + if err != nil { + return nil, err + } + + return &Any{ + TypeUrl: MsgTypeURL(v), + Value: bz, + cachedValue: v, + }, nil +} + +// UnsafePackAnyWithCache packs the value x in the Any and instead of returning the error +// in the case of a packing failure, keeps the cached value. This should only +// be used in situations where compatibility is needed with amino. Amino-only +// values can safely be packed using this method when they will only be +// marshaled with amino and not protobuf. +func UnsafePackAnyWithCache(x interface{}) *Any { + if msg, ok := x.(proto.Message); ok { + any, err := NewAnyWithCacheWithValue(msg) + if err == nil { + return any + } + } + return &Any{cachedValue: x} +} + +// pack packs the value x in the Any or returns an error. This also caches +// the packed value so that it can be retrieved from GetCachedValue without +// unmarshalling +func (any *Any) pack(x proto.Message) error { + any.TypeUrl = MsgTypeURL(x) + + var ( + bz []byte + err error + ) + if msg, ok := x.(protov2.Message); ok { + protov2MarshalOpts := protov2.MarshalOptions{Deterministic: true} + bz, err = protov2MarshalOpts.Marshal(msg) + } else { + bz, err = proto.Marshal(x) + } + if err != nil { + return err + } + + any.Value = bz + any.cachedValue = x + + return nil +} + +// GetCachedValue returns the cached value from the Any if present +func (any *Any) GetCachedValue() interface{} { + return any.cachedValue +} + +// ResetCachedValue seta a nil cachedValue +func (any *Any) ResetCachedValue() { + any.cachedValue = nil +} + +// GoString returns a string representing valid go code to reproduce the current state of +// the struct. +func (any *Any) GoString() string { + if any == nil { + return "nil" + } + extra := "" + if any.XXX_unrecognized != nil { + extra = fmt.Sprintf(",\n XXX_unrecognized: %#v,\n", any.XXX_unrecognized) + } + return fmt.Sprintf("&Any{TypeUrl: %#v,\n Value: %#v%s\n}", + any.TypeUrl, any.Value, extra) +} + +// String implements the stringer interface +func (any *Any) String() string { + if any == nil { + return "nil" + } + return fmt.Sprintf("&Any{TypeUrl:%v,Value:%v,XXX_unrecognized:%v}", + any.TypeUrl, any.Value, any.XXX_unrecognized) +} diff --git a/types/any/compat.go b/types/any/compat.go new file mode 100644 index 00000000..25b0e43a --- /dev/null +++ b/types/any/compat.go @@ -0,0 +1,210 @@ +package types + +import ( + "fmt" + "reflect" + "runtime/debug" + + "github.com/cosmos/gogoproto/jsonpb" + "github.com/cosmos/gogoproto/proto" + "github.com/tendermint/go-amino" +) + +type anyCompat struct { + aminoBz []byte + jsonBz []byte + err error +} + +var Debug = true + +func anyCompatError(errType string, x interface{}) error { + if Debug { + debug.PrintStack() + } + return fmt.Errorf( + "%s marshaling error for %+v, this is likely because "+ + "amino is being used directly (instead of codec.LegacyAmino which is preferred) "+ + "or UnpackInterfacesMessage is not defined for some type which contains "+ + "a protobuf Any either directly or via one of its members. To see a "+ + "stacktrace of where the error is coming from, set the var Debug = true "+ + "in codec/types/compat.go", + errType, x, + ) +} + +func (any Any) MarshalAmino() ([]byte, error) { + ac := any.compat + if ac == nil { + return nil, anyCompatError("amino binary marshal", any) + } + return ac.aminoBz, ac.err +} + +func (any *Any) UnmarshalAmino(bz []byte) error { + any.compat = &anyCompat{ + aminoBz: bz, + err: nil, + } + return nil +} + +func (any *Any) MarshalJSON() ([]byte, error) { + ac := any.compat + if ac == nil { + return nil, anyCompatError("JSON marshal", any) + } + return ac.jsonBz, ac.err +} + +func (any *Any) UnmarshalJSON(bz []byte) error { + any.compat = &anyCompat{ + jsonBz: bz, + err: nil, + } + return nil +} + +// AminoUnpacker is an AnyUnpacker provided for backwards compatibility with +// amino for the binary un-marshaling phase +type AminoUnpacker struct { + Cdc *amino.Codec +} + +var _ AnyUnpacker = AminoUnpacker{} + +func (a AminoUnpacker) UnpackAny(any *Any, iface interface{}) error { + ac := any.compat + if ac == nil { + return anyCompatError("amino binary unmarshal", reflect.TypeOf(iface)) + } + err := a.Cdc.UnmarshalBinaryBare(ac.aminoBz, iface) + if err != nil { + return err + } + val := reflect.ValueOf(iface).Elem().Interface() + err = UnpackInterfaces(val, a) + if err != nil { + return err + } + if m, ok := val.(proto.Message); ok { + if err = any.pack(m); err != nil { + return err + } + } else { + any.cachedValue = val + } + + // this is necessary for tests that use reflect.DeepEqual and compare + // proto vs amino marshaled values + any.compat = nil + + return nil +} + +// AminoUnpacker is an AnyUnpacker provided for backwards compatibility with +// amino for the binary marshaling phase +type AminoPacker struct { + Cdc *amino.Codec +} + +var _ AnyUnpacker = AminoPacker{} + +func (a AminoPacker) UnpackAny(any *Any, _ interface{}) error { + err := UnpackInterfaces(any.cachedValue, a) + if err != nil { + return err + } + bz, err := a.Cdc.MarshalBinaryBare(any.cachedValue) + any.compat = &anyCompat{ + aminoBz: bz, + err: err, + } + return err +} + +// AminoUnpacker is an AnyUnpacker provided for backwards compatibility with +// amino for the JSON marshaling phase +type AminoJSONUnpacker struct { + Cdc *amino.Codec +} + +var _ AnyUnpacker = AminoJSONUnpacker{} + +func (a AminoJSONUnpacker) UnpackAny(any *Any, iface interface{}) error { + ac := any.compat + if ac == nil { + return anyCompatError("JSON unmarshal", reflect.TypeOf(iface)) + } + err := a.Cdc.UnmarshalJSON(ac.jsonBz, iface) + if err != nil { + return err + } + val := reflect.ValueOf(iface).Elem().Interface() + err = UnpackInterfaces(val, a) + if err != nil { + return err + } + if m, ok := val.(proto.Message); ok { + if err = any.pack(m); err != nil { + return err + } + } else { + any.cachedValue = val + } + + // this is necessary for tests that use reflect.DeepEqual and compare + // proto vs amino marshaled values + any.compat = nil + + return nil +} + +// AminoUnpacker is an AnyUnpacker provided for backwards compatibility with +// amino for the JSON un-marshaling phase +type AminoJSONPacker struct { + Cdc *amino.Codec +} + +var _ AnyUnpacker = AminoJSONPacker{} + +func (a AminoJSONPacker) UnpackAny(any *Any, _ interface{}) error { + err := UnpackInterfaces(any.cachedValue, a) + if err != nil { + return err + } + bz, err := a.Cdc.MarshalJSON(any.cachedValue) + any.compat = &anyCompat{ + jsonBz: bz, + err: err, + } + return err +} + +// ProtoJSONPacker is an AnyUnpacker provided for compatibility with jsonpb +type ProtoJSONPacker struct { + JSONPBMarshaler *jsonpb.Marshaler +} + +var _ AnyUnpacker = ProtoJSONPacker{} + +func (a ProtoJSONPacker) UnpackAny(any *Any, _ interface{}) error { + if any == nil { + return nil + } + + if any.cachedValue != nil { + err := UnpackInterfaces(any.cachedValue, a) + if err != nil { + return err + } + } + + bz, err := a.JSONPBMarshaler.MarshalToString(any) + any.compat = &anyCompat{ + jsonBz: []byte(bz), + err: err, + } + + return err +} diff --git a/types/any/doc.go b/types/any/doc.go new file mode 100644 index 00000000..9f89f0c9 --- /dev/null +++ b/types/any/doc.go @@ -0,0 +1,6 @@ +/* +Package types defines a custom wrapper for google.protobuf.Any which supports +cached values as well as InterfaceRegistry which keeps track of types which can +be used with Any for both security and introspection +*/ +package types diff --git a/types/any/test/animal.go b/types/any/test/animal.go new file mode 100644 index 00000000..e6fa8941 --- /dev/null +++ b/types/any/test/animal.go @@ -0,0 +1,84 @@ +package test + +// nolint + +import ( + "fmt" + "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/gogoproto/types/any" +) + +type Animal interface { + proto.Message + + Greet() string +} + +type Cartoon interface { + proto.Message + + Identify() string +} + +func (c *Cat) Greet() string { + return fmt.Sprintf("Meow, my name is %s", c.Moniker) +} + +func (c *Bird) Identify() string { + return "This is Tweety." +} + +func (d *Dog) Greet() string { + return fmt.Sprintf("Roof, my name is %s", d.Name) +} + +var _ types.UnpackInterfacesMessage = HasAnimal{} + +func (m HasAnimal) UnpackInterfaces(unpacker types.AnyUnpacker) error { + var animal Animal + return unpacker.UnpackAny(m.Animal, &animal) +} + +type HasAnimalI interface { + TheAnimal() Animal +} + +var _ HasAnimalI = &HasAnimal{} + +func (m HasAnimal) TheAnimal() Animal { + return m.Animal.GetCachedValue().(Animal) +} + +type HasHasAnimalI interface { + TheHasAnimal() HasAnimalI +} + +var _ HasHasAnimalI = &HasHasAnimal{} + +func (m HasHasAnimal) TheHasAnimal() HasAnimalI { + return m.HasAnimal.GetCachedValue().(HasAnimalI) +} + +var _ types.UnpackInterfacesMessage = HasHasAnimal{} + +func (m HasHasAnimal) UnpackInterfaces(unpacker types.AnyUnpacker) error { + var animal HasAnimalI + return unpacker.UnpackAny(m.HasAnimal, &animal) +} + +type HasHasHasAnimalI interface { + TheHasHasAnimal() HasHasAnimalI +} + +var _ HasHasAnimalI = &HasHasAnimal{} + +func (m HasHasHasAnimal) TheHasHasAnimal() HasHasAnimalI { + return m.HasHasAnimal.GetCachedValue().(HasHasAnimalI) +} + +var _ types.UnpackInterfacesMessage = HasHasHasAnimal{} + +func (m HasHasHasAnimal) UnpackInterfaces(unpacker types.AnyUnpacker) error { + var animal HasHasAnimalI + return unpacker.UnpackAny(m.HasHasAnimal, &animal) +} diff --git a/types/any/test/compat_test.go b/types/any/test/compat_test.go new file mode 100644 index 00000000..28433cd7 --- /dev/null +++ b/types/any/test/compat_test.go @@ -0,0 +1,131 @@ +package test + +import ( + types "github.com/cosmos/gogoproto/types/any" + + "testing" + + "github.com/stretchr/testify/suite" + amino "github.com/tendermint/go-amino" +) + +type TypeWithInterface struct { + Animal Animal `json:"animal"` + X int64 `json:"x,omitempty"` +} + +type Suite struct { + suite.Suite + cdc *amino.Codec + a TypeWithInterface + b HasAnimal + spot *Dog +} + +func (s *Suite) SetupTest() { + s.cdc = amino.NewCodec() + s.cdc.RegisterInterface((*Animal)(nil), nil) + s.cdc.RegisterConcrete(&Dog{}, "test/Dog", nil) + + s.spot = &Dog{Size_: "small", Name: "Spot"} + s.a = TypeWithInterface{Animal: s.spot} + + any, err := types.NewAnyWithCacheWithValue(s.spot) + s.Require().NoError(err) + s.b = HasAnimal{Animal: any} +} + +func (s *Suite) TestAminoBinary() { + bz, err := s.cdc.MarshalBinaryBare(s.a) + s.Require().NoError(err) + + // expect plain amino marshal to fail + _, err = s.cdc.MarshalBinaryBare(s.b) + s.Require().Error(err) + + // expect unpack interfaces before amino marshal to succeed + err = types.UnpackInterfaces(s.b, types.AminoPacker{Cdc: s.cdc}) + s.Require().NoError(err) + bz2, err := s.cdc.MarshalBinaryBare(s.b) + s.Require().NoError(err) + s.Require().Equal(bz, bz2) + + var c HasAnimal + err = s.cdc.UnmarshalBinaryBare(bz, &c) + s.Require().NoError(err) + err = types.UnpackInterfaces(c, types.AminoUnpacker{Cdc: s.cdc}) + s.Require().NoError(err) + s.Require().Equal(s.spot, c.Animal.GetCachedValue()) +} + +func (s *Suite) TestAminoJSON() { + bz, err := s.cdc.MarshalJSON(s.a) + s.Require().NoError(err) + + // expect plain amino marshal to fail + _, err = s.cdc.MarshalJSON(s.b) + s.Require().Error(err) + + // expect unpack interfaces before amino marshal to succeed + err = types.UnpackInterfaces(s.b, types.AminoJSONPacker{Cdc: s.cdc}) + s.Require().NoError(err) + bz2, err := s.cdc.MarshalJSON(s.b) + s.Require().NoError(err) + s.Require().Equal(string(bz), string(bz2)) + + var c HasAnimal + err = s.cdc.UnmarshalJSON(bz, &c) + s.Require().NoError(err) + err = types.UnpackInterfaces(c, types.AminoJSONUnpacker{Cdc: s.cdc}) + s.Require().NoError(err) + s.Require().Equal(s.spot, c.Animal.GetCachedValue()) +} + +func (s *Suite) TestNested() { + s.cdc.RegisterInterface((*HasAnimalI)(nil), nil) + s.cdc.RegisterInterface((*HasHasAnimalI)(nil), nil) + s.cdc.RegisterConcrete(&HasAnimal{}, "test/HasAnimal", nil) + s.cdc.RegisterConcrete(&HasHasAnimal{}, "test/HasHasAnimal", nil) + s.cdc.RegisterConcrete(&HasHasHasAnimal{}, "test/HasHasHasAnimal", nil) + + any, err := types.NewAnyWithCacheWithValue(&s.b) + s.Require().NoError(err) + hha := HasHasAnimal{HasAnimal: any} + any2, err := types.NewAnyWithCacheWithValue(&hha) + s.Require().NoError(err) + hhha := HasHasHasAnimal{HasHasAnimal: any2} + + // marshal + err = types.UnpackInterfaces(hhha, types.AminoPacker{Cdc: s.cdc}) + s.Require().NoError(err) + bz, err := s.cdc.MarshalBinaryBare(hhha) + s.Require().NoError(err) + + // unmarshal + var hhha2 HasHasHasAnimal + err = s.cdc.UnmarshalBinaryBare(bz, &hhha2) + s.Require().NoError(err) + err = types.UnpackInterfaces(hhha2, types.AminoUnpacker{Cdc: s.cdc}) + s.Require().NoError(err) + + s.Require().Equal(s.spot, hhha2.TheHasHasAnimal().TheHasAnimal().TheAnimal()) + + // json marshal + err = types.UnpackInterfaces(hhha, types.AminoJSONPacker{Cdc: s.cdc}) + s.Require().NoError(err) + jsonBz, err := s.cdc.MarshalJSON(hhha) + s.Require().NoError(err) + + // json unmarshal + var hhha3 HasHasHasAnimal + err = s.cdc.UnmarshalJSON(jsonBz, &hhha3) + s.Require().NoError(err) + err = types.UnpackInterfaces(hhha3, types.AminoJSONUnpacker{Cdc: s.cdc}) + s.Require().NoError(err) + + s.Require().Equal(s.spot, hhha3.TheHasHasAnimal().TheHasAnimal().TheAnimal()) +} + +func TestSuite(t *testing.T) { + suite.Run(t, &Suite{}) +} diff --git a/types/any/test/test.pb.go b/types/any/test/test.pb.go new file mode 100644 index 00000000..0148b908 --- /dev/null +++ b/types/any/test/test.pb.go @@ -0,0 +1,1973 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: test/test.proto + +package test + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + any "github.com/cosmos/gogoproto/types/any" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Dog struct { + Size_ string `protobuf:"bytes,1,opt,name=size,proto3" json:"size,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Dog) Reset() { *m = Dog{} } +func (m *Dog) String() string { return proto.CompactTextString(m) } +func (*Dog) ProtoMessage() {} +func (*Dog) Descriptor() ([]byte, []int) { + return fileDescriptor_84eb23d74a64bdab, []int{0} +} +func (m *Dog) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Dog) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Dog.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Dog) XXX_Merge(src proto.Message) { + xxx_messageInfo_Dog.Merge(m, src) +} +func (m *Dog) XXX_Size() int { + return m.Size() +} +func (m *Dog) XXX_DiscardUnknown() { + xxx_messageInfo_Dog.DiscardUnknown(m) +} + +var xxx_messageInfo_Dog proto.InternalMessageInfo + +func (m *Dog) GetSize_() string { + if m != nil { + return m.Size_ + } + return "" +} + +func (m *Dog) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +type Cat struct { + Moniker string `protobuf:"bytes,1,opt,name=moniker,proto3" json:"moniker,omitempty"` + Lives int32 `protobuf:"varint,2,opt,name=lives,proto3" json:"lives,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Cat) Reset() { *m = Cat{} } +func (m *Cat) String() string { return proto.CompactTextString(m) } +func (*Cat) ProtoMessage() {} +func (*Cat) Descriptor() ([]byte, []int) { + return fileDescriptor_84eb23d74a64bdab, []int{1} +} +func (m *Cat) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Cat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Cat.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Cat) XXX_Merge(src proto.Message) { + xxx_messageInfo_Cat.Merge(m, src) +} +func (m *Cat) XXX_Size() int { + return m.Size() +} +func (m *Cat) XXX_DiscardUnknown() { + xxx_messageInfo_Cat.DiscardUnknown(m) +} + +var xxx_messageInfo_Cat proto.InternalMessageInfo + +func (m *Cat) GetMoniker() string { + if m != nil { + return m.Moniker + } + return "" +} + +func (m *Cat) GetLives() int32 { + if m != nil { + return m.Lives + } + return 0 +} + +type Bird struct { + Species string `protobuf:"bytes,1,opt,name=species,proto3" json:"species,omitempty"` + Color int32 `protobuf:"varint,2,opt,name=color,proto3" json:"color,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Bird) Reset() { *m = Bird{} } +func (m *Bird) String() string { return proto.CompactTextString(m) } +func (*Bird) ProtoMessage() {} +func (*Bird) Descriptor() ([]byte, []int) { + return fileDescriptor_84eb23d74a64bdab, []int{2} +} +func (m *Bird) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Bird) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Bird.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Bird) XXX_Merge(src proto.Message) { + xxx_messageInfo_Bird.Merge(m, src) +} +func (m *Bird) XXX_Size() int { + return m.Size() +} +func (m *Bird) XXX_DiscardUnknown() { + xxx_messageInfo_Bird.DiscardUnknown(m) +} + +var xxx_messageInfo_Bird proto.InternalMessageInfo + +func (m *Bird) GetSpecies() string { + if m != nil { + return m.Species + } + return "" +} + +func (m *Bird) GetColor() int32 { + if m != nil { + return m.Color + } + return 0 +} + +type HasAnimal struct { + Animal *any.Any `protobuf:"bytes,1,opt,name=animal,proto3" json:"animal,omitempty"` + X int64 `protobuf:"varint,2,opt,name=x,proto3" json:"x,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HasAnimal) Reset() { *m = HasAnimal{} } +func (m *HasAnimal) String() string { return proto.CompactTextString(m) } +func (*HasAnimal) ProtoMessage() {} +func (*HasAnimal) Descriptor() ([]byte, []int) { + return fileDescriptor_84eb23d74a64bdab, []int{3} +} +func (m *HasAnimal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HasAnimal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HasAnimal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *HasAnimal) XXX_Merge(src proto.Message) { + xxx_messageInfo_HasAnimal.Merge(m, src) +} +func (m *HasAnimal) XXX_Size() int { + return m.Size() +} +func (m *HasAnimal) XXX_DiscardUnknown() { + xxx_messageInfo_HasAnimal.DiscardUnknown(m) +} + +var xxx_messageInfo_HasAnimal proto.InternalMessageInfo + +func (m *HasAnimal) GetAnimal() *any.Any { + if m != nil { + return m.Animal + } + return nil +} + +func (m *HasAnimal) GetX() int64 { + if m != nil { + return m.X + } + return 0 +} + +type HasHasAnimal struct { + HasAnimal *any.Any `protobuf:"bytes,1,opt,name=has_animal,json=hasAnimal,proto3" json:"has_animal,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HasHasAnimal) Reset() { *m = HasHasAnimal{} } +func (m *HasHasAnimal) String() string { return proto.CompactTextString(m) } +func (*HasHasAnimal) ProtoMessage() {} +func (*HasHasAnimal) Descriptor() ([]byte, []int) { + return fileDescriptor_84eb23d74a64bdab, []int{4} +} +func (m *HasHasAnimal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HasHasAnimal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HasHasAnimal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *HasHasAnimal) XXX_Merge(src proto.Message) { + xxx_messageInfo_HasHasAnimal.Merge(m, src) +} +func (m *HasHasAnimal) XXX_Size() int { + return m.Size() +} +func (m *HasHasAnimal) XXX_DiscardUnknown() { + xxx_messageInfo_HasHasAnimal.DiscardUnknown(m) +} + +var xxx_messageInfo_HasHasAnimal proto.InternalMessageInfo + +func (m *HasHasAnimal) GetHasAnimal() *any.Any { + if m != nil { + return m.HasAnimal + } + return nil +} + +type HasHasHasAnimal struct { + HasHasAnimal *any.Any `protobuf:"bytes,1,opt,name=has_has_animal,json=hasHasAnimal,proto3" json:"has_has_animal,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HasHasHasAnimal) Reset() { *m = HasHasHasAnimal{} } +func (m *HasHasHasAnimal) String() string { return proto.CompactTextString(m) } +func (*HasHasHasAnimal) ProtoMessage() {} +func (*HasHasHasAnimal) Descriptor() ([]byte, []int) { + return fileDescriptor_84eb23d74a64bdab, []int{5} +} +func (m *HasHasHasAnimal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HasHasHasAnimal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HasHasHasAnimal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *HasHasHasAnimal) XXX_Merge(src proto.Message) { + xxx_messageInfo_HasHasHasAnimal.Merge(m, src) +} +func (m *HasHasHasAnimal) XXX_Size() int { + return m.Size() +} +func (m *HasHasHasAnimal) XXX_DiscardUnknown() { + xxx_messageInfo_HasHasHasAnimal.DiscardUnknown(m) +} + +var xxx_messageInfo_HasHasHasAnimal proto.InternalMessageInfo + +func (m *HasHasHasAnimal) GetHasHasAnimal() *any.Any { + if m != nil { + return m.HasHasAnimal + } + return nil +} + +// bad MultiSignature with extra fields +type BadMultiSignature struct { + Signatures [][]byte `protobuf:"bytes,1,rep,name=signatures,proto3" json:"signatures,omitempty"` + MaliciousField []byte `protobuf:"bytes,5,opt,name=malicious_field,json=maliciousField,proto3" json:"malicious_field,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BadMultiSignature) Reset() { *m = BadMultiSignature{} } +func (m *BadMultiSignature) String() string { return proto.CompactTextString(m) } +func (*BadMultiSignature) ProtoMessage() {} +func (*BadMultiSignature) Descriptor() ([]byte, []int) { + return fileDescriptor_84eb23d74a64bdab, []int{6} +} +func (m *BadMultiSignature) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BadMultiSignature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BadMultiSignature.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BadMultiSignature) XXX_Merge(src proto.Message) { + xxx_messageInfo_BadMultiSignature.Merge(m, src) +} +func (m *BadMultiSignature) XXX_Size() int { + return m.Size() +} +func (m *BadMultiSignature) XXX_DiscardUnknown() { + xxx_messageInfo_BadMultiSignature.DiscardUnknown(m) +} + +var xxx_messageInfo_BadMultiSignature proto.InternalMessageInfo + +func (m *BadMultiSignature) GetSignatures() [][]byte { + if m != nil { + return m.Signatures + } + return nil +} + +func (m *BadMultiSignature) GetMaliciousField() []byte { + if m != nil { + return m.MaliciousField + } + return nil +} + +type TableModel struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Number uint64 `protobuf:"varint,3,opt,name=number,proto3" json:"number,omitempty"` + Metadata []byte `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *TableModel) Reset() { *m = TableModel{} } +func (m *TableModel) String() string { return proto.CompactTextString(m) } +func (*TableModel) ProtoMessage() {} +func (*TableModel) Descriptor() ([]byte, []int) { + return fileDescriptor_84eb23d74a64bdab, []int{7} +} +func (m *TableModel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TableModel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TableModel.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TableModel) XXX_Merge(src proto.Message) { + xxx_messageInfo_TableModel.Merge(m, src) +} +func (m *TableModel) XXX_Size() int { + return m.Size() +} +func (m *TableModel) XXX_DiscardUnknown() { + xxx_messageInfo_TableModel.DiscardUnknown(m) +} + +var xxx_messageInfo_TableModel proto.InternalMessageInfo + +func (m *TableModel) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + +func (m *TableModel) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *TableModel) GetNumber() uint64 { + if m != nil { + return m.Number + } + return 0 +} + +func (m *TableModel) GetMetadata() []byte { + if m != nil { + return m.Metadata + } + return nil +} + +func init() { + proto.RegisterType((*Dog)(nil), "test.Dog") + proto.RegisterType((*Cat)(nil), "test.Cat") + proto.RegisterType((*Bird)(nil), "test.Bird") + proto.RegisterType((*HasAnimal)(nil), "test.HasAnimal") + proto.RegisterType((*HasHasAnimal)(nil), "test.HasHasAnimal") + proto.RegisterType((*HasHasHasAnimal)(nil), "test.HasHasHasAnimal") + proto.RegisterType((*BadMultiSignature)(nil), "test.BadMultiSignature") + proto.RegisterType((*TableModel)(nil), "test.TableModel") +} + +func init() { proto.RegisterFile("test/test.proto", fileDescriptor_84eb23d74a64bdab) } + +var fileDescriptor_84eb23d74a64bdab = []byte{ + // 397 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xb1, 0xae, 0xd3, 0x30, + 0x18, 0x85, 0xe5, 0x26, 0x2d, 0xf4, 0x27, 0x6a, 0x85, 0x55, 0xa1, 0xd0, 0x21, 0x5c, 0x79, 0xa1, + 0x03, 0x24, 0x12, 0x57, 0x30, 0xdc, 0xed, 0xf6, 0x22, 0xe8, 0xd2, 0x25, 0xb0, 0x57, 0x4e, 0xed, + 0xa6, 0x16, 0x4e, 0x5c, 0xc5, 0x0e, 0x6a, 0x79, 0x1b, 0xde, 0x86, 0xb1, 0x8f, 0x80, 0xfa, 0x24, + 0xc8, 0x4e, 0xd2, 0x76, 0x60, 0xe8, 0x12, 0x9d, 0x73, 0xfc, 0x7f, 0x27, 0xf9, 0x63, 0x18, 0x1b, + 0xae, 0x4d, 0x62, 0x1f, 0xf1, 0xae, 0x52, 0x46, 0x61, 0xdf, 0xea, 0xe9, 0x24, 0x57, 0xb9, 0x72, + 0x41, 0x62, 0x55, 0x73, 0x36, 0x7d, 0x9d, 0x2b, 0x95, 0x4b, 0x9e, 0x38, 0x97, 0xd5, 0x9b, 0x84, + 0x96, 0x87, 0xe6, 0x88, 0xbc, 0x07, 0xef, 0xb3, 0xca, 0x31, 0x06, 0x5f, 0x8b, 0x5f, 0x3c, 0x44, + 0x77, 0x68, 0x36, 0x4c, 0x9d, 0xb6, 0x59, 0x49, 0x0b, 0x1e, 0xf6, 0x9a, 0xcc, 0x6a, 0xf2, 0x11, + 0xbc, 0x27, 0x6a, 0x70, 0x08, 0xcf, 0x0a, 0x55, 0x8a, 0x1f, 0xbc, 0x6a, 0x89, 0xce, 0xe2, 0x09, + 0xf4, 0xa5, 0xf8, 0xc9, 0xb5, 0xa3, 0xfa, 0x69, 0x63, 0xc8, 0x27, 0xf0, 0xe7, 0xa2, 0x62, 0x96, + 0xd3, 0x3b, 0xbe, 0x16, 0x5c, 0x77, 0x5c, 0x6b, 0x2d, 0xb7, 0x56, 0x52, 0x55, 0x1d, 0xe7, 0x0c, + 0xf9, 0x0a, 0xc3, 0x05, 0xd5, 0x8f, 0xa5, 0x28, 0xa8, 0xc4, 0xef, 0x60, 0x40, 0x9d, 0x72, 0xec, + 0x8b, 0x0f, 0x93, 0xb8, 0x59, 0x2b, 0xee, 0xd6, 0x8a, 0x1f, 0xcb, 0x43, 0xda, 0xce, 0xe0, 0x00, + 0xd0, 0xde, 0x95, 0x79, 0x29, 0xda, 0x93, 0x27, 0x08, 0x16, 0x54, 0x5f, 0xba, 0xee, 0x01, 0xb6, + 0x54, 0xaf, 0x6e, 0xe8, 0x1b, 0x6e, 0x3b, 0x88, 0x2c, 0x61, 0xdc, 0x94, 0x5c, 0x7a, 0x1e, 0x60, + 0x64, 0x7b, 0x6e, 0xec, 0x0a, 0xb6, 0x57, 0x2c, 0xc9, 0xe0, 0xe5, 0x9c, 0xb2, 0x65, 0x2d, 0x8d, + 0xf8, 0x26, 0xf2, 0x92, 0x9a, 0xba, 0xe2, 0x38, 0x02, 0xd0, 0x9d, 0xb1, 0x3f, 0xc9, 0x9b, 0x05, + 0xe9, 0x55, 0x82, 0xdf, 0xc2, 0xb8, 0xa0, 0x52, 0xac, 0x85, 0xaa, 0xf5, 0x6a, 0x23, 0xb8, 0x64, + 0x61, 0xff, 0x0e, 0xcd, 0x82, 0x74, 0x74, 0x8e, 0xbf, 0xd8, 0xf4, 0xc1, 0x3f, 0xfe, 0x7e, 0x83, + 0x08, 0x03, 0xf8, 0x4e, 0x33, 0xc9, 0x97, 0x8a, 0x71, 0x89, 0x47, 0xd0, 0x13, 0xcc, 0x7d, 0xa1, + 0x9f, 0xf6, 0x04, 0xfb, 0xdf, 0x0d, 0xe3, 0x57, 0x30, 0x28, 0xeb, 0x22, 0xe3, 0x55, 0xe8, 0xb9, + 0xb9, 0xd6, 0xe1, 0x29, 0x3c, 0x2f, 0xb8, 0xa1, 0x8c, 0x1a, 0x1a, 0xfa, 0xee, 0x8d, 0x67, 0x3f, + 0x0f, 0xfe, 0x9c, 0x22, 0x74, 0x3c, 0x45, 0xe8, 0xef, 0x29, 0x42, 0xd9, 0xc0, 0xed, 0x7c, 0xff, + 0x2f, 0x00, 0x00, 0xff, 0xff, 0xcd, 0xa9, 0x96, 0x46, 0xa3, 0x02, 0x00, 0x00, +} + +func (m *Dog) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Dog) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Dog) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTest(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if len(m.Size_) > 0 { + i -= len(m.Size_) + copy(dAtA[i:], m.Size_) + i = encodeVarintTest(dAtA, i, uint64(len(m.Size_))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Cat) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Cat) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Cat) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if m.Lives != 0 { + i = encodeVarintTest(dAtA, i, uint64(m.Lives)) + i-- + dAtA[i] = 0x10 + } + if len(m.Moniker) > 0 { + i -= len(m.Moniker) + copy(dAtA[i:], m.Moniker) + i = encodeVarintTest(dAtA, i, uint64(len(m.Moniker))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Bird) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Bird) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Bird) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if m.Color != 0 { + i = encodeVarintTest(dAtA, i, uint64(m.Color)) + i-- + dAtA[i] = 0x10 + } + if len(m.Species) > 0 { + i -= len(m.Species) + copy(dAtA[i:], m.Species) + i = encodeVarintTest(dAtA, i, uint64(len(m.Species))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *HasAnimal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HasAnimal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HasAnimal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if m.X != 0 { + i = encodeVarintTest(dAtA, i, uint64(m.X)) + i-- + dAtA[i] = 0x10 + } + if m.Animal != nil { + { + size, err := m.Animal.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *HasHasAnimal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HasHasAnimal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HasHasAnimal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if m.HasAnimal != nil { + { + size, err := m.HasAnimal.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *HasHasHasAnimal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HasHasHasAnimal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HasHasHasAnimal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if m.HasHasAnimal != nil { + { + size, err := m.HasHasAnimal.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *BadMultiSignature) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *BadMultiSignature) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BadMultiSignature) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.MaliciousField) > 0 { + i -= len(m.MaliciousField) + copy(dAtA[i:], m.MaliciousField) + i = encodeVarintTest(dAtA, i, uint64(len(m.MaliciousField))) + i-- + dAtA[i] = 0x2a + } + if len(m.Signatures) > 0 { + for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Signatures[iNdEx]) + copy(dAtA[i:], m.Signatures[iNdEx]) + i = encodeVarintTest(dAtA, i, uint64(len(m.Signatures[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *TableModel) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TableModel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TableModel) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.Metadata) > 0 { + i -= len(m.Metadata) + copy(dAtA[i:], m.Metadata) + i = encodeVarintTest(dAtA, i, uint64(len(m.Metadata))) + i-- + dAtA[i] = 0x22 + } + if m.Number != 0 { + i = encodeVarintTest(dAtA, i, uint64(m.Number)) + i-- + dAtA[i] = 0x18 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTest(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if m.Id != 0 { + i = encodeVarintTest(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintTest(dAtA []byte, offset int, v uint64) int { + offset -= sovTest(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Dog) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Size_) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *Cat) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Moniker) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + if m.Lives != 0 { + n += 1 + sovTest(uint64(m.Lives)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *Bird) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Species) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + if m.Color != 0 { + n += 1 + sovTest(uint64(m.Color)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *HasAnimal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Animal != nil { + l = m.Animal.Size() + n += 1 + l + sovTest(uint64(l)) + } + if m.X != 0 { + n += 1 + sovTest(uint64(m.X)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *HasHasAnimal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.HasAnimal != nil { + l = m.HasAnimal.Size() + n += 1 + l + sovTest(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *HasHasHasAnimal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.HasHasAnimal != nil { + l = m.HasHasAnimal.Size() + n += 1 + l + sovTest(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *BadMultiSignature) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Signatures) > 0 { + for _, b := range m.Signatures { + l = len(b) + n += 1 + l + sovTest(uint64(l)) + } + } + l = len(m.MaliciousField) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *TableModel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Id != 0 { + n += 1 + sovTest(uint64(m.Id)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + if m.Number != 0 { + n += 1 + sovTest(uint64(m.Number)) + } + l = len(m.Metadata) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func sovTest(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTest(x uint64) (n int) { + return sovTest(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Dog) 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 ErrIntOverflowTest + } + 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: Dog: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Dog: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Size_", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Size_ = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Cat) 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 ErrIntOverflowTest + } + 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: Cat: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Cat: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Moniker", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Moniker = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Lives", wireType) + } + m.Lives = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Lives |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Bird) 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 ErrIntOverflowTest + } + 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: Bird: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Bird: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Species", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Species = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Color", wireType) + } + m.Color = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Color |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *HasAnimal) 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 ErrIntOverflowTest + } + 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: HasAnimal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Animal", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Animal == nil { + m.Animal = &any.Any{} + } + if err := m.Animal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field X", wireType) + } + m.X = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.X |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *HasHasAnimal) 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 ErrIntOverflowTest + } + 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: HasHasAnimal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HasHasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HasAnimal", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.HasAnimal == nil { + m.HasAnimal = &any.Any{} + } + if err := m.HasAnimal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *HasHasHasAnimal) 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 ErrIntOverflowTest + } + 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: HasHasHasAnimal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HasHasHasAnimal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HasHasAnimal", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.HasHasAnimal == nil { + m.HasHasAnimal = &any.Any{} + } + if err := m.HasHasAnimal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BadMultiSignature) 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 ErrIntOverflowTest + } + 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: BadMultiSignature: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BadMultiSignature: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signatures = append(m.Signatures, make([]byte, postIndex-iNdEx)) + copy(m.Signatures[len(m.Signatures)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaliciousField", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MaliciousField = append(m.MaliciousField[:0], dAtA[iNdEx:postIndex]...) + if m.MaliciousField == nil { + m.MaliciousField = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TableModel) 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 ErrIntOverflowTest + } + 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: TableModel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TableModel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Number", wireType) + } + m.Number = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Number |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Metadata = append(m.Metadata[:0], dAtA[iNdEx:postIndex]...) + if m.Metadata == nil { + m.Metadata = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTest(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + 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, ErrIntOverflowTest + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + 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, ErrInvalidLengthTest + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTest + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTest + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTest = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTest = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTest = fmt.Errorf("proto: unexpected end of group") +) diff --git a/types/any/unpacker.go b/types/any/unpacker.go new file mode 100644 index 00000000..3d85da40 --- /dev/null +++ b/types/any/unpacker.go @@ -0,0 +1,47 @@ +package types + +// AnyUnpacker is an interface which allows safely unpacking types packed +// in Any's against a whitelist of registered types +type AnyUnpacker interface { + // UnpackAny unpacks the value in any to the interface pointer passed in as + // iface. Note that the type in any must have been registered in the + // underlying whitelist registry as a concrete type for that interface + // Ex: + // var msg sdk.Msg + // err := cdc.UnpackAny(any, &msg) + // ... + UnpackAny(any *Any, iface interface{}) error +} + +// UnpackInterfacesMessage is meant to extend protobuf types (which implement +// proto.Message) to support a post-deserialization phase which unpacks +// types packed within Any's using the whitelist provided by AnyUnpacker +type UnpackInterfacesMessage interface { + // UnpackInterfaces is implemented in order to unpack values packed within + // Any's using the AnyUnpacker. It should generally be implemented as + // follows: + // func (s *MyStruct) UnpackInterfaces(unpacker AnyUnpacker) error { + // var x AnyInterface + // // where X is an Any field on MyStruct + // err := unpacker.UnpackAny(s.X, &x) + // if err != nil { + // return nil + // } + // // where Y is a field on MyStruct that implements UnpackInterfacesMessage itself + // err = s.Y.UnpackInterfaces(unpacker) + // if err != nil { + // return nil + // } + // return nil + // } + UnpackInterfaces(unpacker AnyUnpacker) error +} + +// UnpackInterfaces is a convenience function that calls UnpackInterfaces +// on x if x implements UnpackInterfacesMessage +func UnpackInterfaces(x interface{}, unpacker AnyUnpacker) error { + if msg, ok := x.(UnpackInterfacesMessage); ok { + return msg.UnpackInterfaces(unpacker) + } + return nil +} diff --git a/types/any/util.go b/types/any/util.go new file mode 100644 index 00000000..b29fb33b --- /dev/null +++ b/types/any/util.go @@ -0,0 +1,15 @@ +package types + +import ( + "github.com/cosmos/gogoproto/proto" + protov2 "google.golang.org/protobuf/proto" +) + +// MsgTypeURL returns the TypeURL of a `sdk.Msg`. +func MsgTypeURL(msg proto.Message) string { + if m, ok := msg.(protov2.Message); ok { + return "/" + string(m.ProtoReflect().Descriptor().FullName()) + } + + return "/" + proto.MessageName(msg) +}