Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Proto2 feature : Extensions #5350

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
782db22
Compiler changes (extensions)
ObsidianMinor Nov 14, 2018
467c4e6
Generated changes (extensions)
ObsidianMinor Nov 14, 2018
479ae41
Library changes (extensions)
ObsidianMinor Nov 14, 2018
73b6aec
Adjusted a summary to indicate ContainingType can be null for extensions
ObsidianMinor Nov 16, 2018
6654bf5
Compiler changes (custom option review + access level review)
ObsidianMinor Dec 9, 2018
c7966d7
Generated code changes (custom options + access review)
ObsidianMinor Dec 9, 2018
b733dd3
Library changes (custom options + access review)
ObsidianMinor Dec 9, 2018
f405b3b
Support C# 6 with library changes
ObsidianMinor Dec 12, 2018
6392ce4
Access HasValue by property
ObsidianMinor Dec 12, 2018
a61bbee
Set access level of all extension classes to internal (revert in next…
ObsidianMinor Dec 12, 2018
a281bee
Added null checks to custom options
ObsidianMinor Dec 13, 2018
2ae12df
Rebase on master and regenerate Conformance
ObsidianMinor Dec 15, 2018
ceb0257
Removed second dictionary from ExtensionSet
ObsidianMinor Mar 2, 2019
7ca6478
Rebased compiler changes
ObsidianMinor Mar 15, 2019
3ce1d14
Rebased generated code changes
ObsidianMinor Mar 15, 2019
f46c17d
Rebased library changes + review changes
ObsidianMinor Mar 15, 2019
bc5b673
Add more safety checks to extension accessors
ObsidianMinor Mar 17, 2019
c4857ba
Remove instances where extension sets were unnecessarily allocated
ObsidianMinor Mar 17, 2019
8ba23fe
Remove cleared items from sets
ObsidianMinor Mar 22, 2019
a632607
Remove dead code from IExtensionValue impls
ObsidianMinor Mar 23, 2019
2c1044d
Clean both repeated and single value extensions
ObsidianMinor Mar 28, 2019
ade12cf
Add GetOrRegister method for repeated fields and allow clearing repea…
ObsidianMinor Mar 28, 2019
b7f9176
Add type safe ClearExtension methods, remove non-generic IExtendableM…
ObsidianMinor Mar 28, 2019
75c6d5f
Simplify ExtensionSet.TryMergeFieldFrom
ObsidianMinor Apr 23, 2019
b72a3ff
Rebase on master to resolve conflicts
ObsidianMinor May 2, 2019
896f4d9
Fix Makefile.am
ObsidianMinor May 2, 2019
957873f
Add ObjectIntPair to Makefile.am
ObsidianMinor May 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile.am
Expand Up @@ -148,12 +148,17 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs \
csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs \
csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs \
csharp/src/Google.Protobuf/Extension.cs \
csharp/src/Google.Protobuf/ExtensionRegistry.cs \
csharp/src/Google.Protobuf/ExtensionSet.cs \
csharp/src/Google.Protobuf/ExtensionValue.cs \
csharp/src/Google.Protobuf/FieldCodec.cs \
csharp/src/Google.Protobuf/FieldMaskTree.cs \
csharp/src/Google.Protobuf/FrameworkPortability.cs \
csharp/src/Google.Protobuf/Google.Protobuf.csproj \
csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs \
csharp/src/Google.Protobuf/IDeepCloneable.cs \
csharp/src/Google.Protobuf/IExtendableMessage.cs \
csharp/src/Google.Protobuf/IMessage.cs \
csharp/src/Google.Protobuf/InvalidJsonException.cs \
csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs \
Expand All @@ -164,6 +169,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/LimitedInputStream.cs \
csharp/src/Google.Protobuf/MessageExtensions.cs \
csharp/src/Google.Protobuf/MessageParser.cs \
csharp/src/Google.Protobuf/ObjectIntPair.cs \
csharp/src/Google.Protobuf/ProtoPreconditions.cs \
csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs \
csharp/src/Google.Protobuf/Reflection/CustomOptions.cs \
Expand All @@ -175,6 +181,8 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs \
csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs \
csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs \
csharp/src/Google.Protobuf/Reflection/ExtensionAccessor.cs \
csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs \
csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs \
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs \
csharp/src/Google.Protobuf/Reflection/FieldType.cs \
Expand Down
16 changes: 8 additions & 8 deletions csharp/src/AddressBook/Addressbook.cs
Expand Up @@ -37,9 +37,9 @@ public static partial class AddressbookReflection {
"ZHJlc3NCb29rYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person), global::Google.Protobuf.Examples.AddressBook.Person.Parser, new[]{ "Name", "Id", "Email", "Phones", "LastUpdated" }, null, new[]{ typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber), global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser, new[]{ "Number", "Type" }, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.AddressBook), global::Google.Protobuf.Examples.AddressBook.AddressBook.Parser, new[]{ "People" }, null, null, null)
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person), global::Google.Protobuf.Examples.AddressBook.Person.Parser, new[]{ "Name", "Id", "Email", "Phones", "LastUpdated" }, null, new[]{ typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber), global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser, new[]{ "Number", "Type" }, null, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.AddressBook), global::Google.Protobuf.Examples.AddressBook.AddressBook.Parser, new[]{ "People" }, null, null, null, null)
}));
}
#endregion
Expand Down Expand Up @@ -347,7 +347,7 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {

/// <summary>Field number for the "type" field.</summary>
public const int TypeFieldNumber = 2;
private global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType type_ = 0;
private global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType type_ = global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.Mobile;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType Type {
get { return type_; }
Expand Down Expand Up @@ -378,7 +378,7 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
public override int GetHashCode() {
int hash = 1;
if (Number.Length != 0) hash ^= Number.GetHashCode();
if (Type != 0) hash ^= Type.GetHashCode();
if (Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.Mobile) hash ^= Type.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
Expand All @@ -396,7 +396,7 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
output.WriteRawTag(10);
output.WriteString(Number);
}
if (Type != 0) {
if (Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.Mobile) {
output.WriteRawTag(16);
output.WriteEnum((int) Type);
}
Expand All @@ -411,7 +411,7 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
if (Number.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Number);
}
if (Type != 0) {
if (Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.Mobile) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type);
}
if (_unknownFields != null) {
Expand All @@ -428,7 +428,7 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
if (other.Number.Length != 0) {
Number = other.Number;
}
if (other.Type != 0) {
if (other.Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.Mobile) {
Type = other.Type;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
Expand Down
Expand Up @@ -55,9 +55,9 @@ public static partial class BenchmarkMessage1Proto3Reflection {
"YmVuY2htYXJrc0gB+AEBYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.Proto3.GoogleMessage1), global::Benchmarks.Proto3.GoogleMessage1.Parser, new[]{ "Field1", "Field9", "Field18", "Field80", "Field81", "Field2", "Field3", "Field280", "Field6", "Field22", "Field4", "Field5", "Field59", "Field7", "Field16", "Field130", "Field12", "Field17", "Field13", "Field14", "Field104", "Field100", "Field101", "Field102", "Field103", "Field29", "Field30", "Field60", "Field271", "Field272", "Field150", "Field23", "Field24", "Field25", "Field15", "Field78", "Field67", "Field68", "Field128", "Field129", "Field131" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.Proto3.GoogleMessage1SubMessage), global::Benchmarks.Proto3.GoogleMessage1SubMessage.Parser, new[]{ "Field1", "Field2", "Field3", "Field15", "Field12", "Field13", "Field14", "Field16", "Field19", "Field20", "Field28", "Field21", "Field22", "Field23", "Field206", "Field203", "Field204", "Field205", "Field207", "Field300" }, null, null, null)
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.Proto3.GoogleMessage1), global::Benchmarks.Proto3.GoogleMessage1.Parser, new[]{ "Field1", "Field9", "Field18", "Field80", "Field81", "Field2", "Field3", "Field280", "Field6", "Field22", "Field4", "Field5", "Field59", "Field7", "Field16", "Field130", "Field12", "Field17", "Field13", "Field14", "Field104", "Field100", "Field101", "Field102", "Field103", "Field29", "Field30", "Field60", "Field271", "Field272", "Field150", "Field23", "Field24", "Field25", "Field15", "Field78", "Field67", "Field68", "Field128", "Field129", "Field131" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.Proto3.GoogleMessage1SubMessage), global::Benchmarks.Proto3.GoogleMessage1SubMessage.Parser, new[]{ "Field1", "Field2", "Field3", "Field15", "Field12", "Field13", "Field14", "Field16", "Field19", "Field20", "Field28", "Field21", "Field22", "Field23", "Field206", "Field203", "Field204", "Field205", "Field207", "Field300" }, null, null, null, null)
}));
}
#endregion
Expand Down
4 changes: 2 additions & 2 deletions csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs
Expand Up @@ -30,8 +30,8 @@ public static partial class BenchmarksReflection {
"a3NiBnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.BenchmarkDataset), global::Benchmarks.BenchmarkDataset.Parser, new[]{ "Name", "MessageName", "Payload" }, null, null, null)
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.BenchmarkDataset), global::Benchmarks.BenchmarkDataset.Parser, new[]{ "Name", "MessageName", "Payload" }, null, null, null, null)
}));
}
#endregion
Expand Down
30 changes: 15 additions & 15 deletions csharp/src/Google.Protobuf.Conformance/Conformance.cs
Expand Up @@ -48,11 +48,11 @@ public static partial class ConformanceReflection {
"Z2xlLnByb3RvYnVmLmNvbmZvcm1hbmNlYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.FailureSet), global::Conformance.FailureSet.Parser, new[]{ "Failure" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "TextPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions", "PrintUnknownFields" }, new[]{ "Payload" }, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload", "TextPayload" }, new[]{ "Result" }, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.JspbEncodingConfig), global::Conformance.JspbEncodingConfig.Parser, new[]{ "UseJspbArrayAnyFormat" }, null, null, null)
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.FailureSet), global::Conformance.FailureSet.Parser, new[]{ "Failure" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "TextPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions", "PrintUnknownFields" }, new[]{ "Payload" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload", "TextPayload" }, new[]{ "Result" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.JspbEncodingConfig), global::Conformance.JspbEncodingConfig.Parser, new[]{ "UseJspbArrayAnyFormat" }, null, null, null, null)
}));
}
#endregion
Expand Down Expand Up @@ -337,7 +337,7 @@ public sealed partial class ConformanceRequest : pb::IMessage<ConformanceRequest

/// <summary>Field number for the "requested_output_format" field.</summary>
public const int RequestedOutputFormatFieldNumber = 3;
private global::Conformance.WireFormat requestedOutputFormat_ = 0;
private global::Conformance.WireFormat requestedOutputFormat_ = global::Conformance.WireFormat.Unspecified;
/// <summary>
/// Which format should the testee serialize its message to?
/// </summary>
Expand Down Expand Up @@ -367,7 +367,7 @@ public sealed partial class ConformanceRequest : pb::IMessage<ConformanceRequest

/// <summary>Field number for the "test_category" field.</summary>
public const int TestCategoryFieldNumber = 5;
private global::Conformance.TestCategory testCategory_ = 0;
private global::Conformance.TestCategory testCategory_ = global::Conformance.TestCategory.UnspecifiedTest;
/// <summary>
/// Each test is given a specific test category. Some category may need
/// spedific support in testee programs. Refer to the defintion of TestCategory
Expand Down Expand Up @@ -464,9 +464,9 @@ public enum PayloadOneofCase {
if (payloadCase_ == PayloadOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode();
if (payloadCase_ == PayloadOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode();
if (payloadCase_ == PayloadOneofCase.TextPayload) hash ^= TextPayload.GetHashCode();
if (RequestedOutputFormat != 0) hash ^= RequestedOutputFormat.GetHashCode();
if (RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) hash ^= RequestedOutputFormat.GetHashCode();
if (MessageType.Length != 0) hash ^= MessageType.GetHashCode();
if (TestCategory != 0) hash ^= TestCategory.GetHashCode();
if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) hash ^= TestCategory.GetHashCode();
if (jspbEncodingOptions_ != null) hash ^= JspbEncodingOptions.GetHashCode();
if (PrintUnknownFields != false) hash ^= PrintUnknownFields.GetHashCode();
hash ^= (int) payloadCase_;
Expand All @@ -491,15 +491,15 @@ public enum PayloadOneofCase {
output.WriteRawTag(18);
output.WriteString(JsonPayload);
}
if (RequestedOutputFormat != 0) {
if (RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) {
output.WriteRawTag(24);
output.WriteEnum((int) RequestedOutputFormat);
}
if (MessageType.Length != 0) {
output.WriteRawTag(34);
output.WriteString(MessageType);
}
if (TestCategory != 0) {
if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) {
output.WriteRawTag(40);
output.WriteEnum((int) TestCategory);
}
Expand Down Expand Up @@ -539,13 +539,13 @@ public enum PayloadOneofCase {
if (payloadCase_ == PayloadOneofCase.TextPayload) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload);
}
if (RequestedOutputFormat != 0) {
if (RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) RequestedOutputFormat);
}
if (MessageType.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(MessageType);
}
if (TestCategory != 0) {
if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) TestCategory);
}
if (jspbEncodingOptions_ != null) {
Expand All @@ -565,13 +565,13 @@ public enum PayloadOneofCase {
if (other == null) {
return;
}
if (other.RequestedOutputFormat != 0) {
if (other.RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) {
RequestedOutputFormat = other.RequestedOutputFormat;
}
if (other.MessageType.Length != 0) {
MessageType = other.MessageType;
}
if (other.TestCategory != 0) {
if (other.TestCategory != global::Conformance.TestCategory.UnspecifiedTest) {
TestCategory = other.TestCategory;
}
if (other.jspbEncodingOptions_ != null) {
Expand Down