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

Add support for proto3 optional fields in C# #7382

Merged
merged 6 commits into from Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Makefile.am
Expand Up @@ -122,6 +122,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs \
csharp/src/Google.Protobuf.Test/JsonParserTest.cs \
csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs \
csharp/src/Google.Protobuf.Test/Proto3OptionalTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs \
Expand All @@ -148,6 +149,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs \
csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs \
csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs \
Expand Down
3 changes: 2 additions & 1 deletion csharp/generate_protos.sh
Expand Up @@ -63,7 +63,8 @@ $PROTOC -Isrc -Icsharp/protos \
csharp/protos/unittest_issue6936_c.proto \
src/google/protobuf/unittest_well_known_types.proto \
src/google/protobuf/test_messages_proto3.proto \
src/google/protobuf/test_messages_proto2.proto
src/google/protobuf/test_messages_proto2.proto \
src/google/protobuf/unittest_proto3_optional.proto

# AddressBook sample protos
$PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \
Expand Down
144 changes: 72 additions & 72 deletions csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs
Expand Up @@ -15521,7 +15521,6 @@ public sealed partial class BoolMessage : pb::IMessage<BoolMessage> {
public sealed partial class TestOneof : pb::IMessage<TestOneof> {
private static readonly pb::MessageParser<TestOneof> _parser = new pb::MessageParser<TestOneof>(() => new TestOneof());
private pb::UnknownFieldSet _unknownFields;
private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<TestOneof> Parser { get { return _parser; } }

Expand All @@ -15544,7 +15543,6 @@ public sealed partial class TestOneof : pb::IMessage<TestOneof> {

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public TestOneof(TestOneof other) : this() {
_hasBits0 = other._hasBits0;
switch (other.FooCase) {
case FooOneofCase.FooInt:
FooInt = other.FooInt;
Expand Down Expand Up @@ -16934,21 +16932,21 @@ public sealed partial class TestOneof2 : pb::IMessage<TestOneof2> {
private int bazInt_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int BazInt {
get { if ((_hasBits0 & 16) != 0) { return bazInt_; } else { return BazIntDefaultValue; } }
get { if ((_hasBits0 & 1) != 0) { return bazInt_; } else { return BazIntDefaultValue; } }
set {
_hasBits0 |= 16;
_hasBits0 |= 1;
bazInt_ = value;
}
}
/// <summary>Gets whether the "baz_int" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasBazInt {
get { return (_hasBits0 & 16) != 0; }
get { return (_hasBits0 & 1) != 0; }
}
/// <summary>Clears the value of the "baz_int" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearBazInt() {
_hasBits0 &= ~16;
_hasBits0 &= ~1;
}

/// <summary>Field number for the "baz_string" field.</summary>
Expand Down Expand Up @@ -17767,7 +17765,6 @@ public sealed partial class NestedMessage : pb::IMessage<NestedMessage> {
public sealed partial class TestRequiredOneof : pb::IMessage<TestRequiredOneof> {
private static readonly pb::MessageParser<TestRequiredOneof> _parser = new pb::MessageParser<TestRequiredOneof>(() => new TestRequiredOneof());
private pb::UnknownFieldSet _unknownFields;
private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<TestRequiredOneof> Parser { get { return _parser; } }

Expand All @@ -17790,7 +17787,6 @@ public sealed partial class TestRequiredOneof : pb::IMessage<TestRequiredOneof>

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public TestRequiredOneof(TestRequiredOneof other) : this() {
_hasBits0 = other._hasBits0;
switch (other.FooCase) {
case FooOneofCase.FooInt:
FooInt = other.FooInt;
Expand Down