diff options
author | Jon Skeet <jonskeet@google.com> | 2018-01-03 09:57:58 +0000 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2018-01-15 02:53:45 -0500 |
commit | 47b7d2c7cadf74ceec90fc5042232819cd0dd557 (patch) | |
tree | 1ca71757c1550c134fa0fd55952b4d0ff63df3ed /csharp/src/Google.Protobuf/UnknownFieldSet.cs | |
parent | 9f80df026933901883da1d556b38292e14836612 (diff) | |
download | protobuf-47b7d2c7cadf74ceec90fc5042232819cd0dd557.tar.gz protobuf-47b7d2c7cadf74ceec90fc5042232819cd0dd557.tar.bz2 protobuf-47b7d2c7cadf74ceec90fc5042232819cd0dd557.zip |
Add DiscardUnknownFields support for C#
By default, unknown fields are preserved when parsing. To discard
them, use a parser configured to do so:
var parser = MyMessage.Parser.WithDiscardUnknownFields(true);
Diffstat (limited to 'csharp/src/Google.Protobuf/UnknownFieldSet.cs')
-rw-r--r-- | csharp/src/Google.Protobuf/UnknownFieldSet.cs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/csharp/src/Google.Protobuf/UnknownFieldSet.cs b/csharp/src/Google.Protobuf/UnknownFieldSet.cs index b43f4774..6404c3c0 100644 --- a/csharp/src/Google.Protobuf/UnknownFieldSet.cs +++ b/csharp/src/Google.Protobuf/UnknownFieldSet.cs @@ -230,7 +230,8 @@ namespace Google.Protobuf /// <summary> /// Create a new UnknownFieldSet if unknownFields is null. /// Parse a single field from <paramref name="input"/> and merge it - /// into unknownFields. + /// into unknownFields. If <paramref name="input"/> is configured to discard unknown fields, + /// <paramref name="unknownFields"/> will be returned as-is and the field will be skipped. /// </summary> /// <param name="unknownFields">The UnknownFieldSet which need to be merged</param> /// <param name="input">The coded input stream containing the field</param> @@ -238,6 +239,11 @@ namespace Google.Protobuf public static UnknownFieldSet MergeFieldFrom(UnknownFieldSet unknownFields, CodedInputStream input) { + if (input.DiscardUnknownFields) + { + input.SkipLastField(); + return unknownFields; + } if (unknownFields == null) { unknownFields = new UnknownFieldSet(); |