proto: add proto3 encode/decode test cases

Change-Id: I5f859fbd34cbd3e95a6c39a5581791dedc619e6b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/169477
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
Damien Neil 2019-03-26 13:55:02 -07:00
parent e63c4c4b81
commit 3b46adeb85
5 changed files with 1709 additions and 35 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,111 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
syntax = "proto3";
package goproto.proto.test3;
import "test3/test_import.proto";
option go_package = "github.com/golang/protobuf/v2/internal/testprotos/test3";
message TestAllTypes {
message NestedMessage {
int32 a = 1;
TestAllTypes corecursive = 2;
}
enum NestedEnum {
FOO = 0;
BAR = 1;
BAZ = 2;
NEG = -1; // Intentionally negative.
}
int32 optional_int32 = 1;
int64 optional_int64 = 2;
uint32 optional_uint32 = 3;
uint64 optional_uint64 = 4;
sint32 optional_sint32 = 5;
sint64 optional_sint64 = 6;
fixed32 optional_fixed32 = 7;
fixed64 optional_fixed64 = 8;
sfixed32 optional_sfixed32 = 9;
sfixed64 optional_sfixed64 = 10;
float optional_float = 11;
double optional_double = 12;
bool optional_bool = 13;
string optional_string = 14;
bytes optional_bytes = 15;
NestedMessage optional_nested_message = 18;
ForeignMessage optional_foreign_message = 19;
ImportMessage optional_import_message = 20;
NestedEnum optional_nested_enum = 21;
ForeignEnum optional_foreign_enum = 22;
ImportEnum optional_import_enum = 23;
repeated int32 repeated_int32 = 31;
repeated int64 repeated_int64 = 32;
repeated uint32 repeated_uint32 = 33;
repeated uint64 repeated_uint64 = 34;
repeated sint32 repeated_sint32 = 35;
repeated sint64 repeated_sint64 = 36;
repeated fixed32 repeated_fixed32 = 37;
repeated fixed64 repeated_fixed64 = 38;
repeated sfixed32 repeated_sfixed32 = 39;
repeated sfixed64 repeated_sfixed64 = 40;
repeated float repeated_float = 41;
repeated double repeated_double = 42;
repeated bool repeated_bool = 43;
repeated string repeated_string = 44;
repeated bytes repeated_bytes = 45;
repeated NestedMessage repeated_nested_message = 48;
repeated ForeignMessage repeated_foreign_message = 49;
repeated ImportMessage repeated_importmessage = 50;
repeated NestedEnum repeated_nested_enum = 51;
repeated ForeignEnum repeated_foreign_enum = 52;
repeated ImportEnum repeated_importenum = 53;
map < int32, int32> map_int32_int32 = 56;
map < int64, int64> map_int64_int64 = 57;
map < uint32, uint32> map_uint32_uint32 = 58;
map < uint64, uint64> map_uint64_uint64 = 59;
map < sint32, sint32> map_sint32_sint32 = 60;
map < sint64, sint64> map_sint64_sint64 = 61;
map < fixed32, fixed32> map_fixed32_fixed32 = 62;
map < fixed64, fixed64> map_fixed64_fixed64 = 63;
map <sfixed32, sfixed32> map_sfixed32_sfixed32 = 64;
map <sfixed64, sfixed64> map_sfixed64_sfixed64 = 65;
map < int32, float> map_int32_float = 66;
map < int32, double> map_int32_double = 67;
map < bool, bool> map_bool_bool = 68;
map < string, string> map_string_string = 69;
map < string, bytes> map_string_bytes = 70;
map < string, NestedMessage> map_string_nested_message = 71;
map < string, NestedEnum> map_string_nested_enum = 73;
oneof oneof_field {
uint32 oneof_uint32 = 111;
NestedMessage oneof_nested_message = 112;
string oneof_string = 113;
bytes oneof_bytes = 114;
bool oneof_bool = 115;
uint64 oneof_uint64 = 116;
float oneof_float = 117;
double oneof_double = 118;
NestedEnum oneof_enum = 119;
}
}
message ForeignMessage {
int32 c = 1;
int32 d = 2;
}
enum ForeignEnum {
FOREIGN_ZERO = 0;
FOREIGN_FOO = 4;
FOREIGN_BAR = 5;
FOREIGN_BAZ = 6;
}

View File

@ -0,0 +1,107 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: test3/test_import.proto
package test3
import (
protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
protoregistry "github.com/golang/protobuf/v2/reflect/protoregistry"
protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
)
type ImportEnum int32
const (
ImportEnum_IMPORT_ZERO ImportEnum = 0
)
func (e ImportEnum) Type() protoreflect.EnumType {
return xxx_File_test3_test_import_proto_enumTypes[0]
}
func (e ImportEnum) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(e)
}
// Deprecated: Use ImportEnum.Type.Values instead.
var ImportEnum_name = map[int32]string{
0: "IMPORT_ZERO",
}
// Deprecated: Use ImportEnum.Type.Values instead.
var ImportEnum_value = map[string]int32{
"IMPORT_ZERO": 0,
}
func (x ImportEnum) String() string {
return protoimpl.X.EnumStringOf(x.Type(), protoreflect.EnumNumber(x))
}
// Deprecated: Use ImportEnum.Type instead.
func (ImportEnum) EnumDescriptor() ([]byte, []int) {
return xxx_File_test3_test_import_proto_rawdesc_gzipped, []int{0}
}
type ImportMessage struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ImportMessage) ProtoReflect() protoreflect.Message {
return xxx_File_test3_test_import_proto_messageTypes[0].MessageOf(m)
}
func (m *ImportMessage) Reset() { *m = ImportMessage{} }
func (m *ImportMessage) String() string { return protoimpl.X.MessageStringOf(m) }
func (*ImportMessage) ProtoMessage() {}
// Deprecated: Use ImportMessage.ProtoReflect.Type instead.
func (*ImportMessage) Descriptor() ([]byte, []int) {
return xxx_File_test3_test_import_proto_rawdesc_gzipped, []int{0}
}
var xxx_File_test3_test_import_proto_rawdesc = []byte{
// 161 bytes of the wire-encoded FileDescriptorProto
0x0a, 0x17, 0x74, 0x65, 0x73, 0x74, 0x33, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x6d, 0x70,
0x6f, 0x72, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x67, 0x6f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x33, 0x22, 0x0f,
0x0a, 0x0d, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a,
0x1d, 0x0a, 0x0a, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x0f, 0x0a,
0x0b, 0x49, 0x4d, 0x50, 0x4f, 0x52, 0x54, 0x5f, 0x5a, 0x45, 0x52, 0x4f, 0x10, 0x00, 0x42, 0x39,
0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c,
0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x32, 0x2f,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x33, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var xxx_File_test3_test_import_proto_rawdesc_gzipped = protoimpl.X.CompressGZIP(xxx_File_test3_test_import_proto_rawdesc)
const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
var File_test3_test_import_proto protoreflect.FileDescriptor
var xxx_File_test3_test_import_proto_enumTypes = make([]protoreflect.EnumType, 1)
var xxx_File_test3_test_import_proto_messageTypes = make([]protoimpl.MessageType, 1)
var xxx_File_test3_test_import_proto_goTypes = []interface{}{
(ImportEnum)(0), // 0: goproto.proto.test3.ImportEnum
(*ImportMessage)(nil), // 1: goproto.proto.test3.ImportMessage
}
var xxx_File_test3_test_import_proto_depIdxs = []int32{}
func init() { xxx_File_test3_test_import_proto_init() }
func xxx_File_test3_test_import_proto_init() {
if File_test3_test_import_proto != nil {
return
}
File_test3_test_import_proto = protoimpl.FileBuilder{
RawDescriptor: xxx_File_test3_test_import_proto_rawdesc,
GoTypes: xxx_File_test3_test_import_proto_goTypes,
DependencyIndexes: xxx_File_test3_test_import_proto_depIdxs,
EnumOutputTypes: xxx_File_test3_test_import_proto_enumTypes,
MessageOutputTypes: xxx_File_test3_test_import_proto_messageTypes,
FilesRegistry: protoregistry.GlobalFiles,
TypesRegistry: protoregistry.GlobalTypes,
}.Init()
xxx_File_test3_test_import_proto_goTypes = nil
xxx_File_test3_test_import_proto_depIdxs = nil
}

View File

@ -0,0 +1,16 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
syntax = "proto3";
package goproto.proto.test3;
option go_package = "github.com/golang/protobuf/v2/internal/testprotos/test3";
message ImportMessage {
}
enum ImportEnum {
IMPORT_ZERO = 0;
}

View File

@ -16,6 +16,7 @@ import (
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
testpb "github.com/golang/protobuf/v2/internal/testprotos/test"
test3pb "github.com/golang/protobuf/v2/internal/testprotos/test3"
)
type testProto struct {
@ -69,6 +70,23 @@ var testProtos = []testProto{
OptionalString: scalar.String("string"),
OptionalBytes: []byte("bytes"),
OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum(),
}, &test3pb.TestAllTypes{
OptionalInt32: 1001,
OptionalInt64: 1002,
OptionalUint32: 1003,
OptionalUint64: 1004,
OptionalSint32: 1005,
OptionalSint64: 1006,
OptionalFixed32: 1007,
OptionalFixed64: 1008,
OptionalSfixed32: 1009,
OptionalSfixed64: 1010,
OptionalFloat: 1011.5,
OptionalDouble: 1012.5,
OptionalBool: true,
OptionalString: "string",
OptionalBytes: []byte("bytes"),
OptionalNestedEnum: test3pb.TestAllTypes_BAR,
}, build(
&testpb.TestAllExtensions{},
extend(testpb.E_OptionalInt32Extension, scalar.Int32(1001)),
@ -155,6 +173,13 @@ var testProtos = []testProto{
OptionalInt32: scalar.Int32(43),
},
},
}, &test3pb.TestAllTypes{
OptionalNestedMessage: &test3pb.TestAllTypes_NestedMessage{
A: 42,
Corecursive: &test3pb.TestAllTypes{
OptionalInt32: 43,
},
},
}, build(
&testpb.TestAllExtensions{},
extend(testpb.E_OptionalNestedMessageExtension, &testpb.TestAllTypes_NestedMessage{
@ -182,6 +207,13 @@ var testProtos = []testProto{
OptionalInt32: scalar.Int32(43),
},
},
}, &test3pb.TestAllTypes{
OptionalNestedMessage: &test3pb.TestAllTypes_NestedMessage{
A: 42,
Corecursive: &test3pb.TestAllTypes{
OptionalInt32: 43,
},
},
}, build(
&testpb.TestAllExtensions{},
extend(testpb.E_OptionalNestedMessageExtension, &testpb.TestAllTypes_NestedMessage{
@ -208,6 +240,10 @@ var testProtos = []testProto{
OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{
A: scalar.Int32(2),
},
}, &test3pb.TestAllTypes{
OptionalNestedMessage: &test3pb.TestAllTypes_NestedMessage{
A: 2,
},
}, build(
&testpb.TestAllExtensions{},
extend(testpb.E_OptionalNestedMessageExtension, &testpb.TestAllTypes_NestedMessage{
@ -245,6 +281,26 @@ var testProtos = []testProto{
testpb.TestAllTypes_FOO,
testpb.TestAllTypes_BAR,
},
}, &test3pb.TestAllTypes{
RepeatedInt32: []int32{1001, 2001},
RepeatedInt64: []int64{1002, 2002},
RepeatedUint32: []uint32{1003, 2003},
RepeatedUint64: []uint64{1004, 2004},
RepeatedSint32: []int32{1005, 2005},
RepeatedSint64: []int64{1006, 2006},
RepeatedFixed32: []uint32{1007, 2007},
RepeatedFixed64: []uint64{1008, 2008},
RepeatedSfixed32: []int32{1009, 2009},
RepeatedSfixed64: []int64{1010, 2010},
RepeatedFloat: []float32{1011.5, 2011.5},
RepeatedDouble: []float64{1012.5, 2012.5},
RepeatedBool: []bool{true, false},
RepeatedString: []string{"foo", "bar"},
RepeatedBytes: [][]byte{[]byte("FOO"), []byte("BAR")},
RepeatedNestedEnum: []test3pb.TestAllTypes_NestedEnum{
test3pb.TestAllTypes_FOO,
test3pb.TestAllTypes_BAR,
},
}, build(
&testpb.TestAllExtensions{},
extend(testpb.E_RepeatedInt32Extension, []int32{1001, 2001}),
@ -322,6 +378,24 @@ var testProtos = []testProto{
testpb.TestAllTypes_FOO,
testpb.TestAllTypes_BAR,
},
}, &test3pb.TestAllTypes{
RepeatedInt32: []int32{1001, 2001},
RepeatedInt64: []int64{1002, 2002},
RepeatedUint32: []uint32{1003, 2003},
RepeatedUint64: []uint64{1004, 2004},
RepeatedSint32: []int32{1005, 2005},
RepeatedSint64: []int64{1006, 2006},
RepeatedFixed32: []uint32{1007, 2007},
RepeatedFixed64: []uint64{1008, 2008},
RepeatedSfixed32: []int32{1009, 2009},
RepeatedSfixed64: []int64{1010, 2010},
RepeatedFloat: []float32{1011.5, 2011.5},
RepeatedDouble: []float64{1012.5, 2012.5},
RepeatedBool: []bool{true, false},
RepeatedNestedEnum: []test3pb.TestAllTypes_NestedEnum{
test3pb.TestAllTypes_FOO,
test3pb.TestAllTypes_BAR,
},
}, build(
&testpb.TestAllExtensions{},
extend(testpb.E_RepeatedInt32Extension, []int32{1001, 2001}),
@ -395,6 +469,11 @@ var testProtos = []testProto{
{A: scalar.Int32(1)},
{A: scalar.Int32(2)},
},
}, &test3pb.TestAllTypes{
RepeatedNestedMessage: []*test3pb.TestAllTypes_NestedMessage{
{A: 1},
{A: 2},
},
}, build(
&testpb.TestAllExtensions{},
extend(testpb.E_RepeatedNestedMessageExtension, []*testpb.TestAllTypes_NestedMessage{
@ -460,6 +539,30 @@ var testProtos = []testProto{
"73.1.key": testpb.TestAllTypes_FOO,
"73.2.key": testpb.TestAllTypes_BAR,
},
}, &test3pb.TestAllTypes{
MapInt32Int32: map[int32]int32{1056: 1156, 2056: 2156},
MapInt64Int64: map[int64]int64{1057: 1157, 2057: 2157},
MapUint32Uint32: map[uint32]uint32{1058: 1158, 2058: 2158},
MapUint64Uint64: map[uint64]uint64{1059: 1159, 2059: 2159},
MapSint32Sint32: map[int32]int32{1060: 1160, 2060: 2160},
MapSint64Sint64: map[int64]int64{1061: 1161, 2061: 2161},
MapFixed32Fixed32: map[uint32]uint32{1062: 1162, 2062: 2162},
MapFixed64Fixed64: map[uint64]uint64{1063: 1163, 2063: 2163},
MapSfixed32Sfixed32: map[int32]int32{1064: 1164, 2064: 2164},
MapSfixed64Sfixed64: map[int64]int64{1065: 1165, 2065: 2165},
MapInt32Float: map[int32]float32{1066: 1166.5, 2066: 2166.5},
MapInt32Double: map[int32]float64{1067: 1167.5, 2067: 2167.5},
MapBoolBool: map[bool]bool{true: false, false: true},
MapStringString: map[string]string{"69.1.key": "69.1.val", "69.2.key": "69.2.val"},
MapStringBytes: map[string][]byte{"70.1.key": []byte("70.1.val"), "70.2.key": []byte("70.2.val")},
MapStringNestedMessage: map[string]*test3pb.TestAllTypes_NestedMessage{
"71.1.key": {A: 1171},
"71.2.key": {A: 2171},
},
MapStringNestedEnum: map[string]test3pb.TestAllTypes_NestedEnum{
"73.1.key": test3pb.TestAllTypes_FOO,
"73.2.key": test3pb.TestAllTypes_BAR,
},
}},
wire: pack.Message{
pack.Tag{56, pack.BytesType}, pack.LengthPrefix(pack.Message{
@ -605,28 +708,42 @@ var testProtos = []testProto{
}.Marshal(),
},
{
desc: "oneof (uint32)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{1111}}},
wire: pack.Message{pack.Tag{111, pack.VarintType}, pack.Varint(1111)}.Marshal(),
desc: "oneof (uint32)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{1111}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofUint32{1111}},
},
wire: pack.Message{pack.Tag{111, pack.VarintType}, pack.Varint(1111)}.Marshal(),
},
{
desc: "oneof (message)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofNestedMessage{
&testpb.TestAllTypes_NestedMessage{A: scalar.Int32(1112)},
}}},
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofNestedMessage{
&testpb.TestAllTypes_NestedMessage{A: scalar.Int32(1112)},
}}, &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofNestedMessage{
&test3pb.TestAllTypes_NestedMessage{A: 1112},
}},
},
wire: pack.Message{pack.Tag{112, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Message{pack.Tag{1, pack.VarintType}, pack.Varint(1112)},
})}.Marshal(),
},
{
desc: "oneof (overridden message)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofNestedMessage{
&testpb.TestAllTypes_NestedMessage{
Corecursive: &testpb.TestAllTypes{
OptionalInt32: scalar.Int32(43),
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofNestedMessage{
&testpb.TestAllTypes_NestedMessage{
Corecursive: &testpb.TestAllTypes{
OptionalInt32: scalar.Int32(43),
},
},
},
}}},
}}, &test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofNestedMessage{
&test3pb.TestAllTypes_NestedMessage{
Corecursive: &test3pb.TestAllTypes{
OptionalInt32: 43,
},
},
}}},
wire: pack.Message{
pack.Tag{112, pack.BytesType}, pack.LengthPrefix(pack.Message{
pack.Message{pack.Tag{1, pack.VarintType}, pack.Varint(1)},
@ -639,43 +756,67 @@ var testProtos = []testProto{
}.Marshal(),
},
{
desc: "oneof (string)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofString{"1113"}}},
wire: pack.Message{pack.Tag{113, pack.BytesType}, pack.String("1113")}.Marshal(),
desc: "oneof (string)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofString{"1113"}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofString{"1113"}},
},
wire: pack.Message{pack.Tag{113, pack.BytesType}, pack.String("1113")}.Marshal(),
},
{
desc: "oneof (bytes)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofBytes{[]byte("1114")}}},
wire: pack.Message{pack.Tag{114, pack.BytesType}, pack.String("1114")}.Marshal(),
desc: "oneof (bytes)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofBytes{[]byte("1114")}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofBytes{[]byte("1114")}},
},
wire: pack.Message{pack.Tag{114, pack.BytesType}, pack.String("1114")}.Marshal(),
},
{
desc: "oneof (bool)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofBool{true}}},
wire: pack.Message{pack.Tag{115, pack.VarintType}, pack.Bool(true)}.Marshal(),
desc: "oneof (bool)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofBool{true}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofBool{true}},
},
wire: pack.Message{pack.Tag{115, pack.VarintType}, pack.Bool(true)}.Marshal(),
},
{
desc: "oneof (uint64)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint64{116}}},
wire: pack.Message{pack.Tag{116, pack.VarintType}, pack.Varint(116)}.Marshal(),
desc: "oneof (uint64)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint64{116}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofUint64{116}},
},
wire: pack.Message{pack.Tag{116, pack.VarintType}, pack.Varint(116)}.Marshal(),
},
{
desc: "oneof (float)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofFloat{117.5}}},
wire: pack.Message{pack.Tag{117, pack.Fixed32Type}, pack.Float32(117.5)}.Marshal(),
desc: "oneof (float)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofFloat{117.5}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofFloat{117.5}},
},
wire: pack.Message{pack.Tag{117, pack.Fixed32Type}, pack.Float32(117.5)}.Marshal(),
},
{
desc: "oneof (double)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofDouble{118.5}}},
wire: pack.Message{pack.Tag{118, pack.Fixed64Type}, pack.Float64(118.5)}.Marshal(),
desc: "oneof (double)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofDouble{118.5}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofDouble{118.5}},
},
wire: pack.Message{pack.Tag{118, pack.Fixed64Type}, pack.Float64(118.5)}.Marshal(),
},
{
desc: "oneof (enum)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofEnum{testpb.TestAllTypes_BAR}}},
wire: pack.Message{pack.Tag{119, pack.VarintType}, pack.Varint(int(testpb.TestAllTypes_BAR))}.Marshal(),
desc: "oneof (enum)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofEnum{testpb.TestAllTypes_BAR}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofEnum{test3pb.TestAllTypes_BAR}},
},
wire: pack.Message{pack.Tag{119, pack.VarintType}, pack.Varint(int(testpb.TestAllTypes_BAR))}.Marshal(),
},
{
desc: "oneof (overridden value)",
decodeTo: []proto.Message{&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint64{2}}},
desc: "oneof (overridden value)",
decodeTo: []proto.Message{
&testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint64{2}},
&test3pb.TestAllTypes{OneofField: &test3pb.TestAllTypes_OneofUint64{2}},
},
wire: pack.Message{
pack.Tag{111, pack.VarintType}, pack.Varint(1),
pack.Tag{116, pack.VarintType}, pack.Varint(2),
@ -693,6 +834,11 @@ var testProtos = []testProto{
unknown(100000, pack.Message{
pack.Tag{100000, pack.VarintType}, pack.Varint(1),
}.Marshal()),
), build(
&test3pb.TestAllTypes{},
unknown(100000, pack.Message{
pack.Tag{100000, pack.VarintType}, pack.Varint(1),
}.Marshal()),
)},
wire: pack.Message{
pack.Tag{100000, pack.VarintType}, pack.Varint(1),
@ -705,6 +851,11 @@ var testProtos = []testProto{
unknown(1, pack.Message{
pack.Tag{1, pack.BytesType}, pack.String("string"),
}.Marshal()),
), build(
&test3pb.TestAllTypes{},
unknown(1, pack.Message{
pack.Tag{1, pack.BytesType}, pack.String("string"),
}.Marshal()),
)},
wire: pack.Message{
pack.Tag{1, pack.BytesType}, pack.String("string"),
@ -715,6 +866,8 @@ var testProtos = []testProto{
decodeTo: []proto.Message{
&testpb.TestAllTypes{
MapInt32Int32: map[int32]int32{1: 0},
}, &test3pb.TestAllTypes{
MapInt32Int32: map[int32]int32{1: 0},
},
},
wire: pack.Message{