diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs
index d3e1ea9534..c05125c629 100644
--- a/csharp/src/AddressBook/Addressbook.cs
+++ b/csharp/src/AddressBook/Addressbook.cs
@@ -260,7 +260,9 @@ namespace Google.Protobuf.Examples.AddressBook {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -440,7 +442,9 @@ namespace Google.Protobuf.Examples.AddressBook {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Number = input.ReadString();
@@ -573,7 +577,9 @@ namespace Google.Protobuf.Examples.AddressBook {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
people_.AddEntriesFrom(input, _repeated_people_codec);
diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs
index cd9b77abe5..1642669e92 100644
--- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs
+++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs
@@ -343,7 +343,9 @@ namespace Conformance {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
ProtobufPayload = input.ReadBytes();
@@ -683,7 +685,9 @@ namespace Conformance {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
ParseError = input.ReadString();
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
index 6d3cd026d1..2844ca62ce 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
@@ -541,7 +541,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
mapInt32Int32_.AddEntriesFrom(input, _map_mapInt32Int32_codec);
@@ -737,7 +739,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
if (testMap_ == null) {
@@ -861,7 +865,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
mapInt32Message_.AddEntriesFrom(input, _map_mapInt32Message_codec);
@@ -1001,7 +1007,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
map1_.AddEntriesFrom(input, _map_map1_codec);
@@ -1350,7 +1358,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
mapInt32Int32_.AddEntriesFrom(input, _map_mapInt32Int32_codec);
@@ -1531,7 +1541,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
type_.AddEntriesFrom(input, _map_type_codec);
@@ -1666,7 +1678,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
entry_.AddEntriesFrom(input, _map_entry_codec);
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
index d74422b59b..683dc41d0e 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
@@ -2867,7 +2867,9 @@ namespace ProtobufTestMessages.Proto3 {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
OptionalInt32 = input.ReadInt32();
@@ -3582,7 +3584,9 @@ namespace ProtobufTestMessages.Proto3 {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
A = input.ReadInt32();
@@ -3723,7 +3727,9 @@ namespace ProtobufTestMessages.Proto3 {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
C = input.ReadInt32();
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
index 2a9efe55ff..9b9ffe2560 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
@@ -352,7 +352,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Field1 = input.ReadString();
@@ -478,7 +480,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -579,7 +583,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -680,7 +686,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -781,7 +789,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -882,7 +892,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -996,7 +1008,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -1097,7 +1111,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -1198,7 +1214,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -1299,7 +1317,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -1400,7 +1420,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -1501,7 +1523,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -1690,7 +1714,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Foo = input.ReadInt32();
@@ -1902,7 +1928,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
if (bar_ == null) {
@@ -2051,7 +2079,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Waldo = input.ReadInt32();
@@ -2185,7 +2215,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Qux = input.ReadInt32();
@@ -2293,7 +2325,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -2475,7 +2509,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
I = input.ReadInt32();
@@ -2615,7 +2651,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Fieldname = input.ReadInt32();
@@ -2723,7 +2761,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -2855,7 +2895,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
NestedField = input.ReadInt32();
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs
index 6bf9715171..931dc2eb03 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs
@@ -167,7 +167,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
D = input.ReadInt32();
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs
index 97d181aff4..fee0120b42 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs
@@ -155,7 +155,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
E = input.ReadInt32();
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
index f27ab64074..f8296b0fab 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
@@ -181,7 +181,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -284,7 +286,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -387,7 +391,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -554,7 +560,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Value = (global::UnitTest.Issues.TestProtos.NegativeEnum) input.ReadEnum();
@@ -669,7 +677,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -899,7 +909,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
PrimitiveValue = input.ReadInt32();
@@ -1056,7 +1068,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Item = input.ReadInt32();
@@ -1209,7 +1223,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Types_ = input.ReadInt32();
@@ -1323,7 +1339,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -1647,7 +1665,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
PlainString = input.ReadString();
@@ -1847,7 +1867,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -2047,7 +2069,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Text = input.ReadString();
@@ -2211,7 +2235,9 @@ namespace UnitTest.Issues.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
X = input.ReadInt32();
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
index bbbee22c7b..1d4367b781 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
@@ -1387,7 +1387,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
SingleInt32 = input.ReadInt32();
@@ -1755,7 +1757,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Bb = input.ReadInt32();
@@ -1938,7 +1942,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
if (child_ == null) {
@@ -2082,7 +2088,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
DeprecatedInt32 = input.ReadInt32();
@@ -2215,7 +2223,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
C = input.ReadInt32();
@@ -2320,7 +2330,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -2451,7 +2463,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
if (foreignNested_ == null) {
@@ -2614,7 +2628,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
A = input.ReadInt32();
@@ -2774,7 +2790,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
if (a_ == null) {
@@ -2916,7 +2934,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
if (bb_ == null) {
@@ -3075,7 +3095,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
if (a_ == null) {
@@ -3211,7 +3233,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Value = (global::Google.Protobuf.TestProtos.TestEnumWithDupValue) input.ReadEnum();
@@ -3483,7 +3507,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
PrimitiveField = input.ReadInt32();
@@ -3724,7 +3750,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
MyInt = input.ReadInt64();
@@ -3899,7 +3927,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Bb = input.ReadInt32();
@@ -4037,7 +4067,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
SparseEnum = (global::Google.Protobuf.TestProtos.TestSparseEnum) input.ReadEnum();
@@ -4169,7 +4201,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Data = input.ReadString();
@@ -4290,7 +4324,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
data_.AddEntriesFrom(input, _repeated_data_codec);
@@ -4419,7 +4455,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Data = input.ReadBytes();
@@ -4548,7 +4586,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Data = input.ReadBytes();
@@ -4680,7 +4720,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Data = input.ReadInt32();
@@ -4809,7 +4851,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Data = input.ReadUInt32();
@@ -4938,7 +4982,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Data = input.ReadInt64();
@@ -5067,7 +5113,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Data = input.ReadUInt64();
@@ -5196,7 +5244,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Data = input.ReadBool();
@@ -5413,7 +5463,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
FooInt = input.ReadInt32();
@@ -5755,7 +5807,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 722:
case 720: {
@@ -6154,7 +6208,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 722:
case 720: {
@@ -6435,7 +6491,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 98:
case 101: {
@@ -6593,7 +6651,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
A = input.ReadString();
@@ -6701,7 +6761,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -6802,7 +6864,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -6903,7 +6967,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -7004,7 +7070,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -7105,7 +7173,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -7206,7 +7276,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -7307,7 +7379,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
@@ -7438,7 +7512,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Text = input.ReadString();
@@ -7585,7 +7661,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
NestedText = input.ReadString();
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
index 45f8ece646..a36825dc32 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
@@ -788,7 +788,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
if (anyField_ == null) {
@@ -1316,7 +1318,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
anyField_.AddEntriesFrom(input, _repeated_anyField_codec);
@@ -2027,7 +2031,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
global::Google.Protobuf.WellKnownTypes.Any subBuilder = new global::Google.Protobuf.WellKnownTypes.Any();
@@ -2538,7 +2544,9 @@ namespace Google.Protobuf.TestProtos {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
anyField_.AddEntriesFrom(input, _map_anyField_codec);
diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb
index 94ff381705..69950675d8 100644
Binary files a/csharp/src/Google.Protobuf.Test/testprotos.pb and b/csharp/src/Google.Protobuf.Test/testprotos.pb differ
diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs
index 0a829545e2..0428fb54e6 100644
--- a/csharp/src/Google.Protobuf/CodedInputStream.cs
+++ b/csharp/src/Google.Protobuf/CodedInputStream.cs
@@ -373,7 +373,7 @@ namespace Google.Protobuf
if (IsAtEnd)
{
lastTag = 0;
- return 0; // This is the only case in which we return 0.
+ return 0;
}
lastTag = ReadRawVarint32();
@@ -383,6 +383,10 @@ namespace Google.Protobuf
// If we actually read a tag with a field of 0, that's not a valid tag.
throw InvalidProtocolBufferException.InvalidTag();
}
+ if (ReachedLimit)
+ {
+ return 0;
+ }
return lastTag;
}
@@ -591,6 +595,20 @@ namespace Google.Protobuf
PopLimit(oldLimit);
}
+ ///
+ /// Reads an embedded group field from the stream.
+ ///
+ public void ReadGroup(IMessage builder)
+ {
+ if (recursionDepth >= recursionLimit)
+ {
+ throw InvalidProtocolBufferException.RecursionLimitExceeded();
+ }
+ ++recursionDepth;
+ builder.MergeFrom(this);
+ --recursionDepth;
+ }
+
///
/// Reads a bytes field value from the stream.
///
diff --git a/csharp/src/Google.Protobuf/CodedOutputStream.cs b/csharp/src/Google.Protobuf/CodedOutputStream.cs
index 6211aac32c..f9ad29086b 100644
--- a/csharp/src/Google.Protobuf/CodedOutputStream.cs
+++ b/csharp/src/Google.Protobuf/CodedOutputStream.cs
@@ -303,6 +303,15 @@ namespace Google.Protobuf
value.WriteTo(this);
}
+ ///
+ /// Writes a group, without a tag, to the stream.
+ ///
+ /// The value to write
+ public void WriteGroup(IMessage value)
+ {
+ value.WriteTo(this);
+ }
+
///
/// Write a byte string, without a tag, to the stream.
/// The data is length-prefixed.
diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
index 613ca9c48e..827bc71183 100644
--- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
+++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
@@ -208,6 +208,10 @@ namespace Google.Protobuf.Collections
{
output.WriteTag(tag);
writer(output, array[i]);
+ if (codec.EndTag != 0)
+ {
+ output.WriteTag(codec.EndTag);
+ }
}
}
}
diff --git a/csharp/src/Google.Protobuf/FieldCodec.cs b/csharp/src/Google.Protobuf/FieldCodec.cs
index a11f2420e3..221ad5fd2d 100644
--- a/csharp/src/Google.Protobuf/FieldCodec.cs
+++ b/csharp/src/Google.Protobuf/FieldCodec.cs
@@ -225,6 +225,19 @@ namespace Google.Protobuf
(output, value) => output.WriteMessage(value), message => CodedOutputStream.ComputeMessageSize(message), tag);
}
+ ///
+ /// Retrieves a codec suitable for a group field with the given tag.
+ ///
+ /// The start group tag.
+ /// The end group tag.
+ /// A parser to use for the group message type.
+ /// A codec for given tag
+ public static FieldCodec ForGroup(uint startTag, uint endTag, MessageParser parser) where T : IMessage
+ {
+ return new FieldCodec(input => { T message = parser.CreateTemplate(); input.ReadGroup(message); return message; },
+ (output, value) => output.WriteGroup(value), message => CodedOutputStream.ComputeGroupSize(message), startTag, endTag);
+ }
+
///
/// Creates a codec for a wrapper type of a class - which must be string or ByteString.
///
@@ -235,7 +248,7 @@ namespace Google.Protobuf
input => WrapperCodecs.Read(input, nestedCodec),
(output, value) => WrapperCodecs.Write(output, value, nestedCodec),
value => WrapperCodecs.CalculateSize(value, nestedCodec),
- tag,
+ tag, 0,
null); // Default value for the wrapper
}
@@ -250,7 +263,7 @@ namespace Google.Protobuf
input => WrapperCodecs.Read(input, nestedCodec),
(output, value) => WrapperCodecs.Write(output, value.Value, nestedCodec),
value => value == null ? 0 : WrapperCodecs.CalculateSize(value.Value, nestedCodec),
- tag,
+ tag, 0,
null); // Default value for the wrapper
}
@@ -399,6 +412,14 @@ namespace Google.Protobuf
///
internal uint Tag { get; }
+ ///
+ /// Gets the end tag of the codec or 0 if there is no end tag
+ ///
+ ///
+ /// The end tag of the codec.
+ ///
+ internal uint EndTag { get; }
+
///
/// Default value for this codec. Usually the same for every instance of the same type, but
/// for string/ByteString wrapper fields the codec's default value is null, whereas for
@@ -424,7 +445,8 @@ namespace Google.Protobuf
Func reader,
Action writer,
Func sizeCalculator,
- uint tag) : this(reader, writer, sizeCalculator, tag, DefaultDefault)
+ uint tag,
+ uint endTag = 0) : this(reader, writer, sizeCalculator, tag, endTag, DefaultDefault)
{
}
@@ -433,6 +455,7 @@ namespace Google.Protobuf
Action writer,
Func sizeCalculator,
uint tag,
+ uint endTag,
T defaultValue)
{
ValueReader = reader;
@@ -455,6 +478,10 @@ namespace Google.Protobuf
{
output.WriteTag(Tag);
ValueWriter(output, value);
+ if (EndTag != 0)
+ {
+ output.WriteTag(EndTag);
+ }
}
}
diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
index 0c33e63df4..f101cd3526 100644
--- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
@@ -302,7 +302,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
file_.AddEntriesFrom(input, _repeated_file_codec);
@@ -733,7 +735,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -1098,7 +1102,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -1357,7 +1363,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Start = input.ReadInt32();
@@ -1560,7 +1568,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Start = input.ReadInt32();
@@ -1693,7 +1703,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 7994: {
uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
@@ -2200,7 +2212,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -2487,7 +2501,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -2732,7 +2748,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -2948,7 +2966,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Start = input.ReadInt32();
@@ -3177,7 +3197,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -3385,7 +3407,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -3735,7 +3759,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -6923,7 +6949,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 18: {
name_.AddEntriesFrom(input, _repeated_name_codec);
@@ -7136,7 +7164,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
NamePart_ = input.ReadString();
@@ -7315,7 +7345,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
location_.AddEntriesFrom(input, _repeated_location_codec);
@@ -7623,7 +7655,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10:
case 8: {
@@ -7776,7 +7810,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
annotation_.AddEntriesFrom(input, _repeated_annotation_codec);
@@ -8027,7 +8063,9 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10:
case 8: {
diff --git a/csharp/src/Google.Protobuf/UnknownField.cs b/csharp/src/Google.Protobuf/UnknownField.cs
index 0d6eed6357..2b13fdb3ec 100644
--- a/csharp/src/Google.Protobuf/UnknownField.cs
+++ b/csharp/src/Google.Protobuf/UnknownField.cs
@@ -55,6 +55,7 @@ namespace Google.Protobuf
private List fixed32List;
private List fixed64List;
private List lengthDelimitedList;
+ private List groupList;
///
/// Creates a new UnknownField.
@@ -77,7 +78,8 @@ namespace Google.Protobuf
&& Lists.Equals(varintList, otherField.varintList)
&& Lists.Equals(fixed32List, otherField.fixed32List)
&& Lists.Equals(fixed64List, otherField.fixed64List)
- && Lists.Equals(lengthDelimitedList, otherField.lengthDelimitedList);
+ && Lists.Equals(lengthDelimitedList, otherField.lengthDelimitedList)
+ && Lists.Equals(groupList, otherField.groupList);
}
///
@@ -90,6 +92,7 @@ namespace Google.Protobuf
hash = hash * 47 + Lists.GetHashCode(fixed32List);
hash = hash * 47 + Lists.GetHashCode(fixed64List);
hash = hash * 47 + Lists.GetHashCode(lengthDelimitedList);
+ hash = hash * 47 + Lists.GetHashCode(groupList);
return hash;
}
@@ -133,6 +136,15 @@ namespace Google.Protobuf
output.WriteBytes(value);
}
}
+ if (groupList != null)
+ {
+ foreach (UnknownFieldSet value in groupList)
+ {
+ output.WriteTag(fieldNumber, WireFormat.WireType.StartGroup);
+ value.WriteTo(output);
+ output.WriteTag(fieldNumber, WireFormat.WireType.EndGroup);
+ }
+ }
}
///
@@ -168,6 +180,14 @@ namespace Google.Protobuf
result += CodedOutputStream.ComputeBytesSize(value);
}
}
+ if (groupList != null)
+ {
+ result += CodedOutputStream.ComputeTagSize(fieldNumber) * 2 * groupList.Count;
+ foreach (UnknownFieldSet value in groupList)
+ {
+ result += value.CalculateSize();
+ }
+ }
return result;
}
@@ -182,6 +202,7 @@ namespace Google.Protobuf
fixed32List = AddAll(fixed32List, other.fixed32List);
fixed64List = AddAll(fixed64List, other.fixed64List);
lengthDelimitedList = AddAll(lengthDelimitedList, other.lengthDelimitedList);
+ groupList = AddAll(groupList, other.groupList);
return this;
}
@@ -245,6 +266,12 @@ namespace Google.Protobuf
return this;
}
+ internal UnknownField AddGroup(UnknownFieldSet value)
+ {
+ groupList = Add(groupList, value);
+ return this;
+ }
+
///
/// Adds to the , creating
/// a new list if is null. The list is returned - either
diff --git a/csharp/src/Google.Protobuf/UnknownFieldSet.cs b/csharp/src/Google.Protobuf/UnknownFieldSet.cs
index 6404c3c08f..9121567621 100644
--- a/csharp/src/Google.Protobuf/UnknownFieldSet.cs
+++ b/csharp/src/Google.Protobuf/UnknownFieldSet.cs
@@ -183,7 +183,7 @@ namespace Google.Protobuf
///
/// The coded input stream containing the field
/// false if the tag is an "end group" tag, true otherwise
- private void MergeFieldFrom(CodedInputStream input)
+ private bool MergeFieldFrom(CodedInputStream input)
{
uint tag = input.LastTag;
int number = WireFormat.GetTagFieldNumber(tag);
@@ -193,34 +193,40 @@ namespace Google.Protobuf
{
ulong uint64 = input.ReadUInt64();
GetOrAddField(number).AddVarint(uint64);
- return;
+ return true;
}
case WireFormat.WireType.Fixed32:
{
uint uint32 = input.ReadFixed32();
GetOrAddField(number).AddFixed32(uint32);
- return;
+ return true;
}
case WireFormat.WireType.Fixed64:
{
ulong uint64 = input.ReadFixed64();
GetOrAddField(number).AddFixed64(uint64);
- return;
+ return true;
}
case WireFormat.WireType.LengthDelimited:
{
ByteString bytes = input.ReadBytes();
GetOrAddField(number).AddLengthDelimited(bytes);
- return;
+ return true;
}
case WireFormat.WireType.StartGroup:
{
- input.SkipGroup(tag);
- return;
+ uint endTag = WireFormat.MakeTag(number, WireFormat.WireType.EndGroup);
+ UnknownFieldSet set = new UnknownFieldSet();
+ while (input.ReadTag() != endTag)
+ {
+ set.MergeFieldFrom(input);
+ }
+ GetOrAddField(number).AddGroup(set);
+ return true;
}
case WireFormat.WireType.EndGroup:
{
- throw new InvalidProtocolBufferException("Merge an unknown field of end-group tag, indicating that the corresponding start-group was missing.");
+ return false;
}
default:
throw new InvalidOperationException("Wire Type is invalid.");
@@ -248,8 +254,34 @@ namespace Google.Protobuf
{
unknownFields = new UnknownFieldSet();
}
- unknownFields.MergeFieldFrom(input);
+ if (!unknownFields.MergeFieldFrom(input))
+ {
+ throw new InvalidProtocolBufferException("Merge an unknown field of end-group tag, indicating that the corresponding start-group was missing."); // match the old code-gen
+ }
return unknownFields;
+ }
+
+ ///
+ /// Create a new UnknownFieldSet if unknownFields is null.
+ /// Parse a single field from and merge it
+ /// into unknownFields. If is configured to discard unknown fields,
+ /// will be returned as-is and the field will be skipped.
+ ///
+ /// The UnknownFieldSet which need to be merged
+ /// The coded input stream containing the field
+ /// The merged UnknownFieldSet
+ public static bool MergeFieldFrom(ref UnknownFieldSet unknownFields, CodedInputStream input)
+ {
+ if (input.DiscardUnknownFields)
+ {
+ input.SkipLastField();
+ return true;
+ }
+ if (unknownFields == null)
+ {
+ unknownFields = new UnknownFieldSet();
+ }
+ return unknownFields.MergeFieldFrom(input);
}
///
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
index dd9911067e..b1ed0bc307 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
@@ -292,7 +292,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
TypeUrl = input.ReadString();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
index 438e1db8da..a566e40640 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
@@ -345,7 +345,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -661,7 +663,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -925,7 +929,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
index 2858b532b6..691ca334ea 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
@@ -254,7 +254,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Seconds = input.ReadInt64();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
index 2113add9bc..03ffc4a057 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
@@ -143,7 +143,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
}
}
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
index 6ad31a50ea..8114aa3924 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
@@ -352,7 +352,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
paths_.AddEntriesFrom(input, _repeated_paths_codec);
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
index 124ddaa712..2cae68631d 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
@@ -165,7 +165,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
FileName = input.ReadString();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
index 194b81e965..9667472522 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
@@ -189,7 +189,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
fields_.AddEntriesFrom(input, _map_fields_codec);
@@ -513,7 +515,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
kind_ = input.ReadEnum();
@@ -673,7 +677,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
values_.AddEntriesFrom(input, _repeated_values_codec);
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
index 984e226fd4..9e37e9dda7 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
@@ -273,7 +273,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Seconds = input.ReadInt64();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
index 52bd343ba8..adea910634 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
@@ -328,7 +328,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -723,7 +725,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Kind = (global::Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum();
@@ -1100,7 +1104,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -1300,7 +1306,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
@@ -1480,7 +1488,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Name = input.ReadString();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
index 25a65aa72c..679eb0f234 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
@@ -177,7 +177,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 9: {
Value = input.ReadDouble();
@@ -314,7 +316,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 13: {
Value = input.ReadFloat();
@@ -451,7 +455,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Value = input.ReadInt64();
@@ -588,7 +594,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Value = input.ReadUInt64();
@@ -725,7 +733,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Value = input.ReadInt32();
@@ -862,7 +872,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Value = input.ReadUInt32();
@@ -999,7 +1011,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 8: {
Value = input.ReadBool();
@@ -1136,7 +1150,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Value = input.ReadString();
@@ -1273,7 +1289,9 @@ namespace Google.Protobuf.WellKnownTypes {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
+ return;
+ }
break;
case 10: {
Value = input.ReadBytes();
diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc
index 124e673b35..be1cd115a5 100644
--- a/src/google/protobuf/compiler/csharp/csharp_message.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_message.cc
@@ -539,7 +539,9 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
} else {
printer->Print(
"default:\n"
- " _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);\n"
+ " if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {\n"
+ " return;\n"
+ " }\n"
" break;\n");
}
for (int i = 0; i < fields_by_number().size(); i++) {
diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_message_field.cc
index 1671460367..899cd7bf7b 100644
--- a/src/google/protobuf/compiler/csharp/csharp_message_field.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_message_field.cc
@@ -37,6 +37,8 @@
#include
#include
#include
+#include
+#include
#include
#include
@@ -56,6 +58,21 @@ MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor,
variables_["has_property_check"] = name() + "_ != null";
variables_["has_not_property_check"] = name() + "_ == null";
}
+
+ if (descriptor_->type() == FieldDescriptor::Type::TYPE_GROUP) {
+ int tag_size = internal::WireFormat::TagSize(descriptor_->number(), descriptor_->type()) / 2;
+ uint tag = internal::WireFormatLite::MakeTag(
+ descriptor_->number(),
+ internal::WireFormatLite::WIRETYPE_END_GROUP);
+ uint8 tag_array[5];
+ io::CodedOutputStream::WriteTagToArray(tag, tag_array);
+ string tag_bytes = SimpleItoa(tag_array[0]);
+ for (int i = 1; i < tag_size; i++) {
+ tag_bytes += ", " + SimpleItoa(tag_array[i]);
+ }
+ variables_["end_tag"] = SimpleItoa(tag);
+ variables_["end_tag_bytes"] = tag_bytes;
+ }
}
MessageFieldGenerator::~MessageFieldGenerator() {
@@ -114,25 +131,47 @@ void MessageFieldGenerator::GenerateParsingCode(io::Printer* printer) {
variables_,
"if ($has_not_property_check$) {\n"
" $property_name$ = new $type_name$();\n"
- "}\n"
- "input.ReadMessage($property_name$);\n");
+ "}\n");
+ if (descriptor_->type() == FieldDescriptor::Type::TYPE_MESSAGE) {
+ printer->Print(variables_, "input.ReadMessage($property_name$);\n");
+ } else {
+ printer->Print(variables_, "input.ReadGroup($property_name$);\n");
+ }
}
void MessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
- printer->Print(
- variables_,
- "if ($has_property_check$) {\n"
- " output.WriteRawTag($tag_bytes$);\n"
- " output.WriteMessage($property_name$);\n"
- "}\n");
+ if (descriptor_->type() == FieldDescriptor::Type::TYPE_MESSAGE) {
+ printer->Print(
+ variables_,
+ "if ($has_property_check$) {\n"
+ " output.WriteRawTag($tag_bytes$);\n"
+ " output.WriteMessage($property_name$);\n"
+ "}\n");
+ } else {
+ printer->Print(
+ variables_,
+ "if ($has_property_check$) {\n"
+ " output.WriteRawTag($tag_bytes$);\n"
+ " output.WriteGroup($property_name$);\n"
+ " output.WriteRawTag($end_tag_bytes$);\n"
+ "}\n");
+ }
}
void MessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {
- printer->Print(
- variables_,
- "if ($has_property_check$) {\n"
- " size += $tag_size$ + pb::CodedOutputStream.ComputeMessageSize($property_name$);\n"
- "}\n");
+ if (descriptor_->type() == FieldDescriptor::Type::TYPE_MESSAGE) {
+ printer->Print(
+ variables_,
+ "if ($has_property_check$) {\n"
+ " size += $tag_size$ + pb::CodedOutputStream.ComputeMessageSize($property_name$);\n"
+ "}\n");
+ } else {
+ printer->Print(
+ variables_,
+ "if ($has_property_check$) {\n"
+ " size += $tag_size$ + $tag_size$ + pb::CodedOutputStream.ComputeGroupSize($property_name$);\n"
+ "}\n");
+ }
}
void MessageFieldGenerator::WriteHash(io::Printer* printer) {
@@ -160,9 +199,15 @@ void MessageFieldGenerator::GenerateFreezingCode(io::Printer* printer) {
}
void MessageFieldGenerator::GenerateCodecCode(io::Printer* printer) {
- printer->Print(
- variables_,
- "pb::FieldCodec.ForMessage($tag$, $type_name$.Parser)");
+ if (descriptor_->type() == FieldDescriptor::Type::TYPE_MESSAGE) {
+ printer->Print(
+ variables_,
+ "pb::FieldCodec.ForMessage($tag$, $type_name$.Parser)");
+ } else {
+ printer->Print(
+ variables_,
+ "pb::FieldCodec.ForGroup($tag$, $end_tag$, $type_name$.Parser)");
+ }
}
MessageOneofFieldGenerator::MessageOneofFieldGenerator(
@@ -228,9 +273,13 @@ void MessageOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) {
"$type_name$ subBuilder = new $type_name$();\n"
"if ($has_property_check$) {\n"
" subBuilder.MergeFrom($property_name$);\n"
- "}\n"
- "input.ReadMessage(subBuilder);\n"
- "$property_name$ = subBuilder;\n");
+ "}\n");
+ if (descriptor_->type() == FieldDescriptor::Type::TYPE_MESSAGE) {
+ printer->Print("input.ReadMessage(subBuilder);\n");
+ } else {
+ printer->Print("input.ReadGroup(subBuilder);\n");
+ }
+ printer->Print(variables_, "$property_name$ = subBuilder;\n");
}
void MessageOneofFieldGenerator::WriteToString(io::Printer* printer) {