mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-04-17 11:42:38 +00:00
all: add editions support for extensions
Before this change the implementation would ignore editions options set on extension declarations. This change also add much more coverage for valid messages. Change-Id: I0e7029b1430a39859cdd4a93667ac20c7e0ff20e Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/565396 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com> Auto-Submit: Lasse Folger <lassefolger@google.com>
This commit is contained in:
parent
7d98b0e8ab
commit
11de0a6409
@ -420,10 +420,11 @@ type (
|
||||
L2 *ExtensionL2 // protected by fileDesc.once
|
||||
}
|
||||
ExtensionL1 struct {
|
||||
Number protoreflect.FieldNumber
|
||||
Extendee protoreflect.MessageDescriptor
|
||||
Cardinality protoreflect.Cardinality
|
||||
Kind protoreflect.Kind
|
||||
Number protoreflect.FieldNumber
|
||||
Extendee protoreflect.MessageDescriptor
|
||||
Cardinality protoreflect.Cardinality
|
||||
Kind protoreflect.Kind
|
||||
EditionFeatures EditionFeatures
|
||||
}
|
||||
ExtensionL2 struct {
|
||||
Options func() protoreflect.ProtoMessage
|
||||
|
@ -556,6 +556,7 @@ func (od *Oneof) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd protoref
|
||||
func (xd *Extension) unmarshalFull(b []byte, sb *strs.Builder) {
|
||||
var rawTypeName []byte
|
||||
var rawOptions []byte
|
||||
xd.L1.EditionFeatures = featuresFromParentDesc(xd.L1.Extendee)
|
||||
xd.L2 = new(ExtensionL2)
|
||||
for len(b) > 0 {
|
||||
num, typ, n := protowire.ConsumeTag(b)
|
||||
@ -587,6 +588,12 @@ func (xd *Extension) unmarshalFull(b []byte, sb *strs.Builder) {
|
||||
b = b[m:]
|
||||
}
|
||||
}
|
||||
if xd.Syntax() == protoreflect.Editions && xd.L1.Kind == protoreflect.MessageKind && xd.L1.EditionFeatures.IsDelimitedEncoded {
|
||||
xd.L1.Kind = protoreflect.GroupKind
|
||||
}
|
||||
if xd.Syntax() == protoreflect.Editions && xd.L1.EditionFeatures.IsLegacyRequired {
|
||||
xd.L1.Cardinality = protoreflect.Required
|
||||
}
|
||||
if rawTypeName != nil {
|
||||
name := makeFullName(sb, rawTypeName)
|
||||
switch xd.L1.Kind {
|
||||
@ -611,6 +618,13 @@ func (xd *Extension) unmarshalOptions(b []byte) {
|
||||
case genid.FieldOptions_Packed_field_number:
|
||||
xd.L2.IsPacked = protowire.DecodeBool(v)
|
||||
}
|
||||
case protowire.BytesType:
|
||||
v, m := protowire.ConsumeBytes(b)
|
||||
b = b[m:]
|
||||
switch num {
|
||||
case genid.FieldOptions_Features_field_number:
|
||||
xd.L1.EditionFeatures = unmarshalFeatureSet(v, xd.L1.EditionFeatures)
|
||||
}
|
||||
default:
|
||||
m := protowire.ConsumeFieldValue(num, typ, b)
|
||||
b = b[m:]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -126,6 +126,10 @@ message TestAllTypes {
|
||||
NestedEnum default_nested_enum = 96 [default = BAR];
|
||||
ForeignEnum default_foreign_enum = 97 [default = FOREIGN_BAR];
|
||||
|
||||
message OneofGroup {
|
||||
int32 a = 1;
|
||||
int32 b = 2;
|
||||
}
|
||||
oneof oneof_field {
|
||||
uint32 oneof_uint32 = 111;
|
||||
NestedMessage oneof_nested_message = 112;
|
||||
@ -136,6 +140,7 @@ message TestAllTypes {
|
||||
float oneof_float = 117;
|
||||
double oneof_double = 118;
|
||||
NestedEnum oneof_enum = 119;
|
||||
OneofGroup oneofgroup = 121 [features.message_encoding = DELIMITED];
|
||||
}
|
||||
|
||||
// A oneof with exactly one field.
|
||||
@ -168,3 +173,73 @@ message TestRequiredForeign {
|
||||
TestRequired oneof_message = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message TestRequiredGroupFields {
|
||||
message OptionalGroup {
|
||||
int32 a = 2 [features.field_presence = LEGACY_REQUIRED];
|
||||
}
|
||||
OptionalGroup optionalgroup = 1 [features.message_encoding = DELIMITED];
|
||||
message RepeatedGroup {
|
||||
int32 a = 4 [features.field_presence = LEGACY_REQUIRED];
|
||||
}
|
||||
repeated RepeatedGroup repeatedgroup = 3
|
||||
[features.message_encoding = DELIMITED];
|
||||
}
|
||||
|
||||
message TestPackedTypes {
|
||||
repeated int32 packed_int32 = 90 [features.repeated_field_encoding = PACKED];
|
||||
repeated int64 packed_int64 = 91 [features.repeated_field_encoding = PACKED];
|
||||
repeated uint32 packed_uint32 = 92
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated uint64 packed_uint64 = 93
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated sint32 packed_sint32 = 94
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated sint64 packed_sint64 = 95
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated fixed32 packed_fixed32 = 96
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated fixed64 packed_fixed64 = 97
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated sfixed32 packed_sfixed32 = 98
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated sfixed64 packed_sfixed64 = 99
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated float packed_float = 100 [features.repeated_field_encoding = PACKED];
|
||||
repeated double packed_double = 101
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated bool packed_bool = 102 [features.repeated_field_encoding = PACKED];
|
||||
repeated ForeignEnum packed_enum = 103
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
}
|
||||
|
||||
message TestPackedExtensions {
|
||||
extensions 1 to max;
|
||||
}
|
||||
|
||||
extend TestPackedExtensions {
|
||||
repeated int32 packed_int32 = 90 [features.repeated_field_encoding = PACKED];
|
||||
repeated int64 packed_int64 = 91 [features.repeated_field_encoding = PACKED];
|
||||
repeated uint32 packed_uint32 = 92
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated uint64 packed_uint64 = 93
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated sint32 packed_sint32 = 94
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated sint64 packed_sint64 = 95
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated fixed32 packed_fixed32 = 96
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated fixed64 packed_fixed64 = 97
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated sfixed32 packed_sfixed32 = 98
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated sfixed64 packed_sfixed64 = 99
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated float packed_float = 100 [features.repeated_field_encoding = PACKED];
|
||||
repeated double packed_double = 101
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
repeated bool packed_bool = 102 [features.repeated_field_encoding = PACKED];
|
||||
repeated ForeignEnum packed_enum = 103
|
||||
[features.repeated_field_encoding = PACKED];
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{21, protopack.VarintType}, protopack.Varint(int(testpb.TestAllTypes_BAR)),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "zero values",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -142,8 +143,9 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{15, protopack.BytesType}, protopack.Bytes(nil),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "proto3 zero values",
|
||||
desc: "editions zero values on implicit fields",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
"singular_int32": 0,
|
||||
"singular_int64": 0,
|
||||
@ -160,25 +162,26 @@ var testValidMessages = []testProto{
|
||||
"singular_bool": false,
|
||||
"singular_string": "",
|
||||
"singular_bytes": []byte{},
|
||||
}, &test3pb.TestAllTypes{}),
|
||||
}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{81, protopack.VarintType}, protopack.Varint(0),
|
||||
protopack.Tag{82, protopack.VarintType}, protopack.Varint(0),
|
||||
protopack.Tag{83, protopack.VarintType}, protopack.Uvarint(0),
|
||||
protopack.Tag{84, protopack.VarintType}, protopack.Uvarint(0),
|
||||
protopack.Tag{85, protopack.VarintType}, protopack.Svarint(0),
|
||||
protopack.Tag{86, protopack.VarintType}, protopack.Svarint(0),
|
||||
protopack.Tag{87, protopack.Fixed32Type}, protopack.Uint32(0),
|
||||
protopack.Tag{88, protopack.Fixed64Type}, protopack.Uint64(0),
|
||||
protopack.Tag{89, protopack.Fixed32Type}, protopack.Int32(0),
|
||||
protopack.Tag{90, protopack.Fixed64Type}, protopack.Int64(0),
|
||||
protopack.Tag{91, protopack.Fixed32Type}, protopack.Float32(0),
|
||||
protopack.Tag{92, protopack.Fixed64Type}, protopack.Float64(0),
|
||||
protopack.Tag{93, protopack.VarintType}, protopack.Bool(false),
|
||||
protopack.Tag{94, protopack.BytesType}, protopack.String(""),
|
||||
protopack.Tag{95, protopack.BytesType}, protopack.Bytes(nil),
|
||||
protopack.Tag{124, protopack.VarintType}, protopack.Varint(0),
|
||||
protopack.Tag{125, protopack.VarintType}, protopack.Varint(0),
|
||||
protopack.Tag{126, protopack.VarintType}, protopack.Uvarint(0),
|
||||
protopack.Tag{127, protopack.VarintType}, protopack.Uvarint(0),
|
||||
protopack.Tag{128, protopack.VarintType}, protopack.Svarint(0),
|
||||
protopack.Tag{129, protopack.VarintType}, protopack.Svarint(0),
|
||||
protopack.Tag{130, protopack.Fixed32Type}, protopack.Uint32(0),
|
||||
protopack.Tag{131, protopack.Fixed64Type}, protopack.Uint64(0),
|
||||
protopack.Tag{132, protopack.Fixed32Type}, protopack.Int32(0),
|
||||
protopack.Tag{133, protopack.Fixed64Type}, protopack.Int64(0),
|
||||
protopack.Tag{134, protopack.Fixed32Type}, protopack.Float32(0),
|
||||
protopack.Tag{135, protopack.Fixed64Type}, protopack.Float64(0),
|
||||
protopack.Tag{136, protopack.VarintType}, protopack.Bool(false),
|
||||
protopack.Tag{137, protopack.BytesType}, protopack.String(""),
|
||||
protopack.Tag{138, protopack.BytesType}, protopack.Bytes(nil),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "groups",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -186,7 +189,7 @@ var testValidMessages = []testProto{
|
||||
"a": 1017,
|
||||
"same_field_number": 1016,
|
||||
},
|
||||
}, &testpb.TestAllTypes{}, &testpb.TestAllExtensions{}),
|
||||
}, &testpb.TestAllTypes{}, &testpb.TestAllExtensions{}, &testeditionspb.TestAllTypes{}, &testeditionspb.TestAllExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{16, protopack.StartGroupType},
|
||||
protopack.Tag{17, protopack.VarintType}, protopack.Varint(1017),
|
||||
@ -194,13 +197,14 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{16, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "groups (field overridden)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
"optionalgroup": protobuild.Message{
|
||||
"a": 2,
|
||||
},
|
||||
}, &testpb.TestAllTypes{}, &testpb.TestAllExtensions{}),
|
||||
}, &testpb.TestAllTypes{}, &testpb.TestAllExtensions{}, &testeditionspb.TestAllTypes{}, &testeditionspb.TestAllExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{16, protopack.StartGroupType},
|
||||
protopack.Tag{17, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -210,6 +214,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{16, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "messages",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -229,6 +234,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "messages (split across multiple tags)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -250,6 +256,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "messages (field overridden)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -266,6 +273,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "basic repeated types",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -321,6 +329,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{51, protopack.VarintType}, protopack.Varint(int(testpb.TestAllTypes_BAR)),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "basic repeated types (packed encoding)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -385,6 +394,7 @@ var testValidMessages = []testProto{
|
||||
},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "basic repeated types (zero-length packed encoding)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -420,6 +430,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{51, protopack.BytesType}, protopack.LengthPrefix{},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "packed repeated types",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -484,6 +495,7 @@ var testValidMessages = []testProto{
|
||||
},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "packed repeated types (zero length)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -501,7 +513,7 @@ var testValidMessages = []testProto{
|
||||
"packed_double": []float64{},
|
||||
"packed_bool": []bool{},
|
||||
"packed_enum": []string{},
|
||||
}, &testpb.TestPackedTypes{}, &testpb.TestPackedExtensions{}),
|
||||
}, &testpb.TestPackedTypes{}, &testpb.TestPackedExtensions{}, &testeditionspb.TestPackedTypes{}, &testeditionspb.TestPackedExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{90, protopack.BytesType}, protopack.LengthPrefix{},
|
||||
protopack.Tag{91, protopack.BytesType}, protopack.LengthPrefix{},
|
||||
@ -519,6 +531,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{103, protopack.BytesType}, protopack.LengthPrefix{},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "repeated messages",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -538,6 +551,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "repeated nil messages",
|
||||
decodeTo: []proto.Message{&testpb.TestAllTypes{
|
||||
@ -546,6 +560,12 @@ var testValidMessages = []testProto{
|
||||
nil,
|
||||
{A: proto.Int32(2)},
|
||||
},
|
||||
}, &testeditionspb.TestAllTypes{
|
||||
RepeatedNestedMessage: []*testeditionspb.TestAllTypes_NestedMessage{
|
||||
{A: proto.Int32(1)},
|
||||
nil,
|
||||
{A: proto.Int32(2)},
|
||||
},
|
||||
}, &test3pb.TestAllTypes{
|
||||
RepeatedNestedMessage: []*test3pb.TestAllTypes_NestedMessage{
|
||||
{A: 1},
|
||||
@ -559,6 +579,13 @@ var testValidMessages = []testProto{
|
||||
nil,
|
||||
{A: proto.Int32(2)},
|
||||
}),
|
||||
), build(
|
||||
&testeditionspb.TestAllExtensions{},
|
||||
extend(testeditionspb.E_RepeatedNestedMessage, []*testeditionspb.TestAllExtensions_NestedMessage{
|
||||
{A: proto.Int32(1)},
|
||||
nil,
|
||||
{A: proto.Int32(2)},
|
||||
}),
|
||||
)},
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{48, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
@ -570,6 +597,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "repeated groups",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -578,7 +606,7 @@ var testValidMessages = []testProto{
|
||||
{},
|
||||
{"a": 2017},
|
||||
},
|
||||
}, &testpb.TestAllTypes{}, &testpb.TestAllExtensions{}),
|
||||
}, &testpb.TestAllTypes{}, &testpb.TestAllExtensions{}, &testeditionspb.TestAllTypes{}, &testeditionspb.TestAllExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{46, protopack.StartGroupType},
|
||||
protopack.Tag{47, protopack.VarintType}, protopack.Varint(1017),
|
||||
@ -590,6 +618,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{46, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "repeated nil groups",
|
||||
decodeTo: []proto.Message{&testpb.TestAllTypes{
|
||||
@ -598,6 +627,12 @@ var testValidMessages = []testProto{
|
||||
nil,
|
||||
{A: proto.Int32(2017)},
|
||||
},
|
||||
}, &testeditionspb.TestAllTypes{
|
||||
Repeatedgroup: []*testeditionspb.TestAllTypes_RepeatedGroup{
|
||||
{A: proto.Int32(1017)},
|
||||
nil,
|
||||
{A: proto.Int32(2017)},
|
||||
},
|
||||
}, build(
|
||||
&testpb.TestAllExtensions{},
|
||||
extend(testpb.E_Repeatedgroup, []*testpb.RepeatedGroup{
|
||||
@ -605,6 +640,13 @@ var testValidMessages = []testProto{
|
||||
nil,
|
||||
{A: proto.Int32(2017)},
|
||||
}),
|
||||
), build(
|
||||
&testeditionspb.TestAllExtensions{},
|
||||
extend(testeditionspb.E_Repeatedgroup, []*testeditionspb.RepeatedGroup{
|
||||
{A: proto.Int32(1017)},
|
||||
nil,
|
||||
{A: proto.Int32(2017)},
|
||||
}),
|
||||
)},
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{46, protopack.StartGroupType},
|
||||
@ -617,6 +659,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{46, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "maps",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -784,6 +827,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "map with value before key",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -805,6 +849,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "map with repeated key and value",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -830,6 +875,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (uint32)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -837,6 +883,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{111, protopack.VarintType}, protopack.Varint(1111)}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (message)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -848,6 +895,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Message{protopack.Tag{1, protopack.VarintType}, protopack.Varint(1112)},
|
||||
})}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (empty message)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -855,6 +903,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{112, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{})}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (merged message)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -876,29 +925,32 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (group)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
"oneofgroup": protobuild.Message{
|
||||
"a": 1,
|
||||
},
|
||||
}, &testpb.TestAllTypes{}),
|
||||
}, &testpb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{121, protopack.StartGroupType},
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
protopack.Tag{121, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (empty group)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
"oneofgroup": protobuild.Message{},
|
||||
}, &testpb.TestAllTypes{}),
|
||||
}, &testpb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{121, protopack.StartGroupType},
|
||||
protopack.Tag{121, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (merged group)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -906,7 +958,7 @@ var testValidMessages = []testProto{
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
},
|
||||
}, &testpb.TestAllTypes{}),
|
||||
}, &testpb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{121, protopack.StartGroupType},
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -916,6 +968,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{121, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (string)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -923,6 +976,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{113, protopack.BytesType}, protopack.String("1113")}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (bytes)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -930,6 +984,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{114, protopack.BytesType}, protopack.String("1114")}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (bool)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -937,6 +992,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{115, protopack.VarintType}, protopack.Bool(true)}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (uint64)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -944,6 +1000,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{116, protopack.VarintType}, protopack.Varint(116)}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (float)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -951,6 +1008,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{117, protopack.Fixed32Type}, protopack.Float32(117.5)}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (double)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -958,6 +1016,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{118, protopack.Fixed64Type}, protopack.Float64(118.5)}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (enum)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -965,6 +1024,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{119, protopack.VarintType}, protopack.Varint(int(testpb.TestAllTypes_BAR))}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (zero)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -972,6 +1032,7 @@ var testValidMessages = []testProto{
|
||||
}, &testpb.TestAllTypes{}, &test3pb.TestAllTypes{}, &testeditionspb.TestAllTypes{}),
|
||||
wire: protopack.Message{protopack.Tag{116, protopack.VarintType}, protopack.Varint(0)}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "oneof (overridden value)",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -982,11 +1043,13 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{116, protopack.VarintType}, protopack.Varint(2),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
// TODO: More unknown field tests for ordering, repeated fields, etc.
|
||||
//
|
||||
// It is currently impossible to produce results that the v1 Equal
|
||||
// considers equivalent to those of the v1 decoder. Figure out if
|
||||
// that's a problem or not.
|
||||
|
||||
{
|
||||
desc: "unknown fields",
|
||||
checkFastInit: true,
|
||||
@ -999,6 +1062,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "discarded unknown fields",
|
||||
unmarshalOptions: proto.UnmarshalOptions{
|
||||
@ -1009,6 +1073,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "field type mismatch",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -1020,6 +1085,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.String("string"),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "map field element mismatch",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -1032,18 +1098,21 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in nil message unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: []proto.Message{(*testpb.TestRequired)(nil)},
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required int32 unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{}, &requiredpb.Int32{}),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required int32 set",
|
||||
checkFastInit: true,
|
||||
@ -1054,12 +1123,14 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required fixed32 unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{}, &requiredpb.Fixed32{}),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required fixed32 set",
|
||||
checkFastInit: true,
|
||||
@ -1070,12 +1141,14 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{1, protopack.Fixed32Type}, protopack.Int32(1),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required fixed64 unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{}, &requiredpb.Fixed64{}),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required fixed64 set",
|
||||
checkFastInit: true,
|
||||
@ -1086,12 +1159,14 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{1, protopack.Fixed64Type}, protopack.Int64(1),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required bytes unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{}, &requiredpb.Bytes{}),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required bytes set",
|
||||
checkFastInit: true,
|
||||
@ -1102,12 +1177,14 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.Bytes(nil),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required message unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{}, &requiredpb.Message{}),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required message set",
|
||||
checkFastInit: true,
|
||||
@ -1118,12 +1195,14 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required group unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{}, &requiredpb.Group{}),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required group set",
|
||||
checkFastInit: true,
|
||||
@ -1135,6 +1214,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{1, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field with incompatible wire type",
|
||||
checkFastInit: true,
|
||||
@ -1144,22 +1224,29 @@ var testValidMessages = []testProto{
|
||||
unknown(protopack.Message{
|
||||
protopack.Tag{1, protopack.Fixed32Type}, protopack.Int32(2),
|
||||
}.Marshal()),
|
||||
), build(
|
||||
&testeditionspb.TestRequired{},
|
||||
unknown(protopack.Message{
|
||||
protopack.Tag{1, protopack.Fixed32Type}, protopack.Int32(2),
|
||||
}.Marshal()),
|
||||
)},
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1, protopack.Fixed32Type}, protopack.Int32(2),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in optional message unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
"optional_message": protobuild.Message{},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in optional message set",
|
||||
checkFastInit: true,
|
||||
@ -1167,13 +1254,14 @@ var testValidMessages = []testProto{
|
||||
"optional_message": protobuild.Message{
|
||||
"required_field": 1,
|
||||
},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in optional message set (split across multiple tags)",
|
||||
checkFastInit: false, // fast init checks don't handle split messages
|
||||
@ -1182,7 +1270,7 @@ var testValidMessages = []testProto{
|
||||
"optional_message": protobuild.Message{
|
||||
"required_field": 1,
|
||||
},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
@ -1190,6 +1278,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in repeated message unset",
|
||||
checkFastInit: true,
|
||||
@ -1199,7 +1288,7 @@ var testValidMessages = []testProto{
|
||||
{"required_field": 1},
|
||||
{},
|
||||
},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -1207,6 +1296,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in repeated message set",
|
||||
checkFastInit: true,
|
||||
@ -1215,7 +1305,7 @@ var testValidMessages = []testProto{
|
||||
{"required_field": 1},
|
||||
{"required_field": 2},
|
||||
},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -1225,6 +1315,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in map message unset",
|
||||
checkFastInit: true,
|
||||
@ -1234,7 +1325,7 @@ var testValidMessages = []testProto{
|
||||
1: {"required_field": 1},
|
||||
2: {},
|
||||
},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -1248,6 +1339,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in absent map message value",
|
||||
checkFastInit: true,
|
||||
@ -1256,13 +1348,14 @@ var testValidMessages = []testProto{
|
||||
"map_message": map[int32]protobuild.Message{
|
||||
2: {},
|
||||
},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(2),
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in map message set",
|
||||
checkFastInit: true,
|
||||
@ -1271,7 +1364,7 @@ var testValidMessages = []testProto{
|
||||
1: {"required_field": 1},
|
||||
2: {"required_field": 2},
|
||||
},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -1287,18 +1380,20 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in optional group unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
"optionalgroup": protobuild.Message{},
|
||||
}, &testpb.TestRequiredGroupFields{}),
|
||||
}, &testpb.TestRequiredGroupFields{}, &testeditionspb.TestRequiredGroupFields{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1, protopack.StartGroupType},
|
||||
protopack.Tag{1, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in optional group set",
|
||||
checkFastInit: true,
|
||||
@ -1306,13 +1401,14 @@ var testValidMessages = []testProto{
|
||||
"optionalgroup": protobuild.Message{
|
||||
"a": 1,
|
||||
},
|
||||
}, &testpb.TestRequiredGroupFields{}),
|
||||
}, &testpb.TestRequiredGroupFields{}, &testeditionspb.TestRequiredGroupFields{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1, protopack.StartGroupType},
|
||||
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1),
|
||||
protopack.Tag{1, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in repeated group unset",
|
||||
checkFastInit: true,
|
||||
@ -1322,7 +1418,7 @@ var testValidMessages = []testProto{
|
||||
{"a": 1},
|
||||
{},
|
||||
},
|
||||
}, &testpb.TestRequiredGroupFields{}),
|
||||
}, &testpb.TestRequiredGroupFields{}, &testeditionspb.TestRequiredGroupFields{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{3, protopack.StartGroupType},
|
||||
protopack.Tag{4, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -1331,6 +1427,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{3, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in repeated group set",
|
||||
checkFastInit: true,
|
||||
@ -1339,7 +1436,7 @@ var testValidMessages = []testProto{
|
||||
{"a": 1},
|
||||
{"a": 2},
|
||||
},
|
||||
}, &testpb.TestRequiredGroupFields{}),
|
||||
}, &testpb.TestRequiredGroupFields{}, &testeditionspb.TestRequiredGroupFields{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{3, protopack.StartGroupType},
|
||||
protopack.Tag{4, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -1349,15 +1446,17 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{3, protopack.EndGroupType},
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in oneof message unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
"oneof_message": protobuild.Message{},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{})}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in oneof message set",
|
||||
checkFastInit: true,
|
||||
@ -1365,22 +1464,24 @@ var testValidMessages = []testProto{
|
||||
"oneof_message": protobuild.Message{
|
||||
"required_field": 1,
|
||||
},
|
||||
}, &testpb.TestRequiredForeign{}),
|
||||
}, &testpb.TestRequiredForeign{}, &testeditionspb.TestRequiredForeign{}),
|
||||
wire: protopack.Message{protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
})}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in extension message unset",
|
||||
checkFastInit: true,
|
||||
partial: true,
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
"single": protobuild.Message{},
|
||||
}, &testpb.TestAllExtensions{}),
|
||||
}, &testpb.TestAllExtensions{}, &testeditionspb.TestAllExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1000, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in extension message set",
|
||||
checkFastInit: true,
|
||||
@ -1388,13 +1489,14 @@ var testValidMessages = []testProto{
|
||||
"single": protobuild.Message{
|
||||
"required_field": 1,
|
||||
},
|
||||
}, &testpb.TestAllExtensions{}),
|
||||
}, &testpb.TestAllExtensions{}, &testeditionspb.TestAllExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1000, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in repeated extension message unset",
|
||||
checkFastInit: true,
|
||||
@ -1404,7 +1506,7 @@ var testValidMessages = []testProto{
|
||||
{"required_field": 1},
|
||||
{},
|
||||
},
|
||||
}, &testpb.TestAllExtensions{}),
|
||||
}, &testpb.TestAllExtensions{}, &testeditionspb.TestAllExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1001, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -1412,6 +1514,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{1001, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "required field in repeated extension message set",
|
||||
checkFastInit: true,
|
||||
@ -1420,7 +1523,7 @@ var testValidMessages = []testProto{
|
||||
{"required_field": 1},
|
||||
{"required_field": 2},
|
||||
},
|
||||
}, &testpb.TestAllExtensions{}),
|
||||
}, &testpb.TestAllExtensions{}, &testeditionspb.TestAllExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{1001, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1),
|
||||
@ -1430,6 +1533,7 @@ var testValidMessages = []testProto{
|
||||
}),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "nil messages",
|
||||
decodeTo: []proto.Message{
|
||||
@ -1439,6 +1543,7 @@ var testValidMessages = []testProto{
|
||||
(*testpb.TestAllExtensions)(nil),
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
desc: "legacy",
|
||||
partial: true,
|
||||
@ -1495,6 +1600,7 @@ var testValidMessages = []testProto{
|
||||
}.Marshal(),
|
||||
validationStatus: impl.ValidationUnknown,
|
||||
},
|
||||
|
||||
{
|
||||
desc: "first reserved field number",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -1506,6 +1612,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{protopack.FirstReservedNumber, protopack.VarintType}, protopack.Varint(1004),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "last reserved field number",
|
||||
decodeTo: makeMessages(protobuild.Message{
|
||||
@ -1517,6 +1624,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{protopack.LastReservedNumber, protopack.VarintType}, protopack.Varint(1005),
|
||||
}.Marshal(),
|
||||
},
|
||||
|
||||
{
|
||||
desc: "nested unknown extension",
|
||||
unmarshalOptions: proto.UnmarshalOptions{
|
||||
@ -1543,7 +1651,7 @@ var testValidMessages = []testProto{
|
||||
},
|
||||
},
|
||||
},
|
||||
}, &testpb.TestAllExtensions{}),
|
||||
}, &testpb.TestAllExtensions{}, &testeditionspb.TestAllExtensions{}),
|
||||
wire: protopack.Message{
|
||||
protopack.Tag{18, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
|
Loading…
x
Reference in New Issue
Block a user