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 --- csharp/src/AddressBook/Addressbook.cs | 48 ++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'csharp/src/AddressBook') diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs index e595e58b..5677bfd5 100644 --- a/csharp/src/AddressBook/Addressbook.cs +++ b/csharp/src/AddressBook/Addressbook.cs @@ -49,6 +49,7 @@ namespace Google.Protobuf.Examples.AddressBook { /// public sealed partial class Person : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Person()); + private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -76,6 +77,7 @@ namespace Google.Protobuf.Examples.AddressBook { email_ = other.email_; phones_ = other.phones_.Clone(); LastUpdated = other.lastUpdated_ != null ? other.LastUpdated.Clone() : null; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -158,7 +160,7 @@ namespace Google.Protobuf.Examples.AddressBook { if (Email != other.Email) return false; if(!phones_.Equals(other.phones_)) return false; if (!object.Equals(LastUpdated, other.LastUpdated)) return false; - return true; + return Equals(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -169,6 +171,9 @@ namespace Google.Protobuf.Examples.AddressBook { if (Email.Length != 0) hash ^= Email.GetHashCode(); hash ^= phones_.GetHashCode(); if (lastUpdated_ != null) hash ^= LastUpdated.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } return hash; } @@ -196,6 +201,9 @@ namespace Google.Protobuf.Examples.AddressBook { output.WriteRawTag(42); output.WriteMessage(LastUpdated); } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -214,6 +222,9 @@ namespace Google.Protobuf.Examples.AddressBook { if (lastUpdated_ != null) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(LastUpdated); } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } return size; } @@ -238,6 +249,7 @@ namespace Google.Protobuf.Examples.AddressBook { } LastUpdated.MergeFrom(other.LastUpdated); } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -246,7 +258,7 @@ namespace Google.Protobuf.Examples.AddressBook { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - input.SkipLastField(); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Name = input.ReadString(); @@ -287,6 +299,7 @@ namespace Google.Protobuf.Examples.AddressBook { public sealed partial class PhoneNumber : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new PhoneNumber()); + private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -311,6 +324,7 @@ namespace Google.Protobuf.Examples.AddressBook { public PhoneNumber(PhoneNumber other) : this() { number_ = other.number_; type_ = other.type_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -355,7 +369,7 @@ namespace Google.Protobuf.Examples.AddressBook { } if (Number != other.Number) return false; if (Type != other.Type) return false; - return true; + return Equals(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -363,6 +377,9 @@ namespace Google.Protobuf.Examples.AddressBook { int hash = 1; if (Number.Length != 0) hash ^= Number.GetHashCode(); if (Type != 0) hash ^= Type.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } return hash; } @@ -381,6 +398,9 @@ namespace Google.Protobuf.Examples.AddressBook { output.WriteRawTag(16); output.WriteEnum((int) Type); } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -392,6 +412,9 @@ namespace Google.Protobuf.Examples.AddressBook { if (Type != 0) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type); } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } return size; } @@ -406,6 +429,7 @@ namespace Google.Protobuf.Examples.AddressBook { if (other.Type != 0) { Type = other.Type; } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -414,7 +438,7 @@ namespace Google.Protobuf.Examples.AddressBook { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - input.SkipLastField(); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { Number = input.ReadString(); @@ -440,6 +464,7 @@ namespace Google.Protobuf.Examples.AddressBook { /// public sealed partial class AddressBook : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new AddressBook()); + private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -463,6 +488,7 @@ namespace Google.Protobuf.Examples.AddressBook { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public AddressBook(AddressBook other) : this() { people_ = other.people_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -494,13 +520,16 @@ namespace Google.Protobuf.Examples.AddressBook { return true; } if(!people_.Equals(other.people_)) return false; - return true; + return Equals(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; hash ^= people_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } return hash; } @@ -512,12 +541,18 @@ namespace Google.Protobuf.Examples.AddressBook { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(pb::CodedOutputStream output) { people_.WriteTo(output, _repeated_people_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; size += people_.CalculateSize(_repeated_people_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } return size; } @@ -527,6 +562,7 @@ namespace Google.Protobuf.Examples.AddressBook { return; } people_.Add(other.people_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -535,7 +571,7 @@ namespace Google.Protobuf.Examples.AddressBook { while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - input.SkipLastField(); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { people_.AddEntriesFrom(input, _repeated_people_codec); -- cgit v1.2.3