Permalink
Browse files

Add unknown field support for csharp (#3936)

 Add unknown field support for csharp
  • Loading branch information...
anandolee committed Dec 13, 2017
1 parent 0a7120a commit bfd254e14f60f77f68f4de8524cd8984191206d5
Showing with 3,017 additions and 345 deletions.
  1. +5 −1 Makefile.am
  2. +0 −1 conformance/failure_list_csharp.txt
  3. +7 −5 csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/GeneratedMessageTest.cs
  4. +1 −0 csharp/protos/unittest_proto3.proto
  5. +42 −6 csharp/src/AddressBook/Addressbook.cs
  6. +28 −4 csharp/src/Google.Protobuf.Conformance/Conformance.cs
  7. +6 −4 csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
  8. +98 −14 csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
  9. +42 −6 csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
  10. +294 −42 csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
  11. +14 −2 csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs
  12. +14 −2 csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs
  13. +182 −26 csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
  14. +621 −87 csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
  15. +56 −8 csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
  16. +128 −0 csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs
  17. +4 −2 csharp/src/Google.Protobuf/CodedInputStream.cs
  18. +89 −0 csharp/src/Google.Protobuf/Collections/Lists.cs
  19. +370 −46 csharp/src/Google.Protobuf/Reflection/Descriptor.cs
  20. +263 −0 csharp/src/Google.Protobuf/UnknownField.cs
  21. +324 −0 csharp/src/Google.Protobuf/UnknownFieldSet.cs
  22. +14 −2 csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
  23. +42 −6 csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
  24. +14 −2 csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
  25. +14 −2 csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
  26. +14 −2 csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
  27. +14 −2 csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
  28. +42 −6 csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
  29. +14 −2 csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
  30. +70 −10 csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
  31. +126 −18 csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
  32. +65 −37 src/google/protobuf/compiler/csharp/csharp_message.cc
View
@@ -121,12 +121,14 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs \
csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs \
csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs \
csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs \
csharp/src/Google.Protobuf.sln \
csharp/src/Google.Protobuf/ByteArray.cs \
csharp/src/Google.Protobuf/ByteString.cs \
csharp/src/Google.Protobuf/CodedInputStream.cs \
csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs \
csharp/src/Google.Protobuf/CodedOutputStream.cs \
csharp/src/Google.Protobuf/Collections/Lists.cs \
csharp/src/Google.Protobuf/Collections/MapField.cs \
csharp/src/Google.Protobuf/Collections/ProtobufEqualityComparers.cs \
csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs \
@@ -196,7 +198,9 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs \
csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs \
csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs \
csharp/src/Google.Protobuf/WireFormat.cs
csharp/src/Google.Protobuf/WireFormat.cs \
csharp/src/Google.Protobuf/UnknownField.cs \
csharp/src/Google.Protobuf/UnknownFieldSet.cs
java_EXTRA_DIST= \
java/README.md \
@@ -1,3 +1,2 @@
Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput
@@ -638,7 +638,7 @@ public void OneofSerialization_DefaultValue()
}
[Test]
public void IgnoreUnknownFields_RealDataStillRead()
public void DiscardUnknownFields_RealDataStillRead()
{
var message = SampleMessages.CreateFullTestAllTypes();
var stream = new MemoryStream();
@@ -652,16 +652,18 @@ public void IgnoreUnknownFields_RealDataStillRead()
stream.Position = 0;
var parsed = TestAllTypes.Parser.ParseFrom(stream);
Assert.AreEqual(message, parsed);
// TODO(jieluo): Add test back after DiscardUnknownFields is supported
// Assert.AreEqual(message, parsed);
}
[Test]
public void IgnoreUnknownFields_AllTypes()
public void DiscardUnknownFields_AllTypes()
{
// Simple way of ensuring we can skip all kinds of fields.
var data = SampleMessages.CreateFullTestAllTypes().ToByteArray();
var empty = Empty.Parser.ParseFrom(data);
Assert.AreEqual(new Empty(), empty);
// TODO(jieluo): Add test back after DiscardUnknownField is supported.
// Assert.AreEqual(new Empty(), empty);
}
// This was originally seen as a conformance test failure.
@@ -720,4 +722,4 @@ public void CustomDiagnosticMessage_DirectToTextWriterCall()
Assert.AreEqual("{ \"c\": 31 }", writer.ToString());
}
}
}
}
@@ -377,3 +377,4 @@ service TestService {
message BarRequest {}
message BarResponse {}
message TestEmptyMessage {}
@@ -49,6 +49,7 @@ public static partial class AddressbookReflection {
/// </summary>
public sealed partial class Person : pb::IMessage<Person> {
private static readonly pb::MessageParser<Person> _parser = new pb::MessageParser<Person>(() => new Person());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Person> Parser { get { return _parser; } }
@@ -76,6 +77,7 @@ public sealed partial class Person : pb::IMessage<Person> {
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 @@ public sealed partial class Person : pb::IMessage<Person> {
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 @@ public sealed partial class Person : pb::IMessage<Person> {
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 @@ public sealed partial class Person : pb::IMessage<Person> {
output.WriteRawTag(42);
output.WriteMessage(LastUpdated);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -214,6 +222,9 @@ public sealed partial class Person : pb::IMessage<Person> {
if (lastUpdated_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(LastUpdated);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
@@ -238,6 +249,7 @@ public sealed partial class Person : pb::IMessage<Person> {
}
LastUpdated.MergeFrom(other.LastUpdated);
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -246,7 +258,7 @@ public sealed partial class Person : pb::IMessage<Person> {
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 @@ public enum PhoneType {
public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
private static readonly pb::MessageParser<PhoneNumber> _parser = new pb::MessageParser<PhoneNumber>(() => new PhoneNumber());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<PhoneNumber> Parser { get { return _parser; } }
@@ -311,6 +324,7 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
public PhoneNumber(PhoneNumber other) : this() {
number_ = other.number_;
type_ = other.type_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -355,14 +369,17 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
}
if (Number != other.Number) return false;
if (Type != other.Type) return false;
return true;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
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 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
output.WriteRawTag(16);
output.WriteEnum((int) Type);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -392,6 +412,9 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
if (Type != 0) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
@@ -406,6 +429,7 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
if (other.Type != 0) {
Type = other.Type;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -414,7 +438,7 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
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 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
/// </summary>
public sealed partial class AddressBook : pb::IMessage<AddressBook> {
private static readonly pb::MessageParser<AddressBook> _parser = new pb::MessageParser<AddressBook>(() => new AddressBook());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<AddressBook> Parser { get { return _parser; } }
@@ -463,6 +488,7 @@ public sealed partial class AddressBook : pb::IMessage<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 @@ public sealed partial class AddressBook : pb::IMessage<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 @@ public sealed partial class AddressBook : pb::IMessage<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 @@ public sealed partial class AddressBook : pb::IMessage<AddressBook> {
return;
}
people_.Add(other.people_);
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -535,7 +571,7 @@ public sealed partial class AddressBook : pb::IMessage<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);
Oops, something went wrong.

0 comments on commit bfd254e

Please sign in to comment.