Merge PR #6076: Proto Any init + evidence

This commit is contained in:
Aaron Craelius
2020-05-05 10:28:20 -04:00
committed by GitHub
parent 7e72e5b8a6
commit 386217209d
82 changed files with 2145 additions and 1304 deletions
+9
View File
@@ -5,6 +5,8 @@ package testdata
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec/types"
)
type Animal interface {
@@ -18,3 +20,10 @@ func (c Cat) Greet() string {
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)
}
+236 -14
View File
@@ -5,6 +5,7 @@ package testdata
import (
fmt "fmt"
types "github.com/cosmos/cosmos-sdk/codec/types"
proto "github.com/gogo/protobuf/proto"
io "io"
math "math"
@@ -126,28 +127,85 @@ func (m *Cat) GetLives() int32 {
return 0
}
type HasAnimal struct {
Animal *types.Any `protobuf:"bytes,1,opt,name=animal,proto3" json:"animal,omitempty"`
X int64 `protobuf:"varint,2,opt,name=x,proto3" json:"x,omitempty"`
}
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_ae1353846770e6e2, []int{2}
}
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() *types.Any {
if m != nil {
return m.Animal
}
return nil
}
func (m *HasAnimal) GetX() int64 {
if m != nil {
return m.X
}
return 0
}
func init() {
proto.RegisterType((*Dog)(nil), "cosmos_sdk.codec.v1.Dog")
proto.RegisterType((*Cat)(nil), "cosmos_sdk.codec.v1.Cat")
proto.RegisterType((*HasAnimal)(nil), "cosmos_sdk.codec.v1.HasAnimal")
}
func init() { proto.RegisterFile("codec/testdata/proto.proto", fileDescriptor_ae1353846770e6e2) }
var fileDescriptor_ae1353846770e6e2 = []byte{
// 195 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4a, 0xce, 0x4f, 0x49,
0x4d, 0xd6, 0x2f, 0x49, 0x2d, 0x2e, 0x49, 0x49, 0x2c, 0x49, 0xd4, 0x2f, 0x28, 0xca, 0x2f, 0xc9,
0xd7, 0x03, 0x93, 0x42, 0xc2, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a,
0x60, 0x65, 0x7a, 0x65, 0x86, 0x4a, 0xba, 0x5c, 0xcc, 0x2e, 0xf9, 0xe9, 0x42, 0x42, 0x5c, 0x2c,
0xc5, 0x99, 0x55, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x60, 0x36, 0x48, 0x2c, 0x2f,
0x31, 0x37, 0x55, 0x82, 0x09, 0x22, 0x06, 0x62, 0x2b, 0x99, 0x72, 0x31, 0x3b, 0x27, 0x96, 0x08,
0x49, 0x70, 0xb1, 0xe7, 0xe6, 0xe7, 0x65, 0x66, 0xa7, 0x16, 0x41, 0x75, 0xc0, 0xb8, 0x42, 0x22,
0x5c, 0xac, 0x39, 0x99, 0x65, 0xa9, 0xc5, 0x60, 0x5d, 0xac, 0x41, 0x10, 0x8e, 0x93, 0xeb, 0x89,
0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3,
0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x69, 0xa7, 0x67, 0x96, 0x64, 0x94, 0x26,
0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x43, 0xdc, 0x07, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x51, 0x7d,
0x93, 0xc4, 0x06, 0xf6, 0x88, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x64, 0x25, 0x07, 0xc7, 0xe6,
0x00, 0x00, 0x00,
// 264 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0xbd, 0x4e, 0xc3, 0x30,
0x14, 0x85, 0x63, 0x42, 0x8b, 0x6a, 0x98, 0x4c, 0x87, 0xd0, 0xc1, 0x42, 0x99, 0x90, 0xa0, 0xb6,
0x00, 0xf1, 0x00, 0xe5, 0x47, 0x30, 0x67, 0x64, 0x41, 0x4e, 0x62, 0x82, 0x95, 0xd8, 0x17, 0xd5,
0x6e, 0xd5, 0xf2, 0x14, 0x3c, 0x16, 0x63, 0x47, 0x46, 0x94, 0xbc, 0x08, 0xaa, 0x9d, 0x0e, 0x5d,
0xec, 0x73, 0xaf, 0xbe, 0x63, 0x1f, 0x1d, 0x3c, 0x29, 0xa0, 0x94, 0x05, 0x77, 0xd2, 0xba, 0x52,
0x38, 0xc1, 0x3f, 0xe7, 0xe0, 0x80, 0xf9, 0x93, 0x9c, 0x16, 0x60, 0x35, 0xd8, 0x37, 0x5b, 0xd6,
0xcc, 0x63, 0x6c, 0x79, 0x3d, 0x39, 0xab, 0x00, 0xaa, 0x46, 0x06, 0x30, 0x5f, 0xbc, 0x73, 0x61,
0xd6, 0x81, 0x4f, 0xa7, 0x38, 0x7e, 0x84, 0x8a, 0x10, 0x7c, 0x68, 0xd5, 0x97, 0x4c, 0xd0, 0x39,
0xba, 0x18, 0x65, 0x5e, 0x6f, 0x77, 0x46, 0x68, 0x99, 0x1c, 0x84, 0xdd, 0x56, 0xa7, 0x77, 0x38,
0x7e, 0x10, 0x8e, 0x24, 0xf8, 0x48, 0x83, 0x51, 0xb5, 0x9c, 0xf7, 0x8e, 0xdd, 0x48, 0xc6, 0x78,
0xd0, 0xa8, 0xa5, 0xb4, 0xde, 0x35, 0xc8, 0xc2, 0x90, 0x3e, 0xe3, 0xd1, 0x8b, 0xb0, 0x33, 0xa3,
0xb4, 0x68, 0xc8, 0x15, 0x1e, 0x0a, 0xaf, 0xbc, 0xf7, 0xf8, 0x66, 0xcc, 0x42, 0x3c, 0xb6, 0x8b,
0xc7, 0x66, 0x66, 0x9d, 0xf5, 0x0c, 0x39, 0xc1, 0x68, 0xe5, 0x1f, 0x8b, 0x33, 0xb4, 0xba, 0x7f,
0xfa, 0x69, 0x29, 0xda, 0xb4, 0x14, 0xfd, 0xb5, 0x14, 0x7d, 0x77, 0x34, 0xda, 0x74, 0x34, 0xfa,
0xed, 0x68, 0xf4, 0x7a, 0x59, 0x29, 0xf7, 0xb1, 0xc8, 0x59, 0x01, 0x9a, 0x87, 0x0e, 0xfa, 0x6b,
0x6a, 0xcb, 0x9a, 0xef, 0x37, 0x96, 0x0f, 0xfd, 0x57, 0xb7, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff,
0x75, 0xe8, 0x4c, 0xa3, 0x4a, 0x01, 0x00, 0x00,
}
func (m *Dog) Marshal() (dAtA []byte, err error) {
@@ -222,6 +280,46 @@ func (m *Cat) MarshalToSizedBuffer(dAtA []byte) (int, error) {
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.X != 0 {
i = encodeVarintProto(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 = encodeVarintProto(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintProto(dAtA []byte, offset int, v uint64) int {
offset -= sovProto(v)
base := offset
@@ -266,6 +364,22 @@ func (m *Cat) Size() (n int) {
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 + sovProto(uint64(l))
}
if m.X != 0 {
n += 1 + sovProto(uint64(m.X))
}
return n
}
func sovProto(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
@@ -493,6 +607,114 @@ func (m *Cat) Unmarshal(dAtA []byte) error {
}
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 ErrIntOverflowProto
}
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 ErrIntOverflowProto
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthProto
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthProto
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Animal == nil {
m.Animal = &types.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 ErrIntOverflowProto
}
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 := skipProto(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthProto
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthProto
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipProto(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
+7
View File
@@ -1,6 +1,8 @@
syntax = "proto3";
package cosmos_sdk.codec.v1;
import "google/protobuf/any.proto";
option go_package = "github.com/cosmos/cosmos-sdk/codec/testdata";
message Dog {
@@ -12,3 +14,8 @@ message Cat {
string moniker = 1;
int32 lives = 2;
}
message HasAnimal {
google.protobuf.Any animal = 1;
int64 x = 2;
}