aboutsummaryrefslogtreecommitdiff
path: root/csharp/src
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src')
-rw-r--r--csharp/src/AddressBook/Addressbook.cs8
-rw-r--r--csharp/src/Google.Protobuf.Conformance/Conformance.cs84
-rw-r--r--csharp/src/Google.Protobuf.Conformance/Program.cs3
-rw-r--r--csharp/src/Google.Protobuf.Test/ByteStringTest.cs2
-rw-r--r--csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj4
-rw-r--r--csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs175
-rw-r--r--csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs150
-rw-r--r--csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs6
-rw-r--r--csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs73
-rw-r--r--csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs18
-rw-r--r--csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs10
-rw-r--r--csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs417
-rw-r--r--csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs69
-rw-r--r--csharp/src/Google.Protobuf.Test/testprotos.pbbin0 -> 204268 bytes
-rw-r--r--csharp/src/Google.Protobuf/Collections/MapField.cs1542
-rw-r--r--csharp/src/Google.Protobuf/Collections/RepeatedField.cs1190
-rw-r--r--csharp/src/Google.Protobuf/Google.Protobuf.csproj8
-rw-r--r--csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs7
-rw-r--r--csharp/src/Google.Protobuf/MessageExtensions.cs50
-rw-r--r--csharp/src/Google.Protobuf/MessageParser.cs12
-rw-r--r--csharp/src/Google.Protobuf/ProtoPreconditions.cs156
-rw-r--r--csharp/src/Google.Protobuf/Reflection/Descriptor.cs2185
-rw-r--r--csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs45
-rw-r--r--csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs112
-rw-r--r--csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs8
-rw-r--r--csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs11
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs1
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs43
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FieldType.cs2
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs144
-rw-r--r--csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs25
-rw-r--r--csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs16
-rw-r--r--csharp/src/Google.Protobuf/Reflection/PartialClasses.cs59
-rw-r--r--csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs10
-rw-r--r--csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs12
-rw-r--r--csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs33
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Any.cs3
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Api.cs10
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs50
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs26
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Type.cs26
-rw-r--r--csharp/src/Google.Protobuf/WireFormat.cs4
45 files changed, 4454 insertions, 2370 deletions
diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs
index 21a8ce02..d3e1ea95 100644
--- a/csharp/src/AddressBook/Addressbook.cs
+++ b/csharp/src/AddressBook/Addressbook.cs
@@ -247,7 +247,7 @@ namespace Google.Protobuf.Examples.AddressBook {
phones_.Add(other.phones_);
if (other.lastUpdated_ != null) {
if (lastUpdated_ == null) {
- lastUpdated_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ LastUpdated = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
LastUpdated.MergeFrom(other.LastUpdated);
}
@@ -280,9 +280,9 @@ namespace Google.Protobuf.Examples.AddressBook {
}
case 42: {
if (lastUpdated_ == null) {
- lastUpdated_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ LastUpdated = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
- input.ReadMessage(lastUpdated_);
+ input.ReadMessage(LastUpdated);
break;
}
}
@@ -447,7 +447,7 @@ namespace Google.Protobuf.Examples.AddressBook {
break;
}
case 16: {
- type_ = (global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) input.ReadEnum();
+ Type = (global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) input.ReadEnum();
break;
}
}
diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs
index 77284824..cd9b77ab 100644
--- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs
+++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs
@@ -24,22 +24,25 @@ namespace Conformance {
static ConformanceReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
- "ChFjb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2UiwAEKEkNvbmZvcm1h",
+ "ChFjb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2Ui1QEKEkNvbmZvcm1h",
"bmNlUmVxdWVzdBIaChBwcm90b2J1Zl9wYXlsb2FkGAEgASgMSAASFgoManNv",
"bl9wYXlsb2FkGAIgASgJSAASOAoXcmVxdWVzdGVkX291dHB1dF9mb3JtYXQY",
"AyABKA4yFy5jb25mb3JtYW5jZS5XaXJlRm9ybWF0EhQKDG1lc3NhZ2VfdHlw",
- "ZRgEIAEoCRIbChNpZ25vcmVfdW5rbm93bl9qc29uGAUgASgIQgkKB3BheWxv",
- "YWQisQEKE0NvbmZvcm1hbmNlUmVzcG9uc2USFQoLcGFyc2VfZXJyb3IYASAB",
- "KAlIABIZCg9zZXJpYWxpemVfZXJyb3IYBiABKAlIABIXCg1ydW50aW1lX2Vy",
- "cm9yGAIgASgJSAASGgoQcHJvdG9idWZfcGF5bG9hZBgDIAEoDEgAEhYKDGpz",
- "b25fcGF5bG9hZBgEIAEoCUgAEhEKB3NraXBwZWQYBSABKAlIAEIICgZyZXN1",
- "bHQqNQoKV2lyZUZvcm1hdBIPCgtVTlNQRUNJRklFRBAAEgwKCFBST1RPQlVG",
- "EAESCAoESlNPThACQiEKH2NvbS5nb29nbGUucHJvdG9idWYuY29uZm9ybWFu",
- "Y2ViBnByb3RvMw=="));
+ "ZRgEIAEoCRIwCg10ZXN0X2NhdGVnb3J5GAUgASgOMhkuY29uZm9ybWFuY2Uu",
+ "VGVzdENhdGVnb3J5QgkKB3BheWxvYWQisQEKE0NvbmZvcm1hbmNlUmVzcG9u",
+ "c2USFQoLcGFyc2VfZXJyb3IYASABKAlIABIZCg9zZXJpYWxpemVfZXJyb3IY",
+ "BiABKAlIABIXCg1ydW50aW1lX2Vycm9yGAIgASgJSAASGgoQcHJvdG9idWZf",
+ "cGF5bG9hZBgDIAEoDEgAEhYKDGpzb25fcGF5bG9hZBgEIAEoCUgAEhEKB3Nr",
+ "aXBwZWQYBSABKAlIAEIICgZyZXN1bHQqNQoKV2lyZUZvcm1hdBIPCgtVTlNQ",
+ "RUNJRklFRBAAEgwKCFBST1RPQlVGEAESCAoESlNPThACKmoKDFRlc3RDYXRl",
+ "Z29yeRIUChBVTlNQRUNJRklFRF9URVNUEAASDwoLQklOQVJZX1RFU1QQARIN",
+ "CglKU09OX1RFU1QQAhIkCiBKU09OX0lHTk9SRV9VTktOT1dOX1BBUlNJTkdf",
+ "VEVTVBADQiEKH2NvbS5nb29nbGUucHJvdG9idWYuY29uZm9ybWFuY2ViBnBy",
+ "b3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
- new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), }, new pbr::GeneratedClrTypeInfo[] {
- new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "RequestedOutputFormat", "MessageType", "IgnoreUnknownJson" }, new[]{ "Payload" }, null, null),
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "RequestedOutputFormat", "MessageType", "TestCategory" }, new[]{ "Payload" }, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped" }, new[]{ "Result" }, null, null)
}));
}
@@ -53,6 +56,26 @@ namespace Conformance {
[pbr::OriginalName("JSON")] Json = 2,
}
+ public enum TestCategory {
+ [pbr::OriginalName("UNSPECIFIED_TEST")] UnspecifiedTest = 0,
+ /// <summary>
+ /// Test binary wire format.
+ /// </summary>
+ [pbr::OriginalName("BINARY_TEST")] BinaryTest = 1,
+ /// <summary>
+ /// Test json wire format.
+ /// </summary>
+ [pbr::OriginalName("JSON_TEST")] JsonTest = 2,
+ /// <summary>
+ /// Similar to JSON_TEST. However, during parsing json, testee should ignore
+ /// unknown fields. This feature is optional. Each implementation can descide
+ /// whether to support it. See
+ /// https://developers.google.com/protocol-buffers/docs/proto3#json_options
+ /// for more detail.
+ /// </summary>
+ [pbr::OriginalName("JSON_IGNORE_UNKNOWN_PARSING_TEST")] JsonIgnoreUnknownParsingTest = 3,
+ }
+
#endregion
#region Messages
@@ -90,7 +113,7 @@ namespace Conformance {
public ConformanceRequest(ConformanceRequest other) : this() {
requestedOutputFormat_ = other.requestedOutputFormat_;
messageType_ = other.messageType_;
- ignoreUnknownJson_ = other.ignoreUnknownJson_;
+ testCategory_ = other.testCategory_;
switch (other.PayloadCase) {
case PayloadOneofCase.ProtobufPayload:
ProtobufPayload = other.ProtobufPayload;
@@ -160,14 +183,19 @@ namespace Conformance {
}
}
- /// <summary>Field number for the "ignore_unknown_json" field.</summary>
- public const int IgnoreUnknownJsonFieldNumber = 5;
- private bool ignoreUnknownJson_;
+ /// <summary>Field number for the "test_category" field.</summary>
+ public const int TestCategoryFieldNumber = 5;
+ private global::Conformance.TestCategory testCategory_ = 0;
+ /// <summary>
+ /// Each test is given a specific test category. Some category may need
+ /// spedific support in testee programs. Refer to the defintion of TestCategory
+ /// for more information.
+ /// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public bool IgnoreUnknownJson {
- get { return ignoreUnknownJson_; }
+ public global::Conformance.TestCategory TestCategory {
+ get { return testCategory_; }
set {
- ignoreUnknownJson_ = value;
+ testCategory_ = value;
}
}
@@ -207,7 +235,7 @@ namespace Conformance {
if (JsonPayload != other.JsonPayload) return false;
if (RequestedOutputFormat != other.RequestedOutputFormat) return false;
if (MessageType != other.MessageType) return false;
- if (IgnoreUnknownJson != other.IgnoreUnknownJson) return false;
+ if (TestCategory != other.TestCategory) return false;
if (PayloadCase != other.PayloadCase) return false;
return Equals(_unknownFields, other._unknownFields);
}
@@ -219,7 +247,7 @@ namespace Conformance {
if (payloadCase_ == PayloadOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode();
if (RequestedOutputFormat != 0) hash ^= RequestedOutputFormat.GetHashCode();
if (MessageType.Length != 0) hash ^= MessageType.GetHashCode();
- if (IgnoreUnknownJson != false) hash ^= IgnoreUnknownJson.GetHashCode();
+ if (TestCategory != 0) hash ^= TestCategory.GetHashCode();
hash ^= (int) payloadCase_;
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -250,9 +278,9 @@ namespace Conformance {
output.WriteRawTag(34);
output.WriteString(MessageType);
}
- if (IgnoreUnknownJson != false) {
+ if (TestCategory != 0) {
output.WriteRawTag(40);
- output.WriteBool(IgnoreUnknownJson);
+ output.WriteEnum((int) TestCategory);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
@@ -274,8 +302,8 @@ namespace Conformance {
if (MessageType.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(MessageType);
}
- if (IgnoreUnknownJson != false) {
- size += 1 + 1;
+ if (TestCategory != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) TestCategory);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
@@ -294,8 +322,8 @@ namespace Conformance {
if (other.MessageType.Length != 0) {
MessageType = other.MessageType;
}
- if (other.IgnoreUnknownJson != false) {
- IgnoreUnknownJson = other.IgnoreUnknownJson;
+ if (other.TestCategory != 0) {
+ TestCategory = other.TestCategory;
}
switch (other.PayloadCase) {
case PayloadOneofCase.ProtobufPayload:
@@ -326,7 +354,7 @@ namespace Conformance {
break;
}
case 24: {
- requestedOutputFormat_ = (global::Conformance.WireFormat) input.ReadEnum();
+ RequestedOutputFormat = (global::Conformance.WireFormat) input.ReadEnum();
break;
}
case 34: {
@@ -334,7 +362,7 @@ namespace Conformance {
break;
}
case 40: {
- IgnoreUnknownJson = input.ReadBool();
+ TestCategory = (global::Conformance.TestCategory) input.ReadEnum();
break;
}
}
diff --git a/csharp/src/Google.Protobuf.Conformance/Program.cs b/csharp/src/Google.Protobuf.Conformance/Program.cs
index 96dc354e..1eac00be 100644
--- a/csharp/src/Google.Protobuf.Conformance/Program.cs
+++ b/csharp/src/Google.Protobuf.Conformance/Program.cs
@@ -87,6 +87,9 @@ namespace Google.Protobuf.Conformance
switch (request.PayloadCase)
{
case ConformanceRequest.PayloadOneofCase.JsonPayload:
+ if (request.TestCategory == global::Conformance.TestCategory.JsonIgnoreUnknownParsingTest) {
+ return new ConformanceResponse { Skipped = "CSharp doesn't support skipping unknown fields in json parsing." };
+ }
var parser = new JsonParser(new JsonParser.Settings(20, typeRegistry));
message = parser.Parse<ProtobufTestMessages.Proto3.TestAllTypesProto3>(request.JsonPayload);
break;
diff --git a/csharp/src/Google.Protobuf.Test/ByteStringTest.cs b/csharp/src/Google.Protobuf.Test/ByteStringTest.cs
index afdd491f..84e6341e 100644
--- a/csharp/src/Google.Protobuf.Test/ByteStringTest.cs
+++ b/csharp/src/Google.Protobuf.Test/ByteStringTest.cs
@@ -227,7 +227,7 @@ namespace Google.Protobuf
{
// We used to have an awful hash algorithm where only the last four
// bytes were relevant. This is a regression test for
- // https://github.com/google/protobuf/issues/2511
+ // https://github.com/protocolbuffers/protobuf/issues/2511
ByteString b1 = ByteString.CopyFrom(100, 1, 2, 3, 4);
ByteString b2 = ByteString.CopyFrom(200, 1, 2, 3, 4);
diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj
index 6a430116..f286e0aa 100644
--- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj
+++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj
@@ -27,4 +27,8 @@
<TargetFrameworks>netcoreapp1.0</TargetFrameworks>
</PropertyGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="testprotos.pb" />
+ </ItemGroup>
+
</Project>
diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs
new file mode 100644
index 00000000..d9d56672
--- /dev/null
+++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs
@@ -0,0 +1,175 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2018 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using Google.Protobuf.Reflection;
+using NUnit.Framework;
+using System.Linq;
+using System.Reflection;
+
+namespace Google.Protobuf.Test.Reflection
+{
+ // In reality this isn't a test for DescriptorDeclaration so much as the way they're loaded.
+ public class DescriptorDeclarationTest
+ {
+ static readonly FileDescriptor unitTestProto3Descriptor = LoadProtos();
+
+ // Note: we don't expose a declaration for FileDescriptor as it doesn't have comments
+ // at the moment and the locations aren't terribly useful.
+
+ // The tests for most elements are quite basic: we don't test every aspect of every element.
+ // The code within the library falls into two categories:
+ // - Exposing the properties for *any* declaration
+ // - Finding the right declaration for an element from the descriptor data
+ // We have a per-element check to make sure we *are* finding the right declaration, and we
+ // check every property of declarations in at least one test, but we don't have a cross-product.
+ // That would effectively be testing protoc, which seems redundant here.
+
+ [Test]
+ public void ServiceComments()
+ {
+ var service = unitTestProto3Descriptor.FindTypeByName<ServiceDescriptor>("TestService");
+ Assert.NotNull(service.Declaration);
+ Assert.AreEqual(" This is a test service\n", service.Declaration.LeadingComments);
+ }
+
+ [Test]
+ public void MethodComments()
+ {
+ var service = unitTestProto3Descriptor.FindTypeByName<ServiceDescriptor>("TestService");
+ var method = service.FindMethodByName("Foo");
+ Assert.NotNull(method.Declaration);
+ Assert.AreEqual(" This is a test method\n", method.Declaration.LeadingComments);
+ }
+
+ [Test]
+ public void MessageComments()
+ {
+ var message = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage");
+ Assert.NotNull(message.Declaration);
+ Assert.AreEqual(" This is a leading comment\n", message.Declaration.LeadingComments);
+ Assert.AreEqual(new[] { " This is leading detached comment 1\n", " This is leading detached comment 2\n" },
+ message.Declaration.LeadingDetachedComments);
+ }
+
+ // Note: this test is somewhat brittle; a change earlier in the proto will break it.
+ [Test]
+ public void MessageLocations()
+ {
+ var message = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage");
+ Assert.NotNull(message.Declaration);
+ Assert.AreEqual(389, message.Declaration.StartLine);
+ Assert.AreEqual(1, message.Declaration.StartColumn);
+
+ Assert.AreEqual(404, message.Declaration.EndLine);
+ Assert.AreEqual(2, message.Declaration.EndColumn);
+ }
+
+ [Test]
+ public void EnumComments()
+ {
+ var descriptor = unitTestProto3Descriptor.FindTypeByName<EnumDescriptor>("CommentEnum");
+ Assert.NotNull(descriptor.Declaration);
+ Assert.AreEqual(" Leading enum comment\n", descriptor.Declaration.LeadingComments);
+ }
+
+ [Test]
+ public void NestedMessageComments()
+ {
+ var outer = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage");
+ var nested = outer.FindDescriptor<MessageDescriptor>("NestedCommentMessage");
+ Assert.NotNull(nested.Declaration);
+ Assert.AreEqual(" Leading nested message comment\n", nested.Declaration.LeadingComments);
+ }
+
+ [Test]
+ public void NestedEnumComments()
+ {
+ var outer = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage");
+ var nested = outer.FindDescriptor<EnumDescriptor>("NestedCommentEnum");
+ Assert.NotNull(nested.Declaration);
+ Assert.AreEqual(" Leading nested enum comment\n", nested.Declaration.LeadingComments);
+ }
+
+ [Test]
+ public void FieldComments()
+ {
+ var message = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage");
+ var field = message.FindFieldByName("text");
+ Assert.NotNull(field.Declaration);
+ Assert.AreEqual(" Leading field comment\n", field.Declaration.LeadingComments);
+ Assert.AreEqual(" Trailing field comment\n", field.Declaration.TrailingComments);
+ }
+
+ [Test]
+ public void NestedMessageFieldComments()
+ {
+ var outer = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage");
+ var nested = outer.FindDescriptor<MessageDescriptor>("NestedCommentMessage");
+ var field = nested.FindFieldByName("nested_text");
+ Assert.NotNull(field.Declaration);
+ Assert.AreEqual(" Leading nested message field comment\n", field.Declaration.LeadingComments);
+ }
+
+ [Test]
+ public void EnumValueComments()
+ {
+ var enumDescriptor = unitTestProto3Descriptor.FindTypeByName<EnumDescriptor>("CommentEnum");
+ var value = enumDescriptor.FindValueByName("ZERO_VALUE");
+ Assert.NotNull(value.Declaration);
+ Assert.AreEqual(" Zero value comment\n", value.Declaration.LeadingComments);
+ }
+
+ [Test]
+ public void NestedEnumValueComments()
+ {
+ var outer = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("CommentMessage");
+ var nested = outer.FindDescriptor<EnumDescriptor>("NestedCommentEnum");
+ var value = nested.FindValueByName("ZERO_VALUE");
+ Assert.NotNull(value.Declaration);
+ Assert.AreEqual(" Zero value comment\n", value.Declaration.LeadingComments);
+ }
+
+ private static FileDescriptor LoadProtos()
+ {
+ var type = typeof(DescriptorDeclarationTest);
+ // TODO: Make this simpler :)
+ FileDescriptorSet descriptorSet;
+ using (var stream = type.GetTypeInfo().Assembly.GetManifestResourceStream($"Google.Protobuf.Test.testprotos.pb"))
+ {
+ descriptorSet = FileDescriptorSet.Parser.ParseFrom(stream);
+ }
+ var byteStrings = descriptorSet.File.Select(f => f.ToByteString()).ToList();
+ var descriptors = FileDescriptor.BuildFromByteStrings(byteStrings);
+ return descriptors.Single(d => d.Name == "unittest_proto3.proto");
+ }
+ }
+}
diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
index 29a376e0..8e1097aa 100644
--- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
+++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
@@ -30,10 +30,11 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
-using System.Linq;
using Google.Protobuf.TestProtos;
using NUnit.Framework;
-using UnitTest.Issues.TestProtos;
+using System;
+using System.Collections.Generic;
+using System.Linq;
namespace Google.Protobuf.Reflection
{
@@ -44,10 +45,32 @@ namespace Google.Protobuf.Reflection
public class DescriptorsTest
{
[Test]
- public void FileDescriptor()
+ public void FileDescriptor_GeneratedCode()
{
- FileDescriptor file = UnittestProto3Reflection.Descriptor;
+ TestFileDescriptor(
+ UnittestProto3Reflection.Descriptor,
+ UnittestImportProto3Reflection.Descriptor,
+ UnittestImportPublicProto3Reflection.Descriptor);
+ }
+ [Test]
+ public void FileDescriptor_BuildFromByteStrings()
+ {
+ // The descriptors have to be supplied in an order such that all the
+ // dependencies come before the descriptors depending on them.
+ var descriptorData = new List<ByteString>
+ {
+ UnittestImportPublicProto3Reflection.Descriptor.SerializedData,
+ UnittestImportProto3Reflection.Descriptor.SerializedData,
+ UnittestProto3Reflection.Descriptor.SerializedData
+ };
+ var converted = FileDescriptor.BuildFromByteStrings(descriptorData);
+ Assert.AreEqual(3, converted.Count);
+ TestFileDescriptor(converted[2], converted[1], converted[0]);
+ }
+
+ private void TestFileDescriptor(FileDescriptor file, FileDescriptor importedFile, FileDescriptor importedPublicFile)
+ {
Assert.AreEqual("unittest_proto3.proto", file.Name);
Assert.AreEqual("protobuf_unittest3", file.Package);
@@ -56,17 +79,12 @@ namespace Google.Protobuf.Reflection
// unittest_proto3.proto doesn't have any public imports, but unittest_import_proto3.proto does.
Assert.AreEqual(0, file.PublicDependencies.Count);
- Assert.AreEqual(1, UnittestImportProto3Reflection.Descriptor.PublicDependencies.Count);
- Assert.AreEqual(UnittestImportPublicProto3Reflection.Descriptor, UnittestImportProto3Reflection.Descriptor.PublicDependencies[0]);
+ Assert.AreEqual(1, importedFile.PublicDependencies.Count);
+ Assert.AreEqual(importedPublicFile, importedFile.PublicDependencies[0]);
Assert.AreEqual(1, file.Dependencies.Count);
- Assert.AreEqual(UnittestImportProto3Reflection.Descriptor, file.Dependencies[0]);
+ Assert.AreEqual(importedFile, file.Dependencies[0]);
- MessageDescriptor messageType = TestAllTypes.Descriptor;
- Assert.AreSame(typeof(TestAllTypes), messageType.ClrType);
- Assert.AreSame(TestAllTypes.Parser, messageType.Parser);
- Assert.AreEqual(messageType, file.MessageTypes[0]);
- Assert.AreEqual(messageType, file.FindTypeByName<MessageDescriptor>("TestAllTypes"));
Assert.Null(file.FindTypeByName<MessageDescriptor>("NoSuchType"));
Assert.Null(file.FindTypeByName<MessageDescriptor>("protobuf_unittest3.TestAllTypes"));
for (int i = 0; i < file.MessageTypes.Count; i++)
@@ -77,8 +95,8 @@ namespace Google.Protobuf.Reflection
Assert.AreEqual(file.EnumTypes[0], file.FindTypeByName<EnumDescriptor>("ForeignEnum"));
Assert.Null(file.FindTypeByName<EnumDescriptor>("NoSuchType"));
Assert.Null(file.FindTypeByName<EnumDescriptor>("protobuf_unittest3.ForeignEnum"));
- Assert.AreEqual(1, UnittestImportProto3Reflection.Descriptor.EnumTypes.Count);
- Assert.AreEqual("ImportEnum", UnittestImportProto3Reflection.Descriptor.EnumTypes[0].Name);
+ Assert.AreEqual(1, importedFile.EnumTypes.Count);
+ Assert.AreEqual("ImportEnum", importedFile.EnumTypes[0].Name);
for (int i = 0; i < file.EnumTypes.Count; i++)
{
Assert.AreEqual(i, file.EnumTypes[i].Index);
@@ -98,6 +116,56 @@ namespace Google.Protobuf.Reflection
}
[Test]
+ public void FileDescriptor_BuildFromByteStrings_MissingDependency()
+ {
+ var descriptorData = new List<ByteString>
+ {
+ UnittestImportProto3Reflection.Descriptor.SerializedData,
+ UnittestProto3Reflection.Descriptor.SerializedData,
+ };
+ // This will fail, because we're missing UnittestImportPublicProto3Reflection
+ Assert.Throws<ArgumentException>(() => FileDescriptor.BuildFromByteStrings(descriptorData));
+ }
+
+ [Test]
+ public void FileDescriptor_BuildFromByteStrings_DuplicateNames()
+ {
+ var descriptorData = new List<ByteString>
+ {
+ UnittestImportPublicProto3Reflection.Descriptor.SerializedData,
+ UnittestImportPublicProto3Reflection.Descriptor.SerializedData,
+ };
+ // This will fail due to the same name being used twice
+ Assert.Throws<ArgumentException>(() => FileDescriptor.BuildFromByteStrings(descriptorData));
+ }
+
+ [Test]
+ public void FileDescriptor_BuildFromByteStrings_IncorrectOrder()
+ {
+ var descriptorData = new List<ByteString>
+ {
+ UnittestProto3Reflection.Descriptor.SerializedData,
+ UnittestImportPublicProto3Reflection.Descriptor.SerializedData,
+ UnittestImportProto3Reflection.Descriptor.SerializedData
+ };
+ // This will fail, because the dependencies should come first
+ Assert.Throws<ArgumentException>(() => FileDescriptor.BuildFromByteStrings(descriptorData));
+
+ }
+
+ [Test]
+ public void MessageDescriptorFromGeneratedCodeFileDescriptor()
+ {
+ var file = UnittestProto3Reflection.Descriptor;
+
+ MessageDescriptor messageType = TestAllTypes.Descriptor;
+ Assert.AreSame(typeof(TestAllTypes), messageType.ClrType);
+ Assert.AreSame(TestAllTypes.Parser, messageType.Parser);
+ Assert.AreEqual(messageType, file.MessageTypes[0]);
+ Assert.AreEqual(messageType, file.FindTypeByName<MessageDescriptor>("TestAllTypes"));
+ }
+
+ [Test]
public void MessageDescriptor()
{
MessageDescriptor messageType = TestAllTypes.Descriptor;
@@ -145,29 +213,61 @@ namespace Google.Protobuf.Reflection
}
[Test]
- public void FieldDescriptor()
+ public void FieldDescriptor_GeneratedCode()
{
- MessageDescriptor messageType = TestAllTypes.Descriptor;
- FieldDescriptor primitiveField = messageType.FindDescriptor<FieldDescriptor>("single_int32");
- FieldDescriptor enumField = messageType.FindDescriptor<FieldDescriptor>("single_nested_enum");
- FieldDescriptor messageField = messageType.FindDescriptor<FieldDescriptor>("single_foreign_message");
+ TestFieldDescriptor(UnittestProto3Reflection.Descriptor, TestAllTypes.Descriptor, ForeignMessage.Descriptor, ImportMessage.Descriptor);
+ }
+
+ [Test]
+ public void FieldDescriptor_BuildFromByteStrings()
+ {
+ // The descriptors have to be supplied in an order such that all the
+ // dependencies come before the descriptors depending on them.
+ var descriptorData = new List<ByteString>
+ {
+ UnittestImportPublicProto3Reflection.Descriptor.SerializedData,
+ UnittestImportProto3Reflection.Descriptor.SerializedData,
+ UnittestProto3Reflection.Descriptor.SerializedData
+ };
+ var converted = FileDescriptor.BuildFromByteStrings(descriptorData);
+ TestFieldDescriptor(
+ converted[2],
+ converted[2].FindTypeByName<MessageDescriptor>("TestAllTypes"),
+ converted[2].FindTypeByName<MessageDescriptor>("ForeignMessage"),
+ converted[1].FindTypeByName<MessageDescriptor>("ImportMessage"));
+ }
+
+ public void TestFieldDescriptor(
+ FileDescriptor unitTestProto3Descriptor,
+ MessageDescriptor testAllTypesDescriptor,
+ MessageDescriptor foreignMessageDescriptor,
+ MessageDescriptor importMessageDescriptor)
+ {
+ FieldDescriptor primitiveField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_int32");
+ FieldDescriptor enumField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_nested_enum");
+ FieldDescriptor foreignMessageField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_foreign_message");
+ FieldDescriptor importMessageField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_import_message");
Assert.AreEqual("single_int32", primitiveField.Name);
Assert.AreEqual("protobuf_unittest3.TestAllTypes.single_int32",
primitiveField.FullName);
Assert.AreEqual(1, primitiveField.FieldNumber);
- Assert.AreEqual(messageType, primitiveField.ContainingType);
- Assert.AreEqual(UnittestProto3Reflection.Descriptor, primitiveField.File);
+ Assert.AreEqual(testAllTypesDescriptor, primitiveField.ContainingType);
+ Assert.AreEqual(unitTestProto3Descriptor, primitiveField.File);
Assert.AreEqual(FieldType.Int32, primitiveField.FieldType);
Assert.IsNull(primitiveField.Proto.Options);
Assert.AreEqual("single_nested_enum", enumField.Name);
Assert.AreEqual(FieldType.Enum, enumField.FieldType);
- // Assert.AreEqual(TestAllTypes.Types.NestedEnum.DescriptorProtoFile, enumField.EnumType);
+ Assert.AreEqual(testAllTypesDescriptor.EnumTypes[0], enumField.EnumType);
+
+ Assert.AreEqual("single_foreign_message", foreignMessageField.Name);
+ Assert.AreEqual(FieldType.Message, foreignMessageField.FieldType);
+ Assert.AreEqual(foreignMessageDescriptor, foreignMessageField.MessageType);
- Assert.AreEqual("single_foreign_message", messageField.Name);
- Assert.AreEqual(FieldType.Message, messageField.FieldType);
- Assert.AreEqual(ForeignMessage.Descriptor, messageField.MessageType);
+ Assert.AreEqual("single_import_message", importMessageField.Name);
+ Assert.AreEqual(FieldType.Message, importMessageField.FieldType);
+ Assert.AreEqual(importMessageDescriptor, importMessageField.MessageType);
}
[Test]
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
index 51715a0c..6d3cd026 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
@@ -724,7 +724,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.testMap_ != null) {
if (testMap_ == null) {
- testMap_ = new global::Google.Protobuf.TestProtos.TestMap();
+ TestMap = new global::Google.Protobuf.TestProtos.TestMap();
}
TestMap.MergeFrom(other.TestMap);
}
@@ -741,9 +741,9 @@ namespace Google.Protobuf.TestProtos {
break;
case 10: {
if (testMap_ == null) {
- testMap_ = new global::Google.Protobuf.TestProtos.TestMap();
+ TestMap = new global::Google.Protobuf.TestProtos.TestMap();
}
- input.ReadMessage(testMap_);
+ input.ReadMessage(TestMap);
break;
}
}
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
index 7353be7b..d74422b5 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
@@ -1171,6 +1171,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "optional_int32_wrapper" field.</summary>
public const int OptionalInt32WrapperFieldNumber = 202;
private static readonly pb::FieldCodec<int?> _single_optionalInt32Wrapper_codec = pb::FieldCodec.ForStructWrapper<int>(1618);
@@ -1183,6 +1184,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "optional_int64_wrapper" field.</summary>
public const int OptionalInt64WrapperFieldNumber = 203;
private static readonly pb::FieldCodec<long?> _single_optionalInt64Wrapper_codec = pb::FieldCodec.ForStructWrapper<long>(1626);
@@ -1195,6 +1197,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "optional_uint32_wrapper" field.</summary>
public const int OptionalUint32WrapperFieldNumber = 204;
private static readonly pb::FieldCodec<uint?> _single_optionalUint32Wrapper_codec = pb::FieldCodec.ForStructWrapper<uint>(1634);
@@ -1207,6 +1210,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "optional_uint64_wrapper" field.</summary>
public const int OptionalUint64WrapperFieldNumber = 205;
private static readonly pb::FieldCodec<ulong?> _single_optionalUint64Wrapper_codec = pb::FieldCodec.ForStructWrapper<ulong>(1642);
@@ -1219,6 +1223,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "optional_float_wrapper" field.</summary>
public const int OptionalFloatWrapperFieldNumber = 206;
private static readonly pb::FieldCodec<float?> _single_optionalFloatWrapper_codec = pb::FieldCodec.ForStructWrapper<float>(1650);
@@ -1231,6 +1236,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "optional_double_wrapper" field.</summary>
public const int OptionalDoubleWrapperFieldNumber = 207;
private static readonly pb::FieldCodec<double?> _single_optionalDoubleWrapper_codec = pb::FieldCodec.ForStructWrapper<double>(1658);
@@ -1243,6 +1249,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "optional_string_wrapper" field.</summary>
public const int OptionalStringWrapperFieldNumber = 208;
private static readonly pb::FieldCodec<string> _single_optionalStringWrapper_codec = pb::FieldCodec.ForClassWrapper<string>(1666);
@@ -1255,6 +1262,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "optional_bytes_wrapper" field.</summary>
public const int OptionalBytesWrapperFieldNumber = 209;
private static readonly pb::FieldCodec<pb::ByteString> _single_optionalBytesWrapper_codec = pb::FieldCodec.ForClassWrapper<pb::ByteString>(1674);
@@ -1267,6 +1275,7 @@ namespace ProtobufTestMessages.Proto3 {
}
}
+
/// <summary>Field number for the "repeated_bool_wrapper" field.</summary>
public const int RepeatedBoolWrapperFieldNumber = 211;
private static readonly pb::FieldCodec<bool?> _repeated_repeatedBoolWrapper_codec
@@ -2598,13 +2607,13 @@ namespace ProtobufTestMessages.Proto3 {
}
if (other.optionalNestedMessage_ != null) {
if (optionalNestedMessage_ == null) {
- optionalNestedMessage_ = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage();
+ OptionalNestedMessage = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage();
}
OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage);
}
if (other.optionalForeignMessage_ != null) {
if (optionalForeignMessage_ == null) {
- optionalForeignMessage_ = new global::ProtobufTestMessages.Proto3.ForeignMessage();
+ OptionalForeignMessage = new global::ProtobufTestMessages.Proto3.ForeignMessage();
}
OptionalForeignMessage.MergeFrom(other.OptionalForeignMessage);
}
@@ -2622,7 +2631,7 @@ namespace ProtobufTestMessages.Proto3 {
}
if (other.recursiveMessage_ != null) {
if (recursiveMessage_ == null) {
- recursiveMessage_ = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3();
+ RecursiveMessage = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3();
}
RecursiveMessage.MergeFrom(other.RecursiveMessage);
}
@@ -2722,37 +2731,37 @@ namespace ProtobufTestMessages.Proto3 {
repeatedBytesWrapper_.Add(other.repeatedBytesWrapper_);
if (other.optionalDuration_ != null) {
if (optionalDuration_ == null) {
- optionalDuration_ = new global::Google.Protobuf.WellKnownTypes.Duration();
+ OptionalDuration = new global::Google.Protobuf.WellKnownTypes.Duration();
}
OptionalDuration.MergeFrom(other.OptionalDuration);
}
if (other.optionalTimestamp_ != null) {
if (optionalTimestamp_ == null) {
- optionalTimestamp_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ OptionalTimestamp = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
OptionalTimestamp.MergeFrom(other.OptionalTimestamp);
}
if (other.optionalFieldMask_ != null) {
if (optionalFieldMask_ == null) {
- optionalFieldMask_ = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ OptionalFieldMask = new global::Google.Protobuf.WellKnownTypes.FieldMask();
}
OptionalFieldMask.MergeFrom(other.OptionalFieldMask);
}
if (other.optionalStruct_ != null) {
if (optionalStruct_ == null) {
- optionalStruct_ = new global::Google.Protobuf.WellKnownTypes.Struct();
+ OptionalStruct = new global::Google.Protobuf.WellKnownTypes.Struct();
}
OptionalStruct.MergeFrom(other.OptionalStruct);
}
if (other.optionalAny_ != null) {
if (optionalAny_ == null) {
- optionalAny_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ OptionalAny = new global::Google.Protobuf.WellKnownTypes.Any();
}
OptionalAny.MergeFrom(other.OptionalAny);
}
if (other.optionalValue_ != null) {
if (optionalValue_ == null) {
- optionalValue_ = new global::Google.Protobuf.WellKnownTypes.Value();
+ OptionalValue = new global::Google.Protobuf.WellKnownTypes.Value();
}
OptionalValue.MergeFrom(other.OptionalValue);
}
@@ -2922,24 +2931,24 @@ namespace ProtobufTestMessages.Proto3 {
}
case 146: {
if (optionalNestedMessage_ == null) {
- optionalNestedMessage_ = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage();
+ OptionalNestedMessage = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage();
}
- input.ReadMessage(optionalNestedMessage_);
+ input.ReadMessage(OptionalNestedMessage);
break;
}
case 154: {
if (optionalForeignMessage_ == null) {
- optionalForeignMessage_ = new global::ProtobufTestMessages.Proto3.ForeignMessage();
+ OptionalForeignMessage = new global::ProtobufTestMessages.Proto3.ForeignMessage();
}
- input.ReadMessage(optionalForeignMessage_);
+ input.ReadMessage(OptionalForeignMessage);
break;
}
case 168: {
- optionalNestedEnum_ = (global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum) input.ReadEnum();
+ OptionalNestedEnum = (global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum) input.ReadEnum();
break;
}
case 176: {
- optionalForeignEnum_ = (global::ProtobufTestMessages.Proto3.ForeignEnum) input.ReadEnum();
+ OptionalForeignEnum = (global::ProtobufTestMessages.Proto3.ForeignEnum) input.ReadEnum();
break;
}
case 194: {
@@ -2952,9 +2961,9 @@ namespace ProtobufTestMessages.Proto3 {
}
case 218: {
if (recursiveMessage_ == null) {
- recursiveMessage_ = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3();
+ RecursiveMessage = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3();
}
- input.ReadMessage(recursiveMessage_);
+ input.ReadMessage(RecursiveMessage);
break;
}
case 250:
@@ -3275,44 +3284,44 @@ namespace ProtobufTestMessages.Proto3 {
}
case 2410: {
if (optionalDuration_ == null) {
- optionalDuration_ = new global::Google.Protobuf.WellKnownTypes.Duration();
+ OptionalDuration = new global::Google.Protobuf.WellKnownTypes.Duration();
}
- input.ReadMessage(optionalDuration_);
+ input.ReadMessage(OptionalDuration);
break;
}
case 2418: {
if (optionalTimestamp_ == null) {
- optionalTimestamp_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ OptionalTimestamp = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
- input.ReadMessage(optionalTimestamp_);
+ input.ReadMessage(OptionalTimestamp);
break;
}
case 2426: {
if (optionalFieldMask_ == null) {
- optionalFieldMask_ = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ OptionalFieldMask = new global::Google.Protobuf.WellKnownTypes.FieldMask();
}
- input.ReadMessage(optionalFieldMask_);
+ input.ReadMessage(OptionalFieldMask);
break;
}
case 2434: {
if (optionalStruct_ == null) {
- optionalStruct_ = new global::Google.Protobuf.WellKnownTypes.Struct();
+ OptionalStruct = new global::Google.Protobuf.WellKnownTypes.Struct();
}
- input.ReadMessage(optionalStruct_);
+ input.ReadMessage(OptionalStruct);
break;
}
case 2442: {
if (optionalAny_ == null) {
- optionalAny_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ OptionalAny = new global::Google.Protobuf.WellKnownTypes.Any();
}
- input.ReadMessage(optionalAny_);
+ input.ReadMessage(OptionalAny);
break;
}
case 2450: {
if (optionalValue_ == null) {
- optionalValue_ = new global::Google.Protobuf.WellKnownTypes.Value();
+ OptionalValue = new global::Google.Protobuf.WellKnownTypes.Value();
}
- input.ReadMessage(optionalValue_);
+ input.ReadMessage(OptionalValue);
break;
}
case 2490: {
@@ -3560,7 +3569,7 @@ namespace ProtobufTestMessages.Proto3 {
}
if (other.corecursive_ != null) {
if (corecursive_ == null) {
- corecursive_ = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3();
+ Corecursive = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3();
}
Corecursive.MergeFrom(other.Corecursive);
}
@@ -3581,9 +3590,9 @@ namespace ProtobufTestMessages.Proto3 {
}
case 18: {
if (corecursive_ == null) {
- corecursive_ = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3();
+ Corecursive = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3();
}
- input.ReadMessage(corecursive_);
+ input.ReadMessage(Corecursive);
break;
}
}
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
index 3ab5a48b..2a9efe55 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
@@ -1879,7 +1879,7 @@ namespace UnitTest.Issues.TestProtos {
}
if (other.bar_ != null) {
if (bar_ == null) {
- bar_ = new global::UnitTest.Issues.TestProtos.ComplexOptionType1();
+ Bar = new global::UnitTest.Issues.TestProtos.ComplexOptionType1();
}
Bar.MergeFrom(other.Bar);
}
@@ -1888,7 +1888,7 @@ namespace UnitTest.Issues.TestProtos {
}
if (other.fred_ != null) {
if (fred_ == null) {
- fred_ = new global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4();
+ Fred = new global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4();
}
Fred.MergeFrom(other.Fred);
}
@@ -1906,9 +1906,9 @@ namespace UnitTest.Issues.TestProtos {
break;
case 10: {
if (bar_ == null) {
- bar_ = new global::UnitTest.Issues.TestProtos.ComplexOptionType1();
+ Bar = new global::UnitTest.Issues.TestProtos.ComplexOptionType1();
}
- input.ReadMessage(bar_);
+ input.ReadMessage(Bar);
break;
}
case 16: {
@@ -1917,9 +1917,9 @@ namespace UnitTest.Issues.TestProtos {
}
case 26: {
if (fred_ == null) {
- fred_ = new global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4();
+ Fred = new global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4();
}
- input.ReadMessage(fred_);
+ input.ReadMessage(Fred);
break;
}
case 34: {
@@ -2462,7 +2462,7 @@ namespace UnitTest.Issues.TestProtos {
}
if (other.sub_ != null) {
if (sub_ == null) {
- sub_ = new global::UnitTest.Issues.TestProtos.Aggregate();
+ Sub = new global::UnitTest.Issues.TestProtos.Aggregate();
}
Sub.MergeFrom(other.Sub);
}
@@ -2487,9 +2487,9 @@ namespace UnitTest.Issues.TestProtos {
}
case 26: {
if (sub_ == null) {
- sub_ = new global::UnitTest.Issues.TestProtos.Aggregate();
+ Sub = new global::UnitTest.Issues.TestProtos.Aggregate();
}
- input.ReadMessage(sub_);
+ input.ReadMessage(Sub);
break;
}
}
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
index 819fc201..f27ab640 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
@@ -557,7 +557,7 @@ namespace UnitTest.Issues.TestProtos {
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 8: {
- value_ = (global::UnitTest.Issues.TestProtos.NegativeEnum) input.ReadEnum();
+ Value = (global::UnitTest.Issues.TestProtos.NegativeEnum) input.ReadEnum();
break;
}
case 18:
@@ -881,7 +881,7 @@ namespace UnitTest.Issues.TestProtos {
primitiveArray_.Add(other.primitiveArray_);
if (other.messageValue_ != null) {
if (messageValue_ == null) {
- messageValue_ = new global::UnitTest.Issues.TestProtos.DeprecatedChild();
+ MessageValue = new global::UnitTest.Issues.TestProtos.DeprecatedChild();
}
MessageValue.MergeFrom(other.MessageValue);
}
@@ -912,9 +912,9 @@ namespace UnitTest.Issues.TestProtos {
}
case 26: {
if (messageValue_ == null) {
- messageValue_ = new global::UnitTest.Issues.TestProtos.DeprecatedChild();
+ MessageValue = new global::UnitTest.Issues.TestProtos.DeprecatedChild();
}
- input.ReadMessage(messageValue_);
+ input.ReadMessage(MessageValue);
break;
}
case 34: {
@@ -922,7 +922,7 @@ namespace UnitTest.Issues.TestProtos {
break;
}
case 40: {
- enumValue_ = (global::UnitTest.Issues.TestProtos.DeprecatedEnum) input.ReadEnum();
+ EnumValue = (global::UnitTest.Issues.TestProtos.DeprecatedEnum) input.ReadEnum();
break;
}
case 50:
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
index d5dbe866..bbbee22c 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
@@ -139,23 +139,26 @@ namespace Google.Protobuf.TestProtos {
"NBj//w8gAygEIigKG1Rlc3RDb21tZW50SW5qZWN0aW9uTWVzc2FnZRIJCgFh",
"GAEgASgJIgwKCkZvb1JlcXVlc3QiDQoLRm9vUmVzcG9uc2UiEgoQRm9vQ2xp",
"ZW50TWVzc2FnZSISChBGb29TZXJ2ZXJNZXNzYWdlIgwKCkJhclJlcXVlc3Qi",
- "DQoLQmFyUmVzcG9uc2UiEgoQVGVzdEVtcHR5TWVzc2FnZSpZCgtGb3JlaWdu",
- "RW51bRIXChNGT1JFSUdOX1VOU1BFQ0lGSUVEEAASDwoLRk9SRUlHTl9GT08Q",
- "BBIPCgtGT1JFSUdOX0JBUhAFEg8KC0ZPUkVJR05fQkFaEAYqdQoUVGVzdEVu",
- "dW1XaXRoRHVwVmFsdWUSKAokVEVTVF9FTlVNX1dJVEhfRFVQX1ZBTFVFX1VO",
- "U1BFQ0lGSUVEEAASCAoERk9PMRABEggKBEJBUjEQAhIHCgNCQVoQAxIICgRG",
- "T08yEAESCAoEQkFSMhACGgIQASqdAQoOVGVzdFNwYXJzZUVudW0SIAocVEVT",
- "VF9TUEFSU0VfRU5VTV9VTlNQRUNJRklFRBAAEgwKCFNQQVJTRV9BEHsSDgoI",
- "U1BBUlNFX0IQpucDEg8KCFNQQVJTRV9DELKxgAYSFQoIU1BBUlNFX0QQ8f//",
- "////////ARIVCghTUEFSU0VfRRC03vz///////8BEgwKCFNQQVJTRV9HEAIy",
- "nQEKC1Rlc3RTZXJ2aWNlEkYKA0ZvbxIeLnByb3RvYnVmX3VuaXR0ZXN0My5G",
- "b29SZXF1ZXN0Gh8ucHJvdG9idWZfdW5pdHRlc3QzLkZvb1Jlc3BvbnNlEkYK",
- "A0JhchIeLnByb3RvYnVmX3VuaXR0ZXN0My5CYXJSZXF1ZXN0Gh8ucHJvdG9i",
- "dWZfdW5pdHRlc3QzLkJhclJlc3BvbnNlQixCDVVuaXR0ZXN0UHJvdG+qAhpH",
- "b29nbGUuUHJvdG9idWYuVGVzdFByb3Rvc2IGcHJvdG8z"));
+ "DQoLQmFyUmVzcG9uc2UiEgoQVGVzdEVtcHR5TWVzc2FnZSJwCg5Db21tZW50",
+ "TWVzc2FnZRIMCgR0ZXh0GAEgASgJGisKFE5lc3RlZENvbW1lbnRNZXNzYWdl",
+ "EhMKC25lc3RlZF90ZXh0GAEgASgJIiMKEU5lc3RlZENvbW1lbnRFbnVtEg4K",
+ "ClpFUk9fVkFMVUUQACpZCgtGb3JlaWduRW51bRIXChNGT1JFSUdOX1VOU1BF",
+ "Q0lGSUVEEAASDwoLRk9SRUlHTl9GT08QBBIPCgtGT1JFSUdOX0JBUhAFEg8K",
+ "C0ZPUkVJR05fQkFaEAYqdQoUVGVzdEVudW1XaXRoRHVwVmFsdWUSKAokVEVT",
+ "VF9FTlVNX1dJVEhfRFVQX1ZBTFVFX1VOU1BFQ0lGSUVEEAASCAoERk9PMRAB",
+ "EggKBEJBUjEQAhIHCgNCQVoQAxIICgRGT08yEAESCAoEQkFSMhACGgIQASqd",
+ "AQoOVGVzdFNwYXJzZUVudW0SIAocVEVTVF9TUEFSU0VfRU5VTV9VTlNQRUNJ",
+ "RklFRBAAEgwKCFNQQVJTRV9BEHsSDgoIU1BBUlNFX0IQpucDEg8KCFNQQVJT",
+ "RV9DELKxgAYSFQoIU1BBUlNFX0QQ8f//////////ARIVCghTUEFSU0VfRRC0",
+ "3vz///////8BEgwKCFNQQVJTRV9HEAIqHQoLQ29tbWVudEVudW0SDgoKWkVS",
+ "T19WQUxVRRAAMp0BCgtUZXN0U2VydmljZRJGCgNGb28SHi5wcm90b2J1Zl91",
+ "bml0dGVzdDMuRm9vUmVxdWVzdBofLnByb3RvYnVmX3VuaXR0ZXN0My5Gb29S",
+ "ZXNwb25zZRJGCgNCYXISHi5wcm90b2J1Zl91bml0dGVzdDMuQmFyUmVxdWVz",
+ "dBofLnByb3RvYnVmX3VuaXR0ZXN0My5CYXJSZXNwb25zZUIsQg1Vbml0dGVz",
+ "dFByb3RvqgIaR29vZ2xlLlByb3RvYnVmLlRlc3RQcm90b3NiBnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Google.Protobuf.TestProtos.UnittestImportProto3Reflection.Descriptor, },
- new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.TestProtos.ForeignEnum), typeof(global::Google.Protobuf.TestProtos.TestEnumWithDupValue), typeof(global::Google.Protobuf.TestProtos.TestSparseEnum), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.TestProtos.ForeignEnum), typeof(global::Google.Protobuf.TestProtos.TestEnumWithDupValue), typeof(global::Google.Protobuf.TestProtos.TestSparseEnum), typeof(global::Google.Protobuf.TestProtos.CommentEnum), }, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestAllTypes), global::Google.Protobuf.TestProtos.TestAllTypes.Parser, new[]{ "SingleInt32", "SingleInt64", "SingleUint32", "SingleUint64", "SingleSint32", "SingleSint64", "SingleFixed32", "SingleFixed64", "SingleSfixed32", "SingleSfixed64", "SingleFloat", "SingleDouble", "SingleBool", "SingleString", "SingleBytes", "SingleNestedMessage", "SingleForeignMessage", "SingleImportMessage", "SingleNestedEnum", "SingleForeignEnum", "SingleImportEnum", "SinglePublicImportMessage", "RepeatedInt32", "RepeatedInt64", "RepeatedUint32", "RepeatedUint64", "RepeatedSint32", "RepeatedSint64", "RepeatedFixed32", "RepeatedFixed64", "RepeatedSfixed32", "RepeatedSfixed64", "RepeatedFloat", "RepeatedDouble", "RepeatedBool", "RepeatedString", "RepeatedBytes", "RepeatedNestedMessage", "RepeatedForeignMessage", "RepeatedImportMessage", "RepeatedNestedEnum", "RepeatedForeignEnum", "RepeatedImportEnum", "RepeatedPublicImportMessage", "OneofUint32", "OneofNestedMessage", "OneofString", "OneofBytes" }, new[]{ "OneofField" }, new[]{ typeof(global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage), global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage.Parser, new[]{ "Bb" }, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.NestedTestAllTypes), global::Google.Protobuf.TestProtos.NestedTestAllTypes.Parser, new[]{ "Child", "Payload", "RepeatedChild" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestDeprecatedFields), global::Google.Protobuf.TestProtos.TestDeprecatedFields.Parser, new[]{ "DeprecatedInt32" }, null, null, null),
@@ -190,7 +193,8 @@ namespace Google.Protobuf.TestProtos {
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.FooServerMessage), global::Google.Protobuf.TestProtos.FooServerMessage.Parser, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.BarRequest), global::Google.Protobuf.TestProtos.BarRequest.Parser, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.BarResponse), global::Google.Protobuf.TestProtos.BarResponse.Parser, null, null, null, null),
- new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestEmptyMessage), global::Google.Protobuf.TestProtos.TestEmptyMessage.Parser, null, null, null, null)
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestEmptyMessage), global::Google.Protobuf.TestProtos.TestEmptyMessage.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.CommentMessage), global::Google.Protobuf.TestProtos.CommentMessage.Parser, new[]{ "Text" }, null, new[]{ typeof(global::Google.Protobuf.TestProtos.CommentMessage.Types.NestedCommentEnum) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.CommentMessage.Types.NestedCommentMessage), global::Google.Protobuf.TestProtos.CommentMessage.Types.NestedCommentMessage.Parser, new[]{ "NestedText" }, null, null, null)})
}));
}
#endregion
@@ -233,6 +237,16 @@ namespace Google.Protobuf.TestProtos {
[pbr::OriginalName("SPARSE_G")] SparseG = 2,
}
+ /// <summary>
+ /// Leading enum comment
+ /// </summary>
+ public enum CommentEnum {
+ /// <summary>
+ /// Zero value comment
+ /// </summary>
+ [pbr::OriginalName("ZERO_VALUE")] ZeroValue = 0,
+ }
+
#endregion
#region Messages
@@ -1293,19 +1307,19 @@ namespace Google.Protobuf.TestProtos {
}
if (other.singleNestedMessage_ != null) {
if (singleNestedMessage_ == null) {
- singleNestedMessage_ = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ SingleNestedMessage = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
}
SingleNestedMessage.MergeFrom(other.SingleNestedMessage);
}
if (other.singleForeignMessage_ != null) {
if (singleForeignMessage_ == null) {
- singleForeignMessage_ = new global::Google.Protobuf.TestProtos.ForeignMessage();
+ SingleForeignMessage = new global::Google.Protobuf.TestProtos.ForeignMessage();
}
SingleForeignMessage.MergeFrom(other.SingleForeignMessage);
}
if (other.singleImportMessage_ != null) {
if (singleImportMessage_ == null) {
- singleImportMessage_ = new global::Google.Protobuf.TestProtos.ImportMessage();
+ SingleImportMessage = new global::Google.Protobuf.TestProtos.ImportMessage();
}
SingleImportMessage.MergeFrom(other.SingleImportMessage);
}
@@ -1320,7 +1334,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.singlePublicImportMessage_ != null) {
if (singlePublicImportMessage_ == null) {
- singlePublicImportMessage_ = new global::Google.Protobuf.TestProtos.PublicImportMessage();
+ SinglePublicImportMessage = new global::Google.Protobuf.TestProtos.PublicImportMessage();
}
SinglePublicImportMessage.MergeFrom(other.SinglePublicImportMessage);
}
@@ -1437,42 +1451,42 @@ namespace Google.Protobuf.TestProtos {
}
case 146: {
if (singleNestedMessage_ == null) {
- singleNestedMessage_ = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ SingleNestedMessage = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
}
- input.ReadMessage(singleNestedMessage_);
+ input.ReadMessage(SingleNestedMessage);
break;
}
case 154: {
if (singleForeignMessage_ == null) {
- singleForeignMessage_ = new global::Google.Protobuf.TestProtos.ForeignMessage();
+ SingleForeignMessage = new global::Google.Protobuf.TestProtos.ForeignMessage();
}
- input.ReadMessage(singleForeignMessage_);
+ input.ReadMessage(SingleForeignMessage);
break;
}
case 162: {
if (singleImportMessage_ == null) {
- singleImportMessage_ = new global::Google.Protobuf.TestProtos.ImportMessage();
+ SingleImportMessage = new global::Google.Protobuf.TestProtos.ImportMessage();
}
- input.ReadMessage(singleImportMessage_);
+ input.ReadMessage(SingleImportMessage);
break;
}
case 168: {
- singleNestedEnum_ = (global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum) input.ReadEnum();
+ SingleNestedEnum = (global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum) input.ReadEnum();
break;
}
case 176: {
- singleForeignEnum_ = (global::Google.Protobuf.TestProtos.ForeignEnum) input.ReadEnum();
+ SingleForeignEnum = (global::Google.Protobuf.TestProtos.ForeignEnum) input.ReadEnum();
break;
}
case 184: {
- singleImportEnum_ = (global::Google.Protobuf.TestProtos.ImportEnum) input.ReadEnum();
+ SingleImportEnum = (global::Google.Protobuf.TestProtos.ImportEnum) input.ReadEnum();
break;
}
case 210: {
if (singlePublicImportMessage_ == null) {
- singlePublicImportMessage_ = new global::Google.Protobuf.TestProtos.PublicImportMessage();
+ SinglePublicImportMessage = new global::Google.Protobuf.TestProtos.PublicImportMessage();
}
- input.ReadMessage(singlePublicImportMessage_);
+ input.ReadMessage(SinglePublicImportMessage);
break;
}
case 250:
@@ -1904,13 +1918,13 @@ namespace Google.Protobuf.TestProtos {
}
if (other.child_ != null) {
if (child_ == null) {
- child_ = new global::Google.Protobuf.TestProtos.NestedTestAllTypes();
+ Child = new global::Google.Protobuf.TestProtos.NestedTestAllTypes();
}
Child.MergeFrom(other.Child);
}
if (other.payload_ != null) {
if (payload_ == null) {
- payload_ = new global::Google.Protobuf.TestProtos.TestAllTypes();
+ Payload = new global::Google.Protobuf.TestProtos.TestAllTypes();
}
Payload.MergeFrom(other.Payload);
}
@@ -1928,16 +1942,16 @@ namespace Google.Protobuf.TestProtos {
break;
case 10: {
if (child_ == null) {
- child_ = new global::Google.Protobuf.TestProtos.NestedTestAllTypes();
+ Child = new global::Google.Protobuf.TestProtos.NestedTestAllTypes();
}
- input.ReadMessage(child_);
+ input.ReadMessage(Child);
break;
}
case 18: {
if (payload_ == null) {
- payload_ = new global::Google.Protobuf.TestProtos.TestAllTypes();
+ Payload = new global::Google.Protobuf.TestProtos.TestAllTypes();
}
- input.ReadMessage(payload_);
+ input.ReadMessage(Payload);
break;
}
case 26: {
@@ -2424,7 +2438,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.foreignNested_ != null) {
if (foreignNested_ == null) {
- foreignNested_ = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ ForeignNested = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
}
ForeignNested.MergeFrom(other.ForeignNested);
}
@@ -2441,9 +2455,9 @@ namespace Google.Protobuf.TestProtos {
break;
case 10: {
if (foreignNested_ == null) {
- foreignNested_ = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ ForeignNested = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
}
- input.ReadMessage(foreignNested_);
+ input.ReadMessage(ForeignNested);
break;
}
}
@@ -2744,7 +2758,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.a_ != null) {
if (a_ == null) {
- a_ = new global::Google.Protobuf.TestProtos.TestRecursiveMessage();
+ A = new global::Google.Protobuf.TestProtos.TestRecursiveMessage();
}
A.MergeFrom(other.A);
}
@@ -2764,9 +2778,9 @@ namespace Google.Protobuf.TestProtos {
break;
case 10: {
if (a_ == null) {
- a_ = new global::Google.Protobuf.TestProtos.TestRecursiveMessage();
+ A = new global::Google.Protobuf.TestProtos.TestRecursiveMessage();
}
- input.ReadMessage(a_);
+ input.ReadMessage(A);
break;
}
case 16: {
@@ -2889,7 +2903,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.bb_ != null) {
if (bb_ == null) {
- bb_ = new global::Google.Protobuf.TestProtos.TestMutualRecursionB();
+ Bb = new global::Google.Protobuf.TestProtos.TestMutualRecursionB();
}
Bb.MergeFrom(other.Bb);
}
@@ -2906,9 +2920,9 @@ namespace Google.Protobuf.TestProtos {
break;
case 10: {
if (bb_ == null) {
- bb_ = new global::Google.Protobuf.TestProtos.TestMutualRecursionB();
+ Bb = new global::Google.Protobuf.TestProtos.TestMutualRecursionB();
}
- input.ReadMessage(bb_);
+ input.ReadMessage(Bb);
break;
}
}
@@ -3045,7 +3059,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.a_ != null) {
if (a_ == null) {
- a_ = new global::Google.Protobuf.TestProtos.TestMutualRecursionA();
+ A = new global::Google.Protobuf.TestProtos.TestMutualRecursionA();
}
A.MergeFrom(other.A);
}
@@ -3065,9 +3079,9 @@ namespace Google.Protobuf.TestProtos {
break;
case 10: {
if (a_ == null) {
- a_ = new global::Google.Protobuf.TestProtos.TestMutualRecursionA();
+ A = new global::Google.Protobuf.TestProtos.TestMutualRecursionA();
}
- input.ReadMessage(a_);
+ input.ReadMessage(A);
break;
}
case 16: {
@@ -3200,7 +3214,7 @@ namespace Google.Protobuf.TestProtos {
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 8: {
- value_ = (global::Google.Protobuf.TestProtos.TestEnumWithDupValue) input.ReadEnum();
+ Value = (global::Google.Protobuf.TestProtos.TestEnumWithDupValue) input.ReadEnum();
break;
}
}
@@ -3452,7 +3466,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.messageField_ != null) {
if (messageField_ == null) {
- messageField_ = new global::Google.Protobuf.TestProtos.ForeignMessage();
+ MessageField = new global::Google.Protobuf.TestProtos.ForeignMessage();
}
MessageField.MergeFrom(other.MessageField);
}
@@ -3480,14 +3494,14 @@ namespace Google.Protobuf.TestProtos {
break;
}
case 24: {
- enumField_ = (global::Google.Protobuf.TestProtos.ForeignEnum) input.ReadEnum();
+ EnumField = (global::Google.Protobuf.TestProtos.ForeignEnum) input.ReadEnum();
break;
}
case 34: {
if (messageField_ == null) {
- messageField_ = new global::Google.Protobuf.TestProtos.ForeignMessage();
+ MessageField = new global::Google.Protobuf.TestProtos.ForeignMessage();
}
- input.ReadMessage(messageField_);
+ input.ReadMessage(MessageField);
break;
}
case 58:
@@ -3697,7 +3711,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.singleNestedMessage_ != null) {
if (singleNestedMessage_ == null) {
- singleNestedMessage_ = new global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage();
+ SingleNestedMessage = new global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage();
}
SingleNestedMessage.MergeFrom(other.SingleNestedMessage);
}
@@ -3726,9 +3740,9 @@ namespace Google.Protobuf.TestProtos {
}
case 1602: {
if (singleNestedMessage_ == null) {
- singleNestedMessage_ = new global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage();
+ SingleNestedMessage = new global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage();
}
- input.ReadMessage(singleNestedMessage_);
+ input.ReadMessage(SingleNestedMessage);
break;
}
}
@@ -4026,7 +4040,7 @@ namespace Google.Protobuf.TestProtos {
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 8: {
- sparseEnum_ = (global::Google.Protobuf.TestProtos.TestSparseEnum) input.ReadEnum();
+ SparseEnum = (global::Google.Protobuf.TestProtos.TestSparseEnum) input.ReadEnum();
break;
}
}
@@ -7301,6 +7315,293 @@ namespace Google.Protobuf.TestProtos {
}
+ /// <summary>
+ /// This is a leading comment
+ /// </summary>
+ public sealed partial class CommentMessage : pb::IMessage<CommentMessage> {
+ private static readonly pb::MessageParser<CommentMessage> _parser = new pb::MessageParser<CommentMessage>(() => new CommentMessage());
+ private pb::UnknownFieldSet _unknownFields;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<CommentMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[35]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CommentMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CommentMessage(CommentMessage other) : this() {
+ text_ = other.text_;
+ _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CommentMessage Clone() {
+ return new CommentMessage(this);
+ }
+
+ /// <summary>Field number for the "text" field.</summary>
+ public const int TextFieldNumber = 1;
+ private string text_ = "";
+ /// <summary>
+ /// Leading field comment
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Text {
+ get { return text_; }
+ set {
+ text_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as CommentMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(CommentMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Text != other.Text) return false;
+ return Equals(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Text.Length != 0) hash ^= Text.GetHashCode();
+ if (_unknownFields != null) {
+ hash ^= _unknownFields.GetHashCode();
+ }
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Text.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Text);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(output);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Text.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Text);
+ }
+ if (_unknownFields != null) {
+ size += _unknownFields.CalculateSize();
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(CommentMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Text.Length != 0) {
+ Text = other.Text;
+ }
+ _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ break;
+ case 10: {
+ Text = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the CommentMessage message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ /// <summary>
+ /// Leading nested enum comment
+ /// </summary>
+ public enum NestedCommentEnum {
+ /// <summary>
+ /// Zero value comment
+ /// </summary>
+ [pbr::OriginalName("ZERO_VALUE")] ZeroValue = 0,
+ }
+
+ /// <summary>
+ /// Leading nested message comment
+ /// </summary>
+ public sealed partial class NestedCommentMessage : pb::IMessage<NestedCommentMessage> {
+ private static readonly pb::MessageParser<NestedCommentMessage> _parser = new pb::MessageParser<NestedCommentMessage>(() => new NestedCommentMessage());
+ private pb::UnknownFieldSet _unknownFields;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedCommentMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.CommentMessage.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedCommentMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedCommentMessage(NestedCommentMessage other) : this() {
+ nestedText_ = other.nestedText_;
+ _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedCommentMessage Clone() {
+ return new NestedCommentMessage(this);
+ }
+
+ /// <summary>Field number for the "nested_text" field.</summary>
+ public const int NestedTextFieldNumber = 1;
+ private string nestedText_ = "";
+ /// <summary>
+ /// Leading nested message field comment
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string NestedText {
+ get { return nestedText_; }
+ set {
+ nestedText_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedCommentMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedCommentMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (NestedText != other.NestedText) return false;
+ return Equals(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (NestedText.Length != 0) hash ^= NestedText.GetHashCode();
+ if (_unknownFields != null) {
+ hash ^= _unknownFields.GetHashCode();
+ }
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (NestedText.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(NestedText);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(output);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (NestedText.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(NestedText);
+ }
+ if (_unknownFields != null) {
+ size += _unknownFields.CalculateSize();
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedCommentMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.NestedText.Length != 0) {
+ NestedText = other.NestedText;
+ }
+ _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ break;
+ case 10: {
+ NestedText = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
#endregion
}
diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
index fe913802..45f8ece6 100644
--- a/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
+++ b/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
@@ -342,6 +342,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "float_field" field.</summary>
public const int FloatFieldFieldNumber = 11;
private static readonly pb::FieldCodec<float?> _single_floatField_codec = pb::FieldCodec.ForStructWrapper<float>(90);
@@ -354,6 +355,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "int64_field" field.</summary>
public const int Int64FieldFieldNumber = 12;
private static readonly pb::FieldCodec<long?> _single_int64Field_codec = pb::FieldCodec.ForStructWrapper<long>(98);
@@ -366,6 +368,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "uint64_field" field.</summary>
public const int Uint64FieldFieldNumber = 13;
private static readonly pb::FieldCodec<ulong?> _single_uint64Field_codec = pb::FieldCodec.ForStructWrapper<ulong>(106);
@@ -378,6 +381,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "int32_field" field.</summary>
public const int Int32FieldFieldNumber = 14;
private static readonly pb::FieldCodec<int?> _single_int32Field_codec = pb::FieldCodec.ForStructWrapper<int>(114);
@@ -390,6 +394,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "uint32_field" field.</summary>
public const int Uint32FieldFieldNumber = 15;
private static readonly pb::FieldCodec<uint?> _single_uint32Field_codec = pb::FieldCodec.ForStructWrapper<uint>(122);
@@ -402,6 +407,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "bool_field" field.</summary>
public const int BoolFieldFieldNumber = 16;
private static readonly pb::FieldCodec<bool?> _single_boolField_codec = pb::FieldCodec.ForStructWrapper<bool>(130);
@@ -414,6 +420,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "string_field" field.</summary>
public const int StringFieldFieldNumber = 17;
private static readonly pb::FieldCodec<string> _single_stringField_codec = pb::FieldCodec.ForClassWrapper<string>(138);
@@ -426,6 +433,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "bytes_field" field.</summary>
public const int BytesFieldFieldNumber = 18;
private static readonly pb::FieldCodec<pb::ByteString> _single_bytesField_codec = pb::FieldCodec.ForClassWrapper<pb::ByteString>(146);
@@ -438,6 +446,7 @@ namespace Google.Protobuf.TestProtos {
}
}
+
/// <summary>Field number for the "value_field" field.</summary>
public const int ValueFieldFieldNumber = 19;
private global::Google.Protobuf.WellKnownTypes.Value valueField_;
@@ -667,55 +676,55 @@ namespace Google.Protobuf.TestProtos {
}
if (other.anyField_ != null) {
if (anyField_ == null) {
- anyField_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ AnyField = new global::Google.Protobuf.WellKnownTypes.Any();
}
AnyField.MergeFrom(other.AnyField);
}
if (other.apiField_ != null) {
if (apiField_ == null) {
- apiField_ = new global::Google.Protobuf.WellKnownTypes.Api();
+ ApiField = new global::Google.Protobuf.WellKnownTypes.Api();
}
ApiField.MergeFrom(other.ApiField);
}
if (other.durationField_ != null) {
if (durationField_ == null) {
- durationField_ = new global::Google.Protobuf.WellKnownTypes.Duration();
+ DurationField = new global::Google.Protobuf.WellKnownTypes.Duration();
}
DurationField.MergeFrom(other.DurationField);
}
if (other.emptyField_ != null) {
if (emptyField_ == null) {
- emptyField_ = new global::Google.Protobuf.WellKnownTypes.Empty();
+ EmptyField = new global::Google.Protobuf.WellKnownTypes.Empty();
}
EmptyField.MergeFrom(other.EmptyField);
}
if (other.fieldMaskField_ != null) {
if (fieldMaskField_ == null) {
- fieldMaskField_ = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ FieldMaskField = new global::Google.Protobuf.WellKnownTypes.FieldMask();
}
FieldMaskField.MergeFrom(other.FieldMaskField);
}
if (other.sourceContextField_ != null) {
if (sourceContextField_ == null) {
- sourceContextField_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ SourceContextField = new global::Google.Protobuf.WellKnownTypes.SourceContext();
}
SourceContextField.MergeFrom(other.SourceContextField);
}
if (other.structField_ != null) {
if (structField_ == null) {
- structField_ = new global::Google.Protobuf.WellKnownTypes.Struct();
+ StructField = new global::Google.Protobuf.WellKnownTypes.Struct();
}
StructField.MergeFrom(other.StructField);
}
if (other.timestampField_ != null) {
if (timestampField_ == null) {
- timestampField_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ TimestampField = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
TimestampField.MergeFrom(other.TimestampField);
}
if (other.typeField_ != null) {
if (typeField_ == null) {
- typeField_ = new global::Google.Protobuf.WellKnownTypes.Type();
+ TypeField = new global::Google.Protobuf.WellKnownTypes.Type();
}
TypeField.MergeFrom(other.TypeField);
}
@@ -766,7 +775,7 @@ namespace Google.Protobuf.TestProtos {
}
if (other.valueField_ != null) {
if (valueField_ == null) {
- valueField_ = new global::Google.Protobuf.WellKnownTypes.Value();
+ ValueField = new global::Google.Protobuf.WellKnownTypes.Value();
}
ValueField.MergeFrom(other.ValueField);
}
@@ -783,65 +792,65 @@ namespace Google.Protobuf.TestProtos {
break;
case 10: {
if (anyField_ == null) {
- anyField_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ AnyField = new global::Google.Protobuf.WellKnownTypes.Any();
}
- input.ReadMessage(anyField_);
+ input.ReadMessage(AnyField);
break;
}
case 18: {
if (apiField_ == null) {
- apiField_ = new global::Google.Protobuf.WellKnownTypes.Api();
+ ApiField = new global::Google.Protobuf.WellKnownTypes.Api();
}
- input.ReadMessage(apiField_);
+ input.ReadMessage(ApiField);
break;
}
case 26: {
if (durationField_ == null) {
- durationField_ = new global::Google.Protobuf.WellKnownTypes.Duration();
+ DurationField = new global::Google.Protobuf.WellKnownTypes.Duration();
}
- input.ReadMessage(durationField_);
+ input.ReadMessage(DurationField);
break;
}
case 34: {
if (emptyField_ == null) {
- emptyField_ = new global::Google.Protobuf.WellKnownTypes.Empty();
+ EmptyField = new global::Google.Protobuf.WellKnownTypes.Empty();
}
- input.ReadMessage(emptyField_);
+ input.ReadMessage(EmptyField);
break;
}
case 42: {
if (fieldMaskField_ == null) {
- fieldMaskField_ = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ FieldMaskField = new global::Google.Protobuf.WellKnownTypes.FieldMask();
}
- input.ReadMessage(fieldMaskField_);
+ input.ReadMessage(FieldMaskField);
break;
}
case 50: {
if (sourceContextField_ == null) {
- sourceContextField_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ SourceContextField = new global::Google.Protobuf.WellKnownTypes.SourceContext();
}
- input.ReadMessage(sourceContextField_);
+ input.ReadMessage(SourceContextField);
break;
}
case 58: {
if (structField_ == null) {
- structField_ = new global::Google.Protobuf.WellKnownTypes.Struct();
+ StructField = new global::Google.Protobuf.WellKnownTypes.Struct();
}
- input.ReadMessage(structField_);
+ input.ReadMessage(StructField);
break;
}
case 66: {
if (timestampField_ == null) {
- timestampField_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ TimestampField = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
- input.ReadMessage(timestampField_);
+ input.ReadMessage(TimestampField);
break;
}
case 74: {
if (typeField_ == null) {
- typeField_ = new global::Google.Protobuf.WellKnownTypes.Type();
+ TypeField = new global::Google.Protobuf.WellKnownTypes.Type();
}
- input.ReadMessage(typeField_);
+ input.ReadMessage(TypeField);
break;
}
case 82: {
@@ -909,9 +918,9 @@ namespace Google.Protobuf.TestProtos {
}
case 154: {
if (valueField_ == null) {
- valueField_ = new global::Google.Protobuf.WellKnownTypes.Value();
+ ValueField = new global::Google.Protobuf.WellKnownTypes.Value();
}
- input.ReadMessage(valueField_);
+ input.ReadMessage(ValueField);
break;
}
}
diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb
new file mode 100644
index 00000000..94ff3817
--- /dev/null
+++ b/csharp/src/Google.Protobuf.Test/testprotos.pb
Binary files differ
diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs
index dbbcc148..1924439e 100644
--- a/csharp/src/Google.Protobuf/Collections/MapField.cs
+++ b/csharp/src/Google.Protobuf/Collections/MapField.cs
@@ -1,771 +1,771 @@
-#region Copyright notice and license
-// Protocol Buffers - Google's data interchange format
-// Copyright 2015 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#endregion
-
-using Google.Protobuf.Compatibility;
-using Google.Protobuf.Reflection;
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-
-namespace Google.Protobuf.Collections
-{
- /// <summary>
- /// Representation of a map field in a Protocol Buffer message.
- /// </summary>
- /// <typeparam name="TKey">Key type in the map. Must be a type supported by Protocol Buffer map keys.</typeparam>
- /// <typeparam name="TValue">Value type in the map. Must be a type supported by Protocol Buffers.</typeparam>
- /// <remarks>
- /// <para>
- /// For string keys, the equality comparison is provided by <see cref="StringComparer.Ordinal" />.
- /// </para>
- /// <para>
- /// Null values are not permitted in the map, either for wrapper types or regular messages.
- /// If a map is deserialized from a data stream and the value is missing from an entry, a default value
- /// is created instead. For primitive types, that is the regular default value (0, the empty string and so
- /// on); for message types, an empty instance of the message is created, as if the map entry contained a 0-length
- /// encoded value for the field.
- /// </para>
- /// <para>
- /// This implementation does not generally prohibit the use of key/value types which are not
- /// supported by Protocol Buffers (e.g. using a key type of <code>byte</code>) but nor does it guarantee
- /// that all operations will work in such cases.
- /// </para>
- /// <para>
- /// The order in which entries are returned when iterating over this object is undefined, and may change
- /// in future versions.
- /// </para>
- /// </remarks>
- public sealed class MapField<TKey, TValue> : IDeepCloneable<MapField<TKey, TValue>>, IDictionary<TKey, TValue>, IEquatable<MapField<TKey, TValue>>, IDictionary
-#if !NET35
- , IReadOnlyDictionary<TKey, TValue>
-#endif
- {
- private static readonly EqualityComparer<TValue> ValueEqualityComparer = ProtobufEqualityComparers.GetEqualityComparer<TValue>();
- private static readonly EqualityComparer<TKey> KeyEqualityComparer = ProtobufEqualityComparers.GetEqualityComparer<TKey>();
-
- // TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.)
- private readonly Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>> map =
- new Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>>(KeyEqualityComparer);
- private readonly LinkedList<KeyValuePair<TKey, TValue>> list = new LinkedList<KeyValuePair<TKey, TValue>>();
-
- /// <summary>
- /// Creates a deep clone of this object.
- /// </summary>
- /// <returns>
- /// A deep clone of this object.
- /// </returns>
- public MapField<TKey, TValue> Clone()
- {
- var clone = new MapField<TKey, TValue>();
- // Keys are never cloneable. Values might be.
- if (typeof(IDeepCloneable<TValue>).IsAssignableFrom(typeof(TValue)))
- {
- foreach (var pair in list)
- {
- clone.Add(pair.Key, ((IDeepCloneable<TValue>)pair.Value).Clone());
- }
- }
- else
- {
- // Nothing is cloneable, so we don't need to worry.
- clone.Add(this);
- }
- return clone;
- }
-
- /// <summary>
- /// Adds the specified key/value pair to the map.
- /// </summary>
- /// <remarks>
- /// This operation fails if the key already exists in the map. To replace an existing entry, use the indexer.
- /// </remarks>
- /// <param name="key">The key to add</param>
- /// <param name="value">The value to add.</param>
- /// <exception cref="System.ArgumentException">The given key already exists in map.</exception>
- public void Add(TKey key, TValue value)
- {
- // Validation of arguments happens in ContainsKey and the indexer
- if (ContainsKey(key))
- {
- throw new ArgumentException("Key already exists in map", nameof(key));
- }
- this[key] = value;
- }
-
- /// <summary>
- /// Determines whether the specified key is present in the map.
- /// </summary>
- /// <param name="key">The key to check.</param>
- /// <returns><c>true</c> if the map contains the given key; <c>false</c> otherwise.</returns>
- public bool ContainsKey(TKey key)
- {
- ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
- return map.ContainsKey(key);
- }
-
- private bool ContainsValue(TValue value) =>
- list.Any(pair => ValueEqualityComparer.Equals(pair.Value, value));
-
- /// <summary>
- /// Removes the entry identified by the given key from the map.
- /// </summary>
- /// <param name="key">The key indicating the entry to remove from the map.</param>
- /// <returns><c>true</c> if the map contained the given key before the entry was removed; <c>false</c> otherwise.</returns>
- public bool Remove(TKey key)
- {
- ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
- LinkedListNode<KeyValuePair<TKey, TValue>> node;
- if (map.TryGetValue(key, out node))
- {
- map.Remove(key);
- node.List.Remove(node);
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /// <summary>
- /// Gets the value associated with the specified key.
- /// </summary>
- /// <param name="key">The key whose value to get.</param>
- /// <param name="value">When this method returns, the value associated with the specified key, if the key is found;
- /// otherwise, the default value for the type of the <paramref name="value"/> parameter.
- /// This parameter is passed uninitialized.</param>
- /// <returns><c>true</c> if the map contains an element with the specified key; otherwise, <c>false</c>.</returns>
- public bool TryGetValue(TKey key, out TValue value)
- {
- LinkedListNode<KeyValuePair<TKey, TValue>> node;
- if (map.TryGetValue(key, out node))
- {
- value = node.Value.Value;
- return true;
- }
- else
- {
- value = default(TValue);
- return false;
- }
- }
-
- /// <summary>
- /// Gets or sets the value associated with the specified key.
- /// </summary>
- /// <param name="key">The key of the value to get or set.</param>
- /// <exception cref="KeyNotFoundException">The property is retrieved and key does not exist in the collection.</exception>
- /// <returns>The value associated with the specified key. If the specified key is not found,
- /// a get operation throws a <see cref="KeyNotFoundException"/>, and a set operation creates a new element with the specified key.</returns>
- public TValue this[TKey key]
- {
- get
- {
- ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
- TValue value;
- if (TryGetValue(key, out value))
- {
- return value;
- }
- throw new KeyNotFoundException();
- }
- set
- {
- ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
- // value == null check here is redundant, but avoids boxing.
- if (value == null)
- {
- ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value));
- }
- LinkedListNode<KeyValuePair<TKey, TValue>> node;
- var pair = new KeyValuePair<TKey, TValue>(key, value);
- if (map.TryGetValue(key, out node))
- {
- node.Value = pair;
- }
- else
- {
- node = list.AddLast(pair);
- map[key] = node;
- }
- }
- }
-
- /// <summary>
- /// Gets a collection containing the keys in the map.
- /// </summary>
- public ICollection<TKey> Keys { get { return new MapView<TKey>(this, pair => pair.Key, ContainsKey); } }
-
- /// <summary>
- /// Gets a collection containing the values in the map.
- /// </summary>
- public ICollection<TValue> Values { get { return new MapView<TValue>(this, pair => pair.Value, ContainsValue); } }
-
- /// <summary>
- /// Adds the specified entries to the map. The keys and values are not automatically cloned.
- /// </summary>
- /// <param name="entries">The entries to add to the map.</param>
- public void Add(IDictionary<TKey, TValue> entries)
- {
- ProtoPreconditions.CheckNotNull(entries, nameof(entries));
- foreach (var pair in entries)
- {
- Add(pair.Key, pair.Value);
- }
- }
-
- /// <summary>
- /// Returns an enumerator that iterates through the collection.
- /// </summary>
- /// <returns>
- /// An enumerator that can be used to iterate through the collection.
- /// </returns>
- public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
- {
- return list.GetEnumerator();
- }
-
- /// <summary>
- /// Returns an enumerator that iterates through a collection.
- /// </summary>
- /// <returns>
- /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
- /// </returns>
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- /// <summary>
- /// Adds the specified item to the map.
- /// </summary>
- /// <param name="item">The item to add to the map.</param>
- void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
- {
- Add(item.Key, item.Value);
- }
-
- /// <summary>
- /// Removes all items from the map.
- /// </summary>
- public void Clear()
- {
- list.Clear();
- map.Clear();
- }
-
- /// <summary>
- /// Determines whether map contains an entry equivalent to the given key/value pair.
- /// </summary>
- /// <param name="item">The key/value pair to find.</param>
- /// <returns></returns>
- bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
- {
- TValue value;
- return TryGetValue(item.Key, out value) && ValueEqualityComparer.Equals(item.Value, value);
- }
-
- /// <summary>
- /// Copies the key/value pairs in this map to an array.
- /// </summary>
- /// <param name="array">The array to copy the entries into.</param>
- /// <param name="arrayIndex">The index of the array at which to start copying values.</param>
- void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
- {
- list.CopyTo(array, arrayIndex);
- }
-
- /// <summary>
- /// Removes the specified key/value pair from the map.
- /// </summary>
- /// <remarks>Both the key and the value must be found for the entry to be removed.</remarks>
- /// <param name="item">The key/value pair to remove.</param>
- /// <returns><c>true</c> if the key/value pair was found and removed; <c>false</c> otherwise.</returns>
- bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
- {
- if (item.Key == null)
- {
- throw new ArgumentException("Key is null", nameof(item));
- }
- LinkedListNode<KeyValuePair<TKey, TValue>> node;
- if (map.TryGetValue(item.Key, out node) &&
- EqualityComparer<TValue>.Default.Equals(item.Value, node.Value.Value))
- {
- map.Remove(item.Key);
- node.List.Remove(node);
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /// <summary>
- /// Gets the number of elements contained in the map.
- /// </summary>
- public int Count { get { return list.Count; } }
-
- /// <summary>
- /// Gets a value indicating whether the map is read-only.
- /// </summary>
- public bool IsReadOnly { get { return false; } }
-
- /// <summary>
- /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
- /// </summary>
- /// <param name="other">The <see cref="System.Object" /> to compare with this instance.</param>
- /// <returns>
- /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
- /// </returns>
- public override bool Equals(object other)
- {
- return Equals(other as MapField<TKey, TValue>);
- }
-
- /// <summary>
- /// Returns a hash code for this instance.
- /// </summary>
- /// <returns>
- /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
- /// </returns>
- public override int GetHashCode()
- {
- var keyComparer = KeyEqualityComparer;
- var valueComparer = ValueEqualityComparer;
- int hash = 0;
- foreach (var pair in list)
- {
- hash ^= keyComparer.GetHashCode(pair.Key) * 31 + valueComparer.GetHashCode(pair.Value);
- }
- return hash;
- }
-
- /// <summary>
- /// Compares this map with another for equality.
- /// </summary>
- /// <remarks>
- /// The order of the key/value pairs in the maps is not deemed significant in this comparison.
- /// </remarks>
- /// <param name="other">The map to compare this with.</param>
- /// <returns><c>true</c> if <paramref name="other"/> refers to an equal map; <c>false</c> otherwise.</returns>
- public bool Equals(MapField<TKey, TValue> other)
- {
- if (other == null)
- {
- return false;
- }
- if (other == this)
- {
- return true;
- }
- if (other.Count != this.Count)
- {
- return false;
- }
- var valueComparer = ValueEqualityComparer;
- foreach (var pair in this)
- {
- TValue value;
- if (!other.TryGetValue(pair.Key, out value))
- {
- return false;
- }
- if (!valueComparer.Equals(value, pair.Value))
- {
- return false;
- }
- }
- return true;
- }
-
- /// <summary>
- /// Adds entries to the map from the given stream.
- /// </summary>
- /// <remarks>
- /// It is assumed that the stream is initially positioned after the tag specified by the codec.
- /// This method will continue reading entries from the stream until the end is reached, or
- /// a different tag is encountered.
- /// </remarks>
- /// <param name="input">Stream to read from</param>
- /// <param name="codec">Codec describing how the key/value pairs are encoded</param>
- public void AddEntriesFrom(CodedInputStream input, Codec codec)
- {
- var adapter = new Codec.MessageAdapter(codec);
- do
- {
- adapter.Reset();
- input.ReadMessage(adapter);
- this[adapter.Key] = adapter.Value;
- } while (input.MaybeConsumeTag(codec.MapTag));
- }
-
- /// <summary>
- /// Writes the contents of this map to the given coded output stream, using the specified codec
- /// to encode each entry.
- /// </summary>
- /// <param name="output">The output stream to write to.</param>
- /// <param name="codec">The codec to use for each entry.</param>
- public void WriteTo(CodedOutputStream output, Codec codec)
- {
- var message = new Codec.MessageAdapter(codec);
- foreach (var entry in list)
- {
- message.Key = entry.Key;
- message.Value = entry.Value;
- output.WriteTag(codec.MapTag);
- output.WriteMessage(message);
- }
- }
-
- /// <summary>
- /// Calculates the size of this map based on the given entry codec.
- /// </summary>
- /// <param name="codec">The codec to use to encode each entry.</param>
- /// <returns></returns>
- public int CalculateSize(Codec codec)
- {
- if (Count == 0)
- {
- return 0;
- }
- var message = new Codec.MessageAdapter(codec);
- int size = 0;
- foreach (var entry in list)
- {
- message.Key = entry.Key;
- message.Value = entry.Value;
- size += CodedOutputStream.ComputeRawVarint32Size(codec.MapTag);
- size += CodedOutputStream.ComputeMessageSize(message);
- }
- return size;
- }
-
- /// <summary>
- /// Returns a string representation of this repeated field, in the same
- /// way as it would be represented by the default JSON formatter.
- /// </summary>
- public override string ToString()
- {
- var writer = new StringWriter();
- JsonFormatter.Default.WriteDictionary(writer, this);
- return writer.ToString();
- }
-
- #region IDictionary explicit interface implementation
- void IDictionary.Add(object key, object value)
- {
- Add((TKey)key, (TValue)value);
- }
-
- bool IDictionary.Contains(object key)
- {
- if (!(key is TKey))
- {
- return false;
- }
- return ContainsKey((TKey)key);
- }
-
- IDictionaryEnumerator IDictionary.GetEnumerator()
- {
- return new DictionaryEnumerator(GetEnumerator());
- }
-
- void IDictionary.Remove(object key)
- {
- ProtoPreconditions.CheckNotNull(key, nameof(key));
- if (!(key is TKey))
- {
- return;
- }
- Remove((TKey)key);
- }
-
- void ICollection.CopyTo(Array array, int index)
- {
- // This is ugly and slow as heck, but with any luck it will never be used anyway.
- ICollection temp = this.Select(pair => new DictionaryEntry(pair.Key, pair.Value)).ToList();
- temp.CopyTo(array, index);
- }
-
- bool IDictionary.IsFixedSize { get { return false; } }
-
- ICollection IDictionary.Keys { get { return (ICollection)Keys; } }
-
- ICollection IDictionary.Values { get { return (ICollection)Values; } }
-
- bool ICollection.IsSynchronized { get { return false; } }
-
- object ICollection.SyncRoot { get { return this; } }
-
- object IDictionary.this[object key]
- {
- get
- {
- ProtoPreconditions.CheckNotNull(key, nameof(key));
- if (!(key is TKey))
- {
- return null;
- }
- TValue value;
- TryGetValue((TKey)key, out value);
- return value;
- }
-
- set
- {
- this[(TKey)key] = (TValue)value;
- }
- }
- #endregion
-
- #region IReadOnlyDictionary explicit interface implementation
-#if !NET35
- IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => Keys;
-
- IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values;
-#endif
- #endregion
-
- private class DictionaryEnumerator : IDictionaryEnumerator
- {
- private readonly IEnumerator<KeyValuePair<TKey, TValue>> enumerator;
-
- internal DictionaryEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> enumerator)
- {
- this.enumerator = enumerator;
- }
-
- public bool MoveNext()
- {
- return enumerator.MoveNext();
- }
-
- public void Reset()
- {
- enumerator.Reset();
- }
-
- public object Current { get { return Entry; } }
- public DictionaryEntry Entry { get { return new DictionaryEntry(Key, Value); } }
- public object Key { get { return enumerator.Current.Key; } }
- public object Value { get { return enumerator.Current.Value; } }
- }
-
- /// <summary>
- /// A codec for a specific map field. This contains all the information required to encode and
- /// decode the nested messages.
- /// </summary>
- public sealed class Codec
- {
- private readonly FieldCodec<TKey> keyCodec;
- private readonly FieldCodec<TValue> valueCodec;
- private readonly uint mapTag;
-
- /// <summary>
- /// Creates a new entry codec based on a separate key codec and value codec,
- /// and the tag to use for each map entry.
- /// </summary>
- /// <param name="keyCodec">The key codec.</param>
- /// <param name="valueCodec">The value codec.</param>
- /// <param name="mapTag">The map tag to use to introduce each map entry.</param>
- public Codec(FieldCodec<TKey> keyCodec, FieldCodec<TValue> valueCodec, uint mapTag)
- {
- this.keyCodec = keyCodec;
- this.valueCodec = valueCodec;
- this.mapTag = mapTag;
- }
-
- /// <summary>
- /// The tag used in the enclosing message to indicate map entries.
- /// </summary>
- internal uint MapTag { get { return mapTag; } }
-
- /// <summary>
- /// A mutable message class, used for parsing and serializing. This
- /// delegates the work to a codec, but implements the <see cref="IMessage"/> interface
- /// for interop with <see cref="CodedInputStream"/> and <see cref="CodedOutputStream"/>.
- /// This is nested inside Codec as it's tightly coupled to the associated codec,
- /// and it's simpler if it has direct access to all its fields.
- /// </summary>
- internal class MessageAdapter : IMessage
- {
- private static readonly byte[] ZeroLengthMessageStreamData = new byte[] { 0 };
-
- private readonly Codec codec;
- internal TKey Key { get; set; }
- internal TValue Value { get; set; }
-
- internal MessageAdapter(Codec codec)
- {
- this.codec = codec;
- }
-
- internal void Reset()
- {
- Key = codec.keyCodec.DefaultValue;
- Value = codec.valueCodec.DefaultValue;
- }
-
- public void MergeFrom(CodedInputStream input)
- {
- uint tag;
- while ((tag = input.ReadTag()) != 0)
- {
- if (tag == codec.keyCodec.Tag)
- {
- Key = codec.keyCodec.Read(input);
- }
- else if (tag == codec.valueCodec.Tag)
- {
- Value = codec.valueCodec.Read(input);
- }
- else
- {
- input.SkipLastField();
- }
- }
-
- // Corner case: a map entry with a key but no value, where the value type is a message.
- // Read it as if we'd seen an input stream with no data (i.e. create a "default" message).
- if (Value == null)
- {
- Value = codec.valueCodec.Read(new CodedInputStream(ZeroLengthMessageStreamData));
- }
- }
-
- public void WriteTo(CodedOutputStream output)
- {
- codec.keyCodec.WriteTagAndValue(output, Key);
- codec.valueCodec.WriteTagAndValue(output, Value);
- }
-
- public int CalculateSize()
- {
- return codec.keyCodec.CalculateSizeWithTag(Key) + codec.valueCodec.CalculateSizeWithTag(Value);
- }
-
- MessageDescriptor IMessage.Descriptor { get { return null; } }
- }
- }
-
- private class MapView<T> : ICollection<T>, ICollection
- {
- private readonly MapField<TKey, TValue> parent;
- private readonly Func<KeyValuePair<TKey, TValue>, T> projection;
- private readonly Func<T, bool> containsCheck;
-
- internal MapView(
- MapField<TKey, TValue> parent,
- Func<KeyValuePair<TKey, TValue>, T> projection,
- Func<T, bool> containsCheck)
- {
- this.parent = parent;
- this.projection = projection;
- this.containsCheck = containsCheck;
- }
-
- public int Count { get { return parent.Count; } }
-
- public bool IsReadOnly { get { return true; } }
-
- public bool IsSynchronized { get { return false; } }
-
- public object SyncRoot { get { return parent; } }
-
- public void Add(T item)
- {
- throw new NotSupportedException();
- }
-
- public void Clear()
- {
- throw new NotSupportedException();
- }
-
- public bool Contains(T item)
- {
- return containsCheck(item);
- }
-
- public void CopyTo(T[] array, int arrayIndex)
- {
- if (arrayIndex < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(arrayIndex));
- }
- if (arrayIndex + Count > array.Length)
- {
- throw new ArgumentException("Not enough space in the array", nameof(array));
- }
- foreach (var item in this)
- {
- array[arrayIndex++] = item;
- }
- }
-
- public IEnumerator<T> GetEnumerator()
- {
- return parent.list.Select(projection).GetEnumerator();
- }
-
- public bool Remove(T item)
- {
- throw new NotSupportedException();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public void CopyTo(Array array, int index)
- {
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- if (index + Count > array.Length)
- {
- throw new ArgumentException("Not enough space in the array", nameof(array));
- }
- foreach (var item in this)
- {
- array.SetValue(item, index++);
- }
- }
- }
- }
-}
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using Google.Protobuf.Compatibility;
+using Google.Protobuf.Reflection;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+namespace Google.Protobuf.Collections
+{
+ /// <summary>
+ /// Representation of a map field in a Protocol Buffer message.
+ /// </summary>
+ /// <typeparam name="TKey">Key type in the map. Must be a type supported by Protocol Buffer map keys.</typeparam>
+ /// <typeparam name="TValue">Value type in the map. Must be a type supported by Protocol Buffers.</typeparam>
+ /// <remarks>
+ /// <para>
+ /// For string keys, the equality comparison is provided by <see cref="StringComparer.Ordinal" />.
+ /// </para>
+ /// <para>
+ /// Null values are not permitted in the map, either for wrapper types or regular messages.
+ /// If a map is deserialized from a data stream and the value is missing from an entry, a default value
+ /// is created instead. For primitive types, that is the regular default value (0, the empty string and so
+ /// on); for message types, an empty instance of the message is created, as if the map entry contained a 0-length
+ /// encoded value for the field.
+ /// </para>
+ /// <para>
+ /// This implementation does not generally prohibit the use of key/value types which are not
+ /// supported by Protocol Buffers (e.g. using a key type of <code>byte</code>) but nor does it guarantee
+ /// that all operations will work in such cases.
+ /// </para>
+ /// <para>
+ /// The order in which entries are returned when iterating over this object is undefined, and may change
+ /// in future versions.
+ /// </para>
+ /// </remarks>
+ public sealed class MapField<TKey, TValue> : IDeepCloneable<MapField<TKey, TValue>>, IDictionary<TKey, TValue>, IEquatable<MapField<TKey, TValue>>, IDictionary
+#if !NET35
+ , IReadOnlyDictionary<TKey, TValue>
+#endif
+ {
+ private static readonly EqualityComparer<TValue> ValueEqualityComparer = ProtobufEqualityComparers.GetEqualityComparer<TValue>();
+ private static readonly EqualityComparer<TKey> KeyEqualityComparer = ProtobufEqualityComparers.GetEqualityComparer<TKey>();
+
+ // TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.)
+ private readonly Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>> map =
+ new Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>>(KeyEqualityComparer);
+ private readonly LinkedList<KeyValuePair<TKey, TValue>> list = new LinkedList<KeyValuePair<TKey, TValue>>();
+
+ /// <summary>
+ /// Creates a deep clone of this object.
+ /// </summary>
+ /// <returns>
+ /// A deep clone of this object.
+ /// </returns>
+ public MapField<TKey, TValue> Clone()
+ {
+ var clone = new MapField<TKey, TValue>();
+ // Keys are never cloneable. Values might be.
+ if (typeof(IDeepCloneable<TValue>).IsAssignableFrom(typeof(TValue)))
+ {
+ foreach (var pair in list)
+ {
+ clone.Add(pair.Key, ((IDeepCloneable<TValue>)pair.Value).Clone());
+ }
+ }
+ else
+ {
+ // Nothing is cloneable, so we don't need to worry.
+ clone.Add(this);
+ }
+ return clone;
+ }
+
+ /// <summary>
+ /// Adds the specified key/value pair to the map.
+ /// </summary>
+ /// <remarks>
+ /// This operation fails if the key already exists in the map. To replace an existing entry, use the indexer.
+ /// </remarks>
+ /// <param name="key">The key to add</param>
+ /// <param name="value">The value to add.</param>
+ /// <exception cref="System.ArgumentException">The given key already exists in map.</exception>
+ public void Add(TKey key, TValue value)
+ {
+ // Validation of arguments happens in ContainsKey and the indexer
+ if (ContainsKey(key))
+ {
+ throw new ArgumentException("Key already exists in map", nameof(key));
+ }
+ this[key] = value;
+ }
+
+ /// <summary>
+ /// Determines whether the specified key is present in the map.
+ /// </summary>
+ /// <param name="key">The key to check.</param>
+ /// <returns><c>true</c> if the map contains the given key; <c>false</c> otherwise.</returns>
+ public bool ContainsKey(TKey key)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
+ return map.ContainsKey(key);
+ }
+
+ private bool ContainsValue(TValue value) =>
+ list.Any(pair => ValueEqualityComparer.Equals(pair.Value, value));
+
+ /// <summary>
+ /// Removes the entry identified by the given key from the map.
+ /// </summary>
+ /// <param name="key">The key indicating the entry to remove from the map.</param>
+ /// <returns><c>true</c> if the map contained the given key before the entry was removed; <c>false</c> otherwise.</returns>
+ public bool Remove(TKey key)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
+ LinkedListNode<KeyValuePair<TKey, TValue>> node;
+ if (map.TryGetValue(key, out node))
+ {
+ map.Remove(key);
+ node.List.Remove(node);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Gets the value associated with the specified key.
+ /// </summary>
+ /// <param name="key">The key whose value to get.</param>
+ /// <param name="value">When this method returns, the value associated with the specified key, if the key is found;
+ /// otherwise, the default value for the type of the <paramref name="value"/> parameter.
+ /// This parameter is passed uninitialized.</param>
+ /// <returns><c>true</c> if the map contains an element with the specified key; otherwise, <c>false</c>.</returns>
+ public bool TryGetValue(TKey key, out TValue value)
+ {
+ LinkedListNode<KeyValuePair<TKey, TValue>> node;
+ if (map.TryGetValue(key, out node))
+ {
+ value = node.Value.Value;
+ return true;
+ }
+ else
+ {
+ value = default(TValue);
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the value associated with the specified key.
+ /// </summary>
+ /// <param name="key">The key of the value to get or set.</param>
+ /// <exception cref="KeyNotFoundException">The property is retrieved and key does not exist in the collection.</exception>
+ /// <returns>The value associated with the specified key. If the specified key is not found,
+ /// a get operation throws a <see cref="KeyNotFoundException"/>, and a set operation creates a new element with the specified key.</returns>
+ public TValue this[TKey key]
+ {
+ get
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
+ TValue value;
+ if (TryGetValue(key, out value))
+ {
+ return value;
+ }
+ throw new KeyNotFoundException();
+ }
+ set
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
+ // value == null check here is redundant, but avoids boxing.
+ if (value == null)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value));
+ }
+ LinkedListNode<KeyValuePair<TKey, TValue>> node;
+ var pair = new KeyValuePair<TKey, TValue>(key, value);
+ if (map.TryGetValue(key, out node))
+ {
+ node.Value = pair;
+ }
+ else
+ {
+ node = list.AddLast(pair);
+ map[key] = node;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets a collection containing the keys in the map.
+ /// </summary>
+ public ICollection<TKey> Keys { get { return new MapView<TKey>(this, pair => pair.Key, ContainsKey); } }
+
+ /// <summary>
+ /// Gets a collection containing the values in the map.
+ /// </summary>
+ public ICollection<TValue> Values { get { return new MapView<TValue>(this, pair => pair.Value, ContainsValue); } }
+
+ /// <summary>
+ /// Adds the specified entries to the map. The keys and values are not automatically cloned.
+ /// </summary>
+ /// <param name="entries">The entries to add to the map.</param>
+ public void Add(IDictionary<TKey, TValue> entries)
+ {
+ ProtoPreconditions.CheckNotNull(entries, nameof(entries));
+ foreach (var pair in entries)
+ {
+ Add(pair.Key, pair.Value);
+ }
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through the collection.
+ /// </summary>
+ /// <returns>
+ /// An enumerator that can be used to iterate through the collection.
+ /// </returns>
+ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
+ {
+ return list.GetEnumerator();
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through a collection.
+ /// </summary>
+ /// <returns>
+ /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
+ /// </returns>
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ /// <summary>
+ /// Adds the specified item to the map.
+ /// </summary>
+ /// <param name="item">The item to add to the map.</param>
+ void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
+ {
+ Add(item.Key, item.Value);
+ }
+
+ /// <summary>
+ /// Removes all items from the map.
+ /// </summary>
+ public void Clear()
+ {
+ list.Clear();
+ map.Clear();
+ }
+
+ /// <summary>
+ /// Determines whether map contains an entry equivalent to the given key/value pair.
+ /// </summary>
+ /// <param name="item">The key/value pair to find.</param>
+ /// <returns></returns>
+ bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
+ {
+ TValue value;
+ return TryGetValue(item.Key, out value) && ValueEqualityComparer.Equals(item.Value, value);
+ }
+
+ /// <summary>
+ /// Copies the key/value pairs in this map to an array.
+ /// </summary>
+ /// <param name="array">The array to copy the entries into.</param>
+ /// <param name="arrayIndex">The index of the array at which to start copying values.</param>
+ void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
+ {
+ list.CopyTo(array, arrayIndex);
+ }
+
+ /// <summary>
+ /// Removes the specified key/value pair from the map.
+ /// </summary>
+ /// <remarks>Both the key and the value must be found for the entry to be removed.</remarks>
+ /// <param name="item">The key/value pair to remove.</param>
+ /// <returns><c>true</c> if the key/value pair was found and removed; <c>false</c> otherwise.</returns>
+ bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
+ {
+ if (item.Key == null)
+ {
+ throw new ArgumentException("Key is null", nameof(item));
+ }
+ LinkedListNode<KeyValuePair<TKey, TValue>> node;
+ if (map.TryGetValue(item.Key, out node) &&
+ EqualityComparer<TValue>.Default.Equals(item.Value, node.Value.Value))
+ {
+ map.Remove(item.Key);
+ node.List.Remove(node);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Gets the number of elements contained in the map.
+ /// </summary>
+ public int Count { get { return list.Count; } }
+
+ /// <summary>
+ /// Gets a value indicating whether the map is read-only.
+ /// </summary>
+ public bool IsReadOnly { get { return false; } }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
+ /// </summary>
+ /// <param name="other">The <see cref="System.Object" /> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ public override bool Equals(object other)
+ {
+ return Equals(other as MapField<TKey, TValue>);
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ var keyComparer = KeyEqualityComparer;
+ var valueComparer = ValueEqualityComparer;
+ int hash = 0;
+ foreach (var pair in list)
+ {
+ hash ^= keyComparer.GetHashCode(pair.Key) * 31 + valueComparer.GetHashCode(pair.Value);
+ }
+ return hash;
+ }
+
+ /// <summary>
+ /// Compares this map with another for equality.
+ /// </summary>
+ /// <remarks>
+ /// The order of the key/value pairs in the maps is not deemed significant in this comparison.
+ /// </remarks>
+ /// <param name="other">The map to compare this with.</param>
+ /// <returns><c>true</c> if <paramref name="other"/> refers to an equal map; <c>false</c> otherwise.</returns>
+ public bool Equals(MapField<TKey, TValue> other)
+ {
+ if (other == null)
+ {
+ return false;
+ }
+ if (other == this)
+ {
+ return true;
+ }
+ if (other.Count != this.Count)
+ {
+ return false;
+ }
+ var valueComparer = ValueEqualityComparer;
+ foreach (var pair in this)
+ {
+ TValue value;
+ if (!other.TryGetValue(pair.Key, out value))
+ {
+ return false;
+ }
+ if (!valueComparer.Equals(value, pair.Value))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Adds entries to the map from the given stream.
+ /// </summary>
+ /// <remarks>
+ /// It is assumed that the stream is initially positioned after the tag specified by the codec.
+ /// This method will continue reading entries from the stream until the end is reached, or
+ /// a different tag is encountered.
+ /// </remarks>
+ /// <param name="input">Stream to read from</param>
+ /// <param name="codec">Codec describing how the key/value pairs are encoded</param>
+ public void AddEntriesFrom(CodedInputStream input, Codec codec)
+ {
+ var adapter = new Codec.MessageAdapter(codec);
+ do
+ {
+ adapter.Reset();
+ input.ReadMessage(adapter);
+ this[adapter.Key] = adapter.Value;
+ } while (input.MaybeConsumeTag(codec.MapTag));
+ }
+
+ /// <summary>
+ /// Writes the contents of this map to the given coded output stream, using the specified codec
+ /// to encode each entry.
+ /// </summary>
+ /// <param name="output">The output stream to write to.</param>
+ /// <param name="codec">The codec to use for each entry.</param>
+ public void WriteTo(CodedOutputStream output, Codec codec)
+ {
+ var message = new Codec.MessageAdapter(codec);
+ foreach (var entry in list)
+ {
+ message.Key = entry.Key;
+ message.Value = entry.Value;
+ output.WriteTag(codec.MapTag);
+ output.WriteMessage(message);
+ }
+ }
+
+ /// <summary>
+ /// Calculates the size of this map based on the given entry codec.
+ /// </summary>
+ /// <param name="codec">The codec to use to encode each entry.</param>
+ /// <returns></returns>
+ public int CalculateSize(Codec codec)
+ {
+ if (Count == 0)
+ {
+ return 0;
+ }
+ var message = new Codec.MessageAdapter(codec);
+ int size = 0;
+ foreach (var entry in list)
+ {
+ message.Key = entry.Key;
+ message.Value = entry.Value;
+ size += CodedOutputStream.ComputeRawVarint32Size(codec.MapTag);
+ size += CodedOutputStream.ComputeMessageSize(message);
+ }
+ return size;
+ }
+
+ /// <summary>
+ /// Returns a string representation of this repeated field, in the same
+ /// way as it would be represented by the default JSON formatter.
+ /// </summary>
+ public override string ToString()
+ {
+ var writer = new StringWriter();
+ JsonFormatter.Default.WriteDictionary(writer, this);
+ return writer.ToString();
+ }
+
+ #region IDictionary explicit interface implementation
+ void IDictionary.Add(object key, object value)
+ {
+ Add((TKey)key, (TValue)value);
+ }
+
+ bool IDictionary.Contains(object key)
+ {
+ if (!(key is TKey))
+ {
+ return false;
+ }
+ return ContainsKey((TKey)key);
+ }
+
+ IDictionaryEnumerator IDictionary.GetEnumerator()
+ {
+ return new DictionaryEnumerator(GetEnumerator());
+ }
+
+ void IDictionary.Remove(object key)
+ {
+ ProtoPreconditions.CheckNotNull(key, nameof(key));
+ if (!(key is TKey))
+ {
+ return;
+ }
+ Remove((TKey)key);
+ }
+
+ void ICollection.CopyTo(Array array, int index)
+ {
+ // This is ugly and slow as heck, but with any luck it will never be used anyway.
+ ICollection temp = this.Select(pair => new DictionaryEntry(pair.Key, pair.Value)).ToList();
+ temp.CopyTo(array, index);
+ }
+
+ bool IDictionary.IsFixedSize { get { return false; } }
+
+ ICollection IDictionary.Keys { get { return (ICollection)Keys; } }
+
+ ICollection IDictionary.Values { get { return (ICollection)Values; } }
+
+ bool ICollection.IsSynchronized { get { return false; } }
+
+ object ICollection.SyncRoot { get { return this; } }
+
+ object IDictionary.this[object key]
+ {
+ get
+ {
+ ProtoPreconditions.CheckNotNull(key, nameof(key));
+ if (!(key is TKey))
+ {
+ return null;
+ }
+ TValue value;
+ TryGetValue((TKey)key, out value);
+ return value;
+ }
+
+ set
+ {
+ this[(TKey)key] = (TValue)value;
+ }
+ }
+ #endregion
+
+ #region IReadOnlyDictionary explicit interface implementation
+#if !NET35
+ IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => Keys;
+
+ IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values;
+#endif
+ #endregion
+
+ private class DictionaryEnumerator : IDictionaryEnumerator
+ {
+ private readonly IEnumerator<KeyValuePair<TKey, TValue>> enumerator;
+
+ internal DictionaryEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> enumerator)
+ {
+ this.enumerator = enumerator;
+ }
+
+ public bool MoveNext()
+ {
+ return enumerator.MoveNext();
+ }
+
+ public void Reset()
+ {
+ enumerator.Reset();
+ }
+
+ public object Current { get { return Entry; } }
+ public DictionaryEntry Entry { get { return new DictionaryEntry(Key, Value); } }
+ public object Key { get { return enumerator.Current.Key; } }
+ public object Value { get { return enumerator.Current.Value; } }
+ }
+
+ /// <summary>
+ /// A codec for a specific map field. This contains all the information required to encode and
+ /// decode the nested messages.
+ /// </summary>
+ public sealed class Codec
+ {
+ private readonly FieldCodec<TKey> keyCodec;
+ private readonly FieldCodec<TValue> valueCodec;
+ private readonly uint mapTag;
+
+ /// <summary>
+ /// Creates a new entry codec based on a separate key codec and value codec,
+ /// and the tag to use for each map entry.
+ /// </summary>
+ /// <param name="keyCodec">The key codec.</param>
+ /// <param name="valueCodec">The value codec.</param>
+ /// <param name="mapTag">The map tag to use to introduce each map entry.</param>
+ public Codec(FieldCodec<TKey> keyCodec, FieldCodec<TValue> valueCodec, uint mapTag)
+ {
+ this.keyCodec = keyCodec;
+ this.valueCodec = valueCodec;
+ this.mapTag = mapTag;
+ }
+
+ /// <summary>
+ /// The tag used in the enclosing message to indicate map entries.
+ /// </summary>
+ internal uint MapTag { get { return mapTag; } }
+
+ /// <summary>
+ /// A mutable message class, used for parsing and serializing. This
+ /// delegates the work to a codec, but implements the <see cref="IMessage"/> interface
+ /// for interop with <see cref="CodedInputStream"/> and <see cref="CodedOutputStream"/>.
+ /// This is nested inside Codec as it's tightly coupled to the associated codec,
+ /// and it's simpler if it has direct access to all its fields.
+ /// </summary>
+ internal class MessageAdapter : IMessage
+ {
+ private static readonly byte[] ZeroLengthMessageStreamData = new byte[] { 0 };
+
+ private readonly Codec codec;
+ internal TKey Key { get; set; }
+ internal TValue Value { get; set; }
+
+ internal MessageAdapter(Codec codec)
+ {
+ this.codec = codec;
+ }
+
+ internal void Reset()
+ {
+ Key = codec.keyCodec.DefaultValue;
+ Value = codec.valueCodec.DefaultValue;
+ }
+
+ public void MergeFrom(CodedInputStream input)
+ {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0)
+ {
+ if (tag == codec.keyCodec.Tag)
+ {
+ Key = codec.keyCodec.Read(input);
+ }
+ else if (tag == codec.valueCodec.Tag)
+ {
+ Value = codec.valueCodec.Read(input);
+ }
+ else
+ {
+ input.SkipLastField();
+ }
+ }
+
+ // Corner case: a map entry with a key but no value, where the value type is a message.
+ // Read it as if we'd seen an input stream with no data (i.e. create a "default" message).
+ if (Value == null)
+ {
+ Value = codec.valueCodec.Read(new CodedInputStream(ZeroLengthMessageStreamData));
+ }
+ }
+
+ public void WriteTo(CodedOutputStream output)
+ {
+ codec.keyCodec.WriteTagAndValue(output, Key);
+ codec.valueCodec.WriteTagAndValue(output, Value);
+ }
+
+ public int CalculateSize()
+ {
+ return codec.keyCodec.CalculateSizeWithTag(Key) + codec.valueCodec.CalculateSizeWithTag(Value);
+ }
+
+ MessageDescriptor IMessage.Descriptor { get { return null; } }
+ }
+ }
+
+ private class MapView<T> : ICollection<T>, ICollection
+ {
+ private readonly MapField<TKey, TValue> parent;
+ private readonly Func<KeyValuePair<TKey, TValue>, T> projection;
+ private readonly Func<T, bool> containsCheck;
+
+ internal MapView(
+ MapField<TKey, TValue> parent,
+ Func<KeyValuePair<TKey, TValue>, T> projection,
+ Func<T, bool> containsCheck)
+ {
+ this.parent = parent;
+ this.projection = projection;
+ this.containsCheck = containsCheck;
+ }
+
+ public int Count { get { return parent.Count; } }
+
+ public bool IsReadOnly { get { return true; } }
+
+ public bool IsSynchronized { get { return false; } }
+
+ public object SyncRoot { get { return parent; } }
+
+ public void Add(T item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public void Clear()
+ {
+ throw new NotSupportedException();
+ }
+
+ public bool Contains(T item)
+ {
+ return containsCheck(item);
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ if (arrayIndex < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(arrayIndex));
+ }
+ if (arrayIndex + Count > array.Length)
+ {
+ throw new ArgumentException("Not enough space in the array", nameof(array));
+ }
+ foreach (var item in this)
+ {
+ array[arrayIndex++] = item;
+ }
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ return parent.list.Select(projection).GetEnumerator();
+ }
+
+ public bool Remove(T item)
+ {
+ throw new NotSupportedException();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ public void CopyTo(Array array, int index)
+ {
+ if (index < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ if (index + Count > array.Length)
+ {
+ throw new ArgumentException("Not enough space in the array", nameof(array));
+ }
+ foreach (var item in this)
+ {
+ array.SetValue(item, index++);
+ }
+ }
+ }
+ }
+}
diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
index c18b63e2..613ca9c4 100644
--- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
+++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
@@ -1,595 +1,595 @@
-#region Copyright notice and license
-// Protocol Buffers - Google's data interchange format
-// Copyright 2015 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#endregion
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.IO;
-
-namespace Google.Protobuf.Collections
-{
- /// <summary>
- /// The contents of a repeated field: essentially, a collection with some extra
- /// restrictions (no null values) and capabilities (deep cloning).
- /// </summary>
- /// <remarks>
- /// This implementation does not generally prohibit the use of types which are not
- /// supported by Protocol Buffers but nor does it guarantee that all operations will work in such cases.
- /// </remarks>
- /// <typeparam name="T">The element type of the repeated field.</typeparam>
- public sealed class RepeatedField<T> : IList<T>, IList, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>
-#if !NET35
- , IReadOnlyList<T>
-#endif
- {
- private static readonly EqualityComparer<T> EqualityComparer = ProtobufEqualityComparers.GetEqualityComparer<T>();
- private static readonly T[] EmptyArray = new T[0];
- private const int MinArraySize = 8;
-
- private T[] array = EmptyArray;
- private int count = 0;
-
- /// <summary>
- /// Creates a deep clone of this repeated field.
- /// </summary>
- /// <remarks>
- /// If the field type is
- /// a message type, each element is also cloned; otherwise, it is
- /// assumed that the field type is primitive (including string and
- /// bytes, both of which are immutable) and so a simple copy is
- /// equivalent to a deep clone.
- /// </remarks>
- /// <returns>A deep clone of this repeated field.</returns>
- public RepeatedField<T> Clone()
- {
- RepeatedField<T> clone = new RepeatedField<T>();
- if (array != EmptyArray)
- {
- clone.array = (T[])array.Clone();
- IDeepCloneable<T>[] cloneableArray = clone.array as IDeepCloneable<T>[];
- if (cloneableArray != null)
- {
- for (int i = 0; i < count; i++)
- {
- clone.array[i] = cloneableArray[i].Clone();
- }
- }
- }
- clone.count = count;
- return clone;
- }
-
- /// <summary>
- /// Adds the entries from the given input stream, decoding them with the specified codec.
- /// </summary>
- /// <param name="input">The input stream to read from.</param>
- /// <param name="codec">The codec to use in order to read each entry.</param>
- public void AddEntriesFrom(CodedInputStream input, FieldCodec<T> codec)
- {
- // TODO: Inline some of the Add code, so we can avoid checking the size on every
- // iteration.
- uint tag = input.LastTag;
- var reader = codec.ValueReader;
- // Non-nullable value types can be packed or not.
- if (FieldCodec<T>.IsPackedRepeatedField(tag))
- {
- int length = input.ReadLength();
- if (length > 0)
- {
- int oldLimit = input.PushLimit(length);
- while (!input.ReachedLimit)
- {
- Add(reader(input));
- }
- input.PopLimit(oldLimit);
- }
- // Empty packed field. Odd, but valid - just ignore.
- }
- else
- {
- // Not packed... (possibly not packable)
- do
- {
- Add(reader(input));
- } while (input.MaybeConsumeTag(tag));
- }
- }
-
- /// <summary>
- /// Calculates the size of this collection based on the given codec.
- /// </summary>
- /// <param name="codec">The codec to use when encoding each field.</param>
- /// <returns>The number of bytes that would be written to a <see cref="CodedOutputStream"/> by <see cref="WriteTo"/>,
- /// using the same codec.</returns>
- public int CalculateSize(FieldCodec<T> codec)
- {
- if (count == 0)
- {
- return 0;
- }
- uint tag = codec.Tag;
- if (codec.PackedRepeatedField)
- {
- int dataSize = CalculatePackedDataSize(codec);
- return CodedOutputStream.ComputeRawVarint32Size(tag) +
- CodedOutputStream.ComputeLengthSize(dataSize) +
- dataSize;
- }
- else
- {
- var sizeCalculator = codec.ValueSizeCalculator;
- int size = count * CodedOutputStream.ComputeRawVarint32Size(tag);
- for (int i = 0; i < count; i++)
- {
- size += sizeCalculator(array[i]);
- }
- return size;
- }
- }
-
- private int CalculatePackedDataSize(FieldCodec<T> codec)
- {
- int fixedSize = codec.FixedSize;
- if (fixedSize == 0)
- {
- var calculator = codec.ValueSizeCalculator;
- int tmp = 0;
- for (int i = 0; i < count; i++)
- {
- tmp += calculator(array[i]);
- }
- return tmp;
- }
- else
- {
- return fixedSize * Count;
- }
- }
-
- /// <summary>
- /// Writes the contents of this collection to the given <see cref="CodedOutputStream"/>,
- /// encoding each value using the specified codec.
- /// </summary>
- /// <param name="output">The output stream to write to.</param>
- /// <param name="codec">The codec to use when encoding each value.</param>
- public void WriteTo(CodedOutputStream output, FieldCodec<T> codec)
- {
- if (count == 0)
- {
- return;
- }
- var writer = codec.ValueWriter;
- var tag = codec.Tag;
- if (codec.PackedRepeatedField)
- {
- // Packed primitive type
- uint size = (uint)CalculatePackedDataSize(codec);
- output.WriteTag(tag);
- output.WriteRawVarint32(size);
- for (int i = 0; i < count; i++)
- {
- writer(output, array[i]);
- }
- }
- else
- {
- // Not packed: a simple tag/value pair for each value.
- // Can't use codec.WriteTagAndValue, as that omits default values.
- for (int i = 0; i < count; i++)
- {
- output.WriteTag(tag);
- writer(output, array[i]);
- }
- }
- }
-
- private void EnsureSize(int size)
- {
- if (array.Length < size)
- {
- size = Math.Max(size, MinArraySize);
- int newSize = Math.Max(array.Length * 2, size);
- var tmp = new T[newSize];
- Array.Copy(array, 0, tmp, 0, array.Length);
- array = tmp;
- }
- }
-
- /// <summary>
- /// Adds the specified item to the collection.
- /// </summary>
- /// <param name="item">The item to add.</param>
- public void Add(T item)
- {
- ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
- EnsureSize(count + 1);
- array[count++] = item;
- }
-
- /// <summary>
- /// Removes all items from the collection.
- /// </summary>
- public void Clear()
- {
- array = EmptyArray;
- count = 0;
- }
-
- /// <summary>
- /// Determines whether this collection contains the given item.
- /// </summary>
- /// <param name="item">The item to find.</param>
- /// <returns><c>true</c> if this collection contains the given item; <c>false</c> otherwise.</returns>
- public bool Contains(T item)
- {
- return IndexOf(item) != -1;
- }
-
- /// <summary>
- /// Copies this collection to the given array.
- /// </summary>
- /// <param name="array">The array to copy to.</param>
- /// <param name="arrayIndex">The first index of the array to copy to.</param>
- public void CopyTo(T[] array, int arrayIndex)
- {
- Array.Copy(this.array, 0, array, arrayIndex, count);
- }
-
- /// <summary>
- /// Removes the specified item from the collection
- /// </summary>
- /// <param name="item">The item to remove.</param>
- /// <returns><c>true</c> if the item was found and removed; <c>false</c> otherwise.</returns>
- public bool Remove(T item)
- {
- int index = IndexOf(item);
- if (index == -1)
- {
- return false;
- }
- Array.Copy(array, index + 1, array, index, count - index - 1);
- count--;
- array[count] = default(T);
- return true;
- }
-
- /// <summary>
- /// Gets the number of elements contained in the collection.
- /// </summary>
- public int Count => count;
-
- /// <summary>
- /// Gets a value indicating whether the collection is read-only.
- /// </summary>
- public bool IsReadOnly => false;
-
- /// <summary>
- /// Adds all of the specified values into this collection.
- /// </summary>
- /// <param name="values">The values to add to this collection.</param>
- public void AddRange(IEnumerable<T> values)
- {
- ProtoPreconditions.CheckNotNull(values, nameof(values));
-
- // Optimization 1: If the collection we're adding is already a RepeatedField<T>,
- // we know the values are valid.
- var otherRepeatedField = values as RepeatedField<T>;
- if (otherRepeatedField != null)
- {
- EnsureSize(count + otherRepeatedField.count);
- Array.Copy(otherRepeatedField.array, 0, array, count, otherRepeatedField.count);
- count += otherRepeatedField.count;
- return;
- }
-
- // Optimization 2: The collection is an ICollection, so we can expand
- // just once and ask the collection to copy itself into the array.
- var collection = values as ICollection;
- if (collection != null)
- {
- var extraCount = collection.Count;
- // For reference types and nullable value types, we need to check that there are no nulls
- // present. (This isn't a thread-safe approach, but we don't advertise this is thread-safe.)
- // We expect the JITter to optimize this test to true/false, so it's effectively conditional
- // specialization.
- if (default(T) == null)
- {
- // TODO: Measure whether iterating once to check and then letting the collection copy
- // itself is faster or slower than iterating and adding as we go. For large
- // collections this will not be great in terms of cache usage... but the optimized
- // copy may be significantly faster than doing it one at a time.
- foreach (var item in collection)
- {
- if (item == null)
- {
- throw new ArgumentException("Sequence contained null element", nameof(values));
- }
- }
- }
- EnsureSize(count + extraCount);
- collection.CopyTo(array, count);
- count += extraCount;
- return;
- }
-
- // We *could* check for ICollection<T> as well, but very very few collections implement
- // ICollection<T> but not ICollection. (HashSet<T> does, for one...)
-
- // Fall back to a slower path of adding items one at a time.
- foreach (T item in values)
- {
- Add(item);
- }
- }
-
- /// <summary>
- /// Adds all of the specified values into this collection. This method is present to
- /// allow repeated fields to be constructed from queries within collection initializers.
- /// Within non-collection-initializer code, consider using the equivalent <see cref="AddRange"/>
- /// method instead for clarity.
- /// </summary>
- /// <param name="values">The values to add to this collection.</param>
- public void Add(IEnumerable<T> values)
- {
- AddRange(values);
- }
-
- /// <summary>
- /// Returns an enumerator that iterates through the collection.
- /// </summary>
- /// <returns>
- /// An enumerator that can be used to iterate through the collection.
- /// </returns>
- public IEnumerator<T> GetEnumerator()
- {
- for (int i = 0; i < count; i++)
- {
- yield return array[i];
- }
- }
-
- /// <summary>
- /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
- /// </summary>
- /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
- /// <returns>
- /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
- /// </returns>
- public override bool Equals(object obj)
- {
- return Equals(obj as RepeatedField<T>);
- }
-
- /// <summary>
- /// Returns an enumerator that iterates through a collection.
- /// </summary>
- /// <returns>
- /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
- /// </returns>
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- /// <summary>
- /// Returns a hash code for this instance.
- /// </summary>
- /// <returns>
- /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
- /// </returns>
- public override int GetHashCode()
- {
- int hash = 0;
- for (int i = 0; i < count; i++)
- {
- hash = hash * 31 + array[i].GetHashCode();
- }
- return hash;
- }
-
- /// <summary>
- /// Compares this repeated field with another for equality.
- /// </summary>
- /// <param name="other">The repeated field to compare this with.</param>
- /// <returns><c>true</c> if <paramref name="other"/> refers to an equal repeated field; <c>false</c> otherwise.</returns>
- public bool Equals(RepeatedField<T> other)
- {
- if (ReferenceEquals(other, null))
- {
- return false;
- }
- if (ReferenceEquals(other, this))
- {
- return true;
- }
- if (other.Count != this.Count)
- {
- return false;
- }
- EqualityComparer<T> comparer = EqualityComparer;
- for (int i = 0; i < count; i++)
- {
- if (!comparer.Equals(array[i], other.array[i]))
- {
- return false;
- }
- }
- return true;
- }
-
- /// <summary>
- /// Returns the index of the given item within the collection, or -1 if the item is not
- /// present.
- /// </summary>
- /// <param name="item">The item to find in the collection.</param>
- /// <returns>The zero-based index of the item, or -1 if it is not found.</returns>
- public int IndexOf(T item)
- {
- ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
- EqualityComparer<T> comparer = EqualityComparer;
- for (int i = 0; i < count; i++)
- {
- if (comparer.Equals(array[i], item))
- {
- return i;
- }
- }
- return -1;
- }
-
- /// <summary>
- /// Inserts the given item at the specified index.
- /// </summary>
- /// <param name="index">The index at which to insert the item.</param>
- /// <param name="item">The item to insert.</param>
- public void Insert(int index, T item)
- {
- ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
- if (index < 0 || index > count)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- EnsureSize(count + 1);
- Array.Copy(array, index, array, index + 1, count - index);
- array[index] = item;
- count++;
- }
-
- /// <summary>
- /// Removes the item at the given index.
- /// </summary>
- /// <param name="index">The zero-based index of the item to remove.</param>
- public void RemoveAt(int index)
- {
- if (index < 0 || index >= count)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- Array.Copy(array, index + 1, array, index, count - index - 1);
- count--;
- array[count] = default(T);
- }
-
- /// <summary>
- /// Returns a string representation of this repeated field, in the same
- /// way as it would be represented by the default JSON formatter.
- /// </summary>
- public override string ToString()
- {
- var writer = new StringWriter();
- JsonFormatter.Default.WriteList(writer, this);
- return writer.ToString();
- }
-
- /// <summary>
- /// Gets or sets the item at the specified index.
- /// </summary>
- /// <value>
- /// The element at the specified index.
- /// </value>
- /// <param name="index">The zero-based index of the element to get or set.</param>
- /// <returns>The item at the specified index.</returns>
- public T this[int index]
- {
- get
- {
- if (index < 0 || index >= count)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- return array[index];
- }
- set
- {
- if (index < 0 || index >= count)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value));
- array[index] = value;
- }
- }
-
- #region Explicit interface implementation for IList and ICollection.
- bool IList.IsFixedSize => false;
-
- void ICollection.CopyTo(Array array, int index)
- {
- Array.Copy(this.array, 0, array, index, count);
- }
-
- bool ICollection.IsSynchronized => false;
-
- object ICollection.SyncRoot => this;
-
- object IList.this[int index]
- {
- get { return this[index]; }
- set { this[index] = (T)value; }
- }
-
- int IList.Add(object value)
- {
- Add((T) value);
- return count - 1;
- }
-
- bool IList.Contains(object value)
- {
- return (value is T && Contains((T)value));
- }
-
- int IList.IndexOf(object value)
- {
- if (!(value is T))
- {
- return -1;
- }
- return IndexOf((T)value);
- }
-
- void IList.Insert(int index, object value)
- {
- Insert(index, (T) value);
- }
-
- void IList.Remove(object value)
- {
- if (!(value is T))
- {
- return;
- }
- Remove((T)value);
- }
- #endregion
- }
-}
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Google.Protobuf.Collections
+{
+ /// <summary>
+ /// The contents of a repeated field: essentially, a collection with some extra
+ /// restrictions (no null values) and capabilities (deep cloning).
+ /// </summary>
+ /// <remarks>
+ /// This implementation does not generally prohibit the use of types which are not
+ /// supported by Protocol Buffers but nor does it guarantee that all operations will work in such cases.
+ /// </remarks>
+ /// <typeparam name="T">The element type of the repeated field.</typeparam>
+ public sealed class RepeatedField<T> : IList<T>, IList, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>
+#if !NET35
+ , IReadOnlyList<T>
+#endif
+ {
+ private static readonly EqualityComparer<T> EqualityComparer = ProtobufEqualityComparers.GetEqualityComparer<T>();
+ private static readonly T[] EmptyArray = new T[0];
+ private const int MinArraySize = 8;
+
+ private T[] array = EmptyArray;
+ private int count = 0;
+
+ /// <summary>
+ /// Creates a deep clone of this repeated field.
+ /// </summary>
+ /// <remarks>
+ /// If the field type is
+ /// a message type, each element is also cloned; otherwise, it is
+ /// assumed that the field type is primitive (including string and
+ /// bytes, both of which are immutable) and so a simple copy is
+ /// equivalent to a deep clone.
+ /// </remarks>
+ /// <returns>A deep clone of this repeated field.</returns>
+ public RepeatedField<T> Clone()
+ {
+ RepeatedField<T> clone = new RepeatedField<T>();
+ if (array != EmptyArray)
+ {
+ clone.array = (T[])array.Clone();
+ IDeepCloneable<T>[] cloneableArray = clone.array as IDeepCloneable<T>[];
+ if (cloneableArray != null)
+ {
+ for (int i = 0; i < count; i++)
+ {
+ clone.array[i] = cloneableArray[i].Clone();
+ }
+ }
+ }
+ clone.count = count;
+ return clone;
+ }
+
+ /// <summary>
+ /// Adds the entries from the given input stream, decoding them with the specified codec.
+ /// </summary>
+ /// <param name="input">The input stream to read from.</param>
+ /// <param name="codec">The codec to use in order to read each entry.</param>
+ public void AddEntriesFrom(CodedInputStream input, FieldCodec<T> codec)
+ {
+ // TODO: Inline some of the Add code, so we can avoid checking the size on every
+ // iteration.
+ uint tag = input.LastTag;
+ var reader = codec.ValueReader;
+ // Non-nullable value types can be packed or not.
+ if (FieldCodec<T>.IsPackedRepeatedField(tag))
+ {
+ int length = input.ReadLength();
+ if (length > 0)
+ {
+ int oldLimit = input.PushLimit(length);
+ while (!input.ReachedLimit)
+ {
+ Add(reader(input));
+ }
+ input.PopLimit(oldLimit);
+ }
+ // Empty packed field. Odd, but valid - just ignore.
+ }
+ else
+ {
+ // Not packed... (possibly not packable)
+ do
+ {
+ Add(reader(input));
+ } while (input.MaybeConsumeTag(tag));
+ }
+ }
+
+ /// <summary>
+ /// Calculates the size of this collection based on the given codec.
+ /// </summary>
+ /// <param name="codec">The codec to use when encoding each field.</param>
+ /// <returns>The number of bytes that would be written to a <see cref="CodedOutputStream"/> by <see cref="WriteTo"/>,
+ /// using the same codec.</returns>
+ public int CalculateSize(FieldCodec<T> codec)
+ {
+ if (count == 0)
+ {
+ return 0;
+ }
+ uint tag = codec.Tag;
+ if (codec.PackedRepeatedField)
+ {
+ int dataSize = CalculatePackedDataSize(codec);
+ return CodedOutputStream.ComputeRawVarint32Size(tag) +
+ CodedOutputStream.ComputeLengthSize(dataSize) +
+ dataSize;
+ }
+ else
+ {
+ var sizeCalculator = codec.ValueSizeCalculator;
+ int size = count * CodedOutputStream.ComputeRawVarint32Size(tag);
+ for (int i = 0; i < count; i++)
+ {
+ size += sizeCalculator(array[i]);
+ }
+ return size;
+ }
+ }
+
+ private int CalculatePackedDataSize(FieldCodec<T> codec)
+ {
+ int fixedSize = codec.FixedSize;
+ if (fixedSize == 0)
+ {
+ var calculator = codec.ValueSizeCalculator;
+ int tmp = 0;
+ for (int i = 0; i < count; i++)
+ {
+ tmp += calculator(array[i]);
+ }
+ return tmp;
+ }
+ else
+ {
+ return fixedSize * Count;
+ }
+ }
+
+ /// <summary>
+ /// Writes the contents of this collection to the given <see cref="CodedOutputStream"/>,
+ /// encoding each value using the specified codec.
+ /// </summary>
+ /// <param name="output">The output stream to write to.</param>
+ /// <param name="codec">The codec to use when encoding each value.</param>
+ public void WriteTo(CodedOutputStream output, FieldCodec<T> codec)
+ {
+ if (count == 0)
+ {
+ return;
+ }
+ var writer = codec.ValueWriter;
+ var tag = codec.Tag;
+ if (codec.PackedRepeatedField)
+ {
+ // Packed primitive type
+ uint size = (uint)CalculatePackedDataSize(codec);
+ output.WriteTag(tag);
+ output.WriteRawVarint32(size);
+ for (int i = 0; i < count; i++)
+ {
+ writer(output, array[i]);
+ }
+ }
+ else
+ {
+ // Not packed: a simple tag/value pair for each value.
+ // Can't use codec.WriteTagAndValue, as that omits default values.
+ for (int i = 0; i < count; i++)
+ {
+ output.WriteTag(tag);
+ writer(output, array[i]);
+ }
+ }
+ }
+
+ private void EnsureSize(int size)
+ {
+ if (array.Length < size)
+ {
+ size = Math.Max(size, MinArraySize);
+ int newSize = Math.Max(array.Length * 2, size);
+ var tmp = new T[newSize];
+ Array.Copy(array, 0, tmp, 0, array.Length);
+ array = tmp;
+ }
+ }
+
+ /// <summary>
+ /// Adds the specified item to the collection.
+ /// </summary>
+ /// <param name="item">The item to add.</param>
+ public void Add(T item)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
+ EnsureSize(count + 1);
+ array[count++] = item;
+ }
+
+ /// <summary>
+ /// Removes all items from the collection.
+ /// </summary>
+ public void Clear()
+ {
+ array = EmptyArray;
+ count = 0;
+ }
+
+ /// <summary>
+ /// Determines whether this collection contains the given item.
+ /// </summary>
+ /// <param name="item">The item to find.</param>
+ /// <returns><c>true</c> if this collection contains the given item; <c>false</c> otherwise.</returns>
+ public bool Contains(T item)
+ {
+ return IndexOf(item) != -1;
+ }
+
+ /// <summary>
+ /// Copies this collection to the given array.
+ /// </summary>
+ /// <param name="array">The array to copy to.</param>
+ /// <param name="arrayIndex">The first index of the array to copy to.</param>
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ Array.Copy(this.array, 0, array, arrayIndex, count);
+ }
+
+ /// <summary>
+ /// Removes the specified item from the collection
+ /// </summary>
+ /// <param name="item">The item to remove.</param>
+ /// <returns><c>true</c> if the item was found and removed; <c>false</c> otherwise.</returns>
+ public bool Remove(T item)
+ {
+ int index = IndexOf(item);
+ if (index == -1)
+ {
+ return false;
+ }
+ Array.Copy(array, index + 1, array, index, count - index - 1);
+ count--;
+ array[count] = default(T);
+ return true;
+ }
+
+ /// <summary>
+ /// Gets the number of elements contained in the collection.
+ /// </summary>
+ public int Count => count;
+
+ /// <summary>
+ /// Gets a value indicating whether the collection is read-only.
+ /// </summary>
+ public bool IsReadOnly => false;
+
+ /// <summary>
+ /// Adds all of the specified values into this collection.
+ /// </summary>
+ /// <param name="values">The values to add to this collection.</param>
+ public void AddRange(IEnumerable<T> values)
+ {
+ ProtoPreconditions.CheckNotNull(values, nameof(values));
+
+ // Optimization 1: If the collection we're adding is already a RepeatedField<T>,
+ // we know the values are valid.
+ var otherRepeatedField = values as RepeatedField<T>;
+ if (otherRepeatedField != null)
+ {
+ EnsureSize(count + otherRepeatedField.count);
+ Array.Copy(otherRepeatedField.array, 0, array, count, otherRepeatedField.count);
+ count += otherRepeatedField.count;
+ return;
+ }
+
+ // Optimization 2: The collection is an ICollection, so we can expand
+ // just once and ask the collection to copy itself into the array.
+ var collection = values as ICollection;
+ if (collection != null)
+ {
+ var extraCount = collection.Count;
+ // For reference types and nullable value types, we need to check that there are no nulls
+ // present. (This isn't a thread-safe approach, but we don't advertise this is thread-safe.)
+ // We expect the JITter to optimize this test to true/false, so it's effectively conditional
+ // specialization.
+ if (default(T) == null)
+ {
+ // TODO: Measure whether iterating once to check and then letting the collection copy
+ // itself is faster or slower than iterating and adding as we go. For large
+ // collections this will not be great in terms of cache usage... but the optimized
+ // copy may be significantly faster than doing it one at a time.
+ foreach (var item in collection)
+ {
+ if (item == null)
+ {
+ throw new ArgumentException("Sequence contained null element", nameof(values));
+ }
+ }
+ }
+ EnsureSize(count + extraCount);
+ collection.CopyTo(array, count);
+ count += extraCount;
+ return;
+ }
+
+ // We *could* check for ICollection<T> as well, but very very few collections implement
+ // ICollection<T> but not ICollection. (HashSet<T> does, for one...)
+
+ // Fall back to a slower path of adding items one at a time.
+ foreach (T item in values)
+ {
+ Add(item);
+ }
+ }
+
+ /// <summary>
+ /// Adds all of the specified values into this collection. This method is present to
+ /// allow repeated fields to be constructed from queries within collection initializers.
+ /// Within non-collection-initializer code, consider using the equivalent <see cref="AddRange"/>
+ /// method instead for clarity.
+ /// </summary>
+ /// <param name="values">The values to add to this collection.</param>
+ public void Add(IEnumerable<T> values)
+ {
+ AddRange(values);
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through the collection.
+ /// </summary>
+ /// <returns>
+ /// An enumerator that can be used to iterate through the collection.
+ /// </returns>
+ public IEnumerator<T> GetEnumerator()
+ {
+ for (int i = 0; i < count; i++)
+ {
+ yield return array[i];
+ }
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as RepeatedField<T>);
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through a collection.
+ /// </summary>
+ /// <returns>
+ /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
+ /// </returns>
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ int hash = 0;
+ for (int i = 0; i < count; i++)
+ {
+ hash = hash * 31 + array[i].GetHashCode();
+ }
+ return hash;
+ }
+
+ /// <summary>
+ /// Compares this repeated field with another for equality.
+ /// </summary>
+ /// <param name="other">The repeated field to compare this with.</param>
+ /// <returns><c>true</c> if <paramref name="other"/> refers to an equal repeated field; <c>false</c> otherwise.</returns>
+ public bool Equals(RepeatedField<T> other)
+ {
+ if (ReferenceEquals(other, null))
+ {
+ return false;
+ }
+ if (ReferenceEquals(other, this))
+ {
+ return true;
+ }
+ if (other.Count != this.Count)
+ {
+ return false;
+ }
+ EqualityComparer<T> comparer = EqualityComparer;
+ for (int i = 0; i < count; i++)
+ {
+ if (!comparer.Equals(array[i], other.array[i]))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Returns the index of the given item within the collection, or -1 if the item is not
+ /// present.
+ /// </summary>
+ /// <param name="item">The item to find in the collection.</param>
+ /// <returns>The zero-based index of the item, or -1 if it is not found.</returns>
+ public int IndexOf(T item)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
+ EqualityComparer<T> comparer = EqualityComparer;
+ for (int i = 0; i < count; i++)
+ {
+ if (comparer.Equals(array[i], item))
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /// <summary>
+ /// Inserts the given item at the specified index.
+ /// </summary>
+ /// <param name="index">The index at which to insert the item.</param>
+ /// <param name="item">The item to insert.</param>
+ public void Insert(int index, T item)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
+ if (index < 0 || index > count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ EnsureSize(count + 1);
+ Array.Copy(array, index, array, index + 1, count - index);
+ array[index] = item;
+ count++;
+ }
+
+ /// <summary>
+ /// Removes the item at the given index.
+ /// </summary>
+ /// <param name="index">The zero-based index of the item to remove.</param>
+ public void RemoveAt(int index)
+ {
+ if (index < 0 || index >= count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ Array.Copy(array, index + 1, array, index, count - index - 1);
+ count--;
+ array[count] = default(T);
+ }
+
+ /// <summary>
+ /// Returns a string representation of this repeated field, in the same
+ /// way as it would be represented by the default JSON formatter.
+ /// </summary>
+ public override string ToString()
+ {
+ var writer = new StringWriter();
+ JsonFormatter.Default.WriteList(writer, this);
+ return writer.ToString();
+ }
+
+ /// <summary>
+ /// Gets or sets the item at the specified index.
+ /// </summary>
+ /// <value>
+ /// The element at the specified index.
+ /// </value>
+ /// <param name="index">The zero-based index of the element to get or set.</param>
+ /// <returns>The item at the specified index.</returns>
+ public T this[int index]
+ {
+ get
+ {
+ if (index < 0 || index >= count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ return array[index];
+ }
+ set
+ {
+ if (index < 0 || index >= count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value));
+ array[index] = value;
+ }
+ }
+
+ #region Explicit interface implementation for IList and ICollection.
+ bool IList.IsFixedSize => false;
+
+ void ICollection.CopyTo(Array array, int index)
+ {
+ Array.Copy(this.array, 0, array, index, count);
+ }
+
+ bool ICollection.IsSynchronized => false;
+
+ object ICollection.SyncRoot => this;
+
+ object IList.this[int index]
+ {
+ get { return this[index]; }
+ set { this[index] = (T)value; }
+ }
+
+ int IList.Add(object value)
+ {
+ Add((T) value);
+ return count - 1;
+ }
+
+ bool IList.Contains(object value)
+ {
+ return (value is T && Contains((T)value));
+ }
+
+ int IList.IndexOf(object value)
+ {
+ if (!(value is T))
+ {
+ return -1;
+ }
+ return IndexOf((T)value);
+ }
+
+ void IList.Insert(int index, object value)
+ {
+ Insert(index, (T) value);
+ }
+
+ void IList.Remove(object value)
+ {
+ if (!(value is T))
+ {
+ return;
+ }
+ Remove((T)value);
+ }
+ #endregion
+ }
+}
diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj
index 46728b72..8ea3818a 100644
--- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj
+++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj
@@ -4,7 +4,7 @@
<Description>C# runtime library for Protocol Buffers - Google's data interchange format.</Description>
<Copyright>Copyright 2015, Google Inc.</Copyright>
<AssemblyTitle>Google Protocol Buffers</AssemblyTitle>
- <VersionPrefix>3.6.0</VersionPrefix>
+ <VersionPrefix>3.6.1</VersionPrefix>
<Authors>Google Inc.</Authors>
<TargetFrameworks>netstandard1.0;net45</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -13,10 +13,10 @@
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageTags>Protocol;Buffers;Binary;Serialization;Format;Google;proto;proto3</PackageTags>
<PackageReleaseNotes>C# proto3 support</PackageReleaseNotes>
- <PackageProjectUrl>https://github.com/google/protobuf</PackageProjectUrl>
- <PackageLicenseUrl>https://github.com/google/protobuf/blob/master/LICENSE</PackageLicenseUrl>
+ <PackageProjectUrl>https://github.com/protocolbuffers/protobuf</PackageProjectUrl>
+ <PackageLicenseUrl>https://github.com/protocolbuffers/protobuf/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
- <RepositoryUrl>https://github.com/google/protobuf.git</RepositoryUrl>
+ <RepositoryUrl>https://github.com/protocolbuffers/protobuf.git</RepositoryUrl>
</PropertyGroup>
<!--
diff --git a/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs b/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs
index 0fbc5306..27a97a0e 100644
--- a/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs
+++ b/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs
@@ -125,5 +125,10 @@ namespace Google.Protobuf
return new InvalidProtocolBufferException(
"Stream of protocol messages had invalid tag. Expected tag is length-delimited field 1.");
}
- }
+
+ internal static InvalidProtocolBufferException MissingFields()
+ {
+ return new InvalidProtocolBufferException("Message was missing required fields");
+ }
+}
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/MessageExtensions.cs b/csharp/src/Google.Protobuf/MessageExtensions.cs
index 62181eb9..e1c57dc4 100644
--- a/csharp/src/Google.Protobuf/MessageExtensions.cs
+++ b/csharp/src/Google.Protobuf/MessageExtensions.cs
@@ -30,7 +30,10 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
+using Google.Protobuf.Reflection;
+using System.Collections;
using System.IO;
+using System.Linq;
namespace Google.Protobuf
{
@@ -140,6 +143,53 @@ namespace Google.Protobuf
return ByteString.AttachBytes(message.ToByteArray());
}
+ /// <summary>
+ /// Checks if all required fields in a message have values set. For proto3 messages, this returns true
+ /// </summary>
+ public static bool IsInitialized(this IMessage message)
+ {
+ if (message.Descriptor.File.Proto.Syntax != "proto2")
+ {
+ return true;
+ }
+
+ return message.Descriptor
+ .Fields
+ .InDeclarationOrder()
+ .All(f =>
+ {
+ if (f.IsMap)
+ {
+ var map = (IDictionary)f.Accessor.GetValue(message);
+ return map.Values.OfType<IMessage>().All(IsInitialized);
+ }
+ else if (f.IsRepeated && f.MessageType != null)
+ {
+ var enumerable = (IEnumerable)f.Accessor.GetValue(message);
+ return enumerable.Cast<IMessage>().All(IsInitialized);
+ }
+ else if (f.MessageType != null)
+ {
+ if (f.Accessor.HasValue(message))
+ {
+ return ((IMessage)f.Accessor.GetValue(message)).IsInitialized();
+ }
+ else
+ {
+ return !f.IsRequired;
+ }
+ }
+ else if (f.IsRequired)
+ {
+ return f.Accessor.HasValue(message);
+ }
+ else
+ {
+ return true;
+ }
+ });
+ }
+
// Implementations allowing unknown fields to be discarded.
internal static void MergeFrom(this IMessage message, byte[] data, bool discardUnknownFields)
{
diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs
index 4d35554a..d3fa6cb1 100644
--- a/csharp/src/Google.Protobuf/MessageParser.cs
+++ b/csharp/src/Google.Protobuf/MessageParser.cs
@@ -69,6 +69,7 @@ namespace Google.Protobuf
{
IMessage message = factory();
message.MergeFrom(data, DiscardUnknownFields);
+ CheckMergedRequiredFields(message);
return message;
}
@@ -83,6 +84,7 @@ namespace Google.Protobuf
{
IMessage message = factory();
message.MergeFrom(data, offset, length, DiscardUnknownFields);
+ CheckMergedRequiredFields(message);
return message;
}
@@ -95,6 +97,7 @@ namespace Google.Protobuf
{
IMessage message = factory();
message.MergeFrom(data, DiscardUnknownFields);
+ CheckMergedRequiredFields(message);
return message;
}
@@ -107,6 +110,7 @@ namespace Google.Protobuf
{
IMessage message = factory();
message.MergeFrom(input, DiscardUnknownFields);
+ CheckMergedRequiredFields(message);
return message;
}
@@ -123,6 +127,7 @@ namespace Google.Protobuf
{
IMessage message = factory();
message.MergeDelimitedFrom(input, DiscardUnknownFields);
+ CheckMergedRequiredFields(message);
return message;
}
@@ -135,6 +140,7 @@ namespace Google.Protobuf
{
IMessage message = factory();
MergeFrom(message, input);
+ CheckMergedRequiredFields(message);
return message;
}
@@ -167,6 +173,12 @@ namespace Google.Protobuf
}
}
+ internal static void CheckMergedRequiredFields(IMessage message)
+ {
+ if (!message.IsInitialized())
+ throw new InvalidOperationException("Parsed message does not contain all required fields");
+ }
+
/// <summary>
/// Creates a new message parser which optionally discards unknown fields when parsing.
/// </summary>
diff --git a/csharp/src/Google.Protobuf/ProtoPreconditions.cs b/csharp/src/Google.Protobuf/ProtoPreconditions.cs
index abaeb9b4..590a3bb2 100644
--- a/csharp/src/Google.Protobuf/ProtoPreconditions.cs
+++ b/csharp/src/Google.Protobuf/ProtoPreconditions.cs
@@ -1,79 +1,79 @@
-#region Copyright notice and license
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#endregion
-
-using System;
-
-namespace Google.Protobuf
-{
- /// <summary>
- /// Helper methods for throwing exceptions when preconditions are not met.
- /// </summary>
- /// <remarks>
- /// This class is used internally and by generated code; it is not particularly
- /// expected to be used from application code, although nothing prevents it
- /// from being used that way.
- /// </remarks>
- public static class ProtoPreconditions
- {
- /// <summary>
- /// Throws an ArgumentNullException if the given value is null, otherwise
- /// return the value to the caller.
- /// </summary>
- public static T CheckNotNull<T>(T value, string name) where T : class
- {
- if (value == null)
- {
- throw new ArgumentNullException(name);
- }
- return value;
- }
-
- /// <summary>
- /// Throws an ArgumentNullException if the given value is null, otherwise
- /// return the value to the caller.
- /// </summary>
- /// <remarks>
- /// This is equivalent to <see cref="CheckNotNull{T}(T, string)"/> but without the type parameter
- /// constraint. In most cases, the constraint is useful to prevent you from calling CheckNotNull
- /// with a value type - but it gets in the way if either you want to use it with a nullable
- /// value type, or you want to use it with an unconstrained type parameter.
- /// </remarks>
- internal static T CheckNotNullUnconstrained<T>(T value, string name)
- {
- if (value == null)
- {
- throw new ArgumentNullException(name);
- }
- return value;
- }
- }
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using System;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Helper methods for throwing exceptions when preconditions are not met.
+ /// </summary>
+ /// <remarks>
+ /// This class is used internally and by generated code; it is not particularly
+ /// expected to be used from application code, although nothing prevents it
+ /// from being used that way.
+ /// </remarks>
+ public static class ProtoPreconditions
+ {
+ /// <summary>
+ /// Throws an ArgumentNullException if the given value is null, otherwise
+ /// return the value to the caller.
+ /// </summary>
+ public static T CheckNotNull<T>(T value, string name) where T : class
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ return value;
+ }
+
+ /// <summary>
+ /// Throws an ArgumentNullException if the given value is null, otherwise
+ /// return the value to the caller.
+ /// </summary>
+ /// <remarks>
+ /// This is equivalent to <see cref="CheckNotNull{T}(T, string)"/> but without the type parameter
+ /// constraint. In most cases, the constraint is useful to prevent you from calling CheckNotNull
+ /// with a value type - but it gets in the way if either you want to use it with a nullable
+ /// value type, or you want to use it with an unconstrained type parameter.
+ /// </remarks>
+ internal static T CheckNotNullUnconstrained<T>(T value, string name)
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ return value;
+ }
+ }
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
index 4cbed33b..0c33e63d 100644
--- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
@@ -351,8 +351,8 @@ namespace Google.Protobuf.Reflection {
enumType_ = other.enumType_.Clone();
service_ = other.service_.Clone();
extension_ = other.extension_.Clone();
- options_ = other.options_ != null ? other.options_.Clone() : null;
- sourceCodeInfo_ = other.sourceCodeInfo_ != null ? other.sourceCodeInfo_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
+ sourceCodeInfo_ = other.HasSourceCodeInfo ? other.sourceCodeInfo_.Clone() : null;
syntax_ = other.syntax_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@@ -364,31 +364,55 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
- private string name_ = "";
+ private readonly static string NameDefaultValue = "";
+
+ private string name_;
/// <summary>
/// file name, relative to root of source tree
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Name {
- get { return name_; }
+ get { return name_ ?? NameDefaultValue; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasName {
+ get { return name_ != null; }
+ }
+ /// <summary>Clears the value of the "name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearName() {
+ name_ = null;
+ }
/// <summary>Field number for the "package" field.</summary>
public const int PackageFieldNumber = 2;
- private string package_ = "";
+ private readonly static string PackageDefaultValue = "";
+
+ private string package_;
/// <summary>
/// e.g. "foo", "foo.bar", etc.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Package {
- get { return package_; }
+ get { return package_ ?? PackageDefaultValue; }
set {
package_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "package" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasPackage {
+ get { return package_ != null; }
+ }
+ /// <summary>Clears the value of the "package" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPackage() {
+ package_ = null;
+ }
/// <summary>Field number for the "dependency" field.</summary>
public const int DependencyFieldNumber = 3;
@@ -483,6 +507,16 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
/// <summary>Field number for the "source_code_info" field.</summary>
public const int SourceCodeInfoFieldNumber = 9;
@@ -500,21 +534,43 @@ namespace Google.Protobuf.Reflection {
sourceCodeInfo_ = value;
}
}
+ /// <summary>Gets whether the source_code_info field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasSourceCodeInfo {
+ get { return sourceCodeInfo_ != null; }
+ }
+ /// <summary>Clears the value of the source_code_info field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearSourceCodeInfo() {
+ sourceCodeInfo_ = null;
+ }
/// <summary>Field number for the "syntax" field.</summary>
public const int SyntaxFieldNumber = 12;
- private string syntax_ = "";
+ private readonly static string SyntaxDefaultValue = "";
+
+ private string syntax_;
/// <summary>
/// The syntax of the proto file.
/// The supported values are "proto2" and "proto3".
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Syntax {
- get { return syntax_; }
+ get { return syntax_ ?? SyntaxDefaultValue; }
set {
syntax_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "syntax" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasSyntax {
+ get { return syntax_ != null; }
+ }
+ /// <summary>Clears the value of the "syntax" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearSyntax() {
+ syntax_ = null;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -547,8 +603,8 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Name.Length != 0) hash ^= Name.GetHashCode();
- if (Package.Length != 0) hash ^= Package.GetHashCode();
+ if (HasName) hash ^= Name.GetHashCode();
+ if (HasPackage) hash ^= Package.GetHashCode();
hash ^= dependency_.GetHashCode();
hash ^= publicDependency_.GetHashCode();
hash ^= weakDependency_.GetHashCode();
@@ -556,9 +612,9 @@ namespace Google.Protobuf.Reflection {
hash ^= enumType_.GetHashCode();
hash ^= service_.GetHashCode();
hash ^= extension_.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
- if (sourceCodeInfo_ != null) hash ^= SourceCodeInfo.GetHashCode();
- if (Syntax.Length != 0) hash ^= Syntax.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
+ if (HasSourceCodeInfo) hash ^= SourceCodeInfo.GetHashCode();
+ if (HasSyntax) hash ^= Syntax.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -572,11 +628,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Name.Length != 0) {
+ if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
}
- if (Package.Length != 0) {
+ if (HasPackage) {
output.WriteRawTag(18);
output.WriteString(Package);
}
@@ -585,17 +641,17 @@ namespace Google.Protobuf.Reflection {
enumType_.WriteTo(output, _repeated_enumType_codec);
service_.WriteTo(output, _repeated_service_codec);
extension_.WriteTo(output, _repeated_extension_codec);
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(66);
output.WriteMessage(Options);
}
- if (sourceCodeInfo_ != null) {
+ if (HasSourceCodeInfo) {
output.WriteRawTag(74);
output.WriteMessage(SourceCodeInfo);
}
publicDependency_.WriteTo(output, _repeated_publicDependency_codec);
weakDependency_.WriteTo(output, _repeated_weakDependency_codec);
- if (Syntax.Length != 0) {
+ if (HasSyntax) {
output.WriteRawTag(98);
output.WriteString(Syntax);
}
@@ -607,10 +663,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Name.Length != 0) {
+ if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
- if (Package.Length != 0) {
+ if (HasPackage) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Package);
}
size += dependency_.CalculateSize(_repeated_dependency_codec);
@@ -620,13 +676,13 @@ namespace Google.Protobuf.Reflection {
size += enumType_.CalculateSize(_repeated_enumType_codec);
size += service_.CalculateSize(_repeated_service_codec);
size += extension_.CalculateSize(_repeated_extension_codec);
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
- if (sourceCodeInfo_ != null) {
+ if (HasSourceCodeInfo) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceCodeInfo);
}
- if (Syntax.Length != 0) {
+ if (HasSyntax) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Syntax);
}
if (_unknownFields != null) {
@@ -640,10 +696,10 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Name.Length != 0) {
+ if (other.HasName) {
Name = other.Name;
}
- if (other.Package.Length != 0) {
+ if (other.HasPackage) {
Package = other.Package;
}
dependency_.Add(other.dependency_);
@@ -653,19 +709,19 @@ namespace Google.Protobuf.Reflection {
enumType_.Add(other.enumType_);
service_.Add(other.service_);
extension_.Add(other.extension_);
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.FileOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.FileOptions();
}
Options.MergeFrom(other.Options);
}
- if (other.sourceCodeInfo_ != null) {
- if (sourceCodeInfo_ == null) {
- sourceCodeInfo_ = new global::Google.Protobuf.Reflection.SourceCodeInfo();
+ if (other.HasSourceCodeInfo) {
+ if (!HasSourceCodeInfo) {
+ SourceCodeInfo = new global::Google.Protobuf.Reflection.SourceCodeInfo();
}
SourceCodeInfo.MergeFrom(other.SourceCodeInfo);
}
- if (other.Syntax.Length != 0) {
+ if (other.HasSyntax) {
Syntax = other.Syntax;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
@@ -708,17 +764,17 @@ namespace Google.Protobuf.Reflection {
break;
}
case 66: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.FileOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.FileOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
case 74: {
- if (sourceCodeInfo_ == null) {
- sourceCodeInfo_ = new global::Google.Protobuf.Reflection.SourceCodeInfo();
+ if (!HasSourceCodeInfo) {
+ SourceCodeInfo = new global::Google.Protobuf.Reflection.SourceCodeInfo();
}
- input.ReadMessage(sourceCodeInfo_);
+ input.ReadMessage(SourceCodeInfo);
break;
}
case 82:
@@ -776,7 +832,7 @@ namespace Google.Protobuf.Reflection {
enumType_ = other.enumType_.Clone();
extensionRange_ = other.extensionRange_.Clone();
oneofDecl_ = other.oneofDecl_.Clone();
- options_ = other.options_ != null ? other.options_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
reservedRange_ = other.reservedRange_.Clone();
reservedName_ = other.reservedName_.Clone();
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -789,14 +845,26 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
- private string name_ = "";
+ private readonly static string NameDefaultValue = "";
+
+ private string name_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Name {
- get { return name_; }
+ get { return name_ ?? NameDefaultValue; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasName {
+ get { return name_ != null; }
+ }
+ /// <summary>Clears the value of the "name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearName() {
+ name_ = null;
+ }
/// <summary>Field number for the "field" field.</summary>
public const int FieldFieldNumber = 2;
@@ -868,6 +936,16 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
/// <summary>Field number for the "reserved_range" field.</summary>
public const int ReservedRangeFieldNumber = 9;
@@ -922,14 +1000,14 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (HasName) hash ^= Name.GetHashCode();
hash ^= field_.GetHashCode();
hash ^= extension_.GetHashCode();
hash ^= nestedType_.GetHashCode();
hash ^= enumType_.GetHashCode();
hash ^= extensionRange_.GetHashCode();
hash ^= oneofDecl_.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
hash ^= reservedRange_.GetHashCode();
hash ^= reservedName_.GetHashCode();
if (_unknownFields != null) {
@@ -945,7 +1023,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Name.Length != 0) {
+ if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
}
@@ -954,7 +1032,7 @@ namespace Google.Protobuf.Reflection {
enumType_.WriteTo(output, _repeated_enumType_codec);
extensionRange_.WriteTo(output, _repeated_extensionRange_codec);
extension_.WriteTo(output, _repeated_extension_codec);
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(58);
output.WriteMessage(Options);
}
@@ -969,7 +1047,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Name.Length != 0) {
+ if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
size += field_.CalculateSize(_repeated_field_codec);
@@ -978,7 +1056,7 @@ namespace Google.Protobuf.Reflection {
size += enumType_.CalculateSize(_repeated_enumType_codec);
size += extensionRange_.CalculateSize(_repeated_extensionRange_codec);
size += oneofDecl_.CalculateSize(_repeated_oneofDecl_codec);
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
size += reservedRange_.CalculateSize(_repeated_reservedRange_codec);
@@ -994,7 +1072,7 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Name.Length != 0) {
+ if (other.HasName) {
Name = other.Name;
}
field_.Add(other.field_);
@@ -1003,9 +1081,9 @@ namespace Google.Protobuf.Reflection {
enumType_.Add(other.enumType_);
extensionRange_.Add(other.extensionRange_);
oneofDecl_.Add(other.oneofDecl_);
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.MessageOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.MessageOptions();
}
Options.MergeFrom(other.Options);
}
@@ -1047,10 +1125,10 @@ namespace Google.Protobuf.Reflection {
break;
}
case 58: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.MessageOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.MessageOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
case 66: {
@@ -1076,6 +1154,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class ExtensionRange : pb::IMessage<ExtensionRange> {
private static readonly pb::MessageParser<ExtensionRange> _parser = new pb::MessageParser<ExtensionRange>(() => new ExtensionRange());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<ExtensionRange> Parser { get { return _parser; } }
@@ -1098,9 +1177,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public ExtensionRange(ExtensionRange other) : this() {
+ _hasBits0 = other._hasBits0;
start_ = other.start_;
end_ = other.end_;
- options_ = other.options_ != null ? other.options_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@@ -1111,25 +1191,51 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "start" field.</summary>
public const int StartFieldNumber = 1;
+ private readonly static int StartDefaultValue = 0;
+
private int start_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int Start {
- get { return start_; }
+ get { if ((_hasBits0 & 1) != 0) { return start_; } else { return StartDefaultValue; } }
set {
+ _hasBits0 |= 1;
start_ = value;
}
}
+ /// <summary>Gets whether the "start" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasStart {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "start" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearStart() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "end" field.</summary>
public const int EndFieldNumber = 2;
+ private readonly static int EndDefaultValue = 0;
+
private int end_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int End {
- get { return end_; }
+ get { if ((_hasBits0 & 2) != 0) { return end_; } else { return EndDefaultValue; } }
set {
+ _hasBits0 |= 2;
end_ = value;
}
}
+ /// <summary>Gets whether the "end" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasEnd {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "end" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearEnd() {
+ _hasBits0 &= ~2;
+ }
/// <summary>Field number for the "options" field.</summary>
public const int OptionsFieldNumber = 3;
@@ -1141,6 +1247,16 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -1164,9 +1280,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Start != 0) hash ^= Start.GetHashCode();
- if (End != 0) hash ^= End.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
+ if (HasStart) hash ^= Start.GetHashCode();
+ if (HasEnd) hash ^= End.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -1180,15 +1296,15 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Start != 0) {
+ if (HasStart) {
output.WriteRawTag(8);
output.WriteInt32(Start);
}
- if (End != 0) {
+ if (HasEnd) {
output.WriteRawTag(16);
output.WriteInt32(End);
}
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(26);
output.WriteMessage(Options);
}
@@ -1200,13 +1316,13 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Start != 0) {
+ if (HasStart) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Start);
}
- if (End != 0) {
+ if (HasEnd) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(End);
}
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@@ -1220,15 +1336,15 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Start != 0) {
+ if (other.HasStart) {
Start = other.Start;
}
- if (other.End != 0) {
+ if (other.HasEnd) {
End = other.End;
}
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.ExtensionRangeOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.ExtensionRangeOptions();
}
Options.MergeFrom(other.Options);
}
@@ -1252,10 +1368,10 @@ namespace Google.Protobuf.Reflection {
break;
}
case 26: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.ExtensionRangeOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.ExtensionRangeOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
}
@@ -1272,6 +1388,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class ReservedRange : pb::IMessage<ReservedRange> {
private static readonly pb::MessageParser<ReservedRange> _parser = new pb::MessageParser<ReservedRange>(() => new ReservedRange());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<ReservedRange> Parser { get { return _parser; } }
@@ -1294,6 +1411,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public ReservedRange(ReservedRange other) : this() {
+ _hasBits0 = other._hasBits0;
start_ = other.start_;
end_ = other.end_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -1306,31 +1424,57 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "start" field.</summary>
public const int StartFieldNumber = 1;
+ private readonly static int StartDefaultValue = 0;
+
private int start_;
/// <summary>
/// Inclusive.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int Start {
- get { return start_; }
+ get { if ((_hasBits0 & 1) != 0) { return start_; } else { return StartDefaultValue; } }
set {
+ _hasBits0 |= 1;
start_ = value;
}
}
+ /// <summary>Gets whether the "start" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasStart {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "start" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearStart() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "end" field.</summary>
public const int EndFieldNumber = 2;
+ private readonly static int EndDefaultValue = 0;
+
private int end_;
/// <summary>
/// Exclusive.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int End {
- get { return end_; }
+ get { if ((_hasBits0 & 2) != 0) { return end_; } else { return EndDefaultValue; } }
set {
+ _hasBits0 |= 2;
end_ = value;
}
}
+ /// <summary>Gets whether the "end" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasEnd {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "end" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearEnd() {
+ _hasBits0 &= ~2;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -1353,8 +1497,8 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Start != 0) hash ^= Start.GetHashCode();
- if (End != 0) hash ^= End.GetHashCode();
+ if (HasStart) hash ^= Start.GetHashCode();
+ if (HasEnd) hash ^= End.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -1368,11 +1512,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Start != 0) {
+ if (HasStart) {
output.WriteRawTag(8);
output.WriteInt32(Start);
}
- if (End != 0) {
+ if (HasEnd) {
output.WriteRawTag(16);
output.WriteInt32(End);
}
@@ -1384,10 +1528,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Start != 0) {
+ if (HasStart) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Start);
}
- if (End != 0) {
+ if (HasEnd) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(End);
}
if (_unknownFields != null) {
@@ -1401,10 +1545,10 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Start != 0) {
+ if (other.HasStart) {
Start = other.Start;
}
- if (other.End != 0) {
+ if (other.HasEnd) {
End = other.End;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
@@ -1567,6 +1711,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class FieldDescriptorProto : pb::IMessage<FieldDescriptorProto> {
private static readonly pb::MessageParser<FieldDescriptorProto> _parser = new pb::MessageParser<FieldDescriptorProto>(() => new FieldDescriptorProto());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<FieldDescriptorProto> Parser { get { return _parser; } }
@@ -1589,6 +1734,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public FieldDescriptorProto(FieldDescriptorProto other) : this() {
+ _hasBits0 = other._hasBits0;
name_ = other.name_;
number_ = other.number_;
label_ = other.label_;
@@ -1598,7 +1744,7 @@ namespace Google.Protobuf.Reflection {
defaultValue_ = other.defaultValue_;
oneofIndex_ = other.oneofIndex_;
jsonName_ = other.jsonName_;
- options_ = other.options_ != null ? other.options_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@@ -1609,55 +1755,108 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
- private string name_ = "";
+ private readonly static string NameDefaultValue = "";
+
+ private string name_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Name {
- get { return name_; }
+ get { return name_ ?? NameDefaultValue; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasName {
+ get { return name_ != null; }
+ }
+ /// <summary>Clears the value of the "name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearName() {
+ name_ = null;
+ }
/// <summary>Field number for the "number" field.</summary>
public const int NumberFieldNumber = 3;
+ private readonly static int NumberDefaultValue = 0;
+
private int number_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int Number {
- get { return number_; }
+ get { if ((_hasBits0 & 1) != 0) { return number_; } else { return NumberDefaultValue; } }
set {
+ _hasBits0 |= 1;
number_ = value;
}
}
+ /// <summary>Gets whether the "number" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasNumber {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "number" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearNumber() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "label" field.</summary>
public const int LabelFieldNumber = 4;
- private global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label label_ = 0;
+ private readonly static global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label LabelDefaultValue = global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label.Optional;
+
+ private global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label label_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label Label {
- get { return label_; }
+ get { if ((_hasBits0 & 2) != 0) { return label_; } else { return LabelDefaultValue; } }
set {
+ _hasBits0 |= 2;
label_ = value;
}
}
+ /// <summary>Gets whether the "label" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasLabel {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "label" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearLabel() {
+ _hasBits0 &= ~2;
+ }
/// <summary>Field number for the "type" field.</summary>
public const int TypeFieldNumber = 5;
- private global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type type_ = 0;
+ private readonly static global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type TypeDefaultValue = global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type.Double;
+
+ private global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type type_;
/// <summary>
/// If type_name is set, this need not be set. If both this and type_name
/// are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type Type {
- get { return type_; }
+ get { if ((_hasBits0 & 4) != 0) { return type_; } else { return TypeDefaultValue; } }
set {
+ _hasBits0 |= 4;
type_ = value;
}
}
+ /// <summary>Gets whether the "type" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasType {
+ get { return (_hasBits0 & 4) != 0; }
+ }
+ /// <summary>Clears the value of the "type" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearType() {
+ _hasBits0 &= ~4;
+ }
/// <summary>Field number for the "type_name" field.</summary>
public const int TypeNameFieldNumber = 6;
- private string typeName_ = "";
+ private readonly static string TypeNameDefaultValue = "";
+
+ private string typeName_;
/// <summary>
/// For message and enum types, this is the name of the type. If the name
/// starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
@@ -1667,30 +1866,54 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string TypeName {
- get { return typeName_; }
+ get { return typeName_ ?? TypeNameDefaultValue; }
set {
typeName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "type_name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasTypeName {
+ get { return typeName_ != null; }
+ }
+ /// <summary>Clears the value of the "type_name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearTypeName() {
+ typeName_ = null;
+ }
/// <summary>Field number for the "extendee" field.</summary>
public const int ExtendeeFieldNumber = 2;
- private string extendee_ = "";
+ private readonly static string ExtendeeDefaultValue = "";
+
+ private string extendee_;
/// <summary>
/// For extensions, this is the name of the type being extended. It is
/// resolved in the same manner as type_name.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Extendee {
- get { return extendee_; }
+ get { return extendee_ ?? ExtendeeDefaultValue; }
set {
extendee_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "extendee" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasExtendee {
+ get { return extendee_ != null; }
+ }
+ /// <summary>Clears the value of the "extendee" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearExtendee() {
+ extendee_ = null;
+ }
/// <summary>Field number for the "default_value" field.</summary>
public const int DefaultValueFieldNumber = 7;
- private string defaultValue_ = "";
+ private readonly static string DefaultValueDefaultValue = "";
+
+ private string defaultValue_;
/// <summary>
/// For numeric types, contains the original text representation of the value.
/// For booleans, "true" or "false".
@@ -1700,14 +1923,26 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string DefaultValue {
- get { return defaultValue_; }
+ get { return defaultValue_ ?? DefaultValueDefaultValue; }
set {
defaultValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "default_value" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDefaultValue {
+ get { return defaultValue_ != null; }
+ }
+ /// <summary>Clears the value of the "default_value" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDefaultValue() {
+ defaultValue_ = null;
+ }
/// <summary>Field number for the "oneof_index" field.</summary>
public const int OneofIndexFieldNumber = 9;
+ private readonly static int OneofIndexDefaultValue = 0;
+
private int oneofIndex_;
/// <summary>
/// If set, gives the index of a oneof in the containing type's oneof_decl
@@ -1715,15 +1950,28 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int OneofIndex {
- get { return oneofIndex_; }
+ get { if ((_hasBits0 & 8) != 0) { return oneofIndex_; } else { return OneofIndexDefaultValue; } }
set {
+ _hasBits0 |= 8;
oneofIndex_ = value;
}
}
+ /// <summary>Gets whether the "oneof_index" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOneofIndex {
+ get { return (_hasBits0 & 8) != 0; }
+ }
+ /// <summary>Clears the value of the "oneof_index" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOneofIndex() {
+ _hasBits0 &= ~8;
+ }
/// <summary>Field number for the "json_name" field.</summary>
public const int JsonNameFieldNumber = 10;
- private string jsonName_ = "";
+ private readonly static string JsonNameDefaultValue = "";
+
+ private string jsonName_;
/// <summary>
/// JSON name of this field. The value is set by protocol compiler. If the
/// user has set a "json_name" option on this field, that option's value
@@ -1732,11 +1980,21 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string JsonName {
- get { return jsonName_; }
+ get { return jsonName_ ?? JsonNameDefaultValue; }
set {
jsonName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "json_name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasJsonName {
+ get { return jsonName_ != null; }
+ }
+ /// <summary>Clears the value of the "json_name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearJsonName() {
+ jsonName_ = null;
+ }
/// <summary>Field number for the "options" field.</summary>
public const int OptionsFieldNumber = 8;
@@ -1748,6 +2006,16 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -1778,16 +2046,16 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Name.Length != 0) hash ^= Name.GetHashCode();
- if (Number != 0) hash ^= Number.GetHashCode();
- if (Label != 0) hash ^= Label.GetHashCode();
- if (Type != 0) hash ^= Type.GetHashCode();
- if (TypeName.Length != 0) hash ^= TypeName.GetHashCode();
- if (Extendee.Length != 0) hash ^= Extendee.GetHashCode();
- if (DefaultValue.Length != 0) hash ^= DefaultValue.GetHashCode();
- if (OneofIndex != 0) hash ^= OneofIndex.GetHashCode();
- if (JsonName.Length != 0) hash ^= JsonName.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
+ if (HasName) hash ^= Name.GetHashCode();
+ if (HasNumber) hash ^= Number.GetHashCode();
+ if (HasLabel) hash ^= Label.GetHashCode();
+ if (HasType) hash ^= Type.GetHashCode();
+ if (HasTypeName) hash ^= TypeName.GetHashCode();
+ if (HasExtendee) hash ^= Extendee.GetHashCode();
+ if (HasDefaultValue) hash ^= DefaultValue.GetHashCode();
+ if (HasOneofIndex) hash ^= OneofIndex.GetHashCode();
+ if (HasJsonName) hash ^= JsonName.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -1801,43 +2069,43 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Name.Length != 0) {
+ if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
}
- if (Extendee.Length != 0) {
+ if (HasExtendee) {
output.WriteRawTag(18);
output.WriteString(Extendee);
}
- if (Number != 0) {
+ if (HasNumber) {
output.WriteRawTag(24);
output.WriteInt32(Number);
}
- if (Label != 0) {
+ if (HasLabel) {
output.WriteRawTag(32);
output.WriteEnum((int) Label);
}
- if (Type != 0) {
+ if (HasType) {
output.WriteRawTag(40);
output.WriteEnum((int) Type);
}
- if (TypeName.Length != 0) {
+ if (HasTypeName) {
output.WriteRawTag(50);
output.WriteString(TypeName);
}
- if (DefaultValue.Length != 0) {
+ if (HasDefaultValue) {
output.WriteRawTag(58);
output.WriteString(DefaultValue);
}
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(66);
output.WriteMessage(Options);
}
- if (OneofIndex != 0) {
+ if (HasOneofIndex) {
output.WriteRawTag(72);
output.WriteInt32(OneofIndex);
}
- if (JsonName.Length != 0) {
+ if (HasJsonName) {
output.WriteRawTag(82);
output.WriteString(JsonName);
}
@@ -1849,34 +2117,34 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Name.Length != 0) {
+ if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
- if (Number != 0) {
+ if (HasNumber) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number);
}
- if (Label != 0) {
+ if (HasLabel) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Label);
}
- if (Type != 0) {
+ if (HasType) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type);
}
- if (TypeName.Length != 0) {
+ if (HasTypeName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(TypeName);
}
- if (Extendee.Length != 0) {
+ if (HasExtendee) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Extendee);
}
- if (DefaultValue.Length != 0) {
+ if (HasDefaultValue) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(DefaultValue);
}
- if (OneofIndex != 0) {
+ if (HasOneofIndex) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(OneofIndex);
}
- if (JsonName.Length != 0) {
+ if (HasJsonName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonName);
}
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@@ -1890,36 +2158,36 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Name.Length != 0) {
+ if (other.HasName) {
Name = other.Name;
}
- if (other.Number != 0) {
+ if (other.HasNumber) {
Number = other.Number;
}
- if (other.Label != 0) {
+ if (other.HasLabel) {
Label = other.Label;
}
- if (other.Type != 0) {
+ if (other.HasType) {
Type = other.Type;
}
- if (other.TypeName.Length != 0) {
+ if (other.HasTypeName) {
TypeName = other.TypeName;
}
- if (other.Extendee.Length != 0) {
+ if (other.HasExtendee) {
Extendee = other.Extendee;
}
- if (other.DefaultValue.Length != 0) {
+ if (other.HasDefaultValue) {
DefaultValue = other.DefaultValue;
}
- if (other.OneofIndex != 0) {
+ if (other.HasOneofIndex) {
OneofIndex = other.OneofIndex;
}
- if (other.JsonName.Length != 0) {
+ if (other.HasJsonName) {
JsonName = other.JsonName;
}
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.FieldOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.FieldOptions();
}
Options.MergeFrom(other.Options);
}
@@ -1947,11 +2215,11 @@ namespace Google.Protobuf.Reflection {
break;
}
case 32: {
- label_ = (global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) input.ReadEnum();
+ Label = (global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) input.ReadEnum();
break;
}
case 40: {
- type_ = (global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type) input.ReadEnum();
+ Type = (global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type) input.ReadEnum();
break;
}
case 50: {
@@ -1963,10 +2231,10 @@ namespace Google.Protobuf.Reflection {
break;
}
case 66: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.FieldOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.FieldOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
case 72: {
@@ -2079,7 +2347,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public OneofDescriptorProto(OneofDescriptorProto other) : this() {
name_ = other.name_;
- options_ = other.options_ != null ? other.options_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@@ -2090,14 +2358,26 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
- private string name_ = "";
+ private readonly static string NameDefaultValue = "";
+
+ private string name_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Name {
- get { return name_; }
+ get { return name_ ?? NameDefaultValue; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasName {
+ get { return name_ != null; }
+ }
+ /// <summary>Clears the value of the "name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearName() {
+ name_ = null;
+ }
/// <summary>Field number for the "options" field.</summary>
public const int OptionsFieldNumber = 2;
@@ -2109,6 +2389,16 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -2131,8 +2421,8 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Name.Length != 0) hash ^= Name.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
+ if (HasName) hash ^= Name.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -2146,11 +2436,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Name.Length != 0) {
+ if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
}
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(18);
output.WriteMessage(Options);
}
@@ -2162,10 +2452,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Name.Length != 0) {
+ if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@@ -2179,12 +2469,12 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Name.Length != 0) {
+ if (other.HasName) {
Name = other.Name;
}
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.OneofOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.OneofOptions();
}
Options.MergeFrom(other.Options);
}
@@ -2204,10 +2494,10 @@ namespace Google.Protobuf.Reflection {
break;
}
case 18: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.OneofOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.OneofOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
}
@@ -2246,7 +2536,7 @@ namespace Google.Protobuf.Reflection {
public EnumDescriptorProto(EnumDescriptorProto other) : this() {
name_ = other.name_;
value_ = other.value_.Clone();
- options_ = other.options_ != null ? other.options_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
reservedRange_ = other.reservedRange_.Clone();
reservedName_ = other.reservedName_.Clone();
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -2259,14 +2549,26 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
- private string name_ = "";
+ private readonly static string NameDefaultValue = "";
+
+ private string name_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Name {
- get { return name_; }
+ get { return name_ ?? NameDefaultValue; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasName {
+ get { return name_ != null; }
+ }
+ /// <summary>Clears the value of the "name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearName() {
+ name_ = null;
+ }
/// <summary>Field number for the "value" field.</summary>
public const int ValueFieldNumber = 2;
@@ -2288,6 +2590,16 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
/// <summary>Field number for the "reserved_range" field.</summary>
public const int ReservedRangeFieldNumber = 4;
@@ -2342,9 +2654,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (HasName) hash ^= Name.GetHashCode();
hash ^= value_.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
hash ^= reservedRange_.GetHashCode();
hash ^= reservedName_.GetHashCode();
if (_unknownFields != null) {
@@ -2360,12 +2672,12 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Name.Length != 0) {
+ if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
}
value_.WriteTo(output, _repeated_value_codec);
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(26);
output.WriteMessage(Options);
}
@@ -2379,11 +2691,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Name.Length != 0) {
+ if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
size += value_.CalculateSize(_repeated_value_codec);
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
size += reservedRange_.CalculateSize(_repeated_reservedRange_codec);
@@ -2399,13 +2711,13 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Name.Length != 0) {
+ if (other.HasName) {
Name = other.Name;
}
value_.Add(other.value_);
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.EnumOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.EnumOptions();
}
Options.MergeFrom(other.Options);
}
@@ -2431,10 +2743,10 @@ namespace Google.Protobuf.Reflection {
break;
}
case 26: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.EnumOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.EnumOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
case 34: {
@@ -2464,6 +2776,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class EnumReservedRange : pb::IMessage<EnumReservedRange> {
private static readonly pb::MessageParser<EnumReservedRange> _parser = new pb::MessageParser<EnumReservedRange>(() => new EnumReservedRange());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<EnumReservedRange> Parser { get { return _parser; } }
@@ -2486,6 +2799,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public EnumReservedRange(EnumReservedRange other) : this() {
+ _hasBits0 = other._hasBits0;
start_ = other.start_;
end_ = other.end_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -2498,31 +2812,57 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "start" field.</summary>
public const int StartFieldNumber = 1;
+ private readonly static int StartDefaultValue = 0;
+
private int start_;
/// <summary>
/// Inclusive.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int Start {
- get { return start_; }
+ get { if ((_hasBits0 & 1) != 0) { return start_; } else { return StartDefaultValue; } }
set {
+ _hasBits0 |= 1;
start_ = value;
}
}
+ /// <summary>Gets whether the "start" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasStart {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "start" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearStart() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "end" field.</summary>
public const int EndFieldNumber = 2;
+ private readonly static int EndDefaultValue = 0;
+
private int end_;
/// <summary>
/// Inclusive.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int End {
- get { return end_; }
+ get { if ((_hasBits0 & 2) != 0) { return end_; } else { return EndDefaultValue; } }
set {
+ _hasBits0 |= 2;
end_ = value;
}
}
+ /// <summary>Gets whether the "end" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasEnd {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "end" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearEnd() {
+ _hasBits0 &= ~2;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -2545,8 +2885,8 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Start != 0) hash ^= Start.GetHashCode();
- if (End != 0) hash ^= End.GetHashCode();
+ if (HasStart) hash ^= Start.GetHashCode();
+ if (HasEnd) hash ^= End.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -2560,11 +2900,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Start != 0) {
+ if (HasStart) {
output.WriteRawTag(8);
output.WriteInt32(Start);
}
- if (End != 0) {
+ if (HasEnd) {
output.WriteRawTag(16);
output.WriteInt32(End);
}
@@ -2576,10 +2916,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Start != 0) {
+ if (HasStart) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Start);
}
- if (End != 0) {
+ if (HasEnd) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(End);
}
if (_unknownFields != null) {
@@ -2593,10 +2933,10 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Start != 0) {
+ if (other.HasStart) {
Start = other.Start;
}
- if (other.End != 0) {
+ if (other.HasEnd) {
End = other.End;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
@@ -2635,6 +2975,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class EnumValueDescriptorProto : pb::IMessage<EnumValueDescriptorProto> {
private static readonly pb::MessageParser<EnumValueDescriptorProto> _parser = new pb::MessageParser<EnumValueDescriptorProto>(() => new EnumValueDescriptorProto());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<EnumValueDescriptorProto> Parser { get { return _parser; } }
@@ -2657,9 +2998,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public EnumValueDescriptorProto(EnumValueDescriptorProto other) : this() {
+ _hasBits0 = other._hasBits0;
name_ = other.name_;
number_ = other.number_;
- options_ = other.options_ != null ? other.options_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@@ -2670,25 +3012,50 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
- private string name_ = "";
+ private readonly static string NameDefaultValue = "";
+
+ private string name_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Name {
- get { return name_; }
+ get { return name_ ?? NameDefaultValue; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasName {
+ get { return name_ != null; }
+ }
+ /// <summary>Clears the value of the "name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearName() {
+ name_ = null;
+ }
/// <summary>Field number for the "number" field.</summary>
public const int NumberFieldNumber = 2;
+ private readonly static int NumberDefaultValue = 0;
+
private int number_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int Number {
- get { return number_; }
+ get { if ((_hasBits0 & 1) != 0) { return number_; } else { return NumberDefaultValue; } }
set {
+ _hasBits0 |= 1;
number_ = value;
}
}
+ /// <summary>Gets whether the "number" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasNumber {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "number" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearNumber() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "options" field.</summary>
public const int OptionsFieldNumber = 3;
@@ -2700,6 +3067,16 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -2723,9 +3100,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Name.Length != 0) hash ^= Name.GetHashCode();
- if (Number != 0) hash ^= Number.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
+ if (HasName) hash ^= Name.GetHashCode();
+ if (HasNumber) hash ^= Number.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -2739,15 +3116,15 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Name.Length != 0) {
+ if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
}
- if (Number != 0) {
+ if (HasNumber) {
output.WriteRawTag(16);
output.WriteInt32(Number);
}
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(26);
output.WriteMessage(Options);
}
@@ -2759,13 +3136,13 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Name.Length != 0) {
+ if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
- if (Number != 0) {
+ if (HasNumber) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number);
}
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@@ -2779,15 +3156,15 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Name.Length != 0) {
+ if (other.HasName) {
Name = other.Name;
}
- if (other.Number != 0) {
+ if (other.HasNumber) {
Number = other.Number;
}
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.EnumValueOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.EnumValueOptions();
}
Options.MergeFrom(other.Options);
}
@@ -2811,10 +3188,10 @@ namespace Google.Protobuf.Reflection {
break;
}
case 26: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.EnumValueOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.EnumValueOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
}
@@ -2853,7 +3230,7 @@ namespace Google.Protobuf.Reflection {
public ServiceDescriptorProto(ServiceDescriptorProto other) : this() {
name_ = other.name_;
method_ = other.method_.Clone();
- options_ = other.options_ != null ? other.options_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@@ -2864,14 +3241,26 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
- private string name_ = "";
+ private readonly static string NameDefaultValue = "";
+
+ private string name_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Name {
- get { return name_; }
+ get { return name_ ?? NameDefaultValue; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasName {
+ get { return name_ != null; }
+ }
+ /// <summary>Clears the value of the "name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearName() {
+ name_ = null;
+ }
/// <summary>Field number for the "method" field.</summary>
public const int MethodFieldNumber = 2;
@@ -2893,6 +3282,16 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -2916,9 +3315,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (HasName) hash ^= Name.GetHashCode();
hash ^= method_.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -2932,12 +3331,12 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Name.Length != 0) {
+ if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
}
method_.WriteTo(output, _repeated_method_codec);
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(26);
output.WriteMessage(Options);
}
@@ -2949,11 +3348,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Name.Length != 0) {
+ if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
size += method_.CalculateSize(_repeated_method_codec);
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@@ -2967,13 +3366,13 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Name.Length != 0) {
+ if (other.HasName) {
Name = other.Name;
}
method_.Add(other.method_);
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.ServiceOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.ServiceOptions();
}
Options.MergeFrom(other.Options);
}
@@ -2997,10 +3396,10 @@ namespace Google.Protobuf.Reflection {
break;
}
case 26: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.ServiceOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.ServiceOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
}
@@ -3015,6 +3414,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class MethodDescriptorProto : pb::IMessage<MethodDescriptorProto> {
private static readonly pb::MessageParser<MethodDescriptorProto> _parser = new pb::MessageParser<MethodDescriptorProto>(() => new MethodDescriptorProto());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<MethodDescriptorProto> Parser { get { return _parser; } }
@@ -3037,10 +3437,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public MethodDescriptorProto(MethodDescriptorProto other) : this() {
+ _hasBits0 = other._hasBits0;
name_ = other.name_;
inputType_ = other.inputType_;
outputType_ = other.outputType_;
- options_ = other.options_ != null ? other.options_.Clone() : null;
+ options_ = other.HasOptions ? other.options_.Clone() : null;
clientStreaming_ = other.clientStreaming_;
serverStreaming_ = other.serverStreaming_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -3053,40 +3454,76 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
- private string name_ = "";
+ private readonly static string NameDefaultValue = "";
+
+ private string name_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string Name {
- get { return name_; }
+ get { return name_ ?? NameDefaultValue; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasName {
+ get { return name_ != null; }
+ }
+ /// <summary>Clears the value of the "name" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearName() {
+ name_ = null;
+ }
/// <summary>Field number for the "input_type" field.</summary>
public const int InputTypeFieldNumber = 2;
- private string inputType_ = "";
+ private readonly static string InputTypeDefaultValue = "";
+
+ private string inputType_;
/// <summary>
/// Input and output type names. These are resolved in the same way as
/// FieldDescriptorProto.type_name, but must refer to a message type.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string InputType {
- get { return inputType_; }
+ get { return inputType_ ?? InputTypeDefaultValue; }
set {
inputType_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "input_type" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasInputType {
+ get { return inputType_ != null; }
+ }
+ /// <summary>Clears the value of the "input_type" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearInputType() {
+ inputType_ = null;
+ }
/// <summary>Field number for the "output_type" field.</summary>
public const int OutputTypeFieldNumber = 3;
- private string outputType_ = "";
+ private readonly static string OutputTypeDefaultValue = "";
+
+ private string outputType_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string OutputType {
- get { return outputType_; }
+ get { return outputType_ ?? OutputTypeDefaultValue; }
set {
outputType_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "output_type" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOutputType {
+ get { return outputType_ != null; }
+ }
+ /// <summary>Clears the value of the "output_type" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOutputType() {
+ outputType_ = null;
+ }
/// <summary>Field number for the "options" field.</summary>
public const int OptionsFieldNumber = 4;
@@ -3098,34 +3535,70 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
+ /// <summary>Gets whether the options field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptions {
+ get { return options_ != null; }
+ }
+ /// <summary>Clears the value of the options field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptions() {
+ options_ = null;
+ }
/// <summary>Field number for the "client_streaming" field.</summary>
public const int ClientStreamingFieldNumber = 5;
+ private readonly static bool ClientStreamingDefaultValue = false;
+
private bool clientStreaming_;
/// <summary>
/// Identifies if client streams multiple client messages
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool ClientStreaming {
- get { return clientStreaming_; }
+ get { if ((_hasBits0 & 1) != 0) { return clientStreaming_; } else { return ClientStreamingDefaultValue; } }
set {
+ _hasBits0 |= 1;
clientStreaming_ = value;
}
}
+ /// <summary>Gets whether the "client_streaming" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasClientStreaming {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "client_streaming" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearClientStreaming() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "server_streaming" field.</summary>
public const int ServerStreamingFieldNumber = 6;
+ private readonly static bool ServerStreamingDefaultValue = false;
+
private bool serverStreaming_;
/// <summary>
/// Identifies if server streams multiple server messages
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool ServerStreaming {
- get { return serverStreaming_; }
+ get { if ((_hasBits0 & 2) != 0) { return serverStreaming_; } else { return ServerStreamingDefaultValue; } }
set {
+ _hasBits0 |= 2;
serverStreaming_ = value;
}
}
+ /// <summary>Gets whether the "server_streaming" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasServerStreaming {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "server_streaming" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearServerStreaming() {
+ _hasBits0 &= ~2;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -3152,12 +3625,12 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Name.Length != 0) hash ^= Name.GetHashCode();
- if (InputType.Length != 0) hash ^= InputType.GetHashCode();
- if (OutputType.Length != 0) hash ^= OutputType.GetHashCode();
- if (options_ != null) hash ^= Options.GetHashCode();
- if (ClientStreaming != false) hash ^= ClientStreaming.GetHashCode();
- if (ServerStreaming != false) hash ^= ServerStreaming.GetHashCode();
+ if (HasName) hash ^= Name.GetHashCode();
+ if (HasInputType) hash ^= InputType.GetHashCode();
+ if (HasOutputType) hash ^= OutputType.GetHashCode();
+ if (HasOptions) hash ^= Options.GetHashCode();
+ if (HasClientStreaming) hash ^= ClientStreaming.GetHashCode();
+ if (HasServerStreaming) hash ^= ServerStreaming.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -3171,27 +3644,27 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Name.Length != 0) {
+ if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
}
- if (InputType.Length != 0) {
+ if (HasInputType) {
output.WriteRawTag(18);
output.WriteString(InputType);
}
- if (OutputType.Length != 0) {
+ if (HasOutputType) {
output.WriteRawTag(26);
output.WriteString(OutputType);
}
- if (options_ != null) {
+ if (HasOptions) {
output.WriteRawTag(34);
output.WriteMessage(Options);
}
- if (ClientStreaming != false) {
+ if (HasClientStreaming) {
output.WriteRawTag(40);
output.WriteBool(ClientStreaming);
}
- if (ServerStreaming != false) {
+ if (HasServerStreaming) {
output.WriteRawTag(48);
output.WriteBool(ServerStreaming);
}
@@ -3203,22 +3676,22 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Name.Length != 0) {
+ if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
- if (InputType.Length != 0) {
+ if (HasInputType) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(InputType);
}
- if (OutputType.Length != 0) {
+ if (HasOutputType) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(OutputType);
}
- if (options_ != null) {
+ if (HasOptions) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
- if (ClientStreaming != false) {
+ if (HasClientStreaming) {
size += 1 + 1;
}
- if (ServerStreaming != false) {
+ if (HasServerStreaming) {
size += 1 + 1;
}
if (_unknownFields != null) {
@@ -3232,25 +3705,25 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Name.Length != 0) {
+ if (other.HasName) {
Name = other.Name;
}
- if (other.InputType.Length != 0) {
+ if (other.HasInputType) {
InputType = other.InputType;
}
- if (other.OutputType.Length != 0) {
+ if (other.HasOutputType) {
OutputType = other.OutputType;
}
- if (other.options_ != null) {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.MethodOptions();
+ if (other.HasOptions) {
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.MethodOptions();
}
Options.MergeFrom(other.Options);
}
- if (other.ClientStreaming != false) {
+ if (other.HasClientStreaming) {
ClientStreaming = other.ClientStreaming;
}
- if (other.ServerStreaming != false) {
+ if (other.HasServerStreaming) {
ServerStreaming = other.ServerStreaming;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
@@ -3277,10 +3750,10 @@ namespace Google.Protobuf.Reflection {
break;
}
case 34: {
- if (options_ == null) {
- options_ = new global::Google.Protobuf.Reflection.MethodOptions();
+ if (!HasOptions) {
+ Options = new global::Google.Protobuf.Reflection.MethodOptions();
}
- input.ReadMessage(options_);
+ input.ReadMessage(Options);
break;
}
case 40: {
@@ -3300,6 +3773,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class FileOptions : pb::IMessage<FileOptions> {
private static readonly pb::MessageParser<FileOptions> _parser = new pb::MessageParser<FileOptions>(() => new FileOptions());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<FileOptions> Parser { get { return _parser; } }
@@ -3324,6 +3798,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public FileOptions(FileOptions other) : this() {
+ _hasBits0 = other._hasBits0;
javaPackage_ = other.javaPackage_;
javaOuterClassname_ = other.javaOuterClassname_;
javaMultipleFiles_ = other.javaMultipleFiles_;
@@ -3355,7 +3830,9 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "java_package" field.</summary>
public const int JavaPackageFieldNumber = 1;
- private string javaPackage_ = "";
+ private readonly static string JavaPackageDefaultValue = "";
+
+ private string javaPackage_;
/// <summary>
/// Sets the Java package where classes generated from this .proto will be
/// placed. By default, the proto package is used, but this is often
@@ -3364,15 +3841,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string JavaPackage {
- get { return javaPackage_; }
+ get { return javaPackage_ ?? JavaPackageDefaultValue; }
set {
javaPackage_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "java_package" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasJavaPackage {
+ get { return javaPackage_ != null; }
+ }
+ /// <summary>Clears the value of the "java_package" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearJavaPackage() {
+ javaPackage_ = null;
+ }
/// <summary>Field number for the "java_outer_classname" field.</summary>
public const int JavaOuterClassnameFieldNumber = 8;
- private string javaOuterClassname_ = "";
+ private readonly static string JavaOuterClassnameDefaultValue = "";
+
+ private string javaOuterClassname_;
/// <summary>
/// If set, all the classes from the .proto file are wrapped in a single
/// outer class with the given name. This applies to both Proto1
@@ -3382,14 +3871,26 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string JavaOuterClassname {
- get { return javaOuterClassname_; }
+ get { return javaOuterClassname_ ?? JavaOuterClassnameDefaultValue; }
set {
javaOuterClassname_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "java_outer_classname" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasJavaOuterClassname {
+ get { return javaOuterClassname_ != null; }
+ }
+ /// <summary>Clears the value of the "java_outer_classname" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearJavaOuterClassname() {
+ javaOuterClassname_ = null;
+ }
/// <summary>Field number for the "java_multiple_files" field.</summary>
public const int JavaMultipleFilesFieldNumber = 10;
+ private readonly static bool JavaMultipleFilesDefaultValue = false;
+
private bool javaMultipleFiles_;
/// <summary>
/// If set true, then the Java code generator will generate a separate .java
@@ -3401,14 +3902,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool JavaMultipleFiles {
- get { return javaMultipleFiles_; }
+ get { if ((_hasBits0 & 2) != 0) { return javaMultipleFiles_; } else { return JavaMultipleFilesDefaultValue; } }
set {
+ _hasBits0 |= 2;
javaMultipleFiles_ = value;
}
}
+ /// <summary>Gets whether the "java_multiple_files" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasJavaMultipleFiles {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "java_multiple_files" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearJavaMultipleFiles() {
+ _hasBits0 &= ~2;
+ }
/// <summary>Field number for the "java_generate_equals_and_hash" field.</summary>
public const int JavaGenerateEqualsAndHashFieldNumber = 20;
+ private readonly static bool JavaGenerateEqualsAndHashDefaultValue = false;
+
private bool javaGenerateEqualsAndHash_;
/// <summary>
/// This option does nothing.
@@ -3416,14 +3930,29 @@ namespace Google.Protobuf.Reflection {
[global::System.ObsoleteAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool JavaGenerateEqualsAndHash {
- get { return javaGenerateEqualsAndHash_; }
+ get { if ((_hasBits0 & 32) != 0) { return javaGenerateEqualsAndHash_; } else { return JavaGenerateEqualsAndHashDefaultValue; } }
set {
+ _hasBits0 |= 32;
javaGenerateEqualsAndHash_ = value;
}
}
+ /// <summary>Gets whether the "java_generate_equals_and_hash" field is set</summary>
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasJavaGenerateEqualsAndHash {
+ get { return (_hasBits0 & 32) != 0; }
+ }
+ /// <summary>Clears the value of the "java_generate_equals_and_hash" field</summary>
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearJavaGenerateEqualsAndHash() {
+ _hasBits0 &= ~32;
+ }
/// <summary>Field number for the "java_string_check_utf8" field.</summary>
public const int JavaStringCheckUtf8FieldNumber = 27;
+ private readonly static bool JavaStringCheckUtf8DefaultValue = false;
+
private bool javaStringCheckUtf8_;
/// <summary>
/// If set true, then the Java2 code generator will generate code that
@@ -3435,26 +3964,52 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool JavaStringCheckUtf8 {
- get { return javaStringCheckUtf8_; }
+ get { if ((_hasBits0 & 128) != 0) { return javaStringCheckUtf8_; } else { return JavaStringCheckUtf8DefaultValue; } }
set {
+ _hasBits0 |= 128;
javaStringCheckUtf8_ = value;
}
}
+ /// <summary>Gets whether the "java_string_check_utf8" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasJavaStringCheckUtf8 {
+ get { return (_hasBits0 & 128) != 0; }
+ }
+ /// <summary>Clears the value of the "java_string_check_utf8" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearJavaStringCheckUtf8() {
+ _hasBits0 &= ~128;
+ }
/// <summary>Field number for the "optimize_for" field.</summary>
public const int OptimizeForFieldNumber = 9;
- private global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode optimizeFor_ = 0;
+ private readonly static global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode OptimizeForDefaultValue = global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode.Speed;
+
+ private global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode optimizeFor_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode OptimizeFor {
- get { return optimizeFor_; }
+ get { if ((_hasBits0 & 1) != 0) { return optimizeFor_; } else { return OptimizeForDefaultValue; } }
set {
+ _hasBits0 |= 1;
optimizeFor_ = value;
}
}
+ /// <summary>Gets whether the "optimize_for" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasOptimizeFor {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "optimize_for" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOptimizeFor() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "go_package" field.</summary>
public const int GoPackageFieldNumber = 11;
- private string goPackage_ = "";
+ private readonly static string GoPackageDefaultValue = "";
+
+ private string goPackage_;
/// <summary>
/// Sets the Go package where structs generated from this .proto will be
/// placed. If omitted, the Go package will be derived from the following:
@@ -3464,14 +4019,26 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string GoPackage {
- get { return goPackage_; }
+ get { return goPackage_ ?? GoPackageDefaultValue; }
set {
goPackage_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "go_package" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasGoPackage {
+ get { return goPackage_ != null; }
+ }
+ /// <summary>Clears the value of the "go_package" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearGoPackage() {
+ goPackage_ = null;
+ }
/// <summary>Field number for the "cc_generic_services" field.</summary>
public const int CcGenericServicesFieldNumber = 16;
+ private readonly static bool CcGenericServicesDefaultValue = false;
+
private bool ccGenericServices_;
/// <summary>
/// Should generic services be generated in each language? "Generic" services
@@ -3487,47 +4054,99 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool CcGenericServices {
- get { return ccGenericServices_; }
+ get { if ((_hasBits0 & 4) != 0) { return ccGenericServices_; } else { return CcGenericServicesDefaultValue; } }
set {
+ _hasBits0 |= 4;
ccGenericServices_ = value;
}
}
+ /// <summary>Gets whether the "cc_generic_services" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasCcGenericServices {
+ get { return (_hasBits0 & 4) != 0; }
+ }
+ /// <summary>Clears the value of the "cc_generic_services" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearCcGenericServices() {
+ _hasBits0 &= ~4;
+ }
/// <summary>Field number for the "java_generic_services" field.</summary>
public const int JavaGenericServicesFieldNumber = 17;
+ private readonly static bool JavaGenericServicesDefaultValue = false;
+
private bool javaGenericServices_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool JavaGenericServices {
- get { return javaGenericServices_; }
+ get { if ((_hasBits0 & 8) != 0) { return javaGenericServices_; } else { return JavaGenericServicesDefaultValue; } }
set {
+ _hasBits0 |= 8;
javaGenericServices_ = value;
}
}
+ /// <summary>Gets whether the "java_generic_services" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasJavaGenericServices {
+ get { return (_hasBits0 & 8) != 0; }
+ }
+ /// <summary>Clears the value of the "java_generic_services" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearJavaGenericServices() {
+ _hasBits0 &= ~8;
+ }
/// <summary>Field number for the "py_generic_services" field.</summary>
public const int PyGenericServicesFieldNumber = 18;
+ private readonly static bool PyGenericServicesDefaultValue = false;
+
private bool pyGenericServices_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool PyGenericServices {
- get { return pyGenericServices_; }
+ get { if ((_hasBits0 & 16) != 0) { return pyGenericServices_; } else { return PyGenericServicesDefaultValue; } }
set {
+ _hasBits0 |= 16;
pyGenericServices_ = value;
}
}
+ /// <summary>Gets whether the "py_generic_services" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasPyGenericServices {
+ get { return (_hasBits0 & 16) != 0; }
+ }
+ /// <summary>Clears the value of the "py_generic_services" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPyGenericServices() {
+ _hasBits0 &= ~16;
+ }
/// <summary>Field number for the "php_generic_services" field.</summary>
public const int PhpGenericServicesFieldNumber = 42;
+ private readonly static bool PhpGenericServicesDefaultValue = false;
+
private bool phpGenericServices_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool PhpGenericServices {
- get { return phpGenericServices_; }
+ get { if ((_hasBits0 & 512) != 0) { return phpGenericServices_; } else { return PhpGenericServicesDefaultValue; } }
set {
+ _hasBits0 |= 512;
phpGenericServices_ = value;
}
}
+ /// <summary>Gets whether the "php_generic_services" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasPhpGenericServices {
+ get { return (_hasBits0 & 512) != 0; }
+ }
+ /// <summary>Clears the value of the "php_generic_services" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPhpGenericServices() {
+ _hasBits0 &= ~512;
+ }
/// <summary>Field number for the "deprecated" field.</summary>
public const int DeprecatedFieldNumber = 23;
+ private readonly static bool DeprecatedDefaultValue = false;
+
private bool deprecated_;
/// <summary>
/// Is this file deprecated?
@@ -3537,14 +4156,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Deprecated {
- get { return deprecated_; }
+ get { if ((_hasBits0 & 64) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } }
set {
+ _hasBits0 |= 64;
deprecated_ = value;
}
}
+ /// <summary>Gets whether the "deprecated" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDeprecated {
+ get { return (_hasBits0 & 64) != 0; }
+ }
+ /// <summary>Clears the value of the "deprecated" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDeprecated() {
+ _hasBits0 &= ~64;
+ }
/// <summary>Field number for the "cc_enable_arenas" field.</summary>
public const int CcEnableArenasFieldNumber = 31;
+ private readonly static bool CcEnableArenasDefaultValue = false;
+
private bool ccEnableArenas_;
/// <summary>
/// Enables the use of arenas for the proto messages in this file. This applies
@@ -3552,44 +4184,81 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool CcEnableArenas {
- get { return ccEnableArenas_; }
+ get { if ((_hasBits0 & 256) != 0) { return ccEnableArenas_; } else { return CcEnableArenasDefaultValue; } }
set {
+ _hasBits0 |= 256;
ccEnableArenas_ = value;
}
}
+ /// <summary>Gets whether the "cc_enable_arenas" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasCcEnableArenas {
+ get { return (_hasBits0 & 256) != 0; }
+ }
+ /// <summary>Clears the value of the "cc_enable_arenas" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearCcEnableArenas() {
+ _hasBits0 &= ~256;
+ }
/// <summary>Field number for the "objc_class_prefix" field.</summary>
public const int ObjcClassPrefixFieldNumber = 36;
- private string objcClassPrefix_ = "";
+ private readonly static string ObjcClassPrefixDefaultValue = "";
+
+ private string objcClassPrefix_;
/// <summary>
/// Sets the objective c class prefix which is prepended to all objective c
/// generated classes from this .proto. There is no default.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ObjcClassPrefix {
- get { return objcClassPrefix_; }
+ get { return objcClassPrefix_ ?? ObjcClassPrefixDefaultValue; }
set {
objcClassPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "objc_class_prefix" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasObjcClassPrefix {
+ get { return objcClassPrefix_ != null; }
+ }
+ /// <summary>Clears the value of the "objc_class_prefix" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearObjcClassPrefix() {
+ objcClassPrefix_ = null;
+ }
/// <summary>Field number for the "csharp_namespace" field.</summary>
public const int CsharpNamespaceFieldNumber = 37;
- private string csharpNamespace_ = "";
+ private readonly static string CsharpNamespaceDefaultValue = "";
+
+ private string csharpNamespace_;
/// <summary>
/// Namespace for generated classes; defaults to the package.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string CsharpNamespace {
- get { return csharpNamespace_; }
+ get { return csharpNamespace_ ?? CsharpNamespaceDefaultValue; }
set {
csharpNamespace_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "csharp_namespace" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasCsharpNamespace {
+ get { return csharpNamespace_ != null; }
+ }
+ /// <summary>Clears the value of the "csharp_namespace" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearCsharpNamespace() {
+ csharpNamespace_ = null;
+ }
/// <summary>Field number for the "swift_prefix" field.</summary>
public const int SwiftPrefixFieldNumber = 39;
- private string swiftPrefix_ = "";
+ private readonly static string SwiftPrefixDefaultValue = "";
+
+ private string swiftPrefix_;
/// <summary>
/// By default Swift generators will take the proto package and CamelCase it
/// replacing '.' with underscore and use that to prefix the types/symbols
@@ -3598,30 +4267,54 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string SwiftPrefix {
- get { return swiftPrefix_; }
+ get { return swiftPrefix_ ?? SwiftPrefixDefaultValue; }
set {
swiftPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "swift_prefix" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasSwiftPrefix {
+ get { return swiftPrefix_ != null; }
+ }
+ /// <summary>Clears the value of the "swift_prefix" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearSwiftPrefix() {
+ swiftPrefix_ = null;
+ }
/// <summary>Field number for the "php_class_prefix" field.</summary>
public const int PhpClassPrefixFieldNumber = 40;
- private string phpClassPrefix_ = "";
+ private readonly static string PhpClassPrefixDefaultValue = "";
+
+ private string phpClassPrefix_;
/// <summary>
/// Sets the php class prefix which is prepended to all php generated classes
/// from this .proto. Default is empty.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string PhpClassPrefix {
- get { return phpClassPrefix_; }
+ get { return phpClassPrefix_ ?? PhpClassPrefixDefaultValue; }
set {
phpClassPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "php_class_prefix" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasPhpClassPrefix {
+ get { return phpClassPrefix_ != null; }
+ }
+ /// <summary>Clears the value of the "php_class_prefix" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPhpClassPrefix() {
+ phpClassPrefix_ = null;
+ }
/// <summary>Field number for the "php_namespace" field.</summary>
public const int PhpNamespaceFieldNumber = 41;
- private string phpNamespace_ = "";
+ private readonly static string PhpNamespaceDefaultValue = "";
+
+ private string phpNamespace_;
/// <summary>
/// Use this option to change the namespace of php generated classes. Default
/// is empty. When this option is empty, the package name will be used for
@@ -3629,15 +4322,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string PhpNamespace {
- get { return phpNamespace_; }
+ get { return phpNamespace_ ?? PhpNamespaceDefaultValue; }
set {
phpNamespace_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "php_namespace" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasPhpNamespace {
+ get { return phpNamespace_ != null; }
+ }
+ /// <summary>Clears the value of the "php_namespace" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPhpNamespace() {
+ phpNamespace_ = null;
+ }
/// <summary>Field number for the "php_metadata_namespace" field.</summary>
public const int PhpMetadataNamespaceFieldNumber = 44;
- private string phpMetadataNamespace_ = "";
+ private readonly static string PhpMetadataNamespaceDefaultValue = "";
+
+ private string phpMetadataNamespace_;
/// <summary>
/// Use this option to change the namespace of php generated metadata classes.
/// Default is empty. When this option is empty, the proto file name will be used
@@ -3645,15 +4350,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string PhpMetadataNamespace {
- get { return phpMetadataNamespace_; }
+ get { return phpMetadataNamespace_ ?? PhpMetadataNamespaceDefaultValue; }
set {
phpMetadataNamespace_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "php_metadata_namespace" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasPhpMetadataNamespace {
+ get { return phpMetadataNamespace_ != null; }
+ }
+ /// <summary>Clears the value of the "php_metadata_namespace" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPhpMetadataNamespace() {
+ phpMetadataNamespace_ = null;
+ }
/// <summary>Field number for the "ruby_package" field.</summary>
public const int RubyPackageFieldNumber = 45;
- private string rubyPackage_ = "";
+ private readonly static string RubyPackageDefaultValue = "";
+
+ private string rubyPackage_;
/// <summary>
/// Use this option to change the package of ruby generated classes. Default
/// is empty. When this option is not set, the package name will be used for
@@ -3661,11 +4378,21 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string RubyPackage {
- get { return rubyPackage_; }
+ get { return rubyPackage_ ?? RubyPackageDefaultValue; }
set {
rubyPackage_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "ruby_package" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasRubyPackage {
+ get { return rubyPackage_ != null; }
+ }
+ /// <summary>Clears the value of the "ruby_package" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearRubyPackage() {
+ rubyPackage_ = null;
+ }
/// <summary>Field number for the "uninterpreted_option" field.</summary>
public const int UninterpretedOptionFieldNumber = 999;
@@ -3721,26 +4448,26 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (JavaPackage.Length != 0) hash ^= JavaPackage.GetHashCode();
- if (JavaOuterClassname.Length != 0) hash ^= JavaOuterClassname.GetHashCode();
- if (JavaMultipleFiles != false) hash ^= JavaMultipleFiles.GetHashCode();
- if (JavaGenerateEqualsAndHash != false) hash ^= JavaGenerateEqualsAndHash.GetHashCode();
- if (JavaStringCheckUtf8 != false) hash ^= JavaStringCheckUtf8.GetHashCode();
- if (OptimizeFor != 0) hash ^= OptimizeFor.GetHashCode();
- if (GoPackage.Length != 0) hash ^= GoPackage.GetHashCode();
- if (CcGenericServices != false) hash ^= CcGenericServices.GetHashCode();
- if (JavaGenericServices != false) hash ^= JavaGenericServices.GetHashCode();
- if (PyGenericServices != false) hash ^= PyGenericServices.GetHashCode();
- if (PhpGenericServices != false) hash ^= PhpGenericServices.GetHashCode();
- if (Deprecated != false) hash ^= Deprecated.GetHashCode();
- if (CcEnableArenas != false) hash ^= CcEnableArenas.GetHashCode();
- if (ObjcClassPrefix.Length != 0) hash ^= ObjcClassPrefix.GetHashCode();
- if (CsharpNamespace.Length != 0) hash ^= CsharpNamespace.GetHashCode();
- if (SwiftPrefix.Length != 0) hash ^= SwiftPrefix.GetHashCode();
- if (PhpClassPrefix.Length != 0) hash ^= PhpClassPrefix.GetHashCode();
- if (PhpNamespace.Length != 0) hash ^= PhpNamespace.GetHashCode();
- if (PhpMetadataNamespace.Length != 0) hash ^= PhpMetadataNamespace.GetHashCode();
- if (RubyPackage.Length != 0) hash ^= RubyPackage.GetHashCode();
+ if (HasJavaPackage) hash ^= JavaPackage.GetHashCode();
+ if (HasJavaOuterClassname) hash ^= JavaOuterClassname.GetHashCode();
+ if (HasJavaMultipleFiles) hash ^= JavaMultipleFiles.GetHashCode();
+ if (HasJavaGenerateEqualsAndHash) hash ^= JavaGenerateEqualsAndHash.GetHashCode();
+ if (HasJavaStringCheckUtf8) hash ^= JavaStringCheckUtf8.GetHashCode();
+ if (HasOptimizeFor) hash ^= OptimizeFor.GetHashCode();
+ if (HasGoPackage) hash ^= GoPackage.GetHashCode();
+ if (HasCcGenericServices) hash ^= CcGenericServices.GetHashCode();
+ if (HasJavaGenericServices) hash ^= JavaGenericServices.GetHashCode();
+ if (HasPyGenericServices) hash ^= PyGenericServices.GetHashCode();
+ if (HasPhpGenericServices) hash ^= PhpGenericServices.GetHashCode();
+ if (HasDeprecated) hash ^= Deprecated.GetHashCode();
+ if (HasCcEnableArenas) hash ^= CcEnableArenas.GetHashCode();
+ if (HasObjcClassPrefix) hash ^= ObjcClassPrefix.GetHashCode();
+ if (HasCsharpNamespace) hash ^= CsharpNamespace.GetHashCode();
+ if (HasSwiftPrefix) hash ^= SwiftPrefix.GetHashCode();
+ if (HasPhpClassPrefix) hash ^= PhpClassPrefix.GetHashCode();
+ if (HasPhpNamespace) hash ^= PhpNamespace.GetHashCode();
+ if (HasPhpMetadataNamespace) hash ^= PhpMetadataNamespace.GetHashCode();
+ if (HasRubyPackage) hash ^= RubyPackage.GetHashCode();
hash ^= uninterpretedOption_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -3755,83 +4482,83 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (JavaPackage.Length != 0) {
+ if (HasJavaPackage) {
output.WriteRawTag(10);
output.WriteString(JavaPackage);
}
- if (JavaOuterClassname.Length != 0) {
+ if (HasJavaOuterClassname) {
output.WriteRawTag(66);
output.WriteString(JavaOuterClassname);
}
- if (OptimizeFor != 0) {
+ if (HasOptimizeFor) {
output.WriteRawTag(72);
output.WriteEnum((int) OptimizeFor);
}
- if (JavaMultipleFiles != false) {
+ if (HasJavaMultipleFiles) {
output.WriteRawTag(80);
output.WriteBool(JavaMultipleFiles);
}
- if (GoPackage.Length != 0) {
+ if (HasGoPackage) {
output.WriteRawTag(90);
output.WriteString(GoPackage);
}
- if (CcGenericServices != false) {
+ if (HasCcGenericServices) {
output.WriteRawTag(128, 1);
output.WriteBool(CcGenericServices);
}
- if (JavaGenericServices != false) {
+ if (HasJavaGenericServices) {
output.WriteRawTag(136, 1);
output.WriteBool(JavaGenericServices);
}
- if (PyGenericServices != false) {
+ if (HasPyGenericServices) {
output.WriteRawTag(144, 1);
output.WriteBool(PyGenericServices);
}
- if (JavaGenerateEqualsAndHash != false) {
+ if (HasJavaGenerateEqualsAndHash) {
output.WriteRawTag(160, 1);
output.WriteBool(JavaGenerateEqualsAndHash);
}
- if (Deprecated != false) {
+ if (HasDeprecated) {
output.WriteRawTag(184, 1);
output.WriteBool(Deprecated);
}
- if (JavaStringCheckUtf8 != false) {
+ if (HasJavaStringCheckUtf8) {
output.WriteRawTag(216, 1);
output.WriteBool(JavaStringCheckUtf8);
}
- if (CcEnableArenas != false) {
+ if (HasCcEnableArenas) {
output.WriteRawTag(248, 1);
output.WriteBool(CcEnableArenas);
}
- if (ObjcClassPrefix.Length != 0) {
+ if (HasObjcClassPrefix) {
output.WriteRawTag(162, 2);
output.WriteString(ObjcClassPrefix);
}
- if (CsharpNamespace.Length != 0) {
+ if (HasCsharpNamespace) {
output.WriteRawTag(170, 2);
output.WriteString(CsharpNamespace);
}
- if (SwiftPrefix.Length != 0) {
+ if (HasSwiftPrefix) {
output.WriteRawTag(186, 2);
output.WriteString(SwiftPrefix);
}
- if (PhpClassPrefix.Length != 0) {
+ if (HasPhpClassPrefix) {
output.WriteRawTag(194, 2);
output.WriteString(PhpClassPrefix);
}
- if (PhpNamespace.Length != 0) {
+ if (HasPhpNamespace) {
output.WriteRawTag(202, 2);
output.WriteString(PhpNamespace);
}
- if (PhpGenericServices != false) {
+ if (HasPhpGenericServices) {
output.WriteRawTag(208, 2);
output.WriteBool(PhpGenericServices);
}
- if (PhpMetadataNamespace.Length != 0) {
+ if (HasPhpMetadataNamespace) {
output.WriteRawTag(226, 2);
output.WriteString(PhpMetadataNamespace);
}
- if (RubyPackage.Length != 0) {
+ if (HasRubyPackage) {
output.WriteRawTag(234, 2);
output.WriteString(RubyPackage);
}
@@ -3844,64 +4571,64 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (JavaPackage.Length != 0) {
+ if (HasJavaPackage) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(JavaPackage);
}
- if (JavaOuterClassname.Length != 0) {
+ if (HasJavaOuterClassname) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(JavaOuterClassname);
}
- if (JavaMultipleFiles != false) {
+ if (HasJavaMultipleFiles) {
size += 1 + 1;
}
- if (JavaGenerateEqualsAndHash != false) {
+ if (HasJavaGenerateEqualsAndHash) {
size += 2 + 1;
}
- if (JavaStringCheckUtf8 != false) {
+ if (HasJavaStringCheckUtf8) {
size += 2 + 1;
}
- if (OptimizeFor != 0) {
+ if (HasOptimizeFor) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) OptimizeFor);
}
- if (GoPackage.Length != 0) {
+ if (HasGoPackage) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(GoPackage);
}
- if (CcGenericServices != false) {
+ if (HasCcGenericServices) {
size += 2 + 1;
}
- if (JavaGenericServices != false) {
+ if (HasJavaGenericServices) {
size += 2 + 1;
}
- if (PyGenericServices != false) {
+ if (HasPyGenericServices) {
size += 2 + 1;
}
- if (PhpGenericServices != false) {
+ if (HasPhpGenericServices) {
size += 2 + 1;
}
- if (Deprecated != false) {
+ if (HasDeprecated) {
size += 2 + 1;
}
- if (CcEnableArenas != false) {
+ if (HasCcEnableArenas) {
size += 2 + 1;
}
- if (ObjcClassPrefix.Length != 0) {
+ if (HasObjcClassPrefix) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(ObjcClassPrefix);
}
- if (CsharpNamespace.Length != 0) {
+ if (HasCsharpNamespace) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(CsharpNamespace);
}
- if (SwiftPrefix.Length != 0) {
+ if (HasSwiftPrefix) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(SwiftPrefix);
}
- if (PhpClassPrefix.Length != 0) {
+ if (HasPhpClassPrefix) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(PhpClassPrefix);
}
- if (PhpNamespace.Length != 0) {
+ if (HasPhpNamespace) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(PhpNamespace);
}
- if (PhpMetadataNamespace.Length != 0) {
+ if (HasPhpMetadataNamespace) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(PhpMetadataNamespace);
}
- if (RubyPackage.Length != 0) {
+ if (HasRubyPackage) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(RubyPackage);
}
size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
@@ -3916,64 +4643,64 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.JavaPackage.Length != 0) {
+ if (other.HasJavaPackage) {
JavaPackage = other.JavaPackage;
}
- if (other.JavaOuterClassname.Length != 0) {
+ if (other.HasJavaOuterClassname) {
JavaOuterClassname = other.JavaOuterClassname;
}
- if (other.JavaMultipleFiles != false) {
+ if (other.HasJavaMultipleFiles) {
JavaMultipleFiles = other.JavaMultipleFiles;
}
- if (other.JavaGenerateEqualsAndHash != false) {
+ if (other.HasJavaGenerateEqualsAndHash) {
JavaGenerateEqualsAndHash = other.JavaGenerateEqualsAndHash;
}
- if (other.JavaStringCheckUtf8 != false) {
+ if (other.HasJavaStringCheckUtf8) {
JavaStringCheckUtf8 = other.JavaStringCheckUtf8;
}
- if (other.OptimizeFor != 0) {
+ if (other.HasOptimizeFor) {
OptimizeFor = other.OptimizeFor;
}
- if (other.GoPackage.Length != 0) {
+ if (other.HasGoPackage) {
GoPackage = other.GoPackage;
}
- if (other.CcGenericServices != false) {
+ if (other.HasCcGenericServices) {
CcGenericServices = other.CcGenericServices;
}
- if (other.JavaGenericServices != false) {
+ if (other.HasJavaGenericServices) {
JavaGenericServices = other.JavaGenericServices;
}
- if (other.PyGenericServices != false) {
+ if (other.HasPyGenericServices) {
PyGenericServices = other.PyGenericServices;
}
- if (other.PhpGenericServices != false) {
+ if (other.HasPhpGenericServices) {
PhpGenericServices = other.PhpGenericServices;
}
- if (other.Deprecated != false) {
+ if (other.HasDeprecated) {
Deprecated = other.Deprecated;
}
- if (other.CcEnableArenas != false) {
+ if (other.HasCcEnableArenas) {
CcEnableArenas = other.CcEnableArenas;
}
- if (other.ObjcClassPrefix.Length != 0) {
+ if (other.HasObjcClassPrefix) {
ObjcClassPrefix = other.ObjcClassPrefix;
}
- if (other.CsharpNamespace.Length != 0) {
+ if (other.HasCsharpNamespace) {
CsharpNamespace = other.CsharpNamespace;
}
- if (other.SwiftPrefix.Length != 0) {
+ if (other.HasSwiftPrefix) {
SwiftPrefix = other.SwiftPrefix;
}
- if (other.PhpClassPrefix.Length != 0) {
+ if (other.HasPhpClassPrefix) {
PhpClassPrefix = other.PhpClassPrefix;
}
- if (other.PhpNamespace.Length != 0) {
+ if (other.HasPhpNamespace) {
PhpNamespace = other.PhpNamespace;
}
- if (other.PhpMetadataNamespace.Length != 0) {
+ if (other.HasPhpMetadataNamespace) {
PhpMetadataNamespace = other.PhpMetadataNamespace;
}
- if (other.RubyPackage.Length != 0) {
+ if (other.HasRubyPackage) {
RubyPackage = other.RubyPackage;
}
uninterpretedOption_.Add(other.uninterpretedOption_);
@@ -3997,7 +4724,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 72: {
- optimizeFor_ = (global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) input.ReadEnum();
+ OptimizeFor = (global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) input.ReadEnum();
break;
}
case 80: {
@@ -4106,6 +4833,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class MessageOptions : pb::IMessage<MessageOptions> {
private static readonly pb::MessageParser<MessageOptions> _parser = new pb::MessageParser<MessageOptions>(() => new MessageOptions());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<MessageOptions> Parser { get { return _parser; } }
@@ -4130,6 +4858,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public MessageOptions(MessageOptions other) : this() {
+ _hasBits0 = other._hasBits0;
messageSetWireFormat_ = other.messageSetWireFormat_;
noStandardDescriptorAccessor_ = other.noStandardDescriptorAccessor_;
deprecated_ = other.deprecated_;
@@ -4145,6 +4874,8 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "message_set_wire_format" field.</summary>
public const int MessageSetWireFormatFieldNumber = 1;
+ private readonly static bool MessageSetWireFormatDefaultValue = false;
+
private bool messageSetWireFormat_;
/// <summary>
/// Set true to use the old proto1 MessageSet wire format for extensions.
@@ -4168,14 +4899,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool MessageSetWireFormat {
- get { return messageSetWireFormat_; }
+ get { if ((_hasBits0 & 1) != 0) { return messageSetWireFormat_; } else { return MessageSetWireFormatDefaultValue; } }
set {
+ _hasBits0 |= 1;
messageSetWireFormat_ = value;
}
}
+ /// <summary>Gets whether the "message_set_wire_format" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasMessageSetWireFormat {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "message_set_wire_format" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearMessageSetWireFormat() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "no_standard_descriptor_accessor" field.</summary>
public const int NoStandardDescriptorAccessorFieldNumber = 2;
+ private readonly static bool NoStandardDescriptorAccessorDefaultValue = false;
+
private bool noStandardDescriptorAccessor_;
/// <summary>
/// Disables the generation of the standard "descriptor()" accessor, which can
@@ -4184,14 +4928,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool NoStandardDescriptorAccessor {
- get { return noStandardDescriptorAccessor_; }
+ get { if ((_hasBits0 & 2) != 0) { return noStandardDescriptorAccessor_; } else { return NoStandardDescriptorAccessorDefaultValue; } }
set {
+ _hasBits0 |= 2;
noStandardDescriptorAccessor_ = value;
}
}
+ /// <summary>Gets whether the "no_standard_descriptor_accessor" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasNoStandardDescriptorAccessor {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "no_standard_descriptor_accessor" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearNoStandardDescriptorAccessor() {
+ _hasBits0 &= ~2;
+ }
/// <summary>Field number for the "deprecated" field.</summary>
public const int DeprecatedFieldNumber = 3;
+ private readonly static bool DeprecatedDefaultValue = false;
+
private bool deprecated_;
/// <summary>
/// Is this message deprecated?
@@ -4201,14 +4958,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Deprecated {
- get { return deprecated_; }
+ get { if ((_hasBits0 & 4) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } }
set {
+ _hasBits0 |= 4;
deprecated_ = value;
}
}
+ /// <summary>Gets whether the "deprecated" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDeprecated {
+ get { return (_hasBits0 & 4) != 0; }
+ }
+ /// <summary>Clears the value of the "deprecated" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDeprecated() {
+ _hasBits0 &= ~4;
+ }
/// <summary>Field number for the "map_entry" field.</summary>
public const int MapEntryFieldNumber = 7;
+ private readonly static bool MapEntryDefaultValue = false;
+
private bool mapEntry_;
/// <summary>
/// Whether the message is an automatically generated map entry type for the
@@ -4235,11 +5005,22 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool MapEntry {
- get { return mapEntry_; }
+ get { if ((_hasBits0 & 8) != 0) { return mapEntry_; } else { return MapEntryDefaultValue; } }
set {
+ _hasBits0 |= 8;
mapEntry_ = value;
}
}
+ /// <summary>Gets whether the "map_entry" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasMapEntry {
+ get { return (_hasBits0 & 8) != 0; }
+ }
+ /// <summary>Clears the value of the "map_entry" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearMapEntry() {
+ _hasBits0 &= ~8;
+ }
/// <summary>Field number for the "uninterpreted_option" field.</summary>
public const int UninterpretedOptionFieldNumber = 999;
@@ -4278,10 +5059,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (MessageSetWireFormat != false) hash ^= MessageSetWireFormat.GetHashCode();
- if (NoStandardDescriptorAccessor != false) hash ^= NoStandardDescriptorAccessor.GetHashCode();
- if (Deprecated != false) hash ^= Deprecated.GetHashCode();
- if (MapEntry != false) hash ^= MapEntry.GetHashCode();
+ if (HasMessageSetWireFormat) hash ^= MessageSetWireFormat.GetHashCode();
+ if (HasNoStandardDescriptorAccessor) hash ^= NoStandardDescriptorAccessor.GetHashCode();
+ if (HasDeprecated) hash ^= Deprecated.GetHashCode();
+ if (HasMapEntry) hash ^= MapEntry.GetHashCode();
hash ^= uninterpretedOption_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -4296,19 +5077,19 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (MessageSetWireFormat != false) {
+ if (HasMessageSetWireFormat) {
output.WriteRawTag(8);
output.WriteBool(MessageSetWireFormat);
}
- if (NoStandardDescriptorAccessor != false) {
+ if (HasNoStandardDescriptorAccessor) {
output.WriteRawTag(16);
output.WriteBool(NoStandardDescriptorAccessor);
}
- if (Deprecated != false) {
+ if (HasDeprecated) {
output.WriteRawTag(24);
output.WriteBool(Deprecated);
}
- if (MapEntry != false) {
+ if (HasMapEntry) {
output.WriteRawTag(56);
output.WriteBool(MapEntry);
}
@@ -4321,16 +5102,16 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (MessageSetWireFormat != false) {
+ if (HasMessageSetWireFormat) {
size += 1 + 1;
}
- if (NoStandardDescriptorAccessor != false) {
+ if (HasNoStandardDescriptorAccessor) {
size += 1 + 1;
}
- if (Deprecated != false) {
+ if (HasDeprecated) {
size += 1 + 1;
}
- if (MapEntry != false) {
+ if (HasMapEntry) {
size += 1 + 1;
}
size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
@@ -4345,16 +5126,16 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.MessageSetWireFormat != false) {
+ if (other.HasMessageSetWireFormat) {
MessageSetWireFormat = other.MessageSetWireFormat;
}
- if (other.NoStandardDescriptorAccessor != false) {
+ if (other.HasNoStandardDescriptorAccessor) {
NoStandardDescriptorAccessor = other.NoStandardDescriptorAccessor;
}
- if (other.Deprecated != false) {
+ if (other.HasDeprecated) {
Deprecated = other.Deprecated;
}
- if (other.MapEntry != false) {
+ if (other.HasMapEntry) {
MapEntry = other.MapEntry;
}
uninterpretedOption_.Add(other.uninterpretedOption_);
@@ -4398,6 +5179,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class FieldOptions : pb::IMessage<FieldOptions> {
private static readonly pb::MessageParser<FieldOptions> _parser = new pb::MessageParser<FieldOptions>(() => new FieldOptions());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<FieldOptions> Parser { get { return _parser; } }
@@ -4422,6 +5204,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public FieldOptions(FieldOptions other) : this() {
+ _hasBits0 = other._hasBits0;
ctype_ = other.ctype_;
packed_ = other.packed_;
jstype_ = other.jstype_;
@@ -4439,7 +5222,9 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "ctype" field.</summary>
public const int CtypeFieldNumber = 1;
- private global::Google.Protobuf.Reflection.FieldOptions.Types.CType ctype_ = 0;
+ private readonly static global::Google.Protobuf.Reflection.FieldOptions.Types.CType CtypeDefaultValue = global::Google.Protobuf.Reflection.FieldOptions.Types.CType.String;
+
+ private global::Google.Protobuf.Reflection.FieldOptions.Types.CType ctype_;
/// <summary>
/// The ctype option instructs the C++ code generator to use a different
/// representation of the field than it normally would. See the specific
@@ -4448,14 +5233,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::Google.Protobuf.Reflection.FieldOptions.Types.CType Ctype {
- get { return ctype_; }
+ get { if ((_hasBits0 & 1) != 0) { return ctype_; } else { return CtypeDefaultValue; } }
set {
+ _hasBits0 |= 1;
ctype_ = value;
}
}
+ /// <summary>Gets whether the "ctype" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasCtype {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "ctype" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearCtype() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "packed" field.</summary>
public const int PackedFieldNumber = 2;
+ private readonly static bool PackedDefaultValue = false;
+
private bool packed_;
/// <summary>
/// The packed option can be enabled for repeated primitive fields to enable
@@ -4466,15 +5264,28 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Packed {
- get { return packed_; }
+ get { if ((_hasBits0 & 2) != 0) { return packed_; } else { return PackedDefaultValue; } }
set {
+ _hasBits0 |= 2;
packed_ = value;
}
}
+ /// <summary>Gets whether the "packed" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasPacked {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "packed" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPacked() {
+ _hasBits0 &= ~2;
+ }
/// <summary>Field number for the "jstype" field.</summary>
public const int JstypeFieldNumber = 6;
- private global::Google.Protobuf.Reflection.FieldOptions.Types.JSType jstype_ = 0;
+ private readonly static global::Google.Protobuf.Reflection.FieldOptions.Types.JSType JstypeDefaultValue = global::Google.Protobuf.Reflection.FieldOptions.Types.JSType.JsNormal;
+
+ private global::Google.Protobuf.Reflection.FieldOptions.Types.JSType jstype_;
/// <summary>
/// The jstype option determines the JavaScript type used for values of the
/// field. The option is permitted only for 64 bit integral and fixed types
@@ -4490,14 +5301,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::Google.Protobuf.Reflection.FieldOptions.Types.JSType Jstype {
- get { return jstype_; }
+ get { if ((_hasBits0 & 16) != 0) { return jstype_; } else { return JstypeDefaultValue; } }
set {
+ _hasBits0 |= 16;
jstype_ = value;
}
}
+ /// <summary>Gets whether the "jstype" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasJstype {
+ get { return (_hasBits0 & 16) != 0; }
+ }
+ /// <summary>Clears the value of the "jstype" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearJstype() {
+ _hasBits0 &= ~16;
+ }
/// <summary>Field number for the "lazy" field.</summary>
public const int LazyFieldNumber = 5;
+ private readonly static bool LazyDefaultValue = false;
+
private bool lazy_;
/// <summary>
/// Should this field be parsed lazily? Lazy applies only to message-type
@@ -4530,14 +5354,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Lazy {
- get { return lazy_; }
+ get { if ((_hasBits0 & 8) != 0) { return lazy_; } else { return LazyDefaultValue; } }
set {
+ _hasBits0 |= 8;
lazy_ = value;
}
}
+ /// <summary>Gets whether the "lazy" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasLazy {
+ get { return (_hasBits0 & 8) != 0; }
+ }
+ /// <summary>Clears the value of the "lazy" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearLazy() {
+ _hasBits0 &= ~8;
+ }
/// <summary>Field number for the "deprecated" field.</summary>
public const int DeprecatedFieldNumber = 3;
+ private readonly static bool DeprecatedDefaultValue = false;
+
private bool deprecated_;
/// <summary>
/// Is this field deprecated?
@@ -4547,25 +5384,49 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Deprecated {
- get { return deprecated_; }
+ get { if ((_hasBits0 & 4) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } }
set {
+ _hasBits0 |= 4;
deprecated_ = value;
}
}
+ /// <summary>Gets whether the "deprecated" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDeprecated {
+ get { return (_hasBits0 & 4) != 0; }
+ }
+ /// <summary>Clears the value of the "deprecated" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDeprecated() {
+ _hasBits0 &= ~4;
+ }
/// <summary>Field number for the "weak" field.</summary>
public const int WeakFieldNumber = 10;
+ private readonly static bool WeakDefaultValue = false;
+
private bool weak_;
/// <summary>
/// For Google-internal migration only. Do not use.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Weak {
- get { return weak_; }
+ get { if ((_hasBits0 & 32) != 0) { return weak_; } else { return WeakDefaultValue; } }
set {
+ _hasBits0 |= 32;
weak_ = value;
}
}
+ /// <summary>Gets whether the "weak" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasWeak {
+ get { return (_hasBits0 & 32) != 0; }
+ }
+ /// <summary>Clears the value of the "weak" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearWeak() {
+ _hasBits0 &= ~32;
+ }
/// <summary>Field number for the "uninterpreted_option" field.</summary>
public const int UninterpretedOptionFieldNumber = 999;
@@ -4606,12 +5467,12 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Ctype != 0) hash ^= Ctype.GetHashCode();
- if (Packed != false) hash ^= Packed.GetHashCode();
- if (Jstype != 0) hash ^= Jstype.GetHashCode();
- if (Lazy != false) hash ^= Lazy.GetHashCode();
- if (Deprecated != false) hash ^= Deprecated.GetHashCode();
- if (Weak != false) hash ^= Weak.GetHashCode();
+ if (HasCtype) hash ^= Ctype.GetHashCode();
+ if (HasPacked) hash ^= Packed.GetHashCode();
+ if (HasJstype) hash ^= Jstype.GetHashCode();
+ if (HasLazy) hash ^= Lazy.GetHashCode();
+ if (HasDeprecated) hash ^= Deprecated.GetHashCode();
+ if (HasWeak) hash ^= Weak.GetHashCode();
hash ^= uninterpretedOption_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -4626,27 +5487,27 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Ctype != 0) {
+ if (HasCtype) {
output.WriteRawTag(8);
output.WriteEnum((int) Ctype);
}
- if (Packed != false) {
+ if (HasPacked) {
output.WriteRawTag(16);
output.WriteBool(Packed);
}
- if (Deprecated != false) {
+ if (HasDeprecated) {
output.WriteRawTag(24);
output.WriteBool(Deprecated);
}
- if (Lazy != false) {
+ if (HasLazy) {
output.WriteRawTag(40);
output.WriteBool(Lazy);
}
- if (Jstype != 0) {
+ if (HasJstype) {
output.WriteRawTag(48);
output.WriteEnum((int) Jstype);
}
- if (Weak != false) {
+ if (HasWeak) {
output.WriteRawTag(80);
output.WriteBool(Weak);
}
@@ -4659,22 +5520,22 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Ctype != 0) {
+ if (HasCtype) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Ctype);
}
- if (Packed != false) {
+ if (HasPacked) {
size += 1 + 1;
}
- if (Jstype != 0) {
+ if (HasJstype) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Jstype);
}
- if (Lazy != false) {
+ if (HasLazy) {
size += 1 + 1;
}
- if (Deprecated != false) {
+ if (HasDeprecated) {
size += 1 + 1;
}
- if (Weak != false) {
+ if (HasWeak) {
size += 1 + 1;
}
size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
@@ -4689,22 +5550,22 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Ctype != 0) {
+ if (other.HasCtype) {
Ctype = other.Ctype;
}
- if (other.Packed != false) {
+ if (other.HasPacked) {
Packed = other.Packed;
}
- if (other.Jstype != 0) {
+ if (other.HasJstype) {
Jstype = other.Jstype;
}
- if (other.Lazy != false) {
+ if (other.HasLazy) {
Lazy = other.Lazy;
}
- if (other.Deprecated != false) {
+ if (other.HasDeprecated) {
Deprecated = other.Deprecated;
}
- if (other.Weak != false) {
+ if (other.HasWeak) {
Weak = other.Weak;
}
uninterpretedOption_.Add(other.uninterpretedOption_);
@@ -4720,7 +5581,7 @@ namespace Google.Protobuf.Reflection {
CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 8: {
- ctype_ = (global::Google.Protobuf.Reflection.FieldOptions.Types.CType) input.ReadEnum();
+ Ctype = (global::Google.Protobuf.Reflection.FieldOptions.Types.CType) input.ReadEnum();
break;
}
case 16: {
@@ -4736,7 +5597,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 48: {
- jstype_ = (global::Google.Protobuf.Reflection.FieldOptions.Types.JSType) input.ReadEnum();
+ Jstype = (global::Google.Protobuf.Reflection.FieldOptions.Types.JSType) input.ReadEnum();
break;
}
case 80: {
@@ -4913,6 +5774,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class EnumOptions : pb::IMessage<EnumOptions> {
private static readonly pb::MessageParser<EnumOptions> _parser = new pb::MessageParser<EnumOptions>(() => new EnumOptions());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<EnumOptions> Parser { get { return _parser; } }
@@ -4937,6 +5799,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public EnumOptions(EnumOptions other) : this() {
+ _hasBits0 = other._hasBits0;
allowAlias_ = other.allowAlias_;
deprecated_ = other.deprecated_;
uninterpretedOption_ = other.uninterpretedOption_.Clone();
@@ -4950,6 +5813,8 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "allow_alias" field.</summary>
public const int AllowAliasFieldNumber = 2;
+ private readonly static bool AllowAliasDefaultValue = false;
+
private bool allowAlias_;
/// <summary>
/// Set this option to true to allow mapping different tag names to the same
@@ -4957,14 +5822,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool AllowAlias {
- get { return allowAlias_; }
+ get { if ((_hasBits0 & 1) != 0) { return allowAlias_; } else { return AllowAliasDefaultValue; } }
set {
+ _hasBits0 |= 1;
allowAlias_ = value;
}
}
+ /// <summary>Gets whether the "allow_alias" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasAllowAlias {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "allow_alias" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearAllowAlias() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "deprecated" field.</summary>
public const int DeprecatedFieldNumber = 3;
+ private readonly static bool DeprecatedDefaultValue = false;
+
private bool deprecated_;
/// <summary>
/// Is this enum deprecated?
@@ -4974,11 +5852,22 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Deprecated {
- get { return deprecated_; }
+ get { if ((_hasBits0 & 2) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } }
set {
+ _hasBits0 |= 2;
deprecated_ = value;
}
}
+ /// <summary>Gets whether the "deprecated" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDeprecated {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "deprecated" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDeprecated() {
+ _hasBits0 &= ~2;
+ }
/// <summary>Field number for the "uninterpreted_option" field.</summary>
public const int UninterpretedOptionFieldNumber = 999;
@@ -5015,8 +5904,8 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (AllowAlias != false) hash ^= AllowAlias.GetHashCode();
- if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ if (HasAllowAlias) hash ^= AllowAlias.GetHashCode();
+ if (HasDeprecated) hash ^= Deprecated.GetHashCode();
hash ^= uninterpretedOption_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -5031,11 +5920,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (AllowAlias != false) {
+ if (HasAllowAlias) {
output.WriteRawTag(16);
output.WriteBool(AllowAlias);
}
- if (Deprecated != false) {
+ if (HasDeprecated) {
output.WriteRawTag(24);
output.WriteBool(Deprecated);
}
@@ -5048,10 +5937,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (AllowAlias != false) {
+ if (HasAllowAlias) {
size += 1 + 1;
}
- if (Deprecated != false) {
+ if (HasDeprecated) {
size += 1 + 1;
}
size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
@@ -5066,10 +5955,10 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.AllowAlias != false) {
+ if (other.HasAllowAlias) {
AllowAlias = other.AllowAlias;
}
- if (other.Deprecated != false) {
+ if (other.HasDeprecated) {
Deprecated = other.Deprecated;
}
uninterpretedOption_.Add(other.uninterpretedOption_);
@@ -5105,6 +5994,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class EnumValueOptions : pb::IMessage<EnumValueOptions> {
private static readonly pb::MessageParser<EnumValueOptions> _parser = new pb::MessageParser<EnumValueOptions>(() => new EnumValueOptions());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<EnumValueOptions> Parser { get { return _parser; } }
@@ -5129,6 +6019,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public EnumValueOptions(EnumValueOptions other) : this() {
+ _hasBits0 = other._hasBits0;
deprecated_ = other.deprecated_;
uninterpretedOption_ = other.uninterpretedOption_.Clone();
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -5141,6 +6032,8 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "deprecated" field.</summary>
public const int DeprecatedFieldNumber = 1;
+ private readonly static bool DeprecatedDefaultValue = false;
+
private bool deprecated_;
/// <summary>
/// Is this enum value deprecated?
@@ -5150,11 +6043,22 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Deprecated {
- get { return deprecated_; }
+ get { if ((_hasBits0 & 1) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } }
set {
+ _hasBits0 |= 1;
deprecated_ = value;
}
}
+ /// <summary>Gets whether the "deprecated" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDeprecated {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "deprecated" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDeprecated() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "uninterpreted_option" field.</summary>
public const int UninterpretedOptionFieldNumber = 999;
@@ -5190,7 +6094,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ if (HasDeprecated) hash ^= Deprecated.GetHashCode();
hash ^= uninterpretedOption_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -5205,7 +6109,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Deprecated != false) {
+ if (HasDeprecated) {
output.WriteRawTag(8);
output.WriteBool(Deprecated);
}
@@ -5218,7 +6122,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Deprecated != false) {
+ if (HasDeprecated) {
size += 1 + 1;
}
size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
@@ -5233,7 +6137,7 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Deprecated != false) {
+ if (other.HasDeprecated) {
Deprecated = other.Deprecated;
}
uninterpretedOption_.Add(other.uninterpretedOption_);
@@ -5265,6 +6169,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class ServiceOptions : pb::IMessage<ServiceOptions> {
private static readonly pb::MessageParser<ServiceOptions> _parser = new pb::MessageParser<ServiceOptions>(() => new ServiceOptions());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<ServiceOptions> Parser { get { return _parser; } }
@@ -5289,6 +6194,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public ServiceOptions(ServiceOptions other) : this() {
+ _hasBits0 = other._hasBits0;
deprecated_ = other.deprecated_;
uninterpretedOption_ = other.uninterpretedOption_.Clone();
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -5301,6 +6207,8 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "deprecated" field.</summary>
public const int DeprecatedFieldNumber = 33;
+ private readonly static bool DeprecatedDefaultValue = false;
+
private bool deprecated_;
/// <summary>
/// Is this service deprecated?
@@ -5310,11 +6218,22 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Deprecated {
- get { return deprecated_; }
+ get { if ((_hasBits0 & 1) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } }
set {
+ _hasBits0 |= 1;
deprecated_ = value;
}
}
+ /// <summary>Gets whether the "deprecated" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDeprecated {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "deprecated" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDeprecated() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "uninterpreted_option" field.</summary>
public const int UninterpretedOptionFieldNumber = 999;
@@ -5350,7 +6269,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ if (HasDeprecated) hash ^= Deprecated.GetHashCode();
hash ^= uninterpretedOption_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -5365,7 +6284,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Deprecated != false) {
+ if (HasDeprecated) {
output.WriteRawTag(136, 2);
output.WriteBool(Deprecated);
}
@@ -5378,7 +6297,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Deprecated != false) {
+ if (HasDeprecated) {
size += 2 + 1;
}
size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
@@ -5393,7 +6312,7 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Deprecated != false) {
+ if (other.HasDeprecated) {
Deprecated = other.Deprecated;
}
uninterpretedOption_.Add(other.uninterpretedOption_);
@@ -5425,6 +6344,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class MethodOptions : pb::IMessage<MethodOptions> {
private static readonly pb::MessageParser<MethodOptions> _parser = new pb::MessageParser<MethodOptions>(() => new MethodOptions());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<MethodOptions> Parser { get { return _parser; } }
@@ -5449,6 +6369,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public MethodOptions(MethodOptions other) : this() {
+ _hasBits0 = other._hasBits0;
deprecated_ = other.deprecated_;
idempotencyLevel_ = other.idempotencyLevel_;
uninterpretedOption_ = other.uninterpretedOption_.Clone();
@@ -5462,6 +6383,8 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "deprecated" field.</summary>
public const int DeprecatedFieldNumber = 33;
+ private readonly static bool DeprecatedDefaultValue = false;
+
private bool deprecated_;
/// <summary>
/// Is this method deprecated?
@@ -5471,22 +6394,46 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Deprecated {
- get { return deprecated_; }
+ get { if ((_hasBits0 & 1) != 0) { return deprecated_; } else { return DeprecatedDefaultValue; } }
set {
+ _hasBits0 |= 1;
deprecated_ = value;
}
}
+ /// <summary>Gets whether the "deprecated" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDeprecated {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "deprecated" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDeprecated() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "idempotency_level" field.</summary>
public const int IdempotencyLevelFieldNumber = 34;
- private global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel idempotencyLevel_ = 0;
+ private readonly static global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel IdempotencyLevelDefaultValue = global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel.IdempotencyUnknown;
+
+ private global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel idempotencyLevel_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel IdempotencyLevel {
- get { return idempotencyLevel_; }
+ get { if ((_hasBits0 & 2) != 0) { return idempotencyLevel_; } else { return IdempotencyLevelDefaultValue; } }
set {
+ _hasBits0 |= 2;
idempotencyLevel_ = value;
}
}
+ /// <summary>Gets whether the "idempotency_level" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasIdempotencyLevel {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "idempotency_level" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearIdempotencyLevel() {
+ _hasBits0 &= ~2;
+ }
/// <summary>Field number for the "uninterpreted_option" field.</summary>
public const int UninterpretedOptionFieldNumber = 999;
@@ -5523,8 +6470,8 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Deprecated != false) hash ^= Deprecated.GetHashCode();
- if (IdempotencyLevel != 0) hash ^= IdempotencyLevel.GetHashCode();
+ if (HasDeprecated) hash ^= Deprecated.GetHashCode();
+ if (HasIdempotencyLevel) hash ^= IdempotencyLevel.GetHashCode();
hash ^= uninterpretedOption_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -5539,11 +6486,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Deprecated != false) {
+ if (HasDeprecated) {
output.WriteRawTag(136, 2);
output.WriteBool(Deprecated);
}
- if (IdempotencyLevel != 0) {
+ if (HasIdempotencyLevel) {
output.WriteRawTag(144, 2);
output.WriteEnum((int) IdempotencyLevel);
}
@@ -5556,10 +6503,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Deprecated != false) {
+ if (HasDeprecated) {
size += 2 + 1;
}
- if (IdempotencyLevel != 0) {
+ if (HasIdempotencyLevel) {
size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) IdempotencyLevel);
}
size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
@@ -5574,10 +6521,10 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.Deprecated != false) {
+ if (other.HasDeprecated) {
Deprecated = other.Deprecated;
}
- if (other.IdempotencyLevel != 0) {
+ if (other.HasIdempotencyLevel) {
IdempotencyLevel = other.IdempotencyLevel;
}
uninterpretedOption_.Add(other.uninterpretedOption_);
@@ -5597,7 +6544,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 272: {
- idempotencyLevel_ = (global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) input.ReadEnum();
+ IdempotencyLevel = (global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) input.ReadEnum();
break;
}
case 7994: {
@@ -5645,6 +6592,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class UninterpretedOption : pb::IMessage<UninterpretedOption> {
private static readonly pb::MessageParser<UninterpretedOption> _parser = new pb::MessageParser<UninterpretedOption>(() => new UninterpretedOption());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<UninterpretedOption> Parser { get { return _parser; } }
@@ -5667,6 +6615,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public UninterpretedOption(UninterpretedOption other) : this() {
+ _hasBits0 = other._hasBits0;
name_ = other.name_.Clone();
identifierValue_ = other.identifierValue_;
positiveIntValue_ = other.positiveIntValue_;
@@ -5694,73 +6643,148 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "identifier_value" field.</summary>
public const int IdentifierValueFieldNumber = 3;
- private string identifierValue_ = "";
+ private readonly static string IdentifierValueDefaultValue = "";
+
+ private string identifierValue_;
/// <summary>
/// The value of the uninterpreted option, in whatever type the tokenizer
/// identified it as during parsing. Exactly one of these should be set.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string IdentifierValue {
- get { return identifierValue_; }
+ get { return identifierValue_ ?? IdentifierValueDefaultValue; }
set {
identifierValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "identifier_value" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasIdentifierValue {
+ get { return identifierValue_ != null; }
+ }
+ /// <summary>Clears the value of the "identifier_value" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearIdentifierValue() {
+ identifierValue_ = null;
+ }
/// <summary>Field number for the "positive_int_value" field.</summary>
public const int PositiveIntValueFieldNumber = 4;
+ private readonly static ulong PositiveIntValueDefaultValue = 0UL;
+
private ulong positiveIntValue_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public ulong PositiveIntValue {
- get { return positiveIntValue_; }
+ get { if ((_hasBits0 & 1) != 0) { return positiveIntValue_; } else { return PositiveIntValueDefaultValue; } }
set {
+ _hasBits0 |= 1;
positiveIntValue_ = value;
}
}
+ /// <summary>Gets whether the "positive_int_value" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasPositiveIntValue {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "positive_int_value" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPositiveIntValue() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "negative_int_value" field.</summary>
public const int NegativeIntValueFieldNumber = 5;
+ private readonly static long NegativeIntValueDefaultValue = 0L;
+
private long negativeIntValue_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long NegativeIntValue {
- get { return negativeIntValue_; }
+ get { if ((_hasBits0 & 2) != 0) { return negativeIntValue_; } else { return NegativeIntValueDefaultValue; } }
set {
+ _hasBits0 |= 2;
negativeIntValue_ = value;
}
}
+ /// <summary>Gets whether the "negative_int_value" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasNegativeIntValue {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "negative_int_value" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearNegativeIntValue() {
+ _hasBits0 &= ~2;
+ }
/// <summary>Field number for the "double_value" field.</summary>
public const int DoubleValueFieldNumber = 6;
+ private readonly static double DoubleValueDefaultValue = 0D;
+
private double doubleValue_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public double DoubleValue {
- get { return doubleValue_; }
+ get { if ((_hasBits0 & 4) != 0) { return doubleValue_; } else { return DoubleValueDefaultValue; } }
set {
+ _hasBits0 |= 4;
doubleValue_ = value;
}
}
+ /// <summary>Gets whether the "double_value" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasDoubleValue {
+ get { return (_hasBits0 & 4) != 0; }
+ }
+ /// <summary>Clears the value of the "double_value" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearDoubleValue() {
+ _hasBits0 &= ~4;
+ }
/// <summary>Field number for the "string_value" field.</summary>
public const int StringValueFieldNumber = 7;
- private pb::ByteString stringValue_ = pb::ByteString.Empty;
+ private readonly static pb::ByteString StringValueDefaultValue = pb::ByteString.Empty;
+
+ private pb::ByteString stringValue_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public pb::ByteString StringValue {
- get { return stringValue_; }
+ get { return stringValue_ ?? StringValueDefaultValue; }
set {
stringValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "string_value" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasStringValue {
+ get { return stringValue_ != null; }
+ }
+ /// <summary>Clears the value of the "string_value" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearStringValue() {
+ stringValue_ = null;
+ }
/// <summary>Field number for the "aggregate_value" field.</summary>
public const int AggregateValueFieldNumber = 8;
- private string aggregateValue_ = "";
+ private readonly static string AggregateValueDefaultValue = "";
+
+ private string aggregateValue_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string AggregateValue {
- get { return aggregateValue_; }
+ get { return aggregateValue_ ?? AggregateValueDefaultValue; }
set {
aggregateValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "aggregate_value" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasAggregateValue {
+ get { return aggregateValue_ != null; }
+ }
+ /// <summary>Clears the value of the "aggregate_value" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearAggregateValue() {
+ aggregateValue_ = null;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -5789,12 +6813,12 @@ namespace Google.Protobuf.Reflection {
public override int GetHashCode() {
int hash = 1;
hash ^= name_.GetHashCode();
- if (IdentifierValue.Length != 0) hash ^= IdentifierValue.GetHashCode();
- if (PositiveIntValue != 0UL) hash ^= PositiveIntValue.GetHashCode();
- if (NegativeIntValue != 0L) hash ^= NegativeIntValue.GetHashCode();
- if (DoubleValue != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleValue);
- if (StringValue.Length != 0) hash ^= StringValue.GetHashCode();
- if (AggregateValue.Length != 0) hash ^= AggregateValue.GetHashCode();
+ if (HasIdentifierValue) hash ^= IdentifierValue.GetHashCode();
+ if (HasPositiveIntValue) hash ^= PositiveIntValue.GetHashCode();
+ if (HasNegativeIntValue) hash ^= NegativeIntValue.GetHashCode();
+ if (HasDoubleValue) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleValue);
+ if (HasStringValue) hash ^= StringValue.GetHashCode();
+ if (HasAggregateValue) hash ^= AggregateValue.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -5809,27 +6833,27 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
name_.WriteTo(output, _repeated_name_codec);
- if (IdentifierValue.Length != 0) {
+ if (HasIdentifierValue) {
output.WriteRawTag(26);
output.WriteString(IdentifierValue);
}
- if (PositiveIntValue != 0UL) {
+ if (HasPositiveIntValue) {
output.WriteRawTag(32);
output.WriteUInt64(PositiveIntValue);
}
- if (NegativeIntValue != 0L) {
+ if (HasNegativeIntValue) {
output.WriteRawTag(40);
output.WriteInt64(NegativeIntValue);
}
- if (DoubleValue != 0D) {
+ if (HasDoubleValue) {
output.WriteRawTag(49);
output.WriteDouble(DoubleValue);
}
- if (StringValue.Length != 0) {
+ if (HasStringValue) {
output.WriteRawTag(58);
output.WriteBytes(StringValue);
}
- if (AggregateValue.Length != 0) {
+ if (HasAggregateValue) {
output.WriteRawTag(66);
output.WriteString(AggregateValue);
}
@@ -5842,22 +6866,22 @@ namespace Google.Protobuf.Reflection {
public int CalculateSize() {
int size = 0;
size += name_.CalculateSize(_repeated_name_codec);
- if (IdentifierValue.Length != 0) {
+ if (HasIdentifierValue) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(IdentifierValue);
}
- if (PositiveIntValue != 0UL) {
+ if (HasPositiveIntValue) {
size += 1 + pb::CodedOutputStream.ComputeUInt64Size(PositiveIntValue);
}
- if (NegativeIntValue != 0L) {
+ if (HasNegativeIntValue) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(NegativeIntValue);
}
- if (DoubleValue != 0D) {
+ if (HasDoubleValue) {
size += 1 + 8;
}
- if (StringValue.Length != 0) {
+ if (HasStringValue) {
size += 1 + pb::CodedOutputStream.ComputeBytesSize(StringValue);
}
- if (AggregateValue.Length != 0) {
+ if (HasAggregateValue) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(AggregateValue);
}
if (_unknownFields != null) {
@@ -5872,22 +6896,22 @@ namespace Google.Protobuf.Reflection {
return;
}
name_.Add(other.name_);
- if (other.IdentifierValue.Length != 0) {
+ if (other.HasIdentifierValue) {
IdentifierValue = other.IdentifierValue;
}
- if (other.PositiveIntValue != 0UL) {
+ if (other.HasPositiveIntValue) {
PositiveIntValue = other.PositiveIntValue;
}
- if (other.NegativeIntValue != 0L) {
+ if (other.HasNegativeIntValue) {
NegativeIntValue = other.NegativeIntValue;
}
- if (other.DoubleValue != 0D) {
+ if (other.HasDoubleValue) {
DoubleValue = other.DoubleValue;
}
- if (other.StringValue.Length != 0) {
+ if (other.HasStringValue) {
StringValue = other.StringValue;
}
- if (other.AggregateValue.Length != 0) {
+ if (other.HasAggregateValue) {
AggregateValue = other.AggregateValue;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
@@ -5947,6 +6971,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class NamePart : pb::IMessage<NamePart> {
private static readonly pb::MessageParser<NamePart> _parser = new pb::MessageParser<NamePart>(() => new NamePart());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<NamePart> Parser { get { return _parser; } }
@@ -5969,6 +6994,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public NamePart(NamePart other) : this() {
+ _hasBits0 = other._hasBits0;
namePart_ = other.namePart_;
isExtension_ = other.isExtension_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@@ -5981,25 +7007,50 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "name_part" field.</summary>
public const int NamePart_FieldNumber = 1;
- private string namePart_ = "";
+ private readonly static string NamePart_DefaultValue = "";
+
+ private string namePart_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string NamePart_ {
- get { return namePart_; }
+ get { return namePart_ ?? NamePart_DefaultValue; }
set {
namePart_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "name_part" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasNamePart_ {
+ get { return namePart_ != null; }
+ }
+ /// <summary>Clears the value of the "name_part" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearNamePart_() {
+ namePart_ = null;
+ }
/// <summary>Field number for the "is_extension" field.</summary>
public const int IsExtensionFieldNumber = 2;
+ private readonly static bool IsExtensionDefaultValue = false;
+
private bool isExtension_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool IsExtension {
- get { return isExtension_; }
+ get { if ((_hasBits0 & 1) != 0) { return isExtension_; } else { return IsExtensionDefaultValue; } }
set {
+ _hasBits0 |= 1;
isExtension_ = value;
}
}
+ /// <summary>Gets whether the "is_extension" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasIsExtension {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "is_extension" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearIsExtension() {
+ _hasBits0 &= ~1;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -6022,8 +7073,8 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (NamePart_.Length != 0) hash ^= NamePart_.GetHashCode();
- if (IsExtension != false) hash ^= IsExtension.GetHashCode();
+ if (HasNamePart_) hash ^= NamePart_.GetHashCode();
+ if (HasIsExtension) hash ^= IsExtension.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -6037,11 +7088,11 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (NamePart_.Length != 0) {
+ if (HasNamePart_) {
output.WriteRawTag(10);
output.WriteString(NamePart_);
}
- if (IsExtension != false) {
+ if (HasIsExtension) {
output.WriteRawTag(16);
output.WriteBool(IsExtension);
}
@@ -6053,10 +7104,10 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (NamePart_.Length != 0) {
+ if (HasNamePart_) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(NamePart_);
}
- if (IsExtension != false) {
+ if (HasIsExtension) {
size += 1 + 1;
}
if (_unknownFields != null) {
@@ -6070,10 +7121,10 @@ namespace Google.Protobuf.Reflection {
if (other == null) {
return;
}
- if (other.NamePart_.Length != 0) {
+ if (other.HasNamePart_) {
NamePart_ = other.NamePart_;
}
- if (other.IsExtension != false) {
+ if (other.HasIsExtension) {
IsExtension = other.IsExtension;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
@@ -6370,7 +7421,9 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "leading_comments" field.</summary>
public const int LeadingCommentsFieldNumber = 3;
- private string leadingComments_ = "";
+ private readonly static string LeadingCommentsDefaultValue = "";
+
+ private string leadingComments_;
/// <summary>
/// If this SourceCodeInfo represents a complete declaration, these are any
/// comments appearing before and after the declaration which appear to be
@@ -6422,22 +7475,44 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string LeadingComments {
- get { return leadingComments_; }
+ get { return leadingComments_ ?? LeadingCommentsDefaultValue; }
set {
leadingComments_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "leading_comments" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasLeadingComments {
+ get { return leadingComments_ != null; }
+ }
+ /// <summary>Clears the value of the "leading_comments" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearLeadingComments() {
+ leadingComments_ = null;
+ }
/// <summary>Field number for the "trailing_comments" field.</summary>
public const int TrailingCommentsFieldNumber = 4;
- private string trailingComments_ = "";
+ private readonly static string TrailingCommentsDefaultValue = "";
+
+ private string trailingComments_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string TrailingComments {
- get { return trailingComments_; }
+ get { return trailingComments_ ?? TrailingCommentsDefaultValue; }
set {
trailingComments_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "trailing_comments" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasTrailingComments {
+ get { return trailingComments_ != null; }
+ }
+ /// <summary>Clears the value of the "trailing_comments" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearTrailingComments() {
+ trailingComments_ = null;
+ }
/// <summary>Field number for the "leading_detached_comments" field.</summary>
public const int LeadingDetachedCommentsFieldNumber = 6;
@@ -6475,8 +7550,8 @@ namespace Google.Protobuf.Reflection {
int hash = 1;
hash ^= path_.GetHashCode();
hash ^= span_.GetHashCode();
- if (LeadingComments.Length != 0) hash ^= LeadingComments.GetHashCode();
- if (TrailingComments.Length != 0) hash ^= TrailingComments.GetHashCode();
+ if (HasLeadingComments) hash ^= LeadingComments.GetHashCode();
+ if (HasTrailingComments) hash ^= TrailingComments.GetHashCode();
hash ^= leadingDetachedComments_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@@ -6493,11 +7568,11 @@ namespace Google.Protobuf.Reflection {
public void WriteTo(pb::CodedOutputStream output) {
path_.WriteTo(output, _repeated_path_codec);
span_.WriteTo(output, _repeated_span_codec);
- if (LeadingComments.Length != 0) {
+ if (HasLeadingComments) {
output.WriteRawTag(26);
output.WriteString(LeadingComments);
}
- if (TrailingComments.Length != 0) {
+ if (HasTrailingComments) {
output.WriteRawTag(34);
output.WriteString(TrailingComments);
}
@@ -6512,10 +7587,10 @@ namespace Google.Protobuf.Reflection {
int size = 0;
size += path_.CalculateSize(_repeated_path_codec);
size += span_.CalculateSize(_repeated_span_codec);
- if (LeadingComments.Length != 0) {
+ if (HasLeadingComments) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(LeadingComments);
}
- if (TrailingComments.Length != 0) {
+ if (HasTrailingComments) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(TrailingComments);
}
size += leadingDetachedComments_.CalculateSize(_repeated_leadingDetachedComments_codec);
@@ -6532,10 +7607,10 @@ namespace Google.Protobuf.Reflection {
}
path_.Add(other.path_);
span_.Add(other.span_);
- if (other.LeadingComments.Length != 0) {
+ if (other.HasLeadingComments) {
LeadingComments = other.LeadingComments;
}
- if (other.TrailingComments.Length != 0) {
+ if (other.HasTrailingComments) {
TrailingComments = other.TrailingComments;
}
leadingDetachedComments_.Add(other.leadingDetachedComments_);
@@ -6718,6 +7793,7 @@ namespace Google.Protobuf.Reflection {
internal sealed partial class Annotation : pb::IMessage<Annotation> {
private static readonly pb::MessageParser<Annotation> _parser = new pb::MessageParser<Annotation>(() => new Annotation());
private pb::UnknownFieldSet _unknownFields;
+ private int _hasBits0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Annotation> Parser { get { return _parser; } }
@@ -6740,6 +7816,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Annotation(Annotation other) : this() {
+ _hasBits0 = other._hasBits0;
path_ = other.path_.Clone();
sourceFile_ = other.sourceFile_;
begin_ = other.begin_;
@@ -6768,20 +7845,34 @@ namespace Google.Protobuf.Reflection {
/// <summary>Field number for the "source_file" field.</summary>
public const int SourceFileFieldNumber = 2;
- private string sourceFile_ = "";
+ private readonly static string SourceFileDefaultValue = "";
+
+ private string sourceFile_;
/// <summary>
/// Identifies the filesystem path to the original source .proto.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string SourceFile {
- get { return sourceFile_; }
+ get { return sourceFile_ ?? SourceFileDefaultValue; }
set {
sourceFile_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
+ /// <summary>Gets whether the "source_file" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasSourceFile {
+ get { return sourceFile_ != null; }
+ }
+ /// <summary>Clears the value of the "source_file" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearSourceFile() {
+ sourceFile_ = null;
+ }
/// <summary>Field number for the "begin" field.</summary>
public const int BeginFieldNumber = 3;
+ private readonly static int BeginDefaultValue = 0;
+
private int begin_;
/// <summary>
/// Identifies the starting offset in bytes in the generated code
@@ -6789,14 +7880,27 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int Begin {
- get { return begin_; }
+ get { if ((_hasBits0 & 1) != 0) { return begin_; } else { return BeginDefaultValue; } }
set {
+ _hasBits0 |= 1;
begin_ = value;
}
}
+ /// <summary>Gets whether the "begin" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasBegin {
+ get { return (_hasBits0 & 1) != 0; }
+ }
+ /// <summary>Clears the value of the "begin" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearBegin() {
+ _hasBits0 &= ~1;
+ }
/// <summary>Field number for the "end" field.</summary>
public const int EndFieldNumber = 4;
+ private readonly static int EndDefaultValue = 0;
+
private int end_;
/// <summary>
/// Identifies the ending offset in bytes in the generated code that
@@ -6805,11 +7909,22 @@ namespace Google.Protobuf.Reflection {
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int End {
- get { return end_; }
+ get { if ((_hasBits0 & 2) != 0) { return end_; } else { return EndDefaultValue; } }
set {
+ _hasBits0 |= 2;
end_ = value;
}
}
+ /// <summary>Gets whether the "end" field is set</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasEnd {
+ get { return (_hasBits0 & 2) != 0; }
+ }
+ /// <summary>Clears the value of the "end" field</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearEnd() {
+ _hasBits0 &= ~2;
+ }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@@ -6835,9 +7950,9 @@ namespace Google.Protobuf.Reflection {
public override int GetHashCode() {
int hash = 1;
hash ^= path_.GetHashCode();
- if (SourceFile.Length != 0) hash ^= SourceFile.GetHashCode();
- if (Begin != 0) hash ^= Begin.GetHashCode();
- if (End != 0) hash ^= End.GetHashCode();
+ if (HasSourceFile) hash ^= SourceFile.GetHashCode();
+ if (HasBegin) hash ^= Begin.GetHashCode();
+ if (HasEnd) hash ^= End.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -6852,15 +7967,15 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
path_.WriteTo(output, _repeated_path_codec);
- if (SourceFile.Length != 0) {
+ if (HasSourceFile) {
output.WriteRawTag(18);
output.WriteString(SourceFile);
}
- if (Begin != 0) {
+ if (HasBegin) {
output.WriteRawTag(24);
output.WriteInt32(Begin);
}
- if (End != 0) {
+ if (HasEnd) {
output.WriteRawTag(32);
output.WriteInt32(End);
}
@@ -6873,13 +7988,13 @@ namespace Google.Protobuf.Reflection {
public int CalculateSize() {
int size = 0;
size += path_.CalculateSize(_repeated_path_codec);
- if (SourceFile.Length != 0) {
+ if (HasSourceFile) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(SourceFile);
}
- if (Begin != 0) {
+ if (HasBegin) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Begin);
}
- if (End != 0) {
+ if (HasEnd) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(End);
}
if (_unknownFields != null) {
@@ -6894,13 +8009,13 @@ namespace Google.Protobuf.Reflection {
return;
}
path_.Add(other.path_);
- if (other.SourceFile.Length != 0) {
+ if (other.HasSourceFile) {
SourceFile = other.SourceFile;
}
- if (other.Begin != 0) {
+ if (other.HasBegin) {
Begin = other.Begin;
}
- if (other.End != 0) {
+ if (other.HasEnd) {
End = other.End;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
diff --git a/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs b/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs
index 194041a8..bfbebf17 100644
--- a/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs
+++ b/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs
@@ -30,6 +30,8 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
+using System.Collections.Generic;
+
namespace Google.Protobuf.Reflection
{
/// <summary>
@@ -37,15 +39,11 @@ namespace Google.Protobuf.Reflection
/// </summary>
public abstract class DescriptorBase : IDescriptor
{
- private readonly FileDescriptor file;
- private readonly string fullName;
- private readonly int index;
-
internal DescriptorBase(FileDescriptor file, string fullName, int index)
{
- this.file = file;
- this.fullName = fullName;
- this.index = index;
+ File = file;
+ FullName = fullName;
+ Index = index;
}
/// <value>
@@ -56,10 +54,7 @@ namespace Google.Protobuf.Reflection
/// this descriptor's type. (There can be duplicate values for different
/// types, e.g. one enum type with index 0 and one message type with index 0.)
/// </remarks>
- public int Index
- {
- get { return index; }
- }
+ public int Index { get; }
/// <summary>
/// Returns the name of the entity (field, message etc) being described.
@@ -69,17 +64,29 @@ namespace Google.Protobuf.Reflection
/// <summary>
/// The fully qualified name of the descriptor's target.
/// </summary>
- public string FullName
- {
- get { return fullName; }
- }
+ public string FullName { get; }
/// <value>
/// The file this descriptor was declared in.
/// </value>
- public FileDescriptor File
- {
- get { return file; }
- }
+ public FileDescriptor File { get; }
+
+ /// <summary>
+ /// The declaration information about the descriptor, or null if no declaration information
+ /// is available for this descriptor.
+ /// </summary>
+ /// <remarks>
+ /// This information is typically only available for dynamically loaded descriptors,
+ /// for example within a protoc plugin where the full descriptors, including source info,
+ /// are passed to the code by protoc.
+ /// </remarks>
+ public DescriptorDeclaration Declaration => File.GetDeclaration(this);
+
+ /// <summary>
+ /// Retrieves the list of nested descriptors corresponding to the given field number, if any.
+ /// If the field is unknown or not a nested descriptor list, return null to terminate the search.
+ /// The default implementation returns null.
+ /// </summary>
+ internal virtual IReadOnlyList<DescriptorBase> GetNestedDescriptorListForField(int fieldNumber) => null;
}
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs b/csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs
new file mode 100644
index 00000000..b22048f0
--- /dev/null
+++ b/csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs
@@ -0,0 +1,112 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2018 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Provides additional information about the declaration of a descriptor,
+ /// such as source location and comments.
+ /// </summary>
+ public sealed class DescriptorDeclaration
+ {
+ /// <summary>
+ /// The descriptor this declaration relates to.
+ /// </summary>
+ public IDescriptor Descriptor { get; }
+
+ /// <summary>
+ /// The start line of the declaration within the source file. This value is 1-based.
+ /// </summary>
+ public int StartLine { get; }
+ /// <summary>
+ /// The start column of the declaration within the source file. This value is 1-based.
+ /// </summary>
+ public int StartColumn { get; }
+
+ /// <summary>
+ /// // The end line of the declaration within the source file. This value is 1-based.
+ /// </summary>
+ public int EndLine { get; }
+ /// <summary>
+ /// The end column of the declaration within the source file. This value is 1-based, and
+ /// exclusive. (The final character of the declaration is on the column before this value.)
+ /// </summary>
+ public int EndColumn { get; }
+
+ /// <summary>
+ /// Comments appearing before the declaration. Never null, but may be empty. Multi-line comments
+ /// are represented as a newline-separated string. Leading whitespace and the comment marker ("//")
+ /// are removed from each line.
+ /// </summary>
+ public string LeadingComments { get; }
+
+ /// <summary>
+ /// Comments appearing after the declaration. Never null, but may be empty. Multi-line comments
+ /// are represented as a newline-separated string. Leading whitespace and the comment marker ("//")
+ /// are removed from each line.
+ /// </summary>
+ public string TrailingComments { get; }
+
+ /// <summary>
+ /// Comments appearing before the declaration, but separated from it by blank
+ /// lines. Each string represents a newline-separated paragraph of comments.
+ /// Leading whitespace and the comment marker ("//") are removed from each line.
+ /// The list is never null, but may be empty. Likewise each element is never null, but may be empty.
+ /// </summary>
+ public IReadOnlyList<string> LeadingDetachedComments { get; }
+
+ private DescriptorDeclaration(IDescriptor descriptor, Location location)
+ {
+ // TODO: Validation
+ Descriptor = descriptor;
+ bool hasEndLine = location.Span.Count == 4;
+ // Lines and columns are 0-based in the proto.
+ StartLine = location.Span[0] + 1;
+ StartColumn = location.Span[1] + 1;
+ EndLine = hasEndLine ? location.Span[2] + 1 : StartLine;
+ EndColumn = location.Span[hasEndLine ? 3 : 2] + 1;
+ LeadingComments = location.LeadingComments;
+ TrailingComments = location.TrailingComments;
+ LeadingDetachedComments = new ReadOnlyCollection<string>(location.LeadingDetachedComments.ToList());
+ }
+
+ internal static DescriptorDeclaration FromProto(IDescriptor descriptor, Location location) =>
+ new DescriptorDeclaration(descriptor, location);
+ }
+}
diff --git a/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs b/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs
index 99ca4bf3..9c2160fe 100644
--- a/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs
+++ b/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs
@@ -53,13 +53,13 @@ namespace Google.Protobuf.Reflection
private readonly HashSet<FileDescriptor> dependencies;
- internal DescriptorPool(FileDescriptor[] dependencyFiles)
+ internal DescriptorPool(IEnumerable<FileDescriptor> dependencyFiles)
{
dependencies = new HashSet<FileDescriptor>();
- for (int i = 0; i < dependencyFiles.Length; i++)
+ foreach (var dependencyFile in dependencyFiles)
{
- dependencies.Add(dependencyFiles[i]);
- ImportPublicDependencies(dependencyFiles[i]);
+ dependencies.Add(dependencyFile);
+ ImportPublicDependencies(dependencyFile);
}
foreach (FileDescriptor dependency in dependencyFiles)
diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
index 89c73a61..4c5457a7 100644
--- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
@@ -72,6 +72,17 @@ namespace Google.Protobuf.Reflection
/// </summary>
public override string Name { get { return proto.Name; } }
+ internal override IReadOnlyList<DescriptorBase> GetNestedDescriptorListForField(int fieldNumber)
+ {
+ switch (fieldNumber)
+ {
+ case EnumDescriptorProto.ValueFieldNumber:
+ return (IReadOnlyList<DescriptorBase>) Values;
+ default:
+ return null;
+ }
+ }
+
/// <summary>
/// The CLR type for this enum. For generated code, this will be a CLR enum type.
/// </summary>
diff --git a/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs b/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs
index 82ce5051..85b7d39a 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs
@@ -57,6 +57,7 @@ namespace Google.Protobuf.Reflection
return getValueDelegate(message);
}
+ public abstract bool HasValue(IMessage message);
public abstract void Clear(IMessage message);
public abstract void SetValue(IMessage message, object value);
}
diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
index 2a3d5c7a..0a46f9eb 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
@@ -79,8 +79,7 @@ namespace Google.Protobuf.Reflection
throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
}
ContainingType = parent;
- // OneofIndex "defaults" to -1 due to a hack in FieldDescriptor.OnConstruction.
- if (proto.OneofIndex != -1)
+ if (proto.HasOneofIndex)
{
if (proto.OneofIndex < 0 || proto.OneofIndex >= parent.Proto.OneofDecl.Count)
{
@@ -116,13 +115,18 @@ namespace Google.Protobuf.Reflection
/// that is the responsibility of the accessor.
/// </para>
/// <para>
- /// The value returned by this property will be non-null for all regular fields. However,
- /// if a message containing a map field is introspected, the list of nested messages will include
+ /// In descriptors for generated code, the value returned by this property will be non-null for all
+ /// regular fields. However, if a message containing a map field is introspected, the list of nested messages will include
/// an auto-generated nested key/value pair message for the field. This is not represented in any
/// generated type, and the value of the map field itself is represented by a dictionary in the
/// reflection API. There are never instances of those "hidden" messages, so no accessor is provided
/// and this property will return null.
/// </para>
+ /// <para>
+ /// In dynamically loaded descriptors, the value returned by this property will current be null;
+ /// if and when dynamic messages are supported, it will return a suitable accessor to work with
+ /// them.
+ /// </para>
/// </remarks>
public IFieldAccessor Accessor => accessor;
@@ -179,6 +183,11 @@ namespace Google.Protobuf.Reflection
/// </summary>
public bool IsRepeated => Proto.Label == FieldDescriptorProto.Types.Label.Repeated;
+ /// <summary>
+ /// Returns <c>true</c> if this field is a required field; <c>false</c> otherwise.
+ /// </summary>
+ public bool IsRequired => Proto.Label == FieldDescriptorProto.Types.Label.Required;
+
/// <summary>
/// Returns <c>true</c> if this field is a map field; <c>false</c> otherwise.
/// </summary>
@@ -187,13 +196,8 @@ namespace Google.Protobuf.Reflection
/// <summary>
/// Returns <c>true</c> if this field is a packed, repeated field; <c>false</c> otherwise.
/// </summary>
- public bool IsPacked =>
- // Note the || rather than && here - we're effectively defaulting to packed, because that *is*
- // the default in proto3, which is all we support. We may give the wrong result for the protos
- // within descriptor.proto, but that's okay, as they're never exposed and we don't use IsPacked
- // within the runtime.
- Proto.Options == null || Proto.Options.Packed;
-
+ public bool IsPacked => File.Proto.Syntax == "proto2" ? Proto.Options?.Packed ?? false : !Proto.Options.HasPacked || Proto.Options.Packed;
+
/// <summary>
/// Returns the type of the field.
/// </summary>
@@ -242,9 +246,9 @@ namespace Google.Protobuf.Reflection
{
get
{
- if (fieldType != FieldType.Message)
+ if (fieldType != FieldType.Message && fieldType != FieldType.Group)
{
- throw new InvalidOperationException("MessageType is only valid for message fields.");
+ throw new InvalidOperationException("MessageType is only valid for message or group fields.");
}
return messageType;
}
@@ -260,12 +264,12 @@ namespace Google.Protobuf.Reflection
/// </summary>
internal void CrossLink()
{
- if (Proto.TypeName != "")
+ if (Proto.HasTypeName)
{
IDescriptor typeDescriptor =
File.DescriptorPool.LookupSymbol(Proto.TypeName, this);
- if (Proto.Type != 0)
+ if (Proto.HasType)
{
// Choose field type based on symbol.
if (typeDescriptor is MessageDescriptor)
@@ -282,7 +286,7 @@ namespace Google.Protobuf.Reflection
}
}
- if (fieldType == FieldType.Message)
+ if (fieldType == FieldType.Message || fieldType == FieldType.Group)
{
if (!(typeDescriptor is MessageDescriptor))
{
@@ -290,7 +294,7 @@ namespace Google.Protobuf.Reflection
}
messageType = (MessageDescriptor) typeDescriptor;
- if (Proto.DefaultValue != "")
+ if (Proto.HasDefaultValue)
{
throw new DescriptorValidationException(this, "Messages can't have default values.");
}
@@ -320,7 +324,7 @@ namespace Google.Protobuf.Reflection
File.DescriptorPool.AddFieldByNumber(this);
- if (ContainingType != null && ContainingType.Proto.Options != null && ContainingType.Proto.Options.MessageSetWireFormat)
+ if (ContainingType != null && ContainingType.Proto.HasOptions && ContainingType.Proto.Options.MessageSetWireFormat)
{
throw new DescriptorValidationException(this, "MessageSet format is not supported.");
}
@@ -330,7 +334,8 @@ namespace Google.Protobuf.Reflection
private IFieldAccessor CreateAccessor()
{
// If we're given no property name, that's because we really don't want an accessor.
- // (At the moment, that means it's a map entry message...)
+ // This could be because it's a map message, or it could be that we're loading a FileDescriptor dynamically.
+ // TODO: Support dynamic messages.
if (propertyName == null)
{
return null;
diff --git a/csharp/src/Google.Protobuf/Reflection/FieldType.cs b/csharp/src/Google.Protobuf/Reflection/FieldType.cs
index 1658e34c..37af1791 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldType.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldType.cs
@@ -74,7 +74,7 @@ namespace Google.Protobuf.Reflection
/// </summary>
String,
/// <summary>
- /// The field type used for groups (not supported in this implementation).
+ /// The field type used for groups.
/// </summary>
Group,
/// <summary>
diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
index be94cb10..6d4520c0 100644
--- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
@@ -34,6 +34,10 @@ using Google.Protobuf.WellKnownTypes;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Threading;
+using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
namespace Google.Protobuf.Reflection
{
@@ -54,12 +58,14 @@ namespace Google.Protobuf.Reflection
ForceReflectionInitialization<Value.KindOneofCase>();
}
- private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo)
+ private readonly Lazy<Dictionary<IDescriptor, DescriptorDeclaration>> declarations;
+
+ private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, IEnumerable<FileDescriptor> dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo)
{
SerializedData = descriptorData;
DescriptorPool = pool;
Proto = proto;
- Dependencies = new ReadOnlyCollection<FileDescriptor>((FileDescriptor[]) dependencies.Clone());
+ Dependencies = new ReadOnlyCollection<FileDescriptor>(dependencies.ToList());
PublicDependencies = DeterminePublicDependencies(this, proto, dependencies, allowUnknownDependencies);
@@ -67,15 +73,90 @@ namespace Google.Protobuf.Reflection
MessageTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.MessageType,
(message, index) =>
- new MessageDescriptor(message, this, null, index, generatedCodeInfo.NestedTypes[index]));
+ new MessageDescriptor(message, this, null, index, generatedCodeInfo?.NestedTypes[index]));
EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.EnumType,
(enumType, index) =>
- new EnumDescriptor(enumType, this, null, index, generatedCodeInfo.NestedEnums[index]));
+ new EnumDescriptor(enumType, this, null, index, generatedCodeInfo?.NestedEnums[index]));
Services = DescriptorUtil.ConvertAndMakeReadOnly(proto.Service,
(service, index) =>
new ServiceDescriptor(service, this, index));
+
+ declarations = new Lazy<Dictionary<IDescriptor, DescriptorDeclaration>>(CreateDeclarationMap, LazyThreadSafetyMode.ExecutionAndPublication);
+ }
+
+ private Dictionary<IDescriptor, DescriptorDeclaration> CreateDeclarationMap()
+ {
+ var dictionary = new Dictionary<IDescriptor, DescriptorDeclaration>();
+ foreach (var location in Proto.SourceCodeInfo?.Location ?? Enumerable.Empty<Location>())
+ {
+ var descriptor = FindDescriptorForPath(location.Path);
+ if (descriptor != null)
+ {
+ dictionary[descriptor] = DescriptorDeclaration.FromProto(descriptor, location);
+ }
+ }
+ return dictionary;
+
+ IDescriptor FindDescriptorForPath(IList<int> path)
+ {
+ // All complete declarations have an even, non-empty path length
+ // (There can be an empty path for a descriptor declaration, but that can't have any comments,
+ // so we currently ignore it.)
+ if (path.Count == 0 || (path.Count & 1) != 0)
+ {
+ return null;
+ }
+ IReadOnlyList<DescriptorBase> topLevelList = GetNestedDescriptorListForField(path[0]);
+ DescriptorBase current = GetDescriptorFromList(topLevelList, path[1]);
+
+ for (int i = 2; current != null && i < path.Count; i += 2)
+ {
+ var list = current.GetNestedDescriptorListForField(path[i]);
+ current = GetDescriptorFromList(list, path[i + 1]);
+ }
+ return current;
+ }
+
+ DescriptorBase GetDescriptorFromList(IReadOnlyList<DescriptorBase> list, int index)
+ {
+ // This is fine: it may be a newer version of protobuf than we understand, with a new descriptor
+ // field.
+ if (list == null)
+ {
+ return null;
+ }
+ // We *could* return null to silently continue, but this is basically data corruption.
+ if (index < 0 || index >= list.Count)
+ {
+ // We don't have much extra information to give at this point unfortunately. If this becomes a problem,
+ // we can pass in the complete path and report that and the file name.
+ throw new InvalidProtocolBufferException($"Invalid descriptor location path: index out of range");
+ }
+ return list[index];
+ }
+
+ IReadOnlyList<DescriptorBase> GetNestedDescriptorListForField(int fieldNumber)
+ {
+ switch (fieldNumber)
+ {
+ case FileDescriptorProto.ServiceFieldNumber:
+ return (IReadOnlyList<DescriptorBase>) Services;
+ case FileDescriptorProto.MessageTypeFieldNumber:
+ return (IReadOnlyList<DescriptorBase>) MessageTypes;
+ case FileDescriptorProto.EnumTypeFieldNumber:
+ return (IReadOnlyList<DescriptorBase>) EnumTypes;
+ default:
+ return null;
+ }
+ }
+ }
+
+ internal DescriptorDeclaration GetDeclaration(IDescriptor descriptor)
+ {
+ declarations.Value.TryGetValue(descriptor, out var declaration);
+ return declaration;
}
/// <summary>
@@ -98,13 +179,9 @@ namespace Google.Protobuf.Reflection
/// Extracts public dependencies from direct dependencies. This is a static method despite its
/// first parameter, as the value we're in the middle of constructing is only used for exceptions.
/// </summary>
- private static IList<FileDescriptor> DeterminePublicDependencies(FileDescriptor @this, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies)
+ private static IList<FileDescriptor> DeterminePublicDependencies(FileDescriptor @this, FileDescriptorProto proto, IEnumerable<FileDescriptor> dependencies, bool allowUnknownDependencies)
{
- var nameToFileMap = new Dictionary<string, FileDescriptor>();
- foreach (var file in dependencies)
- {
- nameToFileMap[file.Name] = file;
- }
+ var nameToFileMap = dependencies.ToDictionary(file => file.Name);
var publicDependencies = new List<FileDescriptor>();
for (int i = 0; i < proto.PublicDependency.Count; i++)
{
@@ -114,8 +191,7 @@ namespace Google.Protobuf.Reflection
throw new DescriptorValidationException(@this, "Invalid public dependency index.");
}
string name = proto.Dependency[index];
- FileDescriptor file = nameToFileMap[name];
- if (file == null)
+ if (!nameToFileMap.TryGetValue(name, out var file))
{
if (!allowUnknownDependencies)
{
@@ -316,6 +392,50 @@ namespace Google.Protobuf.Reflection
}
/// <summary>
+ /// Converts the given descriptor binary data into FileDescriptor objects.
+ /// Note: reflection using the returned FileDescriptors is not currently supported.
+ /// </summary>
+ /// <param name="descriptorData">The binary file descriptor proto data. Must not be null, and any
+ /// dependencies must come before the descriptor which depends on them. (If A depends on B, and B
+ /// depends on C, then the descriptors must be presented in the order C, B, A.) This is compatible
+ /// with the order in which protoc provides descriptors to plugins.</param>
+ /// <returns>The file descriptors corresponding to <paramref name="descriptorData"/>.</returns>
+ public static IReadOnlyList<FileDescriptor> BuildFromByteStrings(IEnumerable<ByteString> descriptorData)
+ {
+ ProtoPreconditions.CheckNotNull(descriptorData, nameof(descriptorData));
+
+ // TODO: See if we can build a single DescriptorPool instead of building lots of them.
+ // This will all behave correctly, but it's less efficient than we'd like.
+ var descriptors = new List<FileDescriptor>();
+ var descriptorsByName = new Dictionary<string, FileDescriptor>();
+ foreach (var data in descriptorData)
+ {
+ var proto = FileDescriptorProto.Parser.ParseFrom(data);
+ var dependencies = new List<FileDescriptor>();
+ foreach (var dependencyName in proto.Dependency)
+ {
+ if (!descriptorsByName.TryGetValue(dependencyName, out var dependency))
+ {
+ throw new ArgumentException($"Dependency missing: {dependencyName}");
+ }
+ dependencies.Add(dependency);
+ }
+ var pool = new DescriptorPool(dependencies);
+ FileDescriptor descriptor = new FileDescriptor(
+ data, proto, dependencies, pool,
+ allowUnknownDependencies: false, generatedCodeInfo: null);
+ descriptor.CrossLink();
+ descriptors.Add(descriptor);
+ if (descriptorsByName.ContainsKey(descriptor.Name))
+ {
+ throw new ArgumentException($"Duplicate descriptor name: {descriptor.Name}");
+ }
+ descriptorsByName.Add(descriptor.Name, descriptor);
+ }
+ return new ReadOnlyCollection<FileDescriptor>(descriptors);
+ }
+
+ /// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
diff --git a/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs b/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
index cfe56fde..8f7ef3c6 100644
--- a/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
@@ -52,6 +52,11 @@ namespace Google.Protobuf.Reflection
void Clear(IMessage message);
/// <summary>
+ /// Indicates whether the field in the specified message is set. For proto3 fields, this throws an <see cref="InvalidOperationException"/>
+ /// </summary>
+ bool HasValue(IMessage message);
+
+ /// <summary>
/// Fetches the field value. For repeated values, this will be an
/// <see cref="IList"/> implementation. For map values, this will be an
/// <see cref="IDictionary"/> implementation.
diff --git a/csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs b/csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs
index 9ed7f8c4..56e3dddc 100644
--- a/csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs
@@ -51,6 +51,11 @@ namespace Google.Protobuf.Reflection
list.Clear();
}
+ public override bool HasValue(IMessage message)
+ {
+ throw new InvalidOperationException("HasValue is not implemented for map fields");
+ }
+
public override void SetValue(IMessage message, object value)
{
throw new InvalidOperationException("SetValue is not implemented for map fields");
diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
index 86942acc..03fd63ce 100644
--- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
@@ -72,23 +72,21 @@ namespace Google.Protobuf.Reflection
ClrType = generatedCodeInfo?.ClrType;
ContainingType = parent;
- // Note use of generatedCodeInfo. rather than generatedCodeInfo?. here... we don't expect
- // to see any nested oneofs, types or enums in "not actually generated" code... we do
- // expect fields though (for map entry messages).
+ // If generatedCodeInfo is null, we just won't generate an accessor for any fields.
Oneofs = DescriptorUtil.ConvertAndMakeReadOnly(
proto.OneofDecl,
(oneof, index) =>
- new OneofDescriptor(oneof, file, this, index, generatedCodeInfo.OneofNames[index]));
+ new OneofDescriptor(oneof, file, this, index, generatedCodeInfo?.OneofNames[index]));
NestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(
proto.NestedType,
(type, index) =>
- new MessageDescriptor(type, file, this, index, generatedCodeInfo.NestedTypes[index]));
+ new MessageDescriptor(type, file, this, index, generatedCodeInfo?.NestedTypes[index]));
EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(
proto.EnumType,
(type, index) =>
- new EnumDescriptor(type, file, this, index, generatedCodeInfo.NestedEnums[index]));
+ new EnumDescriptor(type, file, this, index, generatedCodeInfo?.NestedEnums[index]));
fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly(
proto.Field,
@@ -117,6 +115,21 @@ namespace Google.Protobuf.Reflection
/// </summary>
public override string Name => Proto.Name;
+ internal override IReadOnlyList<DescriptorBase> GetNestedDescriptorListForField(int fieldNumber)
+ {
+ switch (fieldNumber)
+ {
+ case DescriptorProto.FieldFieldNumber:
+ return (IReadOnlyList<DescriptorBase>) fieldsInDeclarationOrder;
+ case DescriptorProto.NestedTypeFieldNumber:
+ return (IReadOnlyList<DescriptorBase>) NestedTypes;
+ case DescriptorProto.EnumTypeFieldNumber:
+ return (IReadOnlyList<DescriptorBase>) EnumTypes;
+ default:
+ return null;
+ }
+ }
+
internal DescriptorProto Proto { get; }
/// <summary>
diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
index 5906c2e3..c026bea6 100644
--- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
@@ -85,6 +85,16 @@ namespace Google.Protobuf.Reflection
/// Gets an accessor for reflective access to the values associated with the oneof
/// in a particular message.
/// </summary>
+ /// <remarks>
+ /// <para>
+ /// In descriptors for generated code, the value returned by this property will always be non-null.
+ /// </para>
+ /// <para>
+ /// In dynamically loaded descriptors, the value returned by this property will current be null;
+ /// if and when dynamic messages are supported, it will return a suitable accessor to work with
+ /// them.
+ /// </para>
+ /// </remarks>
/// <value>
/// The accessor used for reflective access.
/// </value>
@@ -110,6 +120,12 @@ namespace Google.Protobuf.Reflection
private OneofAccessor CreateAccessor(string clrName)
{
+ // We won't have a CLR name if this is from a dynamically-loaded FileDescriptor.
+ // TODO: Support dynamic messages.
+ if (clrName == null)
+ {
+ return null;
+ }
var caseProperty = containingType.ClrType.GetProperty(clrName + "Case");
if (caseProperty == null)
{
diff --git a/csharp/src/Google.Protobuf/Reflection/PartialClasses.cs b/csharp/src/Google.Protobuf/Reflection/PartialClasses.cs
deleted file mode 100644
index 8c055d6d..00000000
--- a/csharp/src/Google.Protobuf/Reflection/PartialClasses.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-#region Copyright notice and license
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#endregion
-
-// This file just contains partial classes for any autogenerated classes that need additional support.
-namespace Google.Protobuf.Reflection
-{
- internal partial class FieldDescriptorProto
- {
- // We can't tell the difference between "explicitly set to 0" and "not set"
- // in proto3, but we need to tell the difference for OneofIndex. descriptor.proto
- // is really a proto2 file, but the runtime doesn't know about proto2 semantics...
- // We fake it by defaulting to -1.
- partial void OnConstruction()
- {
- OneofIndex = -1;
- }
- }
-
- internal partial class FieldOptions
- {
- // We can't tell the difference between "explicitly set to false" and "not set"
- // in proto3, but we need to tell the difference for FieldDescriptor.IsPacked.
- // This won't work if we ever need to support proto2, but at that point we'll be
- // able to remove this hack and use field presence instead.
- partial void OnConstruction()
- {
- Packed = true;
- }
- }
-} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
index feaeba0e..b22e8d12 100644
--- a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
+++ b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
@@ -112,6 +112,9 @@ namespace Google.Protobuf.Reflection
internal static Action<IMessage> CreateActionIMessage(MethodInfo method) =>
GetReflectionHelper(method.DeclaringType, typeof(object)).CreateActionIMessage(method);
+ internal static Func<IMessage, bool> CreateFuncIMessageBool(MethodInfo method) =>
+ GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageBool(method);
+
/// <summary>
/// Creates a reflection helper for the given type arguments. Currently these are created on demand
/// rather than cached; this will be "busy" when initially loading a message's descriptor, but after that
@@ -129,6 +132,7 @@ namespace Google.Protobuf.Reflection
Action<IMessage> CreateActionIMessage(MethodInfo method);
Func<IMessage, object> CreateFuncIMessageObject(MethodInfo method);
Action<IMessage, object> CreateActionIMessageObject(MethodInfo method);
+ Func<IMessage, bool> CreateFuncIMessageBool(MethodInfo method);
}
private class ReflectionHelper<T1, T2> : IReflectionHelper
@@ -170,6 +174,12 @@ namespace Google.Protobuf.Reflection
var del = (Action<T1, T2>) method.CreateDelegate(typeof(Action<T1, T2>));
return (message, arg) => del((T1) message, (T2) arg);
}
+
+ public Func<IMessage, bool> CreateFuncIMessageBool(MethodInfo method)
+ {
+ var del = (Func<T1, bool>)method.CreateDelegate(typeof(Func<T1, bool>));
+ return message => del((T1)message);
+ }
}
// Runtime compatibility checking code - see ReflectionHelper<T1, T2>.CreateFuncIMessageInt32 for
diff --git a/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs b/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs
index bd408470..afb4a693 100644
--- a/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs
@@ -51,6 +51,11 @@ namespace Google.Protobuf.Reflection
list.Clear();
}
+ public override bool HasValue(IMessage message)
+ {
+ throw new InvalidOperationException("HasValue is not implemented for repeated fields");
+ }
+
public override void SetValue(IMessage message, object value)
{
throw new InvalidOperationException("SetValue is not implemented for repeated fields");
diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
index fe5c072c..da570551 100644
--- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
@@ -32,6 +32,7 @@
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
namespace Google.Protobuf.Reflection
{
@@ -58,6 +59,17 @@ namespace Google.Protobuf.Reflection
/// </summary>
public override string Name { get { return proto.Name; } }
+ internal override IReadOnlyList<DescriptorBase> GetNestedDescriptorListForField(int fieldNumber)
+ {
+ switch (fieldNumber)
+ {
+ case ServiceDescriptorProto.MethodFieldNumber:
+ return (IReadOnlyList<DescriptorBase>) methods;
+ default:
+ return null;
+ }
+ }
+
internal ServiceDescriptorProto Proto { get { return proto; } }
/// <value>
diff --git a/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs b/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
index bbac2173..d541570f 100644
--- a/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
@@ -48,6 +48,7 @@ namespace Google.Protobuf.Reflection
private readonly Action<IMessage, object> setValueDelegate;
private readonly Action<IMessage> clearDelegate;
+ private readonly Func<IMessage, bool> hasDelegate;
internal SingleFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)
{
@@ -56,16 +57,25 @@ namespace Google.Protobuf.Reflection
throw new ArgumentException("Not all required properties/methods available");
}
setValueDelegate = ReflectionUtil.CreateActionIMessageObject(property.GetSetMethod());
+ if (descriptor.File.Proto.Syntax == "proto2")
+ {
+ MethodInfo hasMethod = property.DeclaringType.GetRuntimeProperty("Has" + property.Name).GetMethod;
+ hasDelegate = ReflectionUtil.CreateFuncIMessageBool(hasMethod ?? throw new ArgumentException("Not all required properties/methods are available"));
+ MethodInfo clearMethod = property.DeclaringType.GetRuntimeMethod("Clear" + property.Name, ReflectionUtil.EmptyTypes);
+ clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod ?? throw new ArgumentException("Not all required properties/methods are available"));
+ }
+ else
+ {
+ hasDelegate = (_) => throw new InvalidOperationException("HasValue is not implemented for proto3 fields"); var clrType = property.PropertyType;
- var clrType = property.PropertyType;
-
- // TODO: Validate that this is a reasonable single field? (Should be a value type, a message type, or string/ByteString.)
- object defaultValue =
- descriptor.FieldType == FieldType.Message ? null
- : clrType == typeof(string) ? ""
- : clrType == typeof(ByteString) ? ByteString.Empty
- : Activator.CreateInstance(clrType);
- clearDelegate = message => SetValue(message, defaultValue);
+ // TODO: Validate that this is a reasonable single field? (Should be a value type, a message type, or string/ByteString.)
+ object defaultValue =
+ descriptor.FieldType == FieldType.Message ? null
+ : clrType == typeof(string) ? ""
+ : clrType == typeof(ByteString) ? ByteString.Empty
+ : Activator.CreateInstance(clrType);
+ clearDelegate = message => SetValue(message, defaultValue);
+ }
}
public override void Clear(IMessage message)
@@ -73,6 +83,11 @@ namespace Google.Protobuf.Reflection
clearDelegate(message);
}
+ public override bool HasValue(IMessage message)
+ {
+ return hasDelegate(message);
+ }
+
public override void SetValue(IMessage message, object value)
{
setValueDelegate(message, value);
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
index 378b61d4..dd991106 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
@@ -159,7 +159,8 @@ namespace Google.Protobuf.WellKnownTypes {
private string typeUrl_ = "";
/// <summary>
/// A URL/resource name that uniquely identifies the type of the serialized
- /// protocol buffer message. The last segment of the URL's path must represent
+ /// protocol buffer message. This string must contain at least
+ /// one "/" character. The last segment of the URL's path must represent
/// the fully qualified name of the type (as in
/// `path/google.protobuf.Duration`). The name should be in a canonical form
/// (e.g., leading "." is not accepted).
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
index e4a4a365..438e1db8 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
@@ -328,7 +328,7 @@ namespace Google.Protobuf.WellKnownTypes {
}
if (other.sourceContext_ != null) {
if (sourceContext_ == null) {
- sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext();
}
SourceContext.MergeFrom(other.SourceContext);
}
@@ -365,9 +365,9 @@ namespace Google.Protobuf.WellKnownTypes {
}
case 42: {
if (sourceContext_ == null) {
- sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext();
}
- input.ReadMessage(sourceContext_);
+ input.ReadMessage(SourceContext);
break;
}
case 50: {
@@ -375,7 +375,7 @@ namespace Google.Protobuf.WellKnownTypes {
break;
}
case 56: {
- syntax_ = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
+ Syntax = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
break;
}
}
@@ -688,7 +688,7 @@ namespace Google.Protobuf.WellKnownTypes {
break;
}
case 56: {
- syntax_ = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
+ Syntax = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
break;
}
}
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
index b73930b2..6ad31a50 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
@@ -25,11 +25,11 @@ namespace Google.Protobuf.WellKnownTypes {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"CiBnb29nbGUvcHJvdG9idWYvZmllbGRfbWFzay5wcm90bxIPZ29vZ2xlLnBy",
- "b3RvYnVmIhoKCUZpZWxkTWFzaxINCgVwYXRocxgBIAMoCUKJAQoTY29tLmdv",
+ "b3RvYnVmIhoKCUZpZWxkTWFzaxINCgVwYXRocxgBIAMoCUKMAQoTY29tLmdv",
"b2dsZS5wcm90b2J1ZkIORmllbGRNYXNrUHJvdG9QAVo5Z29vZ2xlLmdvbGFu",
"Zy5vcmcvZ2VucHJvdG8vcHJvdG9idWYvZmllbGRfbWFzaztmaWVsZF9tYXNr",
- "ogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90",
- "bzM="));
+ "+AEBogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZw",
+ "cm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
@@ -108,57 +108,49 @@ namespace Google.Protobuf.WellKnownTypes {
/// describe the updated values, the API ignores the values of all
/// fields not covered by the mask.
///
- /// If a repeated field is specified for an update operation, the existing
- /// repeated values in the target resource will be overwritten by the new values.
- /// Note that a repeated field is only allowed in the last position of a `paths`
- /// string.
+ /// If a repeated field is specified for an update operation, new values will
+ /// be appended to the existing repeated field in the target resource. Note that
+ /// a repeated field is only allowed in the last position of a `paths` string.
///
/// If a sub-message is specified in the last position of the field mask for an
- /// update operation, then the existing sub-message in the target resource is
- /// overwritten. Given the target message:
+ /// update operation, then new value will be merged into the existing sub-message
+ /// in the target resource.
+ ///
+ /// For example, given the target message:
///
/// f {
/// b {
- /// d : 1
- /// x : 2
+ /// d: 1
+ /// x: 2
/// }
- /// c : 1
+ /// c: [1]
/// }
///
/// And an update message:
///
/// f {
/// b {
- /// d : 10
+ /// d: 10
/// }
+ /// c: [2]
/// }
///
/// then if the field mask is:
///
- /// paths: "f.b"
+ /// paths: ["f.b", "f.c"]
///
/// then the result will be:
///
/// f {
/// b {
- /// d : 10
+ /// d: 10
+ /// x: 2
/// }
- /// c : 1
+ /// c: [1, 2]
/// }
///
- /// However, if the update mask was:
- ///
- /// paths: "f.b.d"
- ///
- /// then the result would be:
- ///
- /// f {
- /// b {
- /// d : 10
- /// x : 2
- /// }
- /// c : 1
- /// }
+ /// An implementation may provide options to override this default behavior for
+ /// repeated and message fields.
///
/// In order to reset a field's value to the default, the field must
/// be in the mask and set to the default value in the provided resource.
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
index ef752be7..984e226f 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
@@ -41,17 +41,19 @@ namespace Google.Protobuf.WellKnownTypes {
}
#region Messages
/// <summary>
- /// A Timestamp represents a point in time independent of any time zone
- /// or calendar, represented as seconds and fractions of seconds at
- /// nanosecond resolution in UTC Epoch time. It is encoded using the
- /// Proleptic Gregorian Calendar which extends the Gregorian calendar
- /// backwards to year one. It is encoded assuming all minutes are 60
- /// seconds long, i.e. leap seconds are "smeared" so that no leap second
- /// table is needed for interpretation. Range is from
- /// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
- /// By restricting to that range, we ensure that we can convert to
- /// and from RFC 3339 date strings.
- /// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
+ /// A Timestamp represents a point in time independent of any time zone or local
+ /// calendar, encoded as a count of seconds and fractions of seconds at
+ /// nanosecond resolution. The count is relative to an epoch at UTC midnight on
+ /// January 1, 1970, in the proleptic Gregorian calendar which extends the
+ /// Gregorian calendar backwards to year one.
+ ///
+ /// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
+ /// second table is needed for interpretation, using a [24-hour linear
+ /// smear](https://developers.google.com/time/smear).
+ ///
+ /// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
+ /// restricting to that range, we ensure that we can convert to and from [RFC
+ /// 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
///
/// # Examples
///
@@ -116,7 +118,7 @@ namespace Google.Protobuf.WellKnownTypes {
/// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
/// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
/// can use the Joda Time's [`ISODateTimeFormat.dateTime()`](
- /// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime--
+ /// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
/// ) to obtain a formatter capable of generating timestamps in this format.
/// </summary>
public sealed partial class Timestamp : pb::IMessage<Timestamp> {
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
index 3e2fe541..52bd343b 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
@@ -312,7 +312,7 @@ namespace Google.Protobuf.WellKnownTypes {
options_.Add(other.options_);
if (other.sourceContext_ != null) {
if (sourceContext_ == null) {
- sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext();
}
SourceContext.MergeFrom(other.SourceContext);
}
@@ -348,13 +348,13 @@ namespace Google.Protobuf.WellKnownTypes {
}
case 42: {
if (sourceContext_ == null) {
- sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext();
}
- input.ReadMessage(sourceContext_);
+ input.ReadMessage(SourceContext);
break;
}
case 48: {
- syntax_ = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
+ Syntax = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
break;
}
}
@@ -726,11 +726,11 @@ namespace Google.Protobuf.WellKnownTypes {
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 8: {
- kind_ = (global::Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum();
+ Kind = (global::Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum();
break;
}
case 16: {
- cardinality_ = (global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality) input.ReadEnum();
+ Cardinality = (global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality) input.ReadEnum();
break;
}
case 24: {
@@ -1084,7 +1084,7 @@ namespace Google.Protobuf.WellKnownTypes {
options_.Add(other.options_);
if (other.sourceContext_ != null) {
if (sourceContext_ == null) {
- sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext();
}
SourceContext.MergeFrom(other.SourceContext);
}
@@ -1116,13 +1116,13 @@ namespace Google.Protobuf.WellKnownTypes {
}
case 34: {
if (sourceContext_ == null) {
- sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext();
}
- input.ReadMessage(sourceContext_);
+ input.ReadMessage(SourceContext);
break;
}
case 40: {
- syntax_ = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
+ Syntax = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
break;
}
}
@@ -1467,7 +1467,7 @@ namespace Google.Protobuf.WellKnownTypes {
}
if (other.value_ != null) {
if (value_ == null) {
- value_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ Value = new global::Google.Protobuf.WellKnownTypes.Any();
}
Value.MergeFrom(other.Value);
}
@@ -1488,9 +1488,9 @@ namespace Google.Protobuf.WellKnownTypes {
}
case 18: {
if (value_ == null) {
- value_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ Value = new global::Google.Protobuf.WellKnownTypes.Any();
}
- input.ReadMessage(value_);
+ input.ReadMessage(Value);
break;
}
}
diff --git a/csharp/src/Google.Protobuf/WireFormat.cs b/csharp/src/Google.Protobuf/WireFormat.cs
index faf1e715..f3adeb15 100644
--- a/csharp/src/Google.Protobuf/WireFormat.cs
+++ b/csharp/src/Google.Protobuf/WireFormat.cs
@@ -61,11 +61,11 @@ namespace Google.Protobuf
/// </summary>
LengthDelimited = 2,
/// <summary>
- /// A "start group" value - not supported by this implementation.
+ /// A "start group" value
/// </summary>
StartGroup = 3,
/// <summary>
- /// An "end group" value - not supported by this implementation.
+ /// An "end group" value
/// </summary>
EndGroup = 4,
/// <summary>