From bfd254e14f60f77f68f4de8524cd8984191206d5 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Wed, 13 Dec 2017 13:48:58 -0800 Subject: Add unknown field support for csharp (#3936) Add unknown field support for csharp --- .../src/Google.Protobuf.Conformance/Conformance.cs | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'csharp/src/Google.Protobuf.Conformance') diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 394607b9..b88df26d 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -62,6 +62,7 @@ namespace Conformance { /// public sealed partial class ConformanceRequest : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ConformanceRequest()); + private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -95,6 +96,7 @@ namespace Conformance { break; } + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -191,7 +193,7 @@ namespace Conformance { if (RequestedOutputFormat != other.RequestedOutputFormat) return false; if (MessageType != other.MessageType) return false; if (PayloadCase != other.PayloadCase) return false; - return true; + return Equals(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -202,6 +204,9 @@ namespace Conformance { if (RequestedOutputFormat != 0) hash ^= RequestedOutputFormat.GetHashCode(); if (MessageType.Length != 0) hash ^= MessageType.GetHashCode(); hash ^= (int) payloadCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } return hash; } @@ -228,6 +233,9 @@ namespace Conformance { output.WriteRawTag(34); output.WriteString(MessageType); } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -245,6 +253,9 @@ namespace Conformance { if (MessageType.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(MessageType); } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } return size; } @@ -268,6 +279,7 @@ namespace Conformance { break; } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -276,7 +288,7 @@ namespace Conformance { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - input.SkipLastField(); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { ProtobufPayload = input.ReadBytes(); @@ -305,6 +317,7 @@ namespace Conformance { /// public sealed partial class ConformanceResponse : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ConformanceResponse()); + private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -348,6 +361,7 @@ namespace Conformance { break; } + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -493,7 +507,7 @@ namespace Conformance { if (JsonPayload != other.JsonPayload) return false; if (Skipped != other.Skipped) return false; if (ResultCase != other.ResultCase) return false; - return true; + return Equals(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -506,6 +520,9 @@ namespace Conformance { if (resultCase_ == ResultOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); if (resultCase_ == ResultOneofCase.Skipped) hash ^= Skipped.GetHashCode(); hash ^= (int) resultCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } return hash; } @@ -540,6 +557,9 @@ namespace Conformance { output.WriteRawTag(50); output.WriteString(SerializeError); } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -563,6 +583,9 @@ namespace Conformance { if (resultCase_ == ResultOneofCase.Skipped) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Skipped); } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } return size; } @@ -592,6 +615,7 @@ namespace Conformance { break; } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -600,7 +624,7 @@ namespace Conformance { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - input.SkipLastField(); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { ParseError = input.ReadString(); -- cgit v1.2.3