diff options
72 files changed, 7862 insertions, 6097 deletions
diff --git a/Makefile.am b/Makefile.am index b0913a58..73c1e6f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -100,6 +100,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf.Test/JsonParserTest.cs \ csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs \ csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs \ + csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs \ csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs \ csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs \ csharp/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs \ @@ -122,6 +123,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs \ csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs \ csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs \ + csharp/src/Google.Protobuf.Test/testprotos.pb \ csharp/src/Google.Protobuf.sln \ csharp/src/Google.Protobuf/ByteArray.cs \ csharp/src/Google.Protobuf/ByteString.cs \ @@ -157,6 +159,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/Reflection/CustomOptions.cs \ csharp/src/Google.Protobuf/Reflection/Descriptor.cs \ csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs \ + csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs \ csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs \ csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs \ csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs \ @@ -176,7 +179,6 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs \ csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs \ csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs \ - csharp/src/Google.Protobuf/Reflection/PartialClasses.cs \ csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs \ csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs \ csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs \ @@ -63,7 +63,7 @@ how to install protobuf runtime for that specific language: | Ruby | [ruby](ruby) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-ruby_all.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fruby_all%2Fcontinuous) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-ruby21.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fruby21%2Fcontinuous)<br/>[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-ruby22.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fruby22%2Fcontinuous) | | | Go | [golang/protobuf](https://github.com/golang/protobuf) | | | | | PHP | [php](php) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-php_all.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fphp_all%2Fcontinuous)<br/>[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/linux-32-bit.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2F32-bit%2Fcontinuous) | [![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-php5.6_mac.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fphp5.6_mac%2Fcontinuous)<br/>[![Build status](https://storage.googleapis.com/protobuf-kokoro-results/status-badge/macos-php7.0_mac.png)](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fphp7.0_mac%2Fcontinuous) | | -| Dart | [dart-lang/protobuf](https://github.com/dart-lang/protobuf) | | | | +| Dart | [dart-lang/protobuf](https://github.com/dart-lang/protobuf) | [![Build Status](https://travis-ci.org/dart-lang/protobuf.svg?branch=master)](https://travis-ci.org/dart-lang/protobuf) | | | Quick Start ----------- diff --git a/conformance/failure_list_php_c.txt b/conformance/failure_list_php_c.txt index 17e0fda4..8053d91a 100644 --- a/conformance/failure_list_php_c.txt +++ b/conformance/failure_list_php_c.txt @@ -5,8 +5,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.DurationHas9FractionalDigits.Validator -Recommended.Proto3.JsonInput.DurationHasZeroFractionalDigit.Validator Recommended.Proto3.JsonInput.Int64FieldBeString.Validator Recommended.Proto3.JsonInput.MapFieldValueIsNull Recommended.Proto3.JsonInput.OneofZeroBytes.JsonOutput @@ -18,13 +16,12 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.TimestampHas9FractionalDigits.Validator -Recommended.Proto3.JsonInput.TimestampHasZeroFractionalDigit.Validator -Recommended.Proto3.JsonInput.TimestampZeroNormalized.Validator Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput +Required.TimestampProtoInputTooLarge.JsonOutput +Required.TimestampProtoInputTooSmall.JsonOutput Required.Proto3.JsonInput.Any.JsonOutput Required.Proto3.JsonInput.Any.ProtobufOutput Required.Proto3.JsonInput.AnyNested.JsonOutput @@ -51,12 +48,8 @@ Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput -Required.Proto3.JsonInput.DurationMaxValue.JsonOutput -Required.Proto3.JsonInput.DurationMaxValue.ProtobufOutput Required.Proto3.JsonInput.DurationMinValue.JsonOutput -Required.Proto3.JsonInput.DurationMinValue.ProtobufOutput Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput -Required.Proto3.JsonInput.DurationRepeatedValue.ProtobufOutput Required.Proto3.JsonInput.FieldMask.JsonOutput Required.Proto3.JsonInput.FieldMask.ProtobufOutput Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput @@ -73,36 +66,8 @@ Required.Proto3.JsonInput.StringFieldUnicodeEscape.JsonOutput Required.Proto3.JsonInput.StringFieldUnicodeEscape.ProtobufOutput Required.Proto3.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.JsonOutput Required.Proto3.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.ProtobufOutput -Required.Proto3.JsonInput.Struct.JsonOutput -Required.Proto3.JsonInput.Struct.ProtobufOutput -Required.Proto3.JsonInput.TimestampMaxValue.JsonOutput -Required.Proto3.JsonInput.TimestampMaxValue.ProtobufOutput -Required.Proto3.JsonInput.TimestampMinValue.JsonOutput -Required.Proto3.JsonInput.TimestampMinValue.ProtobufOutput -Required.Proto3.JsonInput.TimestampRepeatedValue.JsonOutput -Required.Proto3.JsonInput.TimestampRepeatedValue.ProtobufOutput -Required.Proto3.JsonInput.TimestampWithNegativeOffset.JsonOutput -Required.Proto3.JsonInput.TimestampWithNegativeOffset.ProtobufOutput -Required.Proto3.JsonInput.TimestampWithPositiveOffset.JsonOutput -Required.Proto3.JsonInput.TimestampWithPositiveOffset.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptBool.JsonOutput -Required.Proto3.JsonInput.ValueAcceptBool.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptFloat.JsonOutput -Required.Proto3.JsonInput.ValueAcceptFloat.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptInteger.JsonOutput -Required.Proto3.JsonInput.ValueAcceptInteger.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptList.JsonOutput -Required.Proto3.JsonInput.ValueAcceptList.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptNull.JsonOutput -Required.Proto3.JsonInput.ValueAcceptNull.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptObject.JsonOutput -Required.Proto3.JsonInput.ValueAcceptObject.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptString.JsonOutput -Required.Proto3.JsonInput.ValueAcceptString.ProtobufOutput Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput Required.Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.JsonOutput -Required.TimestampProtoInputTooLarge.JsonOutput -Required.TimestampProtoInputTooSmall.JsonOutput diff --git a/csharp/generate_protos.sh b/csharp/generate_protos.sh index 5c748e35..31a4b90c 100755 --- a/csharp/generate_protos.sh +++ b/csharp/generate_protos.sh @@ -43,6 +43,9 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \ # Test protos $PROTOC -Isrc -Icsharp/protos \ --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \ + --descriptor_set_out=csharp/src/Google.Protobuf.Test/testprotos.pb \ + --include_source_info \ + --include_imports \ csharp/protos/map_unittest_proto3.proto \ csharp/protos/unittest_issues.proto \ csharp/protos/unittest_custom_options_proto3.proto \ diff --git a/csharp/protos/unittest_proto3.proto b/csharp/protos/unittest_proto3.proto index ef4933a5..bf88f6bc 100644 --- a/csharp/protos/unittest_proto3.proto +++ b/csharp/protos/unittest_proto3.proto @@ -368,7 +368,9 @@ message FooResponse {} message FooClientMessage {} message FooServerMessage{} +// This is a test service service TestService { + // This is a test method rpc Foo(FooRequest) returns (FooResponse); rpc Bar(BarRequest) returns (BarResponse); } @@ -378,3 +380,31 @@ message BarRequest {} message BarResponse {} message TestEmptyMessage {} + +// This is leading detached comment 1 + +// This is leading detached comment 2 + +// This is a leading comment +message CommentMessage { + // Leading nested message comment + message NestedCommentMessage { + // Leading nested message field comment + string nested_text = 1; + } + + // Leading nested enum comment + enum NestedCommentEnum { + // Zero value comment + ZERO_VALUE = 0; + } + + // Leading field comment + string text = 1; // Trailing field comment +} + +// Leading enum comment +enum CommentEnum { + // Zero value comment + ZERO_VALUE = 0; +} 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 46793ce1..cd9b77ab 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -354,7 +354,7 @@ namespace Conformance { break; } case 24: { - requestedOutputFormat_ = (global::Conformance.WireFormat) input.ReadEnum(); + RequestedOutputFormat = (global::Conformance.WireFormat) input.ReadEnum(); break; } case 34: { @@ -362,7 +362,7 @@ namespace Conformance { break; } case 40: { - testCategory_ = (global::Conformance.TestCategory) input.ReadEnum(); + TestCategory = (global::Conformance.TestCategory) input.ReadEnum(); break; } } 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 586ab47a..8e1097aa 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs @@ -60,9 +60,9 @@ namespace Google.Protobuf.Reflection // dependencies come before the descriptors depending on them. var descriptorData = new List<ByteString> { - UnittestImportPublicProto3Reflection.Descriptor.Proto.ToByteString(), - UnittestImportProto3Reflection.Descriptor.Proto.ToByteString(), - UnittestProto3Reflection.Descriptor.Proto.ToByteString() + UnittestImportPublicProto3Reflection.Descriptor.SerializedData, + UnittestImportProto3Reflection.Descriptor.SerializedData, + UnittestProto3Reflection.Descriptor.SerializedData }; var converted = FileDescriptor.BuildFromByteStrings(descriptorData); Assert.AreEqual(3, converted.Count); @@ -120,8 +120,8 @@ namespace Google.Protobuf.Reflection { var descriptorData = new List<ByteString> { - UnittestImportProto3Reflection.Descriptor.Proto.ToByteString(), - UnittestProto3Reflection.Descriptor.Proto.ToByteString(), + UnittestImportProto3Reflection.Descriptor.SerializedData, + UnittestProto3Reflection.Descriptor.SerializedData, }; // This will fail, because we're missing UnittestImportPublicProto3Reflection Assert.Throws<ArgumentException>(() => FileDescriptor.BuildFromByteStrings(descriptorData)); @@ -132,8 +132,8 @@ namespace Google.Protobuf.Reflection { var descriptorData = new List<ByteString> { - UnittestImportPublicProto3Reflection.Descriptor.Proto.ToByteString(), - UnittestImportPublicProto3Reflection.Descriptor.Proto.ToByteString(), + UnittestImportPublicProto3Reflection.Descriptor.SerializedData, + UnittestImportPublicProto3Reflection.Descriptor.SerializedData, }; // This will fail due to the same name being used twice Assert.Throws<ArgumentException>(() => FileDescriptor.BuildFromByteStrings(descriptorData)); @@ -144,9 +144,9 @@ namespace Google.Protobuf.Reflection { var descriptorData = new List<ByteString> { - UnittestProto3Reflection.Descriptor.Proto.ToByteString(), - UnittestImportPublicProto3Reflection.Descriptor.Proto.ToByteString(), - UnittestImportProto3Reflection.Descriptor.Proto.ToByteString() + UnittestProto3Reflection.Descriptor.SerializedData, + UnittestImportPublicProto3Reflection.Descriptor.SerializedData, + UnittestImportProto3Reflection.Descriptor.SerializedData }; // This will fail, because the dependencies should come first Assert.Throws<ArgumentException>(() => FileDescriptor.BuildFromByteStrings(descriptorData)); @@ -225,9 +225,9 @@ namespace Google.Protobuf.Reflection // dependencies come before the descriptors depending on them. var descriptorData = new List<ByteString> { - UnittestImportPublicProto3Reflection.Descriptor.Proto.ToByteString(), - UnittestImportProto3Reflection.Descriptor.Proto.ToByteString(), - UnittestProto3Reflection.Descriptor.Proto.ToByteString() + UnittestImportPublicProto3Reflection.Descriptor.SerializedData, + UnittestImportProto3Reflection.Descriptor.SerializedData, + UnittestProto3Reflection.Descriptor.SerializedData }; var converted = FileDescriptor.BuildFromByteStrings(descriptorData); TestFieldDescriptor( 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 Binary files differnew file mode 100644 index 00000000..94ff3817 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/testprotos.pb 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/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/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 152467d8..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) { @@ -184,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> @@ -192,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> @@ -247,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; } @@ -265,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) @@ -287,7 +286,7 @@ namespace Google.Protobuf.Reflection } } - if (fieldType == FieldType.Message) + if (fieldType == FieldType.Message || fieldType == FieldType.Group) { if (!(typeDescriptor is MessageDescriptor)) { @@ -295,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."); } @@ -325,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."); } 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 216e03cc..6d4520c0 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -34,7 +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 { @@ -55,6 +58,8 @@ namespace Google.Protobuf.Reflection ForceReflectionInitialization<Value.KindOneofCase>(); } + private readonly Lazy<Dictionary<IDescriptor, DescriptorDeclaration>> declarations; + private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, IEnumerable<FileDescriptor> dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) { SerializedData = descriptorData; @@ -77,6 +82,81 @@ namespace Google.Protobuf.Reflection 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> 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 dbb6768b..03fd63ce 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -115,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/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/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/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>
diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 899b99f0..2bb5f521 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -132,6 +132,12 @@ static void stackenv_uninit(stackenv* se) { // Parsing. // ----------------------------------------------------------------------------- +// TODO(teboring): This shoud be a bit in upb_msgdef +static bool is_wrapper_msg(const upb_msgdef *msg) { + return !strcmp(upb_filedef_name(upb_msgdef_upcast(msg)->file), + "google/protobuf/wrappers.proto"); +} + #define DEREF(msg, ofs, type) *(type*)(((uint8_t *)msg) + ofs) // Creates a handlerdata that simply contains the offset for this field. @@ -420,13 +426,13 @@ static void *submsg_handler(void *closure, const void *hd) { if (Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR(DEREF(message_data(msg), submsgdata->ofs, CACHED_VALUE*))) == IS_NULL) { #if PHP_MAJOR_VERSION < 7 - zval* val = NULL; - MAKE_STD_ZVAL(val); - ZVAL_OBJ(val, subklass->create_object(subklass TSRMLS_CC)); - MessageHeader* intern = UNBOX(MessageHeader, val); + zval val; + ZVAL_OBJ(&val, subklass->create_object(subklass TSRMLS_CC)); + MessageHeader* intern = UNBOX(MessageHeader, &val); custom_data_init(subklass, intern PHP_PROTO_TSRMLS_CC); - php_proto_zval_ptr_dtor(*DEREF(message_data(msg), submsgdata->ofs, zval**)); - *DEREF(message_data(msg), submsgdata->ofs, zval**) = val; + REPLACE_ZVAL_VALUE(DEREF(message_data(msg), submsgdata->ofs, zval**), + &val, 1); + zval_dtor(&val); #else zend_object* obj = subklass->create_object(subklass TSRMLS_CC); ZVAL_OBJ(DEREF(message_data(msg), submsgdata->ofs, zval*), obj); @@ -765,9 +771,16 @@ static void* oneofsubmsg_handler(void* closure, const void* hd) { // Create new message. DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) = OBJ_PROP(&msg->std, oneofdata->property_ofs); - ZVAL_OBJ(CACHED_PTR_TO_ZVAL_PTR( - DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*)), - subklass->create_object(subklass TSRMLS_CC)); +#if PHP_MAJOR_VERSION < 7 + zval val; + ZVAL_OBJ(&val, subklass->create_object(subklass TSRMLS_CC)); + REPLACE_ZVAL_VALUE(DEREF(message_data(msg), oneofdata->ofs, zval**), + &val, 1); + zval_dtor(&val); +#else + zend_object* obj = subklass->create_object(subklass TSRMLS_CC); + ZVAL_OBJ(DEREF(message_data(msg), oneofdata->ofs, zval*), obj); +#endif } DEREF(message_data(msg), oneofdata->case_ofs, uint32_t) = @@ -1080,24 +1093,25 @@ static const upb_json_parsermethod *msgdef_jsonparsermethod(Descriptor* desc) { // ----------------------------------------------------------------------------- static void putmsg(zval* msg, const Descriptor* desc, upb_sink* sink, - int depth TSRMLS_DC); + int depth, bool is_json TSRMLS_DC); static void putrawmsg(MessageHeader* msg, const Descriptor* desc, - upb_sink* sink, int depth TSRMLS_DC); + upb_sink* sink, int depth, bool is_json TSRMLS_DC); -static void putstr(zval* str, const upb_fielddef* f, upb_sink* sink); +static void putstr(zval* str, const upb_fielddef* f, upb_sink* sink, + bool force_default); static void putrawstr(const char* str, int len, const upb_fielddef* f, - upb_sink* sink); + upb_sink* sink, bool force_default); static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, - int depth TSRMLS_DC); + int depth, bool is_json TSRMLS_DC); static void putrawsubmsg(MessageHeader* submsg, const upb_fielddef* f, - upb_sink* sink, int depth TSRMLS_DC); + upb_sink* sink, int depth, bool is_json TSRMLS_DC); static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, - int depth TSRMLS_DC); + int depth, bool is_json TSRMLS_DC); static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, - int depth TSRMLS_DC); + int depth, bool is_json TSRMLS_DC); static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) { upb_selector_t ret; @@ -1106,8 +1120,10 @@ static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) { return ret; } -static void put_optional_value(const void* memory, int len, const upb_fielddef* f, - int depth, upb_sink* sink TSRMLS_DC) { +static void put_optional_value(const void* memory, int len, + const upb_fielddef* f, + int depth, upb_sink* sink, + bool is_json TSRMLS_DC) { assert(upb_fielddef_label(f) == UPB_LABEL_OPTIONAL); switch (upb_fielddef_type(f)) { @@ -1132,7 +1148,8 @@ static void put_optional_value(const void* memory, int len, const upb_fielddef* #undef T case UPB_TYPE_STRING: case UPB_TYPE_BYTES: - putrawstr(memory, len, f, sink); + putrawstr(memory, len, f, sink, + is_json && is_wrapper_msg(upb_fielddef_containingtype(f))); break; case UPB_TYPE_MESSAGE: { #if PHP_MAJOR_VERSION < 7 @@ -1142,7 +1159,7 @@ static void put_optional_value(const void* memory, int len, const upb_fielddef* (MessageHeader*)((char*)(*(zend_object**)memory) - XtOffsetOf(MessageHeader, std)); #endif - putrawsubmsg(submsg, f, sink, depth TSRMLS_CC); + putrawsubmsg(submsg, f, sink, depth, is_json TSRMLS_CC); break; } default: @@ -1181,7 +1198,7 @@ static int raw_value_len(void* memory, int len, const upb_fielddef* f) { } static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, - int depth TSRMLS_DC) { + int depth, bool is_json TSRMLS_DC) { upb_sink subsink; const upb_fielddef* key_field; const upb_fielddef* value_field; @@ -1209,13 +1226,14 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, // Serialize key. const char *key = map_iter_key(&it, &len); - put_optional_value(key, len, key_field, depth + 1, &entry_sink TSRMLS_CC); + put_optional_value(key, len, key_field, depth + 1, + &entry_sink, is_json TSRMLS_CC); // Serialize value. upb_value value = map_iter_value(&it, &len); put_optional_value(raw_value(upb_value_memory(&value), value_field), raw_value_len(upb_value_memory(&value), len, value_field), - value_field, depth + 1, &entry_sink TSRMLS_CC); + value_field, depth + 1, &entry_sink, is_json TSRMLS_CC); upb_sink_endmsg(&entry_sink, &status); upb_sink_endsubmsg(&subsink, getsel(f, UPB_HANDLER_ENDSUBMSG)); @@ -1225,13 +1243,13 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, } static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, - int depth TSRMLS_DC) { + int depth, bool is_json TSRMLS_DC) { MessageHeader* msg = UNBOX(MessageHeader, msg_php); - putrawmsg(msg, desc, sink, depth TSRMLS_CC); + putrawmsg(msg, desc, sink, depth, is_json TSRMLS_CC); } static void putrawmsg(MessageHeader* msg, const Descriptor* desc, - upb_sink* sink, int depth TSRMLS_DC) { + upb_sink* sink, int depth, bool is_json TSRMLS_DC) { upb_msg_field_iter i; upb_status status; @@ -1268,31 +1286,34 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, zval* map = CACHED_PTR_TO_ZVAL_PTR( DEREF(message_data(msg), offset, CACHED_VALUE*)); if (map != NULL) { - putmap(map, f, sink, depth TSRMLS_CC); + putmap(map, f, sink, depth, is_json TSRMLS_CC); } } else if (upb_fielddef_isseq(f)) { zval* array = CACHED_PTR_TO_ZVAL_PTR( DEREF(message_data(msg), offset, CACHED_VALUE*)); if (array != NULL) { - putarray(array, f, sink, depth TSRMLS_CC); + putarray(array, f, sink, depth, is_json TSRMLS_CC); } } else if (upb_fielddef_isstring(f)) { zval* str = CACHED_PTR_TO_ZVAL_PTR( DEREF(message_data(msg), offset, CACHED_VALUE*)); - if (containing_oneof || Z_STRLEN_P(str) > 0) { - putstr(str, f, sink); + if (containing_oneof || (is_json && is_wrapper_msg(desc->msgdef)) || + Z_STRLEN_P(str) > 0) { + putstr(str, f, sink, is_json && is_wrapper_msg(desc->msgdef)); } } else if (upb_fielddef_issubmsg(f)) { putsubmsg(CACHED_PTR_TO_ZVAL_PTR( DEREF(message_data(msg), offset, CACHED_VALUE*)), - f, sink, depth TSRMLS_CC); + f, sink, depth, is_json TSRMLS_CC); } else { upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); #define T(upbtypeconst, upbtype, ctype, default_value) \ case upbtypeconst: { \ ctype value = DEREF(message_data(msg), offset, ctype); \ - if (containing_oneof || value != default_value) { \ + if (containing_oneof || \ + (is_json && is_wrapper_msg(desc->msgdef)) || \ + value != default_value) { \ upb_sink_put##upbtype(sink, sel, value); \ } \ } break; @@ -1325,7 +1346,8 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, upb_sink_endmsg(sink, &status); } -static void putstr(zval* str, const upb_fielddef *f, upb_sink *sink) { +static void putstr(zval* str, const upb_fielddef *f, + upb_sink *sink, bool force_default) { upb_sink subsink; if (ZVAL_IS_NULL(str)) return; @@ -1336,7 +1358,7 @@ static void putstr(zval* str, const upb_fielddef *f, upb_sink *sink) { &subsink); // For oneof string field, we may get here with string length is zero. - if (Z_STRLEN_P(str) > 0) { + if (Z_STRLEN_P(str) > 0 || force_default) { // Ensure that the string has the correct encoding. We also check at // field-set time, but the user may have mutated the string object since // then. @@ -1353,10 +1375,10 @@ static void putstr(zval* str, const upb_fielddef *f, upb_sink *sink) { } static void putrawstr(const char* str, int len, const upb_fielddef* f, - upb_sink* sink) { + upb_sink* sink, bool force_default) { upb_sink subsink; - if (len == 0) return; + if (len == 0 && !force_default) return; // Ensure that the string has the correct encoding. We also check at field-set // time, but the user may have mutated the string object since then. @@ -1372,27 +1394,27 @@ static void putrawstr(const char* str, int len, const upb_fielddef* f, } static void putsubmsg(zval* submsg_php, const upb_fielddef* f, upb_sink* sink, - int depth TSRMLS_DC) { + int depth, bool is_json TSRMLS_DC) { if (Z_TYPE_P(submsg_php) == IS_NULL) return; MessageHeader *submsg = UNBOX(MessageHeader, submsg_php); - putrawsubmsg(submsg, f, sink, depth TSRMLS_CC); + putrawsubmsg(submsg, f, sink, depth, is_json TSRMLS_CC); } static void putrawsubmsg(MessageHeader* submsg, const upb_fielddef* f, - upb_sink* sink, int depth TSRMLS_DC) { + upb_sink* sink, int depth, bool is_json TSRMLS_DC) { upb_sink subsink; Descriptor* subdesc = UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(upb_fielddef_msgsubdef(f))); upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink); - putrawmsg(submsg, subdesc, &subsink, depth + 1 TSRMLS_CC); + putrawmsg(submsg, subdesc, &subsink, depth + 1, is_json TSRMLS_CC); upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG)); } static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, - int depth TSRMLS_DC) { + int depth, bool is_json TSRMLS_DC) { upb_sink subsink; upb_fieldtype_t type = upb_fielddef_type(f); upb_selector_t sel = 0; @@ -1436,7 +1458,8 @@ static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, const char* rawstr = ZSTR_VAL(*(zend_string**)memory); int len = ZSTR_LEN(*(zend_string**)memory); #endif - putrawstr(rawstr, len, f, &subsink); + putrawstr(rawstr, len, f, &subsink, + is_json && is_wrapper_msg(upb_fielddef_containingtype(f))); break; } case UPB_TYPE_MESSAGE: { @@ -1447,7 +1470,7 @@ static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, (MessageHeader*)((char*)(Z_OBJ_P((zval*)memory)) - XtOffsetOf(MessageHeader, std)); #endif - putrawsubmsg(submsg, f, &subsink, depth TSRMLS_CC); + putrawsubmsg(submsg, f, &subsink, depth, is_json TSRMLS_CC); break; } @@ -1504,7 +1527,7 @@ void serialize_to_string(zval* val, zval* return_value TSRMLS_DC) { stackenv_init(&se, "Error occurred during encoding: %s"); encoder = upb_pb_encoder_create(&se.env, serialize_handlers, &sink.sink); - putmsg(val, desc, upb_pb_encoder_input(encoder), 0 TSRMLS_CC); + putmsg(val, desc, upb_pb_encoder_input(encoder), 0, false TSRMLS_CC); PHP_PROTO_RETVAL_STRINGL(sink.ptr, sink.len, 1); @@ -1571,7 +1594,7 @@ PHP_METHOD(Message, serializeToJsonString) { stackenv_init(&se, "Error occurred during encoding: %s"); printer = upb_json_printer_create(&se.env, serialize_handlers, &sink.sink); - putmsg(getThis(), desc, upb_json_printer_input(printer), 0 TSRMLS_CC); + putmsg(getThis(), desc, upb_json_printer_input(printer), 0, true TSRMLS_CC); PHP_PROTO_RETVAL_STRINGL(sink.ptr, sink.len, 1); diff --git a/php/ext/google/protobuf/upb.c b/php/ext/google/protobuf/upb.c index 90c52aa8..2179e2c7 100644 --- a/php/ext/google/protobuf/upb.c +++ b/php/ext/google/protobuf/upb.c @@ -1,5 +1,23 @@ // Amalgamated source file #include "upb.h" + +#if UINTPTR_MAX == 0xffffffff +#define UPB_SIZE(size32, size64) size32 +#else +#define UPB_SIZE(size32, size64) size64 +#endif + +#define UPB_FIELD_AT(msg, fieldtype, offset) \ + *(fieldtype*)((const char*)(msg) + offset) + +#define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \ + UPB_FIELD_AT(msg, int, case_offset) == case_val \ + ? UPB_FIELD_AT(msg, fieldtype, offset) \ + : default + +#define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \ + UPB_FIELD_AT(msg, int, case_offset) = case_val; \ + UPB_FIELD_AT(msg, fieldtype, offset) = value; /* This file was generated by upbc (the upb compiler) from the input * file: * @@ -11,64 +29,21 @@ #include <stddef.h> -struct google_protobuf_FileDescriptorSet { - upb_array* file; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_FileDescriptorSet_submsgs[1] = { +static const upb_msglayout *const google_protobuf_FileDescriptorSet_submsgs[1] = { &google_protobuf_FileDescriptorProto_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_FileDescriptorSet__fields[1] = { - {1, offsetof(google_protobuf_FileDescriptorSet, file), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_FileDescriptorSet__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorSet_msginit = { +const upb_msglayout google_protobuf_FileDescriptorSet_msginit = { &google_protobuf_FileDescriptorSet_submsgs[0], &google_protobuf_FileDescriptorSet__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_FileDescriptorSet), 1, 0, false, true + UPB_SIZE(4, 8), 1, false, }; -google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_env *env) { - google_protobuf_FileDescriptorSet *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_FileDescriptorSet *msg = google_protobuf_FileDescriptorSet_new(env); - if (upb_decode(buf, msg, &google_protobuf_FileDescriptorSet_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_FileDescriptorSet_serialize(google_protobuf_FileDescriptorSet *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, env, size); -} -const upb_array* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg) { - return msg->file; -} -void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileDescriptorSet *msg, upb_array* value) { - msg->file = value; -} -struct google_protobuf_FileDescriptorProto { - upb_stringview name; - upb_stringview package; - upb_stringview syntax; - google_protobuf_FileOptions* options; - google_protobuf_SourceCodeInfo* source_code_info; - upb_array* dependency; - upb_array* message_type; - upb_array* enum_type; - upb_array* service; - upb_array* extension; - upb_array* public_dependency; - upb_array* weak_dependency; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_FileDescriptorProto_submsgs[6] = { +static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = { &google_protobuf_DescriptorProto_msginit, &google_protobuf_EnumDescriptorProto_msginit, &google_protobuf_FieldDescriptorProto_msginit, @@ -77,131 +52,28 @@ static const upb_msglayout_msginit_v1 *const google_protobuf_FileDescriptorProto &google_protobuf_SourceCodeInfo_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_FileDescriptorProto__fields[12] = { - {1, offsetof(google_protobuf_FileDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {2, offsetof(google_protobuf_FileDescriptorProto, package), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {3, offsetof(google_protobuf_FileDescriptorProto, dependency), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 3}, - {4, offsetof(google_protobuf_FileDescriptorProto, message_type), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, - {5, offsetof(google_protobuf_FileDescriptorProto, enum_type), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 1, 11, 3}, - {6, offsetof(google_protobuf_FileDescriptorProto, service), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 4, 11, 3}, - {7, offsetof(google_protobuf_FileDescriptorProto, extension), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 2, 11, 3}, - {8, offsetof(google_protobuf_FileDescriptorProto, options), 3, UPB_NOT_IN_ONEOF, 3, 11, 1}, - {9, offsetof(google_protobuf_FileDescriptorProto, source_code_info), 4, UPB_NOT_IN_ONEOF, 5, 11, 1}, - {10, offsetof(google_protobuf_FileDescriptorProto, public_dependency), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3}, - {11, offsetof(google_protobuf_FileDescriptorProto, weak_dependency), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3}, - {12, offsetof(google_protobuf_FileDescriptorProto, syntax), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, +static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(16, 32), 2, 0, 9, 1}, + {3, UPB_SIZE(40, 80), 0, 0, 9, 3}, + {4, UPB_SIZE(44, 88), 0, 0, 11, 3}, + {5, UPB_SIZE(48, 96), 0, 1, 11, 3}, + {6, UPB_SIZE(52, 104), 0, 4, 11, 3}, + {7, UPB_SIZE(56, 112), 0, 2, 11, 3}, + {8, UPB_SIZE(32, 64), 4, 3, 11, 1}, + {9, UPB_SIZE(36, 72), 5, 5, 11, 1}, + {10, UPB_SIZE(60, 120), 0, 0, 5, 3}, + {11, UPB_SIZE(64, 128), 0, 0, 5, 3}, + {12, UPB_SIZE(24, 48), 3, 0, 9, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorProto_msginit = { +const upb_msglayout google_protobuf_FileDescriptorProto_msginit = { &google_protobuf_FileDescriptorProto_submsgs[0], &google_protobuf_FileDescriptorProto__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_FileDescriptorProto), 12, 0, false, true + UPB_SIZE(72, 144), 12, false, }; -google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_env *env) { - google_protobuf_FileDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_FileDescriptorProto *msg = google_protobuf_FileDescriptorProto_new(env); - if (upb_decode(buf, msg, &google_protobuf_FileDescriptorProto_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_FileDescriptorProto_serialize(google_protobuf_FileDescriptorProto *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, env, size); -} -upb_stringview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { - return msg->name; -} -void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { - msg->name = value; -} -upb_stringview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { - return msg->package; -} -void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { - msg->package = value; -} -const upb_array* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg) { - return msg->dependency; -} -void google_protobuf_FileDescriptorProto_set_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { - msg->dependency = value; -} -const upb_array* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg) { - return msg->message_type; -} -void google_protobuf_FileDescriptorProto_set_message_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { - msg->message_type = value; -} -const upb_array* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg) { - return msg->enum_type; -} -void google_protobuf_FileDescriptorProto_set_enum_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { - msg->enum_type = value; -} -const upb_array* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg) { - return msg->service; -} -void google_protobuf_FileDescriptorProto_set_service(google_protobuf_FileDescriptorProto *msg, upb_array* value) { - msg->service = value; -} -const upb_array* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg) { - return msg->extension; -} -void google_protobuf_FileDescriptorProto_set_extension(google_protobuf_FileDescriptorProto *msg, upb_array* value) { - msg->extension = value; -} -const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { - return msg->options; -} -void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { - msg->options = value; -} -const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { - return msg->source_code_info; -} -void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { - msg->source_code_info = value; -} -const upb_array* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg) { - return msg->public_dependency; -} -void google_protobuf_FileDescriptorProto_set_public_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { - msg->public_dependency = value; -} -const upb_array* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg) { - return msg->weak_dependency; -} -void google_protobuf_FileDescriptorProto_set_weak_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { - msg->weak_dependency = value; -} -upb_stringview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { - return msg->syntax; -} -void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { - msg->syntax = value; -} -struct google_protobuf_DescriptorProto { - upb_stringview name; - google_protobuf_MessageOptions* options; - upb_array* field; - upb_array* nested_type; - upb_array* enum_type; - upb_array* extension_range; - upb_array* extension; - upb_array* oneof_decl; - upb_array* reserved_range; - upb_array* reserved_name; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_DescriptorProto_submsgs[8] = { +static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[8] = { &google_protobuf_DescriptorProto_msginit, &google_protobuf_DescriptorProto_ExtensionRange_msginit, &google_protobuf_DescriptorProto_ReservedRange_msginit, @@ -211,1694 +83,420 @@ static const upb_msglayout_msginit_v1 *const google_protobuf_DescriptorProto_sub &google_protobuf_OneofDescriptorProto_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto__fields[10] = { - {1, offsetof(google_protobuf_DescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {2, offsetof(google_protobuf_DescriptorProto, field), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 4, 11, 3}, - {3, offsetof(google_protobuf_DescriptorProto, nested_type), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, - {4, offsetof(google_protobuf_DescriptorProto, enum_type), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 3, 11, 3}, - {5, offsetof(google_protobuf_DescriptorProto, extension_range), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 1, 11, 3}, - {6, offsetof(google_protobuf_DescriptorProto, extension), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 4, 11, 3}, - {7, offsetof(google_protobuf_DescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 5, 11, 1}, - {8, offsetof(google_protobuf_DescriptorProto, oneof_decl), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 6, 11, 3}, - {9, offsetof(google_protobuf_DescriptorProto, reserved_range), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 2, 11, 3}, - {10, offsetof(google_protobuf_DescriptorProto, reserved_name), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 3}, +static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(20, 40), 0, 4, 11, 3}, + {3, UPB_SIZE(24, 48), 0, 0, 11, 3}, + {4, UPB_SIZE(28, 56), 0, 3, 11, 3}, + {5, UPB_SIZE(32, 64), 0, 1, 11, 3}, + {6, UPB_SIZE(36, 72), 0, 4, 11, 3}, + {7, UPB_SIZE(16, 32), 2, 5, 11, 1}, + {8, UPB_SIZE(40, 80), 0, 6, 11, 3}, + {9, UPB_SIZE(44, 88), 0, 2, 11, 3}, + {10, UPB_SIZE(48, 96), 0, 0, 9, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_msginit = { +const upb_msglayout google_protobuf_DescriptorProto_msginit = { &google_protobuf_DescriptorProto_submsgs[0], &google_protobuf_DescriptorProto__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto), 10, 0, false, true -}; - -google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_env *env) { - google_protobuf_DescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_DescriptorProto *msg = google_protobuf_DescriptorProto_new(env); - if (upb_decode(buf, msg, &google_protobuf_DescriptorProto_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_DescriptorProto_serialize(google_protobuf_DescriptorProto *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, env, size); -} -upb_stringview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { - return msg->name; -} -void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_stringview value) { - msg->name = value; -} -const upb_array* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg) { - return msg->field; -} -void google_protobuf_DescriptorProto_set_field(google_protobuf_DescriptorProto *msg, upb_array* value) { - msg->field = value; -} -const upb_array* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg) { - return msg->nested_type; -} -void google_protobuf_DescriptorProto_set_nested_type(google_protobuf_DescriptorProto *msg, upb_array* value) { - msg->nested_type = value; -} -const upb_array* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg) { - return msg->enum_type; -} -void google_protobuf_DescriptorProto_set_enum_type(google_protobuf_DescriptorProto *msg, upb_array* value) { - msg->enum_type = value; -} -const upb_array* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg) { - return msg->extension_range; -} -void google_protobuf_DescriptorProto_set_extension_range(google_protobuf_DescriptorProto *msg, upb_array* value) { - msg->extension_range = value; -} -const upb_array* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg) { - return msg->extension; -} -void google_protobuf_DescriptorProto_set_extension(google_protobuf_DescriptorProto *msg, upb_array* value) { - msg->extension = value; -} -const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { - return msg->options; -} -void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { - msg->options = value; -} -const upb_array* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg) { - return msg->oneof_decl; -} -void google_protobuf_DescriptorProto_set_oneof_decl(google_protobuf_DescriptorProto *msg, upb_array* value) { - msg->oneof_decl = value; -} -const upb_array* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg) { - return msg->reserved_range; -} -void google_protobuf_DescriptorProto_set_reserved_range(google_protobuf_DescriptorProto *msg, upb_array* value) { - msg->reserved_range = value; -} -const upb_array* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg) { - return msg->reserved_name; -} -void google_protobuf_DescriptorProto_set_reserved_name(google_protobuf_DescriptorProto *msg, upb_array* value) { - msg->reserved_name = value; -} -struct google_protobuf_DescriptorProto_ExtensionRange { - int32_t start; - int32_t end; - google_protobuf_ExtensionRangeOptions* options; + UPB_SIZE(56, 112), 10, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { +static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { &google_protobuf_ExtensionRangeOptions_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { - {1, offsetof(google_protobuf_DescriptorProto_ExtensionRange, start), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, - {2, offsetof(google_protobuf_DescriptorProto_ExtensionRange, end), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, - {3, offsetof(google_protobuf_DescriptorProto_ExtensionRange, options), 2, UPB_NOT_IN_ONEOF, 0, 11, 1}, +static const upb_msglayout_field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, + {3, UPB_SIZE(12, 16), 3, 0, 11, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ExtensionRange_msginit = { +const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = { &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0], &google_protobuf_DescriptorProto_ExtensionRange__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto_ExtensionRange), 3, 0, false, true + UPB_SIZE(16, 24), 3, false, }; -google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_env *env) { - google_protobuf_DescriptorProto_ExtensionRange *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_DescriptorProto_ExtensionRange *msg = google_protobuf_DescriptorProto_ExtensionRange_new(env); - if (upb_decode(buf, msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_DescriptorProto_ExtensionRange_serialize(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, env, size); -} -int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { - return msg->start; -} -void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { - msg->start = value; -} -int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { - return msg->end; -} -void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { - msg->end = value; -} -const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { - return msg->options; -} -void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { - msg->options = value; -} -struct google_protobuf_DescriptorProto_ReservedRange { - int32_t start; - int32_t end; -}; - -static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto_ReservedRange__fields[2] = { - {1, offsetof(google_protobuf_DescriptorProto_ReservedRange, start), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, - {2, offsetof(google_protobuf_DescriptorProto_ReservedRange, end), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, +static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ReservedRange_msginit = { +const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = { NULL, &google_protobuf_DescriptorProto_ReservedRange__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto_ReservedRange), 2, 0, false, true -}; - -google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_env *env) { - google_protobuf_DescriptorProto_ReservedRange *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_DescriptorProto_ReservedRange *msg = google_protobuf_DescriptorProto_ReservedRange_new(env); - if (upb_decode(buf, msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_DescriptorProto_ReservedRange_serialize(google_protobuf_DescriptorProto_ReservedRange *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, env, size); -} -int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { - return msg->start; -} -void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { - msg->start = value; -} -int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { - return msg->end; -} -void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { - msg->end = value; -} -struct google_protobuf_ExtensionRangeOptions { - upb_array* uninterpreted_option; + UPB_SIZE(12, 12), 2, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_ExtensionRangeOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_ExtensionRangeOptions__fields[1] = { - {999, offsetof(google_protobuf_ExtensionRangeOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_ExtensionRangeOptions__fields[1] = { + {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_ExtensionRangeOptions_msginit = { +const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = { &google_protobuf_ExtensionRangeOptions_submsgs[0], &google_protobuf_ExtensionRangeOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_ExtensionRangeOptions), 1, 0, false, true + UPB_SIZE(4, 8), 1, false, }; -google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_env *env) { - google_protobuf_ExtensionRangeOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_ExtensionRangeOptions *msg = google_protobuf_ExtensionRangeOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_ExtensionRangeOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_ExtensionRangeOptions_serialize(google_protobuf_ExtensionRangeOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, env, size); -} -const upb_array* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_ExtensionRangeOptions_set_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_FieldDescriptorProto { - google_protobuf_FieldDescriptorProto_Label label; - google_protobuf_FieldDescriptorProto_Type type; - int32_t number; - int32_t oneof_index; - upb_stringview name; - upb_stringview extendee; - upb_stringview type_name; - upb_stringview default_value; - upb_stringview json_name; - google_protobuf_FieldOptions* options; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_FieldDescriptorProto_submsgs[1] = { +static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1] = { &google_protobuf_FieldOptions_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_FieldDescriptorProto__fields[10] = { - {1, offsetof(google_protobuf_FieldDescriptorProto, name), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {2, offsetof(google_protobuf_FieldDescriptorProto, extendee), 5, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {3, offsetof(google_protobuf_FieldDescriptorProto, number), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, - {4, offsetof(google_protobuf_FieldDescriptorProto, label), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1}, - {5, offsetof(google_protobuf_FieldDescriptorProto, type), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1}, - {6, offsetof(google_protobuf_FieldDescriptorProto, type_name), 6, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {7, offsetof(google_protobuf_FieldDescriptorProto, default_value), 7, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {8, offsetof(google_protobuf_FieldDescriptorProto, options), 9, UPB_NOT_IN_ONEOF, 0, 11, 1}, - {9, offsetof(google_protobuf_FieldDescriptorProto, oneof_index), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, - {10, offsetof(google_protobuf_FieldDescriptorProto, json_name), 8, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, +static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[10] = { + {1, UPB_SIZE(32, 32), 5, 0, 9, 1}, + {2, UPB_SIZE(40, 48), 6, 0, 9, 1}, + {3, UPB_SIZE(24, 24), 3, 0, 5, 1}, + {4, UPB_SIZE(8, 8), 1, 0, 14, 1}, + {5, UPB_SIZE(16, 16), 2, 0, 14, 1}, + {6, UPB_SIZE(48, 64), 7, 0, 9, 1}, + {7, UPB_SIZE(56, 80), 8, 0, 9, 1}, + {8, UPB_SIZE(72, 112), 10, 0, 11, 1}, + {9, UPB_SIZE(28, 28), 4, 0, 5, 1}, + {10, UPB_SIZE(64, 96), 9, 0, 9, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_FieldDescriptorProto_msginit = { +const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = { &google_protobuf_FieldDescriptorProto_submsgs[0], &google_protobuf_FieldDescriptorProto__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_FieldDescriptorProto), 10, 0, false, true -}; - -google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_env *env) { - google_protobuf_FieldDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_FieldDescriptorProto *msg = google_protobuf_FieldDescriptorProto_new(env); - if (upb_decode(buf, msg, &google_protobuf_FieldDescriptorProto_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_FieldDescriptorProto_serialize(google_protobuf_FieldDescriptorProto *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, env, size); -} -upb_stringview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { - return msg->name; -} -void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { - msg->name = value; -} -upb_stringview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { - return msg->extendee; -} -void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { - msg->extendee = value; -} -int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { - return msg->number; -} -void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { - msg->number = value; -} -google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { - return msg->label; -} -void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value) { - msg->label = value; -} -google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { - return msg->type; -} -void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value) { - msg->type = value; -} -upb_stringview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { - return msg->type_name; -} -void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { - msg->type_name = value; -} -upb_stringview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { - return msg->default_value; -} -void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { - msg->default_value = value; -} -const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { - return msg->options; -} -void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { - msg->options = value; -} -int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { - return msg->oneof_index; -} -void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { - msg->oneof_index = value; -} -upb_stringview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { - return msg->json_name; -} -void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { - msg->json_name = value; -} -struct google_protobuf_OneofDescriptorProto { - upb_stringview name; - google_protobuf_OneofOptions* options; + UPB_SIZE(80, 128), 10, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_OneofDescriptorProto_submsgs[1] = { +static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = { &google_protobuf_OneofOptions_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_OneofDescriptorProto__fields[2] = { - {1, offsetof(google_protobuf_OneofDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {2, offsetof(google_protobuf_OneofDescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 0, 11, 1}, +static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(16, 32), 2, 0, 11, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_OneofDescriptorProto_msginit = { +const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = { &google_protobuf_OneofDescriptorProto_submsgs[0], &google_protobuf_OneofDescriptorProto__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_OneofDescriptorProto), 2, 0, false, true + UPB_SIZE(24, 48), 2, false, }; -google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_env *env) { - google_protobuf_OneofDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_OneofDescriptorProto *msg = google_protobuf_OneofDescriptorProto_new(env); - if (upb_decode(buf, msg, &google_protobuf_OneofDescriptorProto_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_OneofDescriptorProto_serialize(google_protobuf_OneofDescriptorProto *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, env, size); -} -upb_stringview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { - return msg->name; -} -void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_stringview value) { - msg->name = value; -} -const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { - return msg->options; -} -void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { - msg->options = value; -} -struct google_protobuf_EnumDescriptorProto { - upb_stringview name; - google_protobuf_EnumOptions* options; - upb_array* value; - upb_array* reserved_range; - upb_array* reserved_name; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_EnumDescriptorProto_submsgs[3] = { +static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = { &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, &google_protobuf_EnumOptions_msginit, &google_protobuf_EnumValueDescriptorProto_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_EnumDescriptorProto__fields[5] = { - {1, offsetof(google_protobuf_EnumDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {2, offsetof(google_protobuf_EnumDescriptorProto, value), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 2, 11, 3}, - {3, offsetof(google_protobuf_EnumDescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 1, 11, 1}, - {4, offsetof(google_protobuf_EnumDescriptorProto, reserved_range), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, - {5, offsetof(google_protobuf_EnumDescriptorProto, reserved_name), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 3}, +static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(20, 40), 0, 2, 11, 3}, + {3, UPB_SIZE(16, 32), 2, 1, 11, 1}, + {4, UPB_SIZE(24, 48), 0, 0, 11, 3}, + {5, UPB_SIZE(28, 56), 0, 0, 9, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_EnumDescriptorProto_msginit = { +const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = { &google_protobuf_EnumDescriptorProto_submsgs[0], &google_protobuf_EnumDescriptorProto__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_EnumDescriptorProto), 5, 0, false, true + UPB_SIZE(32, 64), 5, false, }; -google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_env *env) { - google_protobuf_EnumDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_EnumDescriptorProto *msg = google_protobuf_EnumDescriptorProto_new(env); - if (upb_decode(buf, msg, &google_protobuf_EnumDescriptorProto_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_EnumDescriptorProto_serialize(google_protobuf_EnumDescriptorProto *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, env, size); -} -upb_stringview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { - return msg->name; -} -void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_stringview value) { - msg->name = value; -} -const upb_array* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg) { - return msg->value; -} -void google_protobuf_EnumDescriptorProto_set_value(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { - msg->value = value; -} -const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { - return msg->options; -} -void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { - msg->options = value; -} -const upb_array* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg) { - return msg->reserved_range; -} -void google_protobuf_EnumDescriptorProto_set_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { - msg->reserved_range = value; -} -const upb_array* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg) { - return msg->reserved_name; -} -void google_protobuf_EnumDescriptorProto_set_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { - msg->reserved_name = value; -} -struct google_protobuf_EnumDescriptorProto_EnumReservedRange { - int32_t start; - int32_t end; -}; - -static const upb_msglayout_fieldinit_v1 google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = { - {1, offsetof(google_protobuf_EnumDescriptorProto_EnumReservedRange, start), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, - {2, offsetof(google_protobuf_EnumDescriptorProto_EnumReservedRange, end), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, +static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {2, UPB_SIZE(8, 8), 2, 0, 5, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { +const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { NULL, &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_EnumDescriptorProto_EnumReservedRange), 2, 0, false, true -}; - -google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_env *env) { - google_protobuf_EnumDescriptorProto_EnumReservedRange *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_EnumDescriptorProto_EnumReservedRange *msg = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(env); - if (upb_decode(buf, msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, env, size); -} -int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { - return msg->start; -} -void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { - msg->start = value; -} -int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { - return msg->end; -} -void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { - msg->end = value; -} -struct google_protobuf_EnumValueDescriptorProto { - int32_t number; - upb_stringview name; - google_protobuf_EnumValueOptions* options; + UPB_SIZE(12, 12), 2, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = { +static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = { &google_protobuf_EnumValueOptions_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_EnumValueDescriptorProto__fields[3] = { - {1, offsetof(google_protobuf_EnumValueDescriptorProto, name), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {2, offsetof(google_protobuf_EnumValueDescriptorProto, number), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, - {3, offsetof(google_protobuf_EnumValueDescriptorProto, options), 2, UPB_NOT_IN_ONEOF, 0, 11, 1}, +static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = { + {1, UPB_SIZE(8, 16), 2, 0, 9, 1}, + {2, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {3, UPB_SIZE(16, 32), 3, 0, 11, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_EnumValueDescriptorProto_msginit = { +const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = { &google_protobuf_EnumValueDescriptorProto_submsgs[0], &google_protobuf_EnumValueDescriptorProto__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_EnumValueDescriptorProto), 3, 0, false, true -}; - -google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_env *env) { - google_protobuf_EnumValueDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_EnumValueDescriptorProto *msg = google_protobuf_EnumValueDescriptorProto_new(env); - if (upb_decode(buf, msg, &google_protobuf_EnumValueDescriptorProto_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_EnumValueDescriptorProto_serialize(google_protobuf_EnumValueDescriptorProto *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, env, size); -} -upb_stringview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { - return msg->name; -} -void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_stringview value) { - msg->name = value; -} -int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { - return msg->number; -} -void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { - msg->number = value; -} -const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { - return msg->options; -} -void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { - msg->options = value; -} -struct google_protobuf_ServiceDescriptorProto { - upb_stringview name; - google_protobuf_ServiceOptions* options; - upb_array* method; + UPB_SIZE(24, 48), 3, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_ServiceDescriptorProto_submsgs[2] = { +static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = { &google_protobuf_MethodDescriptorProto_msginit, &google_protobuf_ServiceOptions_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_ServiceDescriptorProto__fields[3] = { - {1, offsetof(google_protobuf_ServiceDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {2, offsetof(google_protobuf_ServiceDescriptorProto, method), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, - {3, offsetof(google_protobuf_ServiceDescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 1, 11, 1}, +static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = { + {1, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {2, UPB_SIZE(20, 40), 0, 0, 11, 3}, + {3, UPB_SIZE(16, 32), 2, 1, 11, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_ServiceDescriptorProto_msginit = { +const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = { &google_protobuf_ServiceDescriptorProto_submsgs[0], &google_protobuf_ServiceDescriptorProto__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_ServiceDescriptorProto), 3, 0, false, true -}; - -google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_env *env) { - google_protobuf_ServiceDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_ServiceDescriptorProto *msg = google_protobuf_ServiceDescriptorProto_new(env); - if (upb_decode(buf, msg, &google_protobuf_ServiceDescriptorProto_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_ServiceDescriptorProto_serialize(google_protobuf_ServiceDescriptorProto *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, env, size); -} -upb_stringview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { - return msg->name; -} -void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_stringview value) { - msg->name = value; -} -const upb_array* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg) { - return msg->method; -} -void google_protobuf_ServiceDescriptorProto_set_method(google_protobuf_ServiceDescriptorProto *msg, upb_array* value) { - msg->method = value; -} -const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { - return msg->options; -} -void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { - msg->options = value; -} -struct google_protobuf_MethodDescriptorProto { - bool client_streaming; - bool server_streaming; - upb_stringview name; - upb_stringview input_type; - upb_stringview output_type; - google_protobuf_MethodOptions* options; + UPB_SIZE(24, 48), 3, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_MethodDescriptorProto_submsgs[1] = { +static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = { &google_protobuf_MethodOptions_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_MethodDescriptorProto__fields[6] = { - {1, offsetof(google_protobuf_MethodDescriptorProto, name), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {2, offsetof(google_protobuf_MethodDescriptorProto, input_type), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {3, offsetof(google_protobuf_MethodDescriptorProto, output_type), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {4, offsetof(google_protobuf_MethodDescriptorProto, options), 5, UPB_NOT_IN_ONEOF, 0, 11, 1}, - {5, offsetof(google_protobuf_MethodDescriptorProto, client_streaming), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {6, offsetof(google_protobuf_MethodDescriptorProto, server_streaming), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, +static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = { + {1, UPB_SIZE(8, 16), 3, 0, 9, 1}, + {2, UPB_SIZE(16, 32), 4, 0, 9, 1}, + {3, UPB_SIZE(24, 48), 5, 0, 9, 1}, + {4, UPB_SIZE(32, 64), 6, 0, 11, 1}, + {5, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {6, UPB_SIZE(2, 2), 2, 0, 8, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_MethodDescriptorProto_msginit = { +const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = { &google_protobuf_MethodDescriptorProto_submsgs[0], &google_protobuf_MethodDescriptorProto__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_MethodDescriptorProto), 6, 0, false, true + UPB_SIZE(40, 80), 6, false, }; -google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_env *env) { - google_protobuf_MethodDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_MethodDescriptorProto *msg = google_protobuf_MethodDescriptorProto_new(env); - if (upb_decode(buf, msg, &google_protobuf_MethodDescriptorProto_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_MethodDescriptorProto_serialize(google_protobuf_MethodDescriptorProto *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, env, size); -} -upb_stringview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { - return msg->name; -} -void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { - msg->name = value; -} -upb_stringview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { - return msg->input_type; -} -void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { - msg->input_type = value; -} -upb_stringview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { - return msg->output_type; -} -void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { - msg->output_type = value; -} -const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { - return msg->options; -} -void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { - msg->options = value; -} -bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { - return msg->client_streaming; -} -void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { - msg->client_streaming = value; -} -bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { - return msg->server_streaming; -} -void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { - msg->server_streaming = value; -} -struct google_protobuf_FileOptions { - google_protobuf_FileOptions_OptimizeMode optimize_for; - bool java_multiple_files; - bool cc_generic_services; - bool java_generic_services; - bool py_generic_services; - bool java_generate_equals_and_hash; - bool deprecated; - bool java_string_check_utf8; - bool cc_enable_arenas; - bool php_generic_services; - upb_stringview java_package; - upb_stringview java_outer_classname; - upb_stringview go_package; - upb_stringview objc_class_prefix; - upb_stringview csharp_namespace; - upb_stringview swift_prefix; - upb_stringview php_class_prefix; - upb_stringview php_namespace; - upb_array* uninterpreted_option; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_FileOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_FileOptions__fields[19] = { - {1, offsetof(google_protobuf_FileOptions, java_package), 10, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {8, offsetof(google_protobuf_FileOptions, java_outer_classname), 11, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {9, offsetof(google_protobuf_FileOptions, optimize_for), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1}, - {10, offsetof(google_protobuf_FileOptions, java_multiple_files), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {11, offsetof(google_protobuf_FileOptions, go_package), 12, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {16, offsetof(google_protobuf_FileOptions, cc_generic_services), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {17, offsetof(google_protobuf_FileOptions, java_generic_services), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {18, offsetof(google_protobuf_FileOptions, py_generic_services), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {20, offsetof(google_protobuf_FileOptions, java_generate_equals_and_hash), 5, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {23, offsetof(google_protobuf_FileOptions, deprecated), 6, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {27, offsetof(google_protobuf_FileOptions, java_string_check_utf8), 7, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {31, offsetof(google_protobuf_FileOptions, cc_enable_arenas), 8, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {36, offsetof(google_protobuf_FileOptions, objc_class_prefix), 13, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {37, offsetof(google_protobuf_FileOptions, csharp_namespace), 14, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {39, offsetof(google_protobuf_FileOptions, swift_prefix), 15, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {40, offsetof(google_protobuf_FileOptions, php_class_prefix), 16, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {41, offsetof(google_protobuf_FileOptions, php_namespace), 17, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {42, offsetof(google_protobuf_FileOptions, php_generic_services), 9, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {999, offsetof(google_protobuf_FileOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_FileOptions__fields[19] = { + {1, UPB_SIZE(32, 32), 11, 0, 9, 1}, + {8, UPB_SIZE(40, 48), 12, 0, 9, 1}, + {9, UPB_SIZE(8, 8), 1, 0, 14, 1}, + {10, UPB_SIZE(16, 16), 2, 0, 8, 1}, + {11, UPB_SIZE(48, 64), 13, 0, 9, 1}, + {16, UPB_SIZE(17, 17), 3, 0, 8, 1}, + {17, UPB_SIZE(18, 18), 4, 0, 8, 1}, + {18, UPB_SIZE(19, 19), 5, 0, 8, 1}, + {20, UPB_SIZE(20, 20), 6, 0, 8, 1}, + {23, UPB_SIZE(21, 21), 7, 0, 8, 1}, + {27, UPB_SIZE(22, 22), 8, 0, 8, 1}, + {31, UPB_SIZE(23, 23), 9, 0, 8, 1}, + {36, UPB_SIZE(56, 80), 14, 0, 9, 1}, + {37, UPB_SIZE(64, 96), 15, 0, 9, 1}, + {39, UPB_SIZE(72, 112), 16, 0, 9, 1}, + {40, UPB_SIZE(80, 128), 17, 0, 9, 1}, + {41, UPB_SIZE(88, 144), 18, 0, 9, 1}, + {42, UPB_SIZE(24, 24), 10, 0, 8, 1}, + {999, UPB_SIZE(96, 160), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_FileOptions_msginit = { +const upb_msglayout google_protobuf_FileOptions_msginit = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_FileOptions), 19, 0, false, true + UPB_SIZE(104, 176), 19, false, }; -google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_env *env) { - google_protobuf_FileOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_FileOptions *msg = google_protobuf_FileOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_FileOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_FileOptions_serialize(google_protobuf_FileOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_FileOptions_msginit, env, size); -} -upb_stringview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { - return msg->java_package; -} -void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_stringview value) { - msg->java_package = value; -} -upb_stringview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { - return msg->java_outer_classname; -} -void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_stringview value) { - msg->java_outer_classname = value; -} -google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { - return msg->optimize_for; -} -void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value) { - msg->optimize_for = value; -} -bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { - return msg->java_multiple_files; -} -void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { - msg->java_multiple_files = value; -} -upb_stringview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { - return msg->go_package; -} -void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_stringview value) { - msg->go_package = value; -} -bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { - return msg->cc_generic_services; -} -void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { - msg->cc_generic_services = value; -} -bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { - return msg->java_generic_services; -} -void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { - msg->java_generic_services = value; -} -bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { - return msg->py_generic_services; -} -void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { - msg->py_generic_services = value; -} -bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { - return msg->java_generate_equals_and_hash; -} -void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { - msg->java_generate_equals_and_hash = value; -} -bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { - return msg->deprecated; -} -void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { - msg->deprecated = value; -} -bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { - return msg->java_string_check_utf8; -} -void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { - msg->java_string_check_utf8 = value; -} -bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { - return msg->cc_enable_arenas; -} -void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { - msg->cc_enable_arenas = value; -} -upb_stringview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { - return msg->objc_class_prefix; -} -void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { - msg->objc_class_prefix = value; -} -upb_stringview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { - return msg->csharp_namespace; -} -void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { - msg->csharp_namespace = value; -} -upb_stringview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { - return msg->swift_prefix; -} -void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { - msg->swift_prefix = value; -} -upb_stringview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { - return msg->php_class_prefix; -} -void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { - msg->php_class_prefix = value; -} -upb_stringview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { - return msg->php_namespace; -} -void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { - msg->php_namespace = value; -} -bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { - return msg->php_generic_services; -} -void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { - msg->php_generic_services = value; -} -const upb_array* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_FileOptions_set_uninterpreted_option(google_protobuf_FileOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_MessageOptions { - bool message_set_wire_format; - bool no_standard_descriptor_accessor; - bool deprecated; - bool map_entry; - upb_array* uninterpreted_option; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_MessageOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_MessageOptions__fields[5] = { - {1, offsetof(google_protobuf_MessageOptions, message_set_wire_format), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {2, offsetof(google_protobuf_MessageOptions, no_standard_descriptor_accessor), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {3, offsetof(google_protobuf_MessageOptions, deprecated), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {7, offsetof(google_protobuf_MessageOptions, map_entry), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {999, offsetof(google_protobuf_MessageOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_MessageOptions__fields[5] = { + {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {2, UPB_SIZE(2, 2), 2, 0, 8, 1}, + {3, UPB_SIZE(3, 3), 3, 0, 8, 1}, + {7, UPB_SIZE(4, 4), 4, 0, 8, 1}, + {999, UPB_SIZE(8, 8), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_MessageOptions_msginit = { +const upb_msglayout google_protobuf_MessageOptions_msginit = { &google_protobuf_MessageOptions_submsgs[0], &google_protobuf_MessageOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_MessageOptions), 5, 0, false, true + UPB_SIZE(12, 16), 5, false, }; -google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_env *env) { - google_protobuf_MessageOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_MessageOptions *msg = google_protobuf_MessageOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_MessageOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_MessageOptions_serialize(google_protobuf_MessageOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_MessageOptions_msginit, env, size); -} -bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { - return msg->message_set_wire_format; -} -void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { - msg->message_set_wire_format = value; -} -bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { - return msg->no_standard_descriptor_accessor; -} -void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { - msg->no_standard_descriptor_accessor = value; -} -bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { - return msg->deprecated; -} -void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { - msg->deprecated = value; -} -bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { - return msg->map_entry; -} -void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { - msg->map_entry = value; -} -const upb_array* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_MessageOptions_set_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_FieldOptions { - google_protobuf_FieldOptions_CType ctype; - google_protobuf_FieldOptions_JSType jstype; - bool packed; - bool deprecated; - bool lazy; - bool weak; - upb_array* uninterpreted_option; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_FieldOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_FieldOptions__fields[7] = { - {1, offsetof(google_protobuf_FieldOptions, ctype), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1}, - {2, offsetof(google_protobuf_FieldOptions, packed), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {3, offsetof(google_protobuf_FieldOptions, deprecated), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {5, offsetof(google_protobuf_FieldOptions, lazy), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {6, offsetof(google_protobuf_FieldOptions, jstype), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1}, - {10, offsetof(google_protobuf_FieldOptions, weak), 5, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {999, offsetof(google_protobuf_FieldOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = { + {1, UPB_SIZE(8, 8), 1, 0, 14, 1}, + {2, UPB_SIZE(24, 24), 3, 0, 8, 1}, + {3, UPB_SIZE(25, 25), 4, 0, 8, 1}, + {5, UPB_SIZE(26, 26), 5, 0, 8, 1}, + {6, UPB_SIZE(16, 16), 2, 0, 14, 1}, + {10, UPB_SIZE(27, 27), 6, 0, 8, 1}, + {999, UPB_SIZE(28, 32), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_FieldOptions_msginit = { +const upb_msglayout google_protobuf_FieldOptions_msginit = { &google_protobuf_FieldOptions_submsgs[0], &google_protobuf_FieldOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_FieldOptions), 7, 0, false, true -}; - -google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_env *env) { - google_protobuf_FieldOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_FieldOptions *msg = google_protobuf_FieldOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_FieldOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_FieldOptions_serialize(google_protobuf_FieldOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_FieldOptions_msginit, env, size); -} -google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { - return msg->ctype; -} -void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value) { - msg->ctype = value; -} -bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { - return msg->packed; -} -void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { - msg->packed = value; -} -bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { - return msg->deprecated; -} -void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { - msg->deprecated = value; -} -bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { - return msg->lazy; -} -void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { - msg->lazy = value; -} -google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { - return msg->jstype; -} -void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value) { - msg->jstype = value; -} -bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { - return msg->weak; -} -void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { - msg->weak = value; -} -const upb_array* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_FieldOptions_set_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_OneofOptions { - upb_array* uninterpreted_option; + UPB_SIZE(32, 40), 7, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_OneofOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_OneofOptions__fields[1] = { - {999, offsetof(google_protobuf_OneofOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_OneofOptions__fields[1] = { + {999, UPB_SIZE(0, 0), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_OneofOptions_msginit = { +const upb_msglayout google_protobuf_OneofOptions_msginit = { &google_protobuf_OneofOptions_submsgs[0], &google_protobuf_OneofOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_OneofOptions), 1, 0, false, true + UPB_SIZE(4, 8), 1, false, }; -google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_env *env) { - google_protobuf_OneofOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_OneofOptions *google_protobuf_OneofOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_OneofOptions *msg = google_protobuf_OneofOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_OneofOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_OneofOptions_serialize(google_protobuf_OneofOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_OneofOptions_msginit, env, size); -} -const upb_array* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_OneofOptions_set_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_EnumOptions { - bool allow_alias; - bool deprecated; - upb_array* uninterpreted_option; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_EnumOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_EnumOptions__fields[3] = { - {2, offsetof(google_protobuf_EnumOptions, allow_alias), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {3, offsetof(google_protobuf_EnumOptions, deprecated), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {999, offsetof(google_protobuf_EnumOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_EnumOptions__fields[3] = { + {2, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {3, UPB_SIZE(2, 2), 2, 0, 8, 1}, + {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_EnumOptions_msginit = { +const upb_msglayout google_protobuf_EnumOptions_msginit = { &google_protobuf_EnumOptions_submsgs[0], &google_protobuf_EnumOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_EnumOptions), 3, 0, false, true -}; - -google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_env *env) { - google_protobuf_EnumOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_EnumOptions *msg = google_protobuf_EnumOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_EnumOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_EnumOptions_serialize(google_protobuf_EnumOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_EnumOptions_msginit, env, size); -} -bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { - return msg->allow_alias; -} -void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { - msg->allow_alias = value; -} -bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { - return msg->deprecated; -} -void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { - msg->deprecated = value; -} -const upb_array* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_EnumOptions_set_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_EnumValueOptions { - bool deprecated; - upb_array* uninterpreted_option; + UPB_SIZE(8, 16), 3, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_EnumValueOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_EnumValueOptions__fields[2] = { - {1, offsetof(google_protobuf_EnumValueOptions, deprecated), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {999, offsetof(google_protobuf_EnumValueOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_EnumValueOptions__fields[2] = { + {1, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_EnumValueOptions_msginit = { +const upb_msglayout google_protobuf_EnumValueOptions_msginit = { &google_protobuf_EnumValueOptions_submsgs[0], &google_protobuf_EnumValueOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_EnumValueOptions), 2, 0, false, true + UPB_SIZE(8, 16), 2, false, }; -google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_env *env) { - google_protobuf_EnumValueOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_EnumValueOptions *msg = google_protobuf_EnumValueOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_EnumValueOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_EnumValueOptions_serialize(google_protobuf_EnumValueOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, env, size); -} -bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { - return msg->deprecated; -} -void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { - msg->deprecated = value; -} -const upb_array* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_EnumValueOptions_set_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_ServiceOptions { - bool deprecated; - upb_array* uninterpreted_option; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_ServiceOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_ServiceOptions__fields[2] = { - {33, offsetof(google_protobuf_ServiceOptions, deprecated), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {999, offsetof(google_protobuf_ServiceOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_ServiceOptions__fields[2] = { + {33, UPB_SIZE(1, 1), 1, 0, 8, 1}, + {999, UPB_SIZE(4, 8), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_ServiceOptions_msginit = { +const upb_msglayout google_protobuf_ServiceOptions_msginit = { &google_protobuf_ServiceOptions_submsgs[0], &google_protobuf_ServiceOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_ServiceOptions), 2, 0, false, true + UPB_SIZE(8, 16), 2, false, }; -google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_env *env) { - google_protobuf_ServiceOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_ServiceOptions *msg = google_protobuf_ServiceOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_ServiceOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_ServiceOptions_serialize(google_protobuf_ServiceOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, env, size); -} -bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { - return msg->deprecated; -} -void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { - msg->deprecated = value; -} -const upb_array* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_ServiceOptions_set_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_MethodOptions { - google_protobuf_MethodOptions_IdempotencyLevel idempotency_level; - bool deprecated; - upb_array* uninterpreted_option; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_MethodOptions_submsgs[1] = { +static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = { &google_protobuf_UninterpretedOption_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_MethodOptions__fields[3] = { - {33, offsetof(google_protobuf_MethodOptions, deprecated), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1}, - {34, offsetof(google_protobuf_MethodOptions, idempotency_level), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1}, - {999, offsetof(google_protobuf_MethodOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = { + {33, UPB_SIZE(16, 16), 2, 0, 8, 1}, + {34, UPB_SIZE(8, 8), 1, 0, 14, 1}, + {999, UPB_SIZE(20, 24), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_MethodOptions_msginit = { +const upb_msglayout google_protobuf_MethodOptions_msginit = { &google_protobuf_MethodOptions_submsgs[0], &google_protobuf_MethodOptions__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_MethodOptions), 3, 0, false, true -}; - -google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_env *env) { - google_protobuf_MethodOptions *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_MethodOptions *msg = google_protobuf_MethodOptions_new(env); - if (upb_decode(buf, msg, &google_protobuf_MethodOptions_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_MethodOptions_serialize(google_protobuf_MethodOptions *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_MethodOptions_msginit, env, size); -} -bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { - return msg->deprecated; -} -void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { - msg->deprecated = value; -} -google_protobuf_MethodOptions_IdempotencyLevel google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { - return msg->idempotency_level; -} -void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, google_protobuf_MethodOptions_IdempotencyLevel value) { - msg->idempotency_level = value; -} -const upb_array* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg) { - return msg->uninterpreted_option; -} -void google_protobuf_MethodOptions_set_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_array* value) { - msg->uninterpreted_option = value; -} -struct google_protobuf_UninterpretedOption { - uint64_t positive_int_value; - int64_t negative_int_value; - double double_value; - upb_stringview identifier_value; - upb_stringview string_value; - upb_stringview aggregate_value; - upb_array* name; + UPB_SIZE(24, 32), 3, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_UninterpretedOption_submsgs[1] = { +static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = { &google_protobuf_UninterpretedOption_NamePart_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_UninterpretedOption__fields[7] = { - {2, offsetof(google_protobuf_UninterpretedOption, name), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, - {3, offsetof(google_protobuf_UninterpretedOption, identifier_value), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {4, offsetof(google_protobuf_UninterpretedOption, positive_int_value), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 4, 1}, - {5, offsetof(google_protobuf_UninterpretedOption, negative_int_value), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 3, 1}, - {6, offsetof(google_protobuf_UninterpretedOption, double_value), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 1, 1}, - {7, offsetof(google_protobuf_UninterpretedOption, string_value), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 12, 1}, - {8, offsetof(google_protobuf_UninterpretedOption, aggregate_value), 5, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, +static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = { + {2, UPB_SIZE(56, 80), 0, 0, 11, 3}, + {3, UPB_SIZE(32, 32), 4, 0, 9, 1}, + {4, UPB_SIZE(8, 8), 1, 0, 4, 1}, + {5, UPB_SIZE(16, 16), 2, 0, 3, 1}, + {6, UPB_SIZE(24, 24), 3, 0, 1, 1}, + {7, UPB_SIZE(40, 48), 5, 0, 12, 1}, + {8, UPB_SIZE(48, 64), 6, 0, 9, 1}, }; -const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_msginit = { +const upb_msglayout google_protobuf_UninterpretedOption_msginit = { &google_protobuf_UninterpretedOption_submsgs[0], &google_protobuf_UninterpretedOption__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_UninterpretedOption), 7, 0, false, true + UPB_SIZE(64, 96), 7, false, }; -google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_env *env) { - google_protobuf_UninterpretedOption *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_UninterpretedOption *msg = google_protobuf_UninterpretedOption_new(env); - if (upb_decode(buf, msg, &google_protobuf_UninterpretedOption_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_UninterpretedOption_serialize(google_protobuf_UninterpretedOption *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, env, size); -} -const upb_array* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg) { - return msg->name; -} -void google_protobuf_UninterpretedOption_set_name(google_protobuf_UninterpretedOption *msg, upb_array* value) { - msg->name = value; -} -upb_stringview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { - return msg->identifier_value; -} -void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { - msg->identifier_value = value; -} -uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { - return msg->positive_int_value; -} -void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { - msg->positive_int_value = value; -} -int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { - return msg->negative_int_value; -} -void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { - msg->negative_int_value = value; -} -double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { - return msg->double_value; -} -void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { - msg->double_value = value; -} -upb_stringview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { - return msg->string_value; -} -void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { - msg->string_value = value; -} -upb_stringview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { - return msg->aggregate_value; -} -void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { - msg->aggregate_value = value; -} -struct google_protobuf_UninterpretedOption_NamePart { - bool is_extension; - upb_stringview name_part; -}; - -static const upb_msglayout_fieldinit_v1 google_protobuf_UninterpretedOption_NamePart__fields[2] = { - {1, offsetof(google_protobuf_UninterpretedOption_NamePart, name_part), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 2}, - {2, offsetof(google_protobuf_UninterpretedOption_NamePart, is_extension), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 2}, +static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = { + {1, UPB_SIZE(8, 16), 2, 0, 9, 2}, + {2, UPB_SIZE(1, 1), 1, 0, 8, 2}, }; -const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_NamePart_msginit = { +const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = { NULL, &google_protobuf_UninterpretedOption_NamePart__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_UninterpretedOption_NamePart), 2, 0, false, true -}; - -google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_env *env) { - google_protobuf_UninterpretedOption_NamePart *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_UninterpretedOption_NamePart *msg = google_protobuf_UninterpretedOption_NamePart_new(env); - if (upb_decode(buf, msg, &google_protobuf_UninterpretedOption_NamePart_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_UninterpretedOption_NamePart_serialize(google_protobuf_UninterpretedOption_NamePart *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, env, size); -} -upb_stringview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { - return msg->name_part; -} -void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_stringview value) { - msg->name_part = value; -} -bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { - return msg->is_extension; -} -void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { - msg->is_extension = value; -} -struct google_protobuf_SourceCodeInfo { - upb_array* location; + UPB_SIZE(16, 32), 2, false, }; -static const upb_msglayout_msginit_v1 *const google_protobuf_SourceCodeInfo_submsgs[1] = { +static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = { &google_protobuf_SourceCodeInfo_Location_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_SourceCodeInfo__fields[1] = { - {1, offsetof(google_protobuf_SourceCodeInfo, location), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_SourceCodeInfo__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_msginit = { +const upb_msglayout google_protobuf_SourceCodeInfo_msginit = { &google_protobuf_SourceCodeInfo_submsgs[0], &google_protobuf_SourceCodeInfo__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_SourceCodeInfo), 1, 0, false, true -}; - -google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_env *env) { - google_protobuf_SourceCodeInfo *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_SourceCodeInfo *msg = google_protobuf_SourceCodeInfo_new(env); - if (upb_decode(buf, msg, &google_protobuf_SourceCodeInfo_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_SourceCodeInfo_serialize(google_protobuf_SourceCodeInfo *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, env, size); -} -const upb_array* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg) { - return msg->location; -} -void google_protobuf_SourceCodeInfo_set_location(google_protobuf_SourceCodeInfo *msg, upb_array* value) { - msg->location = value; -} -struct google_protobuf_SourceCodeInfo_Location { - upb_stringview leading_comments; - upb_stringview trailing_comments; - upb_array* path; - upb_array* span; - upb_array* leading_detached_comments; + UPB_SIZE(4, 8), 1, false, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_SourceCodeInfo_Location__fields[5] = { - {1, offsetof(google_protobuf_SourceCodeInfo_Location, path), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3}, - {2, offsetof(google_protobuf_SourceCodeInfo_Location, span), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3}, - {3, offsetof(google_protobuf_SourceCodeInfo_Location, leading_comments), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {4, offsetof(google_protobuf_SourceCodeInfo_Location, trailing_comments), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {6, offsetof(google_protobuf_SourceCodeInfo_Location, leading_detached_comments), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 3}, +static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = { + {1, UPB_SIZE(24, 48), 0, 0, 5, 3}, + {2, UPB_SIZE(28, 56), 0, 0, 5, 3}, + {3, UPB_SIZE(8, 16), 1, 0, 9, 1}, + {4, UPB_SIZE(16, 32), 2, 0, 9, 1}, + {6, UPB_SIZE(32, 64), 0, 0, 9, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_Location_msginit = { +const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = { NULL, &google_protobuf_SourceCodeInfo_Location__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_SourceCodeInfo_Location), 5, 0, false, true + UPB_SIZE(40, 80), 5, false, }; -google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_env *env) { - google_protobuf_SourceCodeInfo_Location *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_SourceCodeInfo_Location *msg = google_protobuf_SourceCodeInfo_Location_new(env); - if (upb_decode(buf, msg, &google_protobuf_SourceCodeInfo_Location_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_SourceCodeInfo_Location_serialize(google_protobuf_SourceCodeInfo_Location *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, env, size); -} -const upb_array* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg) { - return msg->path; -} -void google_protobuf_SourceCodeInfo_Location_set_path(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { - msg->path = value; -} -const upb_array* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg) { - return msg->span; -} -void google_protobuf_SourceCodeInfo_Location_set_span(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { - msg->span = value; -} -upb_stringview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { - return msg->leading_comments; -} -void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { - msg->leading_comments = value; -} -upb_stringview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { - return msg->trailing_comments; -} -void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { - msg->trailing_comments = value; -} -const upb_array* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg) { - return msg->leading_detached_comments; -} -void google_protobuf_SourceCodeInfo_Location_set_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { - msg->leading_detached_comments = value; -} -struct google_protobuf_GeneratedCodeInfo { - upb_array* annotation; -}; - -static const upb_msglayout_msginit_v1 *const google_protobuf_GeneratedCodeInfo_submsgs[1] = { +static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = { &google_protobuf_GeneratedCodeInfo_Annotation_msginit, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_GeneratedCodeInfo__fields[1] = { - {1, offsetof(google_protobuf_GeneratedCodeInfo, annotation), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3}, +static const upb_msglayout_field google_protobuf_GeneratedCodeInfo__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, 3}, }; -const upb_msglayout_msginit_v1 google_protobuf_GeneratedCodeInfo_msginit = { +const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = { &google_protobuf_GeneratedCodeInfo_submsgs[0], &google_protobuf_GeneratedCodeInfo__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_GeneratedCodeInfo), 1, 0, false, true + UPB_SIZE(4, 8), 1, false, }; -google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_env *env) { - google_protobuf_GeneratedCodeInfo *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_GeneratedCodeInfo *msg = google_protobuf_GeneratedCodeInfo_new(env); - if (upb_decode(buf, msg, &google_protobuf_GeneratedCodeInfo_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_GeneratedCodeInfo_serialize(google_protobuf_GeneratedCodeInfo *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, env, size); -} -const upb_array* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg) { - return msg->annotation; -} -void google_protobuf_GeneratedCodeInfo_set_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_array* value) { - msg->annotation = value; -} -struct google_protobuf_GeneratedCodeInfo_Annotation { - int32_t begin; - int32_t end; - upb_stringview source_file; - upb_array* path; +static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { + {1, UPB_SIZE(24, 32), 0, 0, 5, 3}, + {2, UPB_SIZE(16, 16), 3, 0, 9, 1}, + {3, UPB_SIZE(4, 4), 1, 0, 5, 1}, + {4, UPB_SIZE(8, 8), 2, 0, 5, 1}, }; -static const upb_msglayout_fieldinit_v1 google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { - {1, offsetof(google_protobuf_GeneratedCodeInfo_Annotation, path), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3}, - {2, offsetof(google_protobuf_GeneratedCodeInfo_Annotation, source_file), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1}, - {3, offsetof(google_protobuf_GeneratedCodeInfo_Annotation, begin), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, - {4, offsetof(google_protobuf_GeneratedCodeInfo_Annotation, end), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1}, -}; - -const upb_msglayout_msginit_v1 google_protobuf_GeneratedCodeInfo_Annotation_msginit = { +const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = { NULL, &google_protobuf_GeneratedCodeInfo_Annotation__fields[0], - NULL, - NULL, /* TODO. default_msg */ - UPB_ALIGNED_SIZEOF(google_protobuf_GeneratedCodeInfo_Annotation), 4, 0, false, true + UPB_SIZE(32, 48), 4, false, }; -google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_env *env) { - google_protobuf_GeneratedCodeInfo_Annotation *msg = upb_env_malloc(env, sizeof(*msg)); - memset(msg, 0, sizeof(*msg)); /* TODO: defaults */ - return msg; -} -google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parsenew(upb_stringview buf, upb_env *env) { - google_protobuf_GeneratedCodeInfo_Annotation *msg = google_protobuf_GeneratedCodeInfo_Annotation_new(env); - if (upb_decode(buf, msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, env)) { - return msg; - } else { - return NULL; - } -} -char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_env *env, size_t *size) { - return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, env, size); -} -const upb_array* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { - return msg->path; -} -void google_protobuf_GeneratedCodeInfo_Annotation_set_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_array* value) { - msg->path = value; -} -upb_stringview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { - return msg->source_file; -} -void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_stringview value) { - msg->source_file = value; -} -int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { - return msg->begin; -} -void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { - msg->begin = value; -} -int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { - return msg->end; -} -void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { - msg->end = value; -} + /* Maps descriptor type -> upb field type. */ @@ -1926,7 +524,6 @@ const uint8_t upb_desctype_to_fieldtype[] = { /* Data pertaining to the parse. */ typedef struct { - upb_env *env; /* Current decoding pointer. Points to the beginning of a field until we * have finished decoding the whole field. */ const char *ptr; @@ -1939,7 +536,7 @@ typedef struct { /* These members are unset for an unknown group frame. */ char *msg; - const upb_msglayout_msginit_v1 *m; + const upb_msglayout *m; } upb_decframe; #define CHK(x) if (!(x)) { return false; } @@ -1948,7 +545,7 @@ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number, const char *limit); static bool upb_decode_message(upb_decstate *d, const char *limit, int group_number, char *msg, - const upb_msglayout_msginit_v1 *l); + const upb_msglayout *l); static bool upb_decode_varint(const char **ptr, const char *limit, uint64_t *val) { @@ -2029,9 +626,7 @@ static void upb_set32(void *msg, size_t ofs, uint32_t val) { static bool upb_append_unknown(upb_decstate *d, upb_decframe *frame, const char *start) { - UPB_UNUSED(d); - UPB_UNUSED(frame); - UPB_UNUSED(start); + upb_msg_addunknown(frame->msg, start, d->ptr - start); return true; } @@ -2070,6 +665,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) { size_t new_bytes; size_t old_bytes; void *new_data; + upb_alloc *alloc = upb_arena_alloc(arr->arena); while (new_size < needed) { new_size *= 2; @@ -2077,7 +673,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) { old_bytes = arr->len * arr->element_size; new_bytes = new_size * arr->element_size; - new_data = upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes); + new_data = upb_realloc(alloc, arr->data, old_bytes, new_bytes); CHK(new_data); arr->data = new_data; @@ -2099,23 +695,21 @@ static void *upb_array_add(upb_array *arr, size_t elements) { } static upb_array *upb_getarr(upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { UPB_ASSERT(field->label == UPB_LABEL_REPEATED); return *(upb_array**)&frame->msg[field->offset]; } -static upb_array *upb_getorcreatearr(upb_decstate *d, - upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { +static upb_array *upb_getorcreatearr(upb_decframe *frame, + const upb_msglayout_field *field) { upb_array *arr = upb_getarr(frame, field); if (!arr) { - arr = upb_env_malloc(d->env, sizeof(*arr)); + upb_fieldtype_t type = upb_desctype_to_fieldtype[field->descriptortype]; + arr = upb_array_new(type, upb_msg_arena(frame->msg)); if (!arr) { return NULL; } - upb_array_init(arr, upb_desctype_to_fieldtype[field->descriptortype], - upb_arena_alloc(upb_env_arena(d->env))); *(upb_array**)&frame->msg[field->offset] = arr; } @@ -2123,26 +717,25 @@ static upb_array *upb_getorcreatearr(upb_decstate *d, } static void upb_sethasbit(upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { - UPB_ASSERT(field->hasbit != UPB_NO_HASBIT); - frame->msg[field->hasbit / 8] |= (1 << (field->hasbit % 8)); + const upb_msglayout_field *field) { + int32_t hasbit = field->presence; + UPB_ASSERT(field->presence > 0); + frame->msg[hasbit / 8] |= (1 << (hasbit % 8)); } static void upb_setoneofcase(upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { - UPB_ASSERT(field->oneof_index != UPB_NOT_IN_ONEOF); - upb_set32(frame->msg, frame->m->oneofs[field->oneof_index].case_offset, - field->number); + const upb_msglayout_field *field) { + UPB_ASSERT(field->presence < 0); + upb_set32(frame->msg, ~field->presence, field->number); } -static char *upb_decode_prepareslot(upb_decstate *d, - upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { +static char *upb_decode_prepareslot(upb_decframe *frame, + const upb_msglayout_field *field) { char *field_mem = frame->msg + field->offset; upb_array *arr; if (field->label == UPB_LABEL_REPEATED) { - arr = upb_getorcreatearr(d, frame, field); + arr = upb_getorcreatearr(frame, field); field_mem = upb_array_reserve(arr, 1); } @@ -2150,36 +743,32 @@ static char *upb_decode_prepareslot(upb_decstate *d, } static void upb_decode_setpresent(upb_decframe *frame, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { if (field->label == UPB_LABEL_REPEATED) { upb_array *arr = upb_getarr(frame, field); UPB_ASSERT(arr->len < arr->size); arr->len++; - } else if (field->oneof_index != UPB_NOT_IN_ONEOF) { + } else if (field->presence < 0) { upb_setoneofcase(frame, field); - } else if (field->hasbit != UPB_NO_HASBIT) { + } else if (field->presence > 0) { upb_sethasbit(frame, field); } } -static bool upb_decode_submsg(upb_decstate *d, - upb_decframe *frame, +static bool upb_decode_submsg(upb_decstate *d, upb_decframe *frame, const char *limit, - const upb_msglayout_fieldinit_v1 *field, + const upb_msglayout_field *field, int group_number) { - char *submsg_slot = upb_decode_prepareslot(d, frame, field); - char *submsg = *(void**)submsg_slot; - const upb_msglayout_msginit_v1 *subm; + char *submsg_slot = upb_decode_prepareslot(frame, field); + char *submsg = *(void **)submsg_slot; + const upb_msglayout *subm; - UPB_ASSERT(field->submsg_index != UPB_NO_SUBMSG); subm = frame->m->submsgs[field->submsg_index]; UPB_ASSERT(subm); if (!submsg) { - submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm)); + submsg = upb_msg_new(subm, upb_msg_arena(frame->msg)); CHK(submsg); - submsg = upb_msg_init( - submsg, (upb_msglayout*)subm, upb_arena_alloc(upb_env_arena(d->env))); *(void**)submsg_slot = submsg; } @@ -2190,11 +779,11 @@ static bool upb_decode_submsg(upb_decstate *d, static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { uint64_t val; void *field_mem; - field_mem = upb_decode_prepareslot(d, frame, field); + field_mem = upb_decode_prepareslot(frame, field); CHK(field_mem); CHK(upb_decode_varint(&d->ptr, frame->limit, &val)); @@ -2235,11 +824,11 @@ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { void *field_mem; uint64_t val; - field_mem = upb_decode_prepareslot(d, frame, field); + field_mem = upb_decode_prepareslot(frame, field); CHK(field_mem); CHK(upb_decode_64bit(&d->ptr, frame->limit, &val)); @@ -2259,11 +848,11 @@ static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame, static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { void *field_mem; uint32_t val; - field_mem = upb_decode_prepareslot(d, frame, field); + field_mem = upb_decode_prepareslot(frame, field); CHK(field_mem); CHK(upb_decode_32bit(&d->ptr, frame->limit, &val)); @@ -2295,9 +884,9 @@ static bool upb_decode_fixedpacked(upb_array *arr, upb_stringview data, static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field, + const upb_msglayout_field *field, upb_stringview val) { - upb_array *arr = upb_getorcreatearr(d, frame, field); + upb_array *arr = upb_getorcreatearr(frame, field); #define VARINT_CASE(ctype, decode) { \ const char *ptr = val.data; \ @@ -2346,7 +935,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, case UPB_DESCRIPTOR_TYPE_SINT64: VARINT_CASE(int64_t, upb_zzdecode_64); case UPB_DESCRIPTOR_TYPE_MESSAGE: { - const upb_msglayout_msginit_v1 *subm; + const upb_msglayout *subm; char *submsg; void *field_mem; @@ -2354,14 +943,11 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, d->ptr -= val.size; /* Create elemente message. */ - UPB_ASSERT(field->submsg_index != UPB_NO_SUBMSG); subm = frame->m->submsgs[field->submsg_index]; UPB_ASSERT(subm); - submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm)); + submsg = upb_msg_new(subm, upb_msg_arena(frame->msg)); CHK(submsg); - submsg = upb_msg_init(submsg, (upb_msglayout*)subm, - upb_arena_alloc(upb_env_arena(d->env))); field_mem = upb_array_add(arr, 1); CHK(field_mem); @@ -2379,7 +965,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame, static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, const char *field_start, - const upb_msglayout_fieldinit_v1 *field) { + const upb_msglayout_field *field) { upb_stringview val; CHK(upb_decode_string(&d->ptr, frame->limit, &val)); @@ -2390,7 +976,7 @@ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, switch ((upb_descriptortype_t)field->descriptortype) { case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_BYTES: { - void *field_mem = upb_decode_prepareslot(d, frame, field); + void *field_mem = upb_decode_prepareslot(frame, field); CHK(field_mem); memcpy(field_mem, &val, sizeof(val)); break; @@ -2409,8 +995,8 @@ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame, } } -static const upb_msglayout_fieldinit_v1 *upb_find_field( - const upb_msglayout_msginit_v1 *l, uint32_t field_number) { +static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, + uint32_t field_number) { /* Lots of optimization opportunities here. */ int i; for (i = 0; i < l->field_count; i++) { @@ -2426,7 +1012,7 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { int field_number; int wire_type; const char *field_start = d->ptr; - const upb_msglayout_fieldinit_v1 *field; + const upb_msglayout_field *field; CHK(upb_decode_tag(&d->ptr, frame->limit, &field_number, &wire_type)); field = upb_find_field(frame->m, field_number); @@ -2453,7 +1039,9 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) { } } else { CHK(field_number != 0); - return upb_skip_unknownfielddata(d, frame, field_number, wire_type); + CHK(upb_skip_unknownfielddata(d, frame, field_number, wire_type)); + CHK(upb_append_unknown(d, frame, field_start)); + return true; } } @@ -2478,7 +1066,7 @@ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number, static bool upb_decode_message(upb_decstate *d, const char *limit, int group_number, char *msg, - const upb_msglayout_msginit_v1 *l) { + const upb_msglayout *l) { upb_decframe frame; frame.group_number = group_number; frame.limit = limit; @@ -2492,11 +1080,9 @@ static bool upb_decode_message(upb_decstate *d, const char *limit, return true; } -bool upb_decode(upb_stringview buf, void *msg, - const upb_msglayout_msginit_v1 *l, upb_env *env) { +bool upb_decode(upb_stringview buf, void *msg, const upb_msglayout *l) { upb_decstate state; state.ptr = buf.data; - state.env = env; return upb_decode_message(&state, buf.data + buf.size, 0, msg, l); } @@ -2866,6 +1452,45 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { return true; } +static void assign_msg_wellknowntype(upb_msgdef *m) { + const char *name = upb_msgdef_fullname(m); + if (name == NULL) { + m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; + return; + } + if (!strcmp(name, "google.protobuf.Duration")) { + m->well_known_type = UPB_WELLKNOWN_DURATION; + } else if (!strcmp(name, "google.protobuf.Timestamp")) { + m->well_known_type = UPB_WELLKNOWN_TIMESTAMP; + } else if (!strcmp(name, "google.protobuf.DoubleValue")) { + m->well_known_type = UPB_WELLKNOWN_DOUBLEVALUE; + } else if (!strcmp(name, "google.protobuf.FloatValue")) { + m->well_known_type = UPB_WELLKNOWN_FLOATVALUE; + } else if (!strcmp(name, "google.protobuf.Int64Value")) { + m->well_known_type = UPB_WELLKNOWN_INT64VALUE; + } else if (!strcmp(name, "google.protobuf.UInt64Value")) { + m->well_known_type = UPB_WELLKNOWN_UINT64VALUE; + } else if (!strcmp(name, "google.protobuf.Int32Value")) { + m->well_known_type = UPB_WELLKNOWN_INT32VALUE; + } else if (!strcmp(name, "google.protobuf.UInt32Value")) { + m->well_known_type = UPB_WELLKNOWN_UINT32VALUE; + } else if (!strcmp(name, "google.protobuf.BoolValue")) { + m->well_known_type = UPB_WELLKNOWN_BOOLVALUE; + } else if (!strcmp(name, "google.protobuf.StringValue")) { + m->well_known_type = UPB_WELLKNOWN_STRINGVALUE; + } else if (!strcmp(name, "google.protobuf.BytesValue")) { + m->well_known_type = UPB_WELLKNOWN_BYTESVALUE; + } else if (!strcmp(name, "google.protobuf.Value")) { + m->well_known_type = UPB_WELLKNOWN_VALUE; + } else if (!strcmp(name, "google.protobuf.ListValue")) { + m->well_known_type = UPB_WELLKNOWN_LISTVALUE; + } else if (!strcmp(name, "google.protobuf.Struct")) { + m->well_known_type = UPB_WELLKNOWN_STRUCT; + } else { + m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; + } +} + bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { size_t i; @@ -2902,6 +1527,8 @@ bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { if (!assign_msg_indices(m, s)) { goto err; } + assign_msg_wellknowntype(m); + /* m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; */ } else if (e) { upb_inttable_compact(&e->iton); } @@ -4094,6 +2721,16 @@ bool upb_msgdef_mapentry(const upb_msgdef *m) { return m->map_entry; } +upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m) { + return m->well_known_type; +} + +bool upb_msgdef_isnumberwrapper(const upb_msgdef *m) { + upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); + return type >= UPB_WELLKNOWN_DOUBLEVALUE && + type <= UPB_WELLKNOWN_UINT32VALUE; +} + void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { upb_inttable_begin(iter, &m->itof); } @@ -4908,7 +3545,7 @@ static uint32_t upb_zzencode_32(int32_t n) { return (n << 1) ^ (n >> 31); } static uint64_t upb_zzencode_64(int64_t n) { return (n << 1) ^ (n >> 63); } typedef struct { - upb_env *env; + upb_alloc *alloc; char *buf, *ptr, *limit; } upb_encstate; @@ -4923,7 +3560,7 @@ static size_t upb_roundup_pow2(size_t bytes) { static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) { size_t old_size = e->limit - e->buf; size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char *new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size); + char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size); CHK(new_buf); /* We want previous data at the end, realloc() put it at the beginning. */ @@ -4987,17 +3624,17 @@ static bool upb_put_float(upb_encstate *e, float d) { return upb_put_fixed32(e, u32); } -static uint32_t upb_readcase(const char *msg, const upb_msglayout_msginit_v1 *m, - int oneof_index) { +static uint32_t upb_readcase(const char *msg, const upb_msglayout_field *f) { uint32_t ret; - memcpy(&ret, msg + m->oneofs[oneof_index].case_offset, sizeof(ret)); + uint32_t offset = ~f->presence; + memcpy(&ret, msg + offset, sizeof(ret)); return ret; } -static bool upb_readhasbit(const char *msg, - const upb_msglayout_fieldinit_v1 *f) { - UPB_ASSERT(f->hasbit != UPB_NO_HASBIT); - return msg[f->hasbit / 8] & (1 << (f->hasbit % 8)); +static bool upb_readhasbit(const char *msg, const upb_msglayout_field *f) { + uint32_t hasbit = f->presence; + UPB_ASSERT(f->presence > 0); + return msg[hasbit / 8] & (1 << (hasbit % 8)); } static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) { @@ -5011,12 +3648,11 @@ static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr, } bool upb_encode_message(upb_encstate *e, const char *msg, - const upb_msglayout_msginit_v1 *m, - size_t *size); + const upb_msglayout *m, size_t *size); static bool upb_encode_array(upb_encstate *e, const char *field_mem, - const upb_msglayout_msginit_v1 *m, - const upb_msglayout_fieldinit_v1 *f) { + const upb_msglayout *m, + const upb_msglayout_field *f) { const upb_array *arr = *(const upb_array**)field_mem; if (arr == NULL || arr->len == 0) { @@ -5082,7 +3718,7 @@ do { ; } while(0) case UPB_DESCRIPTOR_TYPE_GROUP: { void **start = arr->data; void **ptr = start + arr->len; - const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + const upb_msglayout *subm = m->submsgs[f->submsg_index]; do { size_t size; ptr--; @@ -5095,7 +3731,7 @@ do { ; } while(0) case UPB_DESCRIPTOR_TYPE_MESSAGE: { void **start = arr->data; void **ptr = start + arr->len; - const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; + const upb_msglayout *subm = m->submsgs[f->submsg_index]; do { size_t size; ptr--; @@ -5115,11 +3751,9 @@ do { ; } while(0) } static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, - const upb_msglayout_msginit_v1 *m, - const upb_msglayout_fieldinit_v1 *f, - bool is_proto3) { - bool skip_zero_value = is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF; - + const upb_msglayout *m, + const upb_msglayout_field *f, + bool skip_zero_value) { #define CASE(ctype, type, wire_type, encodeval) do { \ ctype val = *(ctype*)field_mem; \ if (skip_zero_value && val == 0) { \ @@ -5166,9 +3800,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, } case UPB_DESCRIPTOR_TYPE_GROUP: { size_t size; - void *submsg = *(void**)field_mem; - const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; - if (skip_zero_value && submsg == NULL) { + void *submsg = *(void **)field_mem; + const upb_msglayout *subm = m->submsgs[f->submsg_index]; + if (submsg == NULL) { return true; } return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && @@ -5177,9 +3811,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, } case UPB_DESCRIPTOR_TYPE_MESSAGE: { size_t size; - void *submsg = *(void**)field_mem; - const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; - if (skip_zero_value && submsg == NULL) { + void *submsg = *(void **)field_mem; + const upb_msglayout *subm = m->submsgs[f->submsg_index]; + if (submsg == NULL) { return true; } return upb_encode_message(e, submsg, subm, &size) && @@ -5191,55 +3825,52 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, UPB_UNREACHABLE(); } -bool upb_encode_hasscalarfield(const char *msg, - const upb_msglayout_msginit_v1 *m, - const upb_msglayout_fieldinit_v1 *f) { - if (f->oneof_index != UPB_NOT_IN_ONEOF) { - return upb_readcase(msg, m, f->oneof_index) == f->number; - } else if (m->is_proto2) { - return upb_readhasbit(msg, f); - } else { - /* For proto3, we'll test for the field being empty later. */ - return true; - } -} - -bool upb_encode_message(upb_encstate* e, const char *msg, - const upb_msglayout_msginit_v1 *m, - size_t *size) { +bool upb_encode_message(upb_encstate *e, const char *msg, + const upb_msglayout *m, size_t *size) { int i; size_t pre_len = e->limit - e->ptr; - - if (msg == NULL) { - return true; - } + const char *unknown; + size_t unknown_size; for (i = m->field_count - 1; i >= 0; i--) { - const upb_msglayout_fieldinit_v1 *f = &m->fields[i]; + const upb_msglayout_field *f = &m->fields[i]; if (f->label == UPB_LABEL_REPEATED) { CHK(upb_encode_array(e, msg + f->offset, m, f)); } else { - if (upb_encode_hasscalarfield(msg, m, f)) { - if (f->oneof_index == UPB_NOT_IN_ONEOF) { - CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, !m->is_proto2)); - } else { - const upb_msglayout_oneofinit_v1 *o = &m->oneofs[f->oneof_index]; - CHK(upb_encode_scalarfield(e, msg + o->data_offset, - m, f, !m->is_proto2)); + bool skip_empty = false; + if (f->presence == 0) { + /* Proto3 presence. */ + skip_empty = true; + } else if (f->presence > 0) { + /* Proto2 presence: hasbit. */ + if (!upb_readhasbit(msg, f)) { + continue; + } + } else { + /* Field is in a oneof. */ + if (upb_readcase(msg, f) != f->number) { + continue; } } + CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, skip_empty)); } } + unknown = upb_msg_getunknown(msg, &unknown_size); + + if (unknown) { + upb_put_bytes(e, unknown, unknown_size); + } + *size = (e->limit - e->ptr) - pre_len; return true; } -char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *m, - upb_env *env, size_t *size) { +char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena, + size_t *size) { upb_encstate e; - e.env = env; + e.alloc = upb_arena_alloc(arena); e.buf = NULL; e.limit = NULL; e.ptr = NULL; @@ -5964,29 +4595,108 @@ bool upb_byteshandler_setendstr(upb_byteshandler *h, } -static bool is_power_of_two(size_t val) { - return (val & (val - 1)) == 0; -} +/** Handlers for upb_msg ******************************************************/ -/* Align up to the given power of 2. */ -static size_t align_up(size_t val, size_t align) { - UPB_ASSERT(is_power_of_two(align)); - return (val + align - 1) & ~(align - 1); +typedef struct { + size_t offset; + int32_t hasbit; +} upb_msg_handlerdata; + +/* Fallback implementation if the handler is not specialized by the producer. */ +#define MSG_WRITER(type, ctype) \ + bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \ + uint8_t *m = c; \ + const upb_msg_handlerdata *d = hd; \ + if (d->hasbit > 0) \ + *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ + *(ctype*)&m[d->offset] = val; \ + return true; \ + } \ + +MSG_WRITER(double, double) +MSG_WRITER(float, float) +MSG_WRITER(int32, int32_t) +MSG_WRITER(int64, int64_t) +MSG_WRITER(uint32, uint32_t) +MSG_WRITER(uint64, uint64_t) +MSG_WRITER(bool, bool) + +bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f, + size_t offset, int32_t hasbit) { + upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; + bool ok; + + upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d)); + if (!d) return false; + d->offset = offset; + d->hasbit = hasbit; + + upb_handlerattr_sethandlerdata(&attr, d); + upb_handlerattr_setalwaysok(&attr, true); + upb_handlers_addcleanup(h, d, upb_gfree); + +#define TYPE(u, l) \ + case UPB_TYPE_##u: \ + ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break; + + ok = false; + + switch (upb_fielddef_type(f)) { + TYPE(INT64, int64); + TYPE(INT32, int32); + TYPE(ENUM, int32); + TYPE(UINT64, uint64); + TYPE(UINT32, uint32); + TYPE(DOUBLE, double); + TYPE(FLOAT, float); + TYPE(BOOL, bool); + default: UPB_ASSERT(false); break; + } +#undef TYPE + + upb_handlerattr_uninit(&attr); + return ok; } -static size_t div_round_up(size_t n, size_t d) { - return (n + d - 1) / d; +bool upb_msg_getscalarhandlerdata(const upb_handlers *h, + upb_selector_t s, + upb_fieldtype_t *type, + size_t *offset, + int32_t *hasbit) { + const upb_msg_handlerdata *d; + upb_func *f = upb_handlers_gethandler(h, s); + + if ((upb_int64_handlerfunc*)f == upb_msg_setint64) { + *type = UPB_TYPE_INT64; + } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) { + *type = UPB_TYPE_INT32; + } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) { + *type = UPB_TYPE_UINT64; + } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) { + *type = UPB_TYPE_UINT32; + } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) { + *type = UPB_TYPE_DOUBLE; + } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) { + *type = UPB_TYPE_FLOAT; + } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) { + *type = UPB_TYPE_BOOL; + } else { + return false; + } + + d = upb_handlers_gethandlerdata(h, s); + *offset = d->offset; + *hasbit = d->hasbit; + return true; } + bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) { return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 || type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 || type == UPB_TYPE_UINT64 || type == UPB_TYPE_STRING; } -void *upb_array_pack(const upb_array *arr, void *p, size_t *ofs, size_t size); -void *upb_map_pack(const upb_map *map, void *p, size_t *ofs, size_t size); - #define PTR_AT(msg, ofs, type) (type*)((char*)msg + ofs) #define VOIDPTR_AT(msg, ofs) PTR_AT(msg, ofs, void) #define ENCODE_MAX_NESTING 64 @@ -6035,7 +4745,7 @@ static size_t upb_msgval_sizeof(upb_fieldtype_t type) { UPB_UNREACHABLE(); } -static uint8_t upb_msg_fieldsize(const upb_msglayout_fieldinit_v1 *field) { +static uint8_t upb_msg_fieldsize(const upb_msglayout_field *field) { if (field->label == UPB_LABEL_REPEATED) { return sizeof(void*); } else { @@ -6043,14 +4753,6 @@ static uint8_t upb_msg_fieldsize(const upb_msglayout_fieldinit_v1 *field) { } } -static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { - if (upb_fielddef_isseq(f)) { - return sizeof(void*); - } else { - return upb_msgval_sizeof(upb_fielddef_type(f)); - } -} - /* TODO(haberman): this is broken right now because upb_msgval can contain * a char* / size_t pair, which is too big for a upb_value. To fix this * we'll probably need to dynamically allocate a upb_msgval and store a @@ -6086,525 +4788,6 @@ static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) { } } -static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) { - switch (upb_fielddef_type(f)) { - case UPB_TYPE_FLOAT: - return upb_msgval_float(upb_fielddef_defaultfloat(f)); - case UPB_TYPE_DOUBLE: - return upb_msgval_double(upb_fielddef_defaultdouble(f)); - case UPB_TYPE_BOOL: - return upb_msgval_bool(upb_fielddef_defaultbool(f)); - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: { - size_t len; - const char *ptr = upb_fielddef_defaultstr(f, &len); - return upb_msgval_makestr(ptr, len); - } - case UPB_TYPE_MESSAGE: - return upb_msgval_msg(NULL); - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: - return upb_msgval_int32(upb_fielddef_defaultint32(f)); - case UPB_TYPE_UINT32: - return upb_msgval_uint32(upb_fielddef_defaultuint32(f)); - case UPB_TYPE_INT64: - return upb_msgval_int64(upb_fielddef_defaultint64(f)); - case UPB_TYPE_UINT64: - return upb_msgval_uint64(upb_fielddef_defaultuint64(f)); - default: - UPB_ASSERT(false); - return upb_msgval_msg(NULL); - } -} - - -/** upb_msglayout *************************************************************/ - -struct upb_msglayout { - struct upb_msglayout_msginit_v1 data; -}; - -static void upb_msglayout_free(upb_msglayout *l) { - upb_gfree(l->data.default_msg); - upb_gfree(l); -} - -static size_t upb_msglayout_place(upb_msglayout *l, size_t size) { - size_t ret; - - l->data.size = align_up(l->data.size, size); - ret = l->data.size; - l->data.size += size; - return ret; -} - -static uint32_t upb_msglayout_offset(const upb_msglayout *l, - const upb_fielddef *f) { - return l->data.fields[upb_fielddef_index(f)].offset; -} - -static uint32_t upb_msglayout_hasbit(const upb_msglayout *l, - const upb_fielddef *f) { - return l->data.fields[upb_fielddef_index(f)].hasbit; -} - -static bool upb_msglayout_initdefault(upb_msglayout *l, const upb_msgdef *m) { - upb_msg_field_iter it; - - if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2 && l->data.size) { - /* Allocate default message and set default values in it. */ - l->data.default_msg = upb_gmalloc(l->data.size); - if (!l->data.default_msg) { - return false; - } - - memset(l->data.default_msg, 0, l->data.size); - - for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* f = upb_msg_iter_field(&it); - - if (upb_fielddef_containingoneof(f)) { - continue; - } - - /* TODO(haberman): handle strings. */ - if (!upb_fielddef_isstring(f) && - !upb_fielddef_issubmsg(f) && - !upb_fielddef_isseq(f)) { - upb_msg_set(l->data.default_msg, - upb_fielddef_index(f), - upb_msgval_fromdefault(f), - l); - } - } - } - - return true; -} - -static bool upb_msglayout_init(const upb_msgdef *m, - upb_msglayout *l, - upb_msgfactory *factory) { - upb_msg_field_iter it; - upb_msg_oneof_iter oit; - size_t hasbit; - size_t submsg_count = 0; - const upb_msglayout_msginit_v1 **submsgs; - upb_msglayout_fieldinit_v1 *fields; - upb_msglayout_oneofinit_v1 *oneofs; - - for (upb_msg_field_begin(&it, m); - !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* f = upb_msg_iter_field(&it); - if (upb_fielddef_issubmsg(f)) { - submsg_count++; - } - } - - memset(l, 0, sizeof(*l)); - - fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields)); - submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs)); - oneofs = upb_gmalloc(upb_msgdef_numoneofs(m) * sizeof(*oneofs)); - - if ((!fields && upb_msgdef_numfields(m)) || - (!submsgs && submsg_count) || - (!oneofs && upb_msgdef_numoneofs(m))) { - /* OOM. */ - upb_gfree(fields); - upb_gfree(submsgs); - upb_gfree(oneofs); - return false; - } - - l->data.field_count = upb_msgdef_numfields(m); - l->data.oneof_count = upb_msgdef_numoneofs(m); - l->data.fields = fields; - l->data.submsgs = submsgs; - l->data.oneofs = oneofs; - l->data.is_proto2 = (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2); - - /* Allocate data offsets in three stages: - * - * 1. hasbits. - * 2. regular fields. - * 3. oneof fields. - * - * OPT: There is a lot of room for optimization here to minimize the size. - */ - - /* Allocate hasbits and set basic field attributes. */ - submsg_count = 0; - for (upb_msg_field_begin(&it, m), hasbit = 0; - !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* f = upb_msg_iter_field(&it); - upb_msglayout_fieldinit_v1 *field = &fields[upb_fielddef_index(f)]; - - field->number = upb_fielddef_number(f); - field->descriptortype = upb_fielddef_descriptortype(f); - field->label = upb_fielddef_label(f); - - if (upb_fielddef_containingoneof(f)) { - field->oneof_index = upb_oneofdef_index(upb_fielddef_containingoneof(f)); - } else { - field->oneof_index = UPB_NOT_IN_ONEOF; - } - - if (upb_fielddef_issubmsg(f)) { - const upb_msglayout *sub_layout = - upb_msgfactory_getlayout(factory, upb_fielddef_msgsubdef(f)); - field->submsg_index = submsg_count++; - submsgs[field->submsg_index] = &sub_layout->data; - } else { - field->submsg_index = UPB_NO_SUBMSG; - } - - if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) { - field->hasbit = hasbit++; - } else { - field->hasbit = UPB_NO_HASBIT; - } - } - - /* Account for space used by hasbits. */ - l->data.size = div_round_up(hasbit, 8); - - /* Allocate non-oneof fields. */ - for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* f = upb_msg_iter_field(&it); - size_t field_size = upb_msg_fielddefsize(f); - size_t index = upb_fielddef_index(f); - - if (upb_fielddef_containingoneof(f)) { - /* Oneofs are handled separately below. */ - continue; - } - - fields[index].offset = upb_msglayout_place(l, field_size); - } - - /* Allocate oneof fields. Each oneof field consists of a uint32 for the case - * and space for the actual data. */ - for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit); - upb_msg_oneof_next(&oit)) { - const upb_oneofdef* o = upb_msg_iter_oneof(&oit); - upb_oneof_iter fit; - - size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ - upb_msglayout_oneofinit_v1 *oneof = &oneofs[upb_oneofdef_index(o)]; - size_t field_size = 0; - - /* Calculate field size: the max of all field sizes. */ - for (upb_oneof_begin(&fit, o); - !upb_oneof_done(&fit); - upb_oneof_next(&fit)) { - const upb_fielddef* f = upb_oneof_iter_field(&fit); - field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f)); - } - - /* Align and allocate case offset. */ - oneof->case_offset = upb_msglayout_place(l, case_size); - oneof->data_offset = upb_msglayout_place(l, field_size); - } - - /* Size of the entire structure should be a multiple of its greatest - * alignment. TODO: track overall alignment for real? */ - l->data.size = align_up(l->data.size, 8); - - return upb_msglayout_initdefault(l, m); -} - - -/** upb_msgfactory ************************************************************/ - -struct upb_msgfactory { - const upb_symtab *symtab; /* We own a ref. */ - upb_inttable layouts; - upb_inttable mergehandlers; -}; - -upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) { - upb_msgfactory *ret = upb_gmalloc(sizeof(*ret)); - - ret->symtab = symtab; - upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR); - upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR); - - return ret; -} - -void upb_msgfactory_free(upb_msgfactory *f) { - upb_inttable_iter i; - upb_inttable_begin(&i, &f->layouts); - for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { - upb_msglayout *l = upb_value_getptr(upb_inttable_iter_value(&i)); - upb_msglayout_free(l); - } - - upb_inttable_begin(&i, &f->mergehandlers); - for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { - const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i)); - upb_handlers_unref(h, f); - } - - upb_inttable_uninit(&f->layouts); - upb_inttable_uninit(&f->mergehandlers); - upb_gfree(f); -} - -const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) { - return f->symtab; -} - -const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, - const upb_msgdef *m) { - upb_value v; - UPB_ASSERT(upb_symtab_lookupmsg(f->symtab, upb_msgdef_fullname(m)) == m); - UPB_ASSERT(!upb_msgdef_mapentry(m)); - - if (upb_inttable_lookupptr(&f->layouts, m, &v)) { - UPB_ASSERT(upb_value_getptr(v)); - return upb_value_getptr(v); - } else { - /* In case of circular dependency, layout has to be inserted first. */ - upb_msglayout *l = upb_gmalloc(sizeof(*l)); - upb_msgfactory *mutable_f = (void*)f; - upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l)); - UPB_ASSERT(l); - if (!upb_msglayout_init(m, l, f)) { - upb_msglayout_free(l); - } - return l; - } -} - -/* Our handlers that we don't expose externally. */ - -void *upb_msg_startstr(void *msg, const void *hd, size_t size_hint) { - uint32_t ofs = (uintptr_t)hd; - upb_alloc *alloc = upb_msg_alloc(msg); - upb_msgval val; - UPB_UNUSED(size_hint); - - val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING)); - - upb_free(alloc, (void*)val.str.data); - val.str.data = NULL; - val.str.size = 0; - - upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING)); - return msg; -} - -size_t upb_msg_str(void *msg, const void *hd, const char *ptr, size_t size, - const upb_bufhandle *handle) { - uint32_t ofs = (uintptr_t)hd; - upb_alloc *alloc = upb_msg_alloc(msg); - upb_msgval val; - size_t newsize; - UPB_UNUSED(handle); - - val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING)); - - newsize = val.str.size + size; - val.str.data = upb_realloc(alloc, (void*)val.str.data, val.str.size, newsize); - - if (!val.str.data) { - return false; - } - - memcpy((char*)val.str.data + val.str.size, ptr, size); - val.str.size = newsize; - upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING)); - return size; -} - -static void callback(const void *closure, upb_handlers *h) { - upb_msgfactory *factory = (upb_msgfactory*)closure; - const upb_msgdef *md = upb_handlers_msgdef(h); - const upb_msglayout* layout = upb_msgfactory_getlayout(factory, md); - upb_msg_field_iter i; - UPB_UNUSED(factory); - - for(upb_msg_field_begin(&i, md); - !upb_msg_field_done(&i); - upb_msg_field_next(&i)) { - const upb_fielddef *f = upb_msg_iter_field(&i); - size_t offset = upb_msglayout_offset(layout, f); - upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; - upb_handlerattr_sethandlerdata(&attr, (void*)offset); - - if (upb_fielddef_isseq(f)) { - } else if (upb_fielddef_isstring(f)) { - upb_handlers_setstartstr(h, f, upb_msg_startstr, &attr); - upb_handlers_setstring(h, f, upb_msg_str, &attr); - } else { - upb_msg_setscalarhandler( - h, f, offset, upb_msglayout_hasbit(layout, f)); - } - } -} - -const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f, - const upb_msgdef *m) { - upb_msgfactory *mutable_f = (void*)f; - - /* TODO(haberman): properly cache these. */ - const upb_handlers *ret = upb_handlers_newfrozen(m, f, callback, f); - upb_inttable_push(&mutable_f->mergehandlers, upb_value_constptr(ret)); - - return ret; -} - -const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f, - const upb_handlers *h) { - const upb_msgdef *md = upb_handlers_msgdef(h); - return (const upb_visitorplan*)upb_msgfactory_getlayout(f, md); -} - - -/** upb_visitor ***************************************************************/ - -struct upb_visitor { - const upb_msglayout *layout; - upb_sink *sink; -}; - -static upb_selector_t getsel2(const upb_fielddef *f, upb_handlertype_t type) { - upb_selector_t ret; - bool ok = upb_handlers_getselector(f, type, &ret); - UPB_ASSERT(ok); - return ret; -} - -static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f, - const upb_msglayout *layout) { - int field_index = upb_fielddef_index(f); - if (upb_fielddef_isseq(f)) { - return upb_msgval_getarr(upb_msg_get(msg, field_index, layout)) != NULL; - } else if (upb_msgdef_syntax(upb_fielddef_containingtype(f)) == - UPB_SYNTAX_PROTO2) { - return upb_msg_has(msg, field_index, layout); - } else { - upb_msgval val = upb_msg_get(msg, field_index, layout); - switch (upb_fielddef_type(f)) { - case UPB_TYPE_FLOAT: - return upb_msgval_getfloat(val) != 0; - case UPB_TYPE_DOUBLE: - return upb_msgval_getdouble(val) != 0; - case UPB_TYPE_BOOL: - return upb_msgval_getbool(val); - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: - return upb_msgval_getint32(val) != 0; - case UPB_TYPE_UINT32: - return upb_msgval_getuint32(val) != 0; - case UPB_TYPE_INT64: - return upb_msgval_getint64(val) != 0; - case UPB_TYPE_UINT64: - return upb_msgval_getuint64(val) != 0; - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: - return upb_msgval_getstr(val).size > 0; - case UPB_TYPE_MESSAGE: - return upb_msgval_getmsg(val) != NULL; - } - UPB_UNREACHABLE(); - } -} - -static bool upb_visitor_visitmsg2(const upb_msg *msg, - const upb_msglayout *layout, upb_sink *sink, - int depth) { - const upb_msgdef *md = upb_handlers_msgdef(sink->handlers); - upb_msg_field_iter i; - upb_status status; - - upb_sink_startmsg(sink); - - /* Protect against cycles (possible because users may freely reassign message - * and repeated fields) by imposing a maximum recursion depth. */ - if (depth > ENCODE_MAX_NESTING) { - return false; - } - - for (upb_msg_field_begin(&i, md); - !upb_msg_field_done(&i); - upb_msg_field_next(&i)) { - upb_fielddef *f = upb_msg_iter_field(&i); - upb_msgval val; - - if (!upb_visitor_hasfield(msg, f, layout)) { - continue; - } - - val = upb_msg_get(msg, upb_fielddef_index(f), layout); - - if (upb_fielddef_isseq(f)) { - const upb_array *arr = upb_msgval_getarr(val); - UPB_ASSERT(arr); - /* TODO: putary(ary, f, sink, depth);*/ - } else if (upb_fielddef_issubmsg(f)) { - const upb_map *map = upb_msgval_getmap(val); - UPB_ASSERT(map); - /* TODO: putmap(map, f, sink, depth);*/ - } else if (upb_fielddef_isstring(f)) { - /* TODO putstr(); */ - } else { - upb_selector_t sel = getsel2(f, upb_handlers_getprimitivehandlertype(f)); - UPB_ASSERT(upb_fielddef_isprimitive(f)); - - switch (upb_fielddef_type(f)) { - case UPB_TYPE_FLOAT: - CHECK_TRUE(upb_sink_putfloat(sink, sel, upb_msgval_getfloat(val))); - break; - case UPB_TYPE_DOUBLE: - CHECK_TRUE(upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val))); - break; - case UPB_TYPE_BOOL: - CHECK_TRUE(upb_sink_putbool(sink, sel, upb_msgval_getbool(val))); - break; - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: - CHECK_TRUE(upb_sink_putint32(sink, sel, upb_msgval_getint32(val))); - break; - case UPB_TYPE_UINT32: - CHECK_TRUE(upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val))); - break; - case UPB_TYPE_INT64: - CHECK_TRUE(upb_sink_putint64(sink, sel, upb_msgval_getint64(val))); - break; - case UPB_TYPE_UINT64: - CHECK_TRUE(upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val))); - break; - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: - case UPB_TYPE_MESSAGE: - UPB_UNREACHABLE(); - } - } - } - - upb_sink_endmsg(sink, &status); - return true; -} - -upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp, - upb_sink *output) { - upb_visitor *visitor = upb_env_malloc(e, sizeof(*visitor)); - visitor->layout = (const upb_msglayout*)vp; - visitor->sink = output; - return visitor; -} - -bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) { - return upb_visitor_visitmsg2(msg, visitor->layout, visitor->sink, 0); -} - /** upb_msg *******************************************************************/ @@ -6619,8 +4802,12 @@ bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) { /* Used when a message is not extendable. */ typedef struct { - /* TODO(haberman): add unknown fields. */ - upb_alloc *alloc; + /* TODO(haberman): use pointer tagging so we we are slim when known unknown + * fields are not present. */ + upb_arena *arena; + char *unknown; + size_t unknown_len; + size_t unknown_size; } upb_msg_internal; /* Used when a message is extendable. */ @@ -6630,7 +4817,7 @@ typedef struct { } upb_msg_internal_withext; static int upb_msg_internalsize(const upb_msglayout *l) { - return sizeof(upb_msg_internal) - l->data.extendable * sizeof(void*); + return sizeof(upb_msg_internal) - l->extendable * sizeof(void *); } static upb_msg_internal *upb_msg_getinternal(upb_msg *msg) { @@ -6643,123 +4830,112 @@ static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) { static upb_msg_internal_withext *upb_msg_getinternalwithext( upb_msg *msg, const upb_msglayout *l) { - UPB_ASSERT(l->data.extendable); + UPB_ASSERT(l->extendable); return VOIDPTR_AT(msg, -sizeof(upb_msg_internal_withext)); } -static const upb_msglayout_fieldinit_v1 *upb_msg_checkfield( - int field_index, const upb_msglayout *l) { - UPB_ASSERT(field_index >= 0 && field_index < l->data.field_count); - return &l->data.fields[field_index]; +void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len) { + upb_msg_internal* in = upb_msg_getinternal(msg); + if (len > in->unknown_size - in->unknown_len) { + upb_alloc *alloc = upb_arena_alloc(in->arena); + size_t need = in->unknown_size + len; + size_t newsize = UPB_MAX(in->unknown_size * 2, need); + in->unknown = upb_realloc(alloc, in->unknown, in->unknown_size, newsize); + in->unknown_size = newsize; + } + memcpy(in->unknown + in->unknown_len, data, len); + in->unknown_len += len; +} + +const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) { + const upb_msg_internal* in = upb_msg_getinternal_const(msg); + *len = in->unknown_len; + return in->unknown; +} + +static const upb_msglayout_field *upb_msg_checkfield(int field_index, + const upb_msglayout *l) { + UPB_ASSERT(field_index >= 0 && field_index < l->field_count); + return &l->fields[field_index]; } -static bool upb_msg_inoneof(const upb_msglayout_fieldinit_v1 *field) { - return field->oneof_index != UPB_NOT_IN_ONEOF; +static bool upb_msg_inoneof(const upb_msglayout_field *field) { + return field->presence < 0; } static uint32_t *upb_msg_oneofcase(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); UPB_ASSERT(upb_msg_inoneof(field)); - return PTR_AT(msg, l->data.oneofs[field->oneof_index].case_offset, uint32_t); + return PTR_AT(msg, ~field->presence, uint32_t); } -size_t upb_msg_sizeof(const upb_msglayout *l) { - return l->data.size + upb_msg_internalsize(l); +static size_t upb_msg_sizeof(const upb_msglayout *l) { + return l->size + upb_msg_internalsize(l); } -upb_msg *upb_msg_init(void *mem, const upb_msglayout *l, upb_alloc *a) { - upb_msg *msg = VOIDPTR_AT(mem, upb_msg_internalsize(l)); +upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a) { + upb_alloc *alloc = upb_arena_alloc(a); + void *mem = upb_malloc(alloc, upb_msg_sizeof(l)); + upb_msg_internal *in; + upb_msg *msg; - /* Initialize normal members. */ - if (l->data.default_msg) { - memcpy(msg, l->data.default_msg, l->data.size); - } else { - memset(msg, 0, l->data.size); + if (!mem) { + return NULL; } + msg = VOIDPTR_AT(mem, upb_msg_internalsize(l)); + + /* Initialize normal members. */ + memset(msg, 0, l->size); + /* Initialize internal members. */ - upb_msg_getinternal(msg)->alloc = a; + in = upb_msg_getinternal(msg); + in->arena = a; + in->unknown = NULL; + in->unknown_len = 0; + in->unknown_size = 0; - if (l->data.extendable) { + if (l->extendable) { upb_msg_getinternalwithext(msg, l)->extdict = NULL; } return msg; } -void *upb_msg_uninit(upb_msg *msg, const upb_msglayout *l) { - if (l->data.extendable) { - upb_inttable *ext_dict = upb_msg_getinternalwithext(msg, l)->extdict; - if (ext_dict) { - upb_inttable_uninit2(ext_dict, upb_msg_alloc(msg)); - upb_free(upb_msg_alloc(msg), ext_dict); - } - } - - return VOIDPTR_AT(msg, -upb_msg_internalsize(l)); -} - -upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a) { - void *mem = upb_malloc(a, upb_msg_sizeof(l)); - return mem ? upb_msg_init(mem, l, a) : NULL; -} - -void upb_msg_free(upb_msg *msg, const upb_msglayout *l) { - upb_free(upb_msg_alloc(msg), upb_msg_uninit(msg, l)); -} - -upb_alloc *upb_msg_alloc(const upb_msg *msg) { - return upb_msg_getinternal_const(msg)->alloc; +upb_arena *upb_msg_arena(const upb_msg *msg) { + return upb_msg_getinternal_const(msg)->arena; } bool upb_msg_has(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); - UPB_ASSERT(l->data.is_proto2); + UPB_ASSERT(field->presence); if (upb_msg_inoneof(field)) { /* Oneofs are set when the oneof number is set to this field. */ return *upb_msg_oneofcase(msg, field_index, l) == field->number; } else { /* Other fields are set when their hasbit is set. */ - uint32_t hasbit = l->data.fields[field_index].hasbit; + uint32_t hasbit = field->presence; return DEREF(msg, hasbit / 8, char) | (1 << (hasbit % 8)); } } upb_msgval upb_msg_get(const upb_msg *msg, int field_index, const upb_msglayout *l) { - const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); int size = upb_msg_fieldsize(field); - - if (upb_msg_inoneof(field)) { - if (*upb_msg_oneofcase(msg, field_index, l) == field->number) { - size_t ofs = l->data.oneofs[field->oneof_index].data_offset; - return upb_msgval_read(msg, ofs, size); - } else { - /* Return default. */ - return upb_msgval_read(l->data.default_msg, field->offset, size); - } - } else { - return upb_msgval_read(msg, field->offset, size); - } + return upb_msgval_read(msg, field->offset, size); } void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val, const upb_msglayout *l) { - const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l); + const upb_msglayout_field *field = upb_msg_checkfield(field_index, l); int size = upb_msg_fieldsize(field); - - if (upb_msg_inoneof(field)) { - size_t ofs = l->data.oneofs[field->oneof_index].data_offset; - *upb_msg_oneofcase(msg, field_index, l) = field->number; - upb_msgval_write(msg, ofs, val, size); - } else { - upb_msgval_write(msg, field->offset, val, size); - } + upb_msgval_write(msg, field->offset, val, size); } @@ -6767,37 +4943,22 @@ void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val, #define DEREF_ARR(arr, i, type) ((type*)arr->data)[i] -size_t upb_array_sizeof(upb_fieldtype_t type) { - UPB_UNUSED(type); - return sizeof(upb_array); -} +upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a) { + upb_alloc *alloc = upb_arena_alloc(a); + upb_array *ret = upb_malloc(alloc, sizeof(upb_array)); -void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *alloc) { - arr->type = type; - arr->data = NULL; - arr->len = 0; - arr->size = 0; - arr->element_size = upb_msgval_sizeof(type); - arr->alloc = alloc; -} - -void upb_array_uninit(upb_array *arr) { - upb_free(arr->alloc, arr->data); -} - -upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a) { - upb_array *ret = upb_malloc(a, upb_array_sizeof(type)); - - if (ret) { - upb_array_init(ret, type, a); + if (!ret) { + return NULL; } - return ret; -} + ret->type = type; + ret->data = NULL; + ret->len = 0; + ret->size = 0; + ret->element_size = upb_msgval_sizeof(type); + ret->arena = a; -void upb_array_free(upb_array *arr) { - upb_array_uninit(arr); - upb_free(arr->alloc, arr); + return ret; } size_t upb_array_size(const upb_array *arr) { @@ -6824,8 +4985,9 @@ bool upb_array_set(upb_array *arr, size_t i, upb_msgval val) { size_t new_size = UPB_MAX(arr->size * 2, 8); size_t new_bytes = new_size * arr->element_size; size_t old_bytes = arr->size * arr->element_size; + upb_alloc *alloc = upb_arena_alloc(arr->arena); upb_msgval *new_data = - upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes); + upb_realloc(alloc, arr->data, old_bytes, new_bytes); if (!new_data) { return false; @@ -6851,7 +5013,7 @@ struct upb_map { /* We may want to optimize this to use inttable where possible, for greater * efficiency and lower memory footprint. */ upb_strtable strtab; - upb_alloc *alloc; + upb_arena *arena; }; static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key, @@ -6902,52 +5064,28 @@ static upb_msgval upb_map_fromkey(upb_fieldtype_t type, const char *key, UPB_UNREACHABLE(); } -size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype) { - /* Size does not currently depend on key/value type. */ - UPB_UNUSED(ktype); - UPB_UNUSED(vtype); - return sizeof(upb_map); -} - -bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype, - upb_alloc *a) { - upb_ctype_t vtabtype = upb_fieldtotabtype(vtype); - UPB_ASSERT(upb_fieldtype_mapkeyok(ktype)); - map->key_type = ktype; - map->val_type = vtype; - map->alloc = a; - - if (!upb_strtable_init2(&map->strtab, vtabtype, a)) { - return false; - } - - return true; -} - -void upb_map_uninit(upb_map *map) { - upb_strtable_uninit2(&map->strtab, map->alloc); -} - upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, - upb_alloc *a) { - upb_map *map = upb_malloc(a, upb_map_sizeof(ktype, vtype)); + upb_arena *a) { + upb_ctype_t vtabtype = upb_fieldtotabtype(vtype); + upb_alloc *alloc = upb_arena_alloc(a); + upb_map *map = upb_malloc(alloc, sizeof(upb_map)); if (!map) { return NULL; } - if (!upb_map_init(map, ktype, vtype, a)) { + UPB_ASSERT(upb_fieldtype_mapkeyok(ktype)); + map->key_type = ktype; + map->val_type = vtype; + map->arena = a; + + if (!upb_strtable_init2(&map->strtab, vtabtype, alloc)) { return NULL; } return map; } -void upb_map_free(upb_map *map) { - upb_map_uninit(map); - upb_free(map->alloc, map); -} - size_t upb_map_size(const upb_map *map) { return upb_strtable_count(&map->strtab); } @@ -6981,7 +5119,7 @@ bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, size_t key_len; upb_value tabval = upb_toval(val); upb_value removedtabval; - upb_alloc *a = map->alloc; + upb_alloc *a = upb_arena_alloc(map->arena); upb_map_tokey(map->key_type, &key, &key_str, &key_len); @@ -6997,7 +5135,7 @@ bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, bool upb_map_del(upb_map *map, upb_msgval key) { const char *key_str; size_t key_len; - upb_alloc *a = map->alloc; + upb_alloc *a = upb_arena_alloc(map->arena); upb_map_tokey(map->key_type, &key, &key_str, &key_len); return upb_strtable_remove3(&map->strtab, key_str, key_len, NULL, a); @@ -7061,100 +5199,258 @@ bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2) { } -/** Handlers for upb_msg ******************************************************/ +static bool is_power_of_two(size_t val) { + return (val & (val - 1)) == 0; +} -typedef struct { - size_t offset; - int32_t hasbit; -} upb_msg_handlerdata; +/* Align up to the given power of 2. */ +static size_t align_up(size_t val, size_t align) { + UPB_ASSERT(is_power_of_two(align)); + return (val + align - 1) & ~(align - 1); +} -/* Fallback implementation if the handler is not specialized by the producer. */ -#define MSG_WRITER(type, ctype) \ - bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \ - uint8_t *m = c; \ - const upb_msg_handlerdata *d = hd; \ - if (d->hasbit > 0) \ - *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ - *(ctype*)&m[d->offset] = val; \ - return true; \ - } \ +static size_t div_round_up(size_t n, size_t d) { + return (n + d - 1) / d; +} -MSG_WRITER(double, double) -MSG_WRITER(float, float) -MSG_WRITER(int32, int32_t) -MSG_WRITER(int64, int64_t) -MSG_WRITER(uint32, uint32_t) -MSG_WRITER(uint64, uint64_t) -MSG_WRITER(bool, bool) +static size_t upb_msgval_sizeof2(upb_fieldtype_t type) { + switch (type) { + case UPB_TYPE_DOUBLE: + case UPB_TYPE_INT64: + case UPB_TYPE_UINT64: + return 8; + case UPB_TYPE_ENUM: + case UPB_TYPE_INT32: + case UPB_TYPE_UINT32: + case UPB_TYPE_FLOAT: + return 4; + case UPB_TYPE_BOOL: + return 1; + case UPB_TYPE_MESSAGE: + return sizeof(void*); + case UPB_TYPE_BYTES: + case UPB_TYPE_STRING: + return sizeof(upb_stringview); + } + UPB_UNREACHABLE(); +} -bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f, - size_t offset, int32_t hasbit) { - upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; - bool ok; +static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { + if (upb_fielddef_isseq(f)) { + return sizeof(void*); + } else { + return upb_msgval_sizeof2(upb_fielddef_type(f)); + } +} - upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d)); - if (!d) return false; - d->offset = offset; - d->hasbit = hasbit; - upb_handlerattr_sethandlerdata(&attr, d); - upb_handlerattr_setalwaysok(&attr, true); - upb_handlers_addcleanup(h, d, upb_gfree); +/** upb_msglayout *************************************************************/ -#define TYPE(u, l) \ - case UPB_TYPE_##u: \ - ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break; +static void upb_msglayout_free(upb_msglayout *l) { + upb_gfree(l); +} - ok = false; +static size_t upb_msglayout_place(upb_msglayout *l, size_t size) { + size_t ret; - switch (upb_fielddef_type(f)) { - TYPE(INT64, int64); - TYPE(INT32, int32); - TYPE(ENUM, int32); - TYPE(UINT64, uint64); - TYPE(UINT32, uint32); - TYPE(DOUBLE, double); - TYPE(FLOAT, float); - TYPE(BOOL, bool); - default: UPB_ASSERT(false); break; + l->size = align_up(l->size, size); + ret = l->size; + l->size += size; + return ret; +} + +static bool upb_msglayout_init(const upb_msgdef *m, + upb_msglayout *l, + upb_msgfactory *factory) { + upb_msg_field_iter it; + upb_msg_oneof_iter oit; + size_t hasbit; + size_t submsg_count = 0; + const upb_msglayout **submsgs; + upb_msglayout_field *fields; + + for (upb_msg_field_begin(&it, m); + !upb_msg_field_done(&it); + upb_msg_field_next(&it)) { + const upb_fielddef* f = upb_msg_iter_field(&it); + if (upb_fielddef_issubmsg(f)) { + submsg_count++; + } } -#undef TYPE - upb_handlerattr_uninit(&attr); - return ok; -} + memset(l, 0, sizeof(*l)); -bool upb_msg_getscalarhandlerdata(const upb_handlers *h, - upb_selector_t s, - upb_fieldtype_t *type, - size_t *offset, - int32_t *hasbit) { - const upb_msg_handlerdata *d; - upb_func *f = upb_handlers_gethandler(h, s); + fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields)); + submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs)); - if ((upb_int64_handlerfunc*)f == upb_msg_setint64) { - *type = UPB_TYPE_INT64; - } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) { - *type = UPB_TYPE_INT32; - } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) { - *type = UPB_TYPE_UINT64; - } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) { - *type = UPB_TYPE_UINT32; - } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) { - *type = UPB_TYPE_DOUBLE; - } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) { - *type = UPB_TYPE_FLOAT; - } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) { - *type = UPB_TYPE_BOOL; - } else { + if ((!fields && upb_msgdef_numfields(m)) || + (!submsgs && submsg_count)) { + /* OOM. */ + upb_gfree(fields); + upb_gfree(submsgs); return false; } - d = upb_handlers_gethandlerdata(h, s); - *offset = d->offset; - *hasbit = d->hasbit; + l->field_count = upb_msgdef_numfields(m); + l->fields = fields; + l->submsgs = submsgs; + + /* Allocate data offsets in three stages: + * + * 1. hasbits. + * 2. regular fields. + * 3. oneof fields. + * + * OPT: There is a lot of room for optimization here to minimize the size. + */ + + /* Allocate hasbits and set basic field attributes. */ + submsg_count = 0; + for (upb_msg_field_begin(&it, m), hasbit = 0; + !upb_msg_field_done(&it); + upb_msg_field_next(&it)) { + const upb_fielddef* f = upb_msg_iter_field(&it); + upb_msglayout_field *field = &fields[upb_fielddef_index(f)]; + + field->number = upb_fielddef_number(f); + field->descriptortype = upb_fielddef_descriptortype(f); + field->label = upb_fielddef_label(f); + + if (upb_fielddef_issubmsg(f)) { + const upb_msglayout *sub_layout = + upb_msgfactory_getlayout(factory, upb_fielddef_msgsubdef(f)); + field->submsg_index = submsg_count++; + submsgs[field->submsg_index] = sub_layout; + } + + if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) { + field->presence = (hasbit++); + } else { + field->presence = 0; + } + } + + /* Account for space used by hasbits. */ + l->size = div_round_up(hasbit, 8); + + /* Allocate non-oneof fields. */ + for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); + upb_msg_field_next(&it)) { + const upb_fielddef* f = upb_msg_iter_field(&it); + size_t field_size = upb_msg_fielddefsize(f); + size_t index = upb_fielddef_index(f); + + if (upb_fielddef_containingoneof(f)) { + /* Oneofs are handled separately below. */ + continue; + } + + fields[index].offset = upb_msglayout_place(l, field_size); + } + + /* Allocate oneof fields. Each oneof field consists of a uint32 for the case + * and space for the actual data. */ + for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit); + upb_msg_oneof_next(&oit)) { + const upb_oneofdef* o = upb_msg_iter_oneof(&oit); + upb_oneof_iter fit; + + size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ + size_t field_size = 0; + uint32_t case_offset; + uint32_t data_offset; + + /* Calculate field size: the max of all field sizes. */ + for (upb_oneof_begin(&fit, o); + !upb_oneof_done(&fit); + upb_oneof_next(&fit)) { + const upb_fielddef* f = upb_oneof_iter_field(&fit); + field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f)); + } + + /* Align and allocate case offset. */ + case_offset = upb_msglayout_place(l, case_size); + data_offset = upb_msglayout_place(l, field_size); + + for (upb_oneof_begin(&fit, o); + !upb_oneof_done(&fit); + upb_oneof_next(&fit)) { + const upb_fielddef* f = upb_oneof_iter_field(&fit); + fields[upb_fielddef_index(f)].offset = data_offset; + fields[upb_fielddef_index(f)].presence = ~case_offset; + } + } + + /* Size of the entire structure should be a multiple of its greatest + * alignment. TODO: track overall alignment for real? */ + l->size = align_up(l->size, 8); + return true; } + + +/** upb_msgfactory ************************************************************/ + +struct upb_msgfactory { + const upb_symtab *symtab; /* We own a ref. */ + upb_inttable layouts; + upb_inttable mergehandlers; +}; + +upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) { + upb_msgfactory *ret = upb_gmalloc(sizeof(*ret)); + + ret->symtab = symtab; + upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR); + upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR); + + return ret; +} + +void upb_msgfactory_free(upb_msgfactory *f) { + upb_inttable_iter i; + upb_inttable_begin(&i, &f->layouts); + for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { + upb_msglayout *l = upb_value_getptr(upb_inttable_iter_value(&i)); + upb_msglayout_free(l); + } + + upb_inttable_begin(&i, &f->mergehandlers); + for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { + const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i)); + upb_handlers_unref(h, f); + } + + upb_inttable_uninit(&f->layouts); + upb_inttable_uninit(&f->mergehandlers); + upb_gfree(f); +} + +const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) { + return f->symtab; +} + +const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, + const upb_msgdef *m) { + upb_value v; + UPB_ASSERT(upb_symtab_lookupmsg(f->symtab, upb_msgdef_fullname(m)) == m); + UPB_ASSERT(!upb_msgdef_mapentry(m)); + + if (upb_inttable_lookupptr(&f->layouts, m, &v)) { + UPB_ASSERT(upb_value_getptr(v)); + return upb_value_getptr(v); + } else { + /* In case of circular dependency, layout has to be inserted first. */ + upb_msglayout *l = upb_gmalloc(sizeof(*l)); + upb_msgfactory *mutable_f = (void*)f; + upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l)); + UPB_ASSERT(l); + if (!upb_msglayout_init(m, l, f)) { + upb_msglayout_free(l); + } + return l; + } +} /* ** upb::RefCounted Implementation ** @@ -8364,9 +6660,10 @@ static size_t begin(const upb_table *t) { /* A simple "subclass" of upb_table that only adds a hash function for strings. */ static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) { + uint32_t len = (uint32_t) k2.str.len; char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1); if (str == NULL) return 0; - memcpy(str, &k2.str.len, sizeof(uint32_t)); + memcpy(str, &len, sizeof(uint32_t)); memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); return (uintptr_t)str; } @@ -9345,28 +7642,28 @@ static upb_inttable reftables[268]; #endif static const upb_msgdef msgs[22] = { - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, &reftables[0], &reftables[1]), - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, &reftables[2], &reftables[3]), - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, &reftables[4], &reftables[5]), - UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, &reftables[6], &reftables[7]), - UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, &reftables[8], &reftables[9]), - UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, &reftables[10], &reftables[11]), - UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, &reftables[12], &reftables[13]), - UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, &reftables[14], &reftables[15]), - UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, &reftables[16], &reftables[17]), - UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, &reftables[18], &reftables[19]), - UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, &reftables[20], &reftables[21]), - UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]), - UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, &reftables[24], &reftables[25]), - UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, &reftables[26], &reftables[27]), - UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, &reftables[28], &reftables[29]), - UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, &reftables[30], &reftables[31]), - UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, &reftables[32], &reftables[33]), - UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, &reftables[34], &reftables[35]), - UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, &reftables[36], &reftables[37]), - UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, &reftables[38], &reftables[39]), - UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, &reftables[40], &reftables[41]), - UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[42], &reftables[43]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[0], &reftables[1]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[2], &reftables[3]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[4], &reftables[5]), + UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[6], &reftables[7]), + UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[8], &reftables[9]), + UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[10], &reftables[11]), + UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[12], &reftables[13]), + UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[14], &reftables[15]), + UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[16], &reftables[17]), + UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[18], &reftables[19]), + UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[20], &reftables[21]), + UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[22], &reftables[23]), + UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[24], &reftables[25]), + UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[26], &reftables[27]), + UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[28], &reftables[29]), + UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[30], &reftables[31]), + UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[32], &reftables[33]), + UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[34], &reftables[35]), + UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[36], &reftables[37]), + UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[38], &reftables[39]), + UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[40], &reftables[41]), + UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[42], &reftables[43]), }; static const upb_fielddef fields[107] = { @@ -10934,6 +9231,7 @@ static size_t msg_name(void *closure, const void *hd, const char *buf, upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); upb_descreader_setscopename(r, name); /* Passes ownership of name. */ + return n; } @@ -14248,7 +12546,7 @@ done: return r; } -#line 1 "upb/json/parser.rl" +//#line 1 "upb/json/parser.rl" /* ** upb::json::Parser (upb_json_parser) ** @@ -14274,24 +12572,33 @@ done: #include <float.h> #include <math.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> +/* Need to define __USE_XOPEN before including time.h to make strptime work. */ +#ifndef __USE_XOPEN +#define __USE_XOPEN +#endif +#include <time.h> + #define UPB_JSON_MAX_DEPTH 64 -static const char *kDoubleValueFullMessageName = "google.protobuf.DoubleValue"; -static const char *kFloatValueFullMessageName = "google.protobuf.FloatValue"; -static const char *kInt64ValueFullMessageName = "google.protobuf.Int64Value"; -static const char *kUInt64ValueFullMessageName = "google.protobuf.UInt64Value"; -static const char *kInt32ValueFullMessageName = "google.protobuf.Int32Value"; -static const char *kUInt32ValueFullMessageName = "google.protobuf.UInt32Value"; -static const char *kBoolValueFullMessageName = "google.protobuf.BoolValue"; -static const char *kStringValueFullMessageName = "google.protobuf.StringValue"; -static const char *kBytesValueFullMessageName = "google.protobuf.BytesValue"; +/* Type of value message */ +enum { + VALUE_NULLVALUE = 0, + VALUE_NUMBERVALUE = 1, + VALUE_STRINGVALUE = 2, + VALUE_BOOLVALUE = 3, + VALUE_STRUCTVALUE = 4, + VALUE_LISTVALUE = 5 +}; /* Forward declare */ static bool is_top_level(upb_json_parser *p); +static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type); +static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type); static bool is_number_wrapper_object(upb_json_parser *p); static bool does_number_wrapper_start(upb_json_parser *p); @@ -14301,16 +12608,28 @@ static bool is_string_wrapper_object(upb_json_parser *p); static bool does_string_wrapper_start(upb_json_parser *p); static bool does_string_wrapper_end(upb_json_parser *p); -static bool is_boolean_wrapper_object(upb_json_parser *p); -static bool does_boolean_wrapper_start(upb_json_parser *p); -static bool does_boolean_wrapper_end(upb_json_parser *p); - static void start_wrapper_object(upb_json_parser *p); static void end_wrapper_object(upb_json_parser *p); +static void start_value_object(upb_json_parser *p, int value_type); +static void end_value_object(upb_json_parser *p); + +static void start_listvalue_object(upb_json_parser *p); +static void end_listvalue_object(upb_json_parser *p); + +static void start_structvalue_object(upb_json_parser *p); +static void end_structvalue_object(upb_json_parser *p); + +static void start_object(upb_json_parser *p); +static void end_object(upb_json_parser *p); + static bool start_subobject(upb_json_parser *p); static void end_subobject(upb_json_parser *p); +static void start_member(upb_json_parser *p); +static void end_member(upb_json_parser *p); +static bool end_membername(upb_json_parser *p); + static const char eof_ch = 'e'; typedef struct { @@ -14380,6 +12699,10 @@ struct upb_json_parser { /* Whether to proceed if unknown field is met. */ bool ignore_json_unknown; + + /* Cache for parsing timestamp due to base and zone are handled in different + * handlers. */ + struct tm tm; }; struct upb_json_parsermethod { @@ -14890,15 +13213,23 @@ static bool end_text(upb_json_parser *p, const char *ptr) { static bool start_number(upb_json_parser *p, const char *ptr) { if (is_top_level(p)) { - if (!is_number_wrapper_object(p)) { + if (is_number_wrapper_object(p)) { + start_wrapper_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_NUMBERVALUE); + } else { return false; } - start_wrapper_object(p); } else if (does_number_wrapper_start(p)) { if (!start_subobject(p)) { return false; } start_wrapper_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) { + return false; + } + start_value_object(p, VALUE_NUMBERVALUE); } multipart_startaccum(p); @@ -14931,6 +13262,15 @@ static bool end_number(upb_json_parser *p, const char *ptr) { if (!is_top_level(p)) { end_subobject(p); } + return true; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; } return true; @@ -15105,26 +13445,75 @@ static bool parser_putbool(upb_json_parser *p, bool val) { static bool end_bool(upb_json_parser *p, bool val) { if (is_top_level(p)) { - if (!is_boolean_wrapper_object(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) { + start_wrapper_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_BOOLVALUE); + } else { return false; } - start_wrapper_object(p); - } else if (does_boolean_wrapper_start(p)) { + } else if (is_wellknown_field(p, UPB_WELLKNOWN_BOOLVALUE)) { if (!start_subobject(p)) { return false; } start_wrapper_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) { + return false; + } + start_value_object(p, VALUE_BOOLVALUE); } if (!parser_putbool(p, val)) { return false; } - if (does_boolean_wrapper_end(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) { end_wrapper_object(p); if (!is_top_level(p)) { end_subobject(p); } + return true; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + return true; +} + +static bool end_null(upb_json_parser *p) { + const char *zero_ptr = "0"; + + if (is_top_level(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_NULLVALUE); + } else { + return true; + } + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) { + return false; + } + start_value_object(p, VALUE_NULLVALUE); + } else { + return true; + } + + /* Fill null_value field. */ + multipart_startaccum(p); + capture_begin(p, zero_ptr); + capture_end(p, zero_ptr + 1); + parse_number(p, false); + + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); } return true; @@ -15132,15 +13521,32 @@ static bool end_bool(upb_json_parser *p, bool val) { static bool start_stringval(upb_json_parser *p) { if (is_top_level(p)) { - if (!is_string_wrapper_object(p)) { + if (is_string_wrapper_object(p)) { + start_wrapper_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || + is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { + start_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_STRINGVALUE); + } else { return false; } - start_wrapper_object(p); } else if (does_string_wrapper_start(p)) { if (!start_subobject(p)) { return false; } start_wrapper_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_TIMESTAMP) || + is_wellknown_field(p, UPB_WELLKNOWN_DURATION)) { + if (!start_subobject(p)) { + return false; + } + start_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) { + return false; + } + start_value_object(p, VALUE_STRINGVALUE); } if (p->top->f == NULL) { @@ -15197,6 +13603,12 @@ static bool start_stringval(upb_json_parser *p) { static bool end_stringval_nontop(upb_json_parser *p) { bool ok = true; + if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || + is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { + multipart_end(p); + return true; + } + if (p->top->f == NULL) { multipart_end(p); return true; @@ -15271,11 +13683,281 @@ static bool end_stringval(upb_json_parser *p) { if (!is_top_level(p)) { end_subobject(p); } + return true; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) || + is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) { + end_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + return true; } return true; } +static void start_duration_base(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +static bool end_duration_base(upb_json_parser *p, const char *ptr) { + size_t len; + const char *buf; + char seconds_buf[14]; + char nanos_buf[12]; + char *end; + int64_t seconds = 0; + int32_t nanos = 0; + double val = 0.0; + const char *seconds_membername = "seconds"; + const char *nanos_membername = "nanos"; + size_t fraction_start; + + if (!capture_end(p, ptr)) { + return false; + } + + buf = accumulate_getptr(p, &len); + + memset(seconds_buf, 0, 14); + memset(nanos_buf, 0, 12); + + /* Find out base end. The maximus duration is 315576000000, which cannot be + * represented by double without losing precision. Thus, we need to handle + * fraction and base separately. */ + for (fraction_start = 0; fraction_start < len && buf[fraction_start] != '.'; + fraction_start++); + + /* Parse base */ + memcpy(seconds_buf, buf, fraction_start); + seconds = strtol(seconds_buf, &end, 10); + if (errno == ERANGE || end != seconds_buf + fraction_start) { + upb_status_seterrf(&p->status, "error parsing duration: %s", + seconds_buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + if (seconds > 315576000000) { + upb_status_seterrf(&p->status, "error parsing duration: " + "maximum acceptable value is " + "315576000000"); + upb_env_reporterror(p->env, &p->status); + return false; + } + + if (seconds < -315576000000) { + upb_status_seterrf(&p->status, "error parsing duration: " + "minimum acceptable value is " + "-315576000000"); + upb_env_reporterror(p->env, &p->status); + return false; + } + + /* Parse fraction */ + nanos_buf[0] = '0'; + memcpy(nanos_buf + 1, buf + fraction_start, len - fraction_start); + val = strtod(nanos_buf, &end); + if (errno == ERANGE || end != nanos_buf + len - fraction_start + 1) { + upb_status_seterrf(&p->status, "error parsing duration: %s", + nanos_buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + nanos = val * 1000000000; + if (seconds < 0) nanos = -nanos; + + /* Clean up buffer */ + multipart_end(p); + + /* Set seconds */ + start_member(p); + capture_begin(p, seconds_membername); + capture_end(p, seconds_membername + 7); + end_membername(p); + upb_sink_putint64(&p->top->sink, parser_getsel(p), seconds); + end_member(p); + + /* Set nanos */ + start_member(p); + capture_begin(p, nanos_membername); + capture_end(p, nanos_membername + 5); + end_membername(p); + upb_sink_putint32(&p->top->sink, parser_getsel(p), nanos); + end_member(p); + + /* Continue previous environment */ + multipart_startaccum(p); + + return true; +} + +static void start_timestamp_base(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +#define UPB_TIMESTAMP_BASE_SIZE 19 + +static bool end_timestamp_base(upb_json_parser *p, const char *ptr) { + size_t len; + const char *buf; + /* 3 for GMT and 1 for ending 0 */ + char timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 4]; + + if (!capture_end(p, ptr)) { + return false; + } + + buf = accumulate_getptr(p, &len); + UPB_ASSERT(len == UPB_TIMESTAMP_BASE_SIZE); + memcpy(timestamp_buf, buf, UPB_TIMESTAMP_BASE_SIZE); + memcpy(timestamp_buf + UPB_TIMESTAMP_BASE_SIZE, "GMT", 3); + timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 3] = 0; + + /* Parse seconds */ + if (strptime(timestamp_buf, "%FT%H:%M:%S%Z", &p->tm) == NULL) { + upb_status_seterrf(&p->status, "error parsing timestamp: %s", buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + /* Clean up buffer */ + multipart_end(p); + multipart_startaccum(p); + + return true; +} + +static void start_timestamp_fraction(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +static bool end_timestamp_fraction(upb_json_parser *p, const char *ptr) { + size_t len; + const char *buf; + char nanos_buf[12]; + char *end; + double val = 0.0; + int32_t nanos; + const char *nanos_membername = "nanos"; + + memset(nanos_buf, 0, 12); + + if (!capture_end(p, ptr)) { + return false; + } + + buf = accumulate_getptr(p, &len); + + if (len > 10) { + upb_status_seterrf(&p->status, + "error parsing timestamp: at most 9-digit fraction."); + upb_env_reporterror(p->env, &p->status); + return false; + } + + /* Parse nanos */ + nanos_buf[0] = '0'; + memcpy(nanos_buf + 1, buf, len); + val = strtod(nanos_buf, &end); + + if (errno == ERANGE || end != nanos_buf + len + 1) { + upb_status_seterrf(&p->status, "error parsing timestamp nanos: %s", + nanos_buf); + upb_env_reporterror(p->env, &p->status); + return false; + } + + nanos = val * 1000000000; + + /* Clean up previous environment */ + multipart_end(p); + + /* Set nanos */ + start_member(p); + capture_begin(p, nanos_membername); + capture_end(p, nanos_membername + 5); + end_membername(p); + upb_sink_putint32(&p->top->sink, parser_getsel(p), nanos); + end_member(p); + + /* Continue previous environment */ + multipart_startaccum(p); + + return true; +} + +static void start_timestamp_zone(upb_json_parser *p, const char *ptr) { + capture_begin(p, ptr); +} + +static bool end_timestamp_zone(upb_json_parser *p, const char *ptr) { + size_t len; + const char *buf; + int hours; + int64_t seconds; + const char *seconds_membername = "seconds"; + + if (!capture_end(p, ptr)) { + return false; + } + + buf = accumulate_getptr(p, &len); + + if (buf[0] != 'Z') { + if (sscanf(buf + 1, "%2d:00", &hours) != 1) { + upb_status_seterrf(&p->status, "error parsing timestamp offset"); + upb_env_reporterror(p->env, &p->status); + return false; + } + + if (buf[0] == '+') { + hours = -hours; + } + + p->tm.tm_hour += hours; + } + + /* Normalize tm */ + seconds = mktime(&p->tm); + + /* Check timestamp boundary */ + if (seconds < -62135596800) { + upb_status_seterrf(&p->status, "error parsing timestamp: " + "minimum acceptable value is " + "0001-01-01T00:00:00Z"); + upb_env_reporterror(p->env, &p->status); + return false; + } + + /* Clean up previous environment */ + multipart_end(p); + + /* Set seconds */ + start_member(p); + capture_begin(p, seconds_membername); + capture_end(p, seconds_membername + 7); + end_membername(p); + upb_sink_putint64(&p->top->sink, parser_getsel(p), seconds); + end_member(p); + + /* Continue previous environment */ + multipart_startaccum(p); + + return true; +} + static void start_member(upb_json_parser *p) { UPB_ASSERT(!p->top->f); multipart_startaccum(p); @@ -15459,10 +14141,6 @@ static void end_member(upb_json_parser *p) { } static bool start_subobject(upb_json_parser *p) { - if (is_top_level(p)) { - return true; - } - if (p->top->f == NULL) { upb_jsonparser_frame *inner; if (!check_stack(p)) return false; @@ -15525,6 +14203,30 @@ static bool start_subobject(upb_json_parser *p) { } } +static bool start_subobject_full(upb_json_parser *p) { + if (is_top_level(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_STRUCTVALUE); + if (!start_subobject(p)) return false; + start_structvalue_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) { + start_structvalue_object(p); + } else { + return true; + } + } else if (is_wellknown_field(p, UPB_WELLKNOWN_STRUCT)) { + if (!start_subobject(p)) return false; + start_structvalue_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) return false; + start_value_object(p, VALUE_STRUCTVALUE); + if (!start_subobject(p)) return false; + start_structvalue_object(p); + } + + return start_subobject(p); +} + static void end_subobject(upb_json_parser *p) { if (is_top_level(p)) { return; @@ -15546,10 +14248,48 @@ static void end_subobject(upb_json_parser *p) { } } +static void end_subobject_full(upb_json_parser *p) { + end_subobject(p); + + if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) { + end_structvalue_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + } +} + static bool start_array(upb_json_parser *p) { upb_jsonparser_frame *inner; upb_selector_t sel; + if (is_top_level(p)) { + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + start_value_object(p, VALUE_LISTVALUE); + if (!start_subobject(p)) return false; + start_listvalue_object(p); + } else if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) { + start_listvalue_object(p); + } else { + return false; + } + } else if (is_wellknown_field(p, UPB_WELLKNOWN_LISTVALUE)) { + if (!start_subobject(p)) return false; + start_listvalue_object(p); + } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) { + if (!start_subobject(p)) return false; + start_value_object(p, VALUE_LISTVALUE); + if (!start_subobject(p)) return false; + start_listvalue_object(p); + } + UPB_ASSERT(p->top->f); if (!upb_fielddef_isseq(p->top->f)) { @@ -15583,6 +14323,20 @@ static void end_array(upb_json_parser *p) { p->top--; sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); upb_sink_endseq(&p->top->sink, sel); + + if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) { + end_listvalue_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + } + + if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) { + end_value_object(p); + if (!is_top_level(p)) { + end_subobject(p); + } + } } static void start_object(upb_json_parser *p) { @@ -15602,69 +14356,103 @@ static void end_object(upb_json_parser *p) { } } -static bool is_double_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kDoubleValueFullMessageName) == 0; +static bool is_string_wrapper(const upb_msgdef *m) { + upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); + return type == UPB_WELLKNOWN_STRINGVALUE || + type == UPB_WELLKNOWN_BYTESVALUE; } -static bool is_float_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kFloatValueFullMessageName) == 0; -} +static void start_wrapper_object(upb_json_parser *p) { + const char *membername = "value"; -static bool is_int64_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kInt64ValueFullMessageName) == 0; -} + start_object(p); -static bool is_uint64_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kUInt64ValueFullMessageName) == 0; + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + 5); + end_membername(p); } -static bool is_int32_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kInt32ValueFullMessageName) == 0; +static void end_wrapper_object(upb_json_parser *p) { + end_member(p); + end_object(p); } -static bool is_uint32_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kUInt32ValueFullMessageName) == 0; -} +static void start_value_object(upb_json_parser *p, int value_type) { + const char *nullmember = "null_value"; + const char *numbermember = "number_value"; + const char *stringmember = "string_value"; + const char *boolmember = "bool_value"; + const char *structmember = "struct_value"; + const char *listmember = "list_value"; + const char *membername = ""; -static bool is_bool_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kBoolValueFullMessageName) == 0; -} + switch (value_type) { + case VALUE_NULLVALUE: + membername = nullmember; + break; + case VALUE_NUMBERVALUE: + membername = numbermember; + break; + case VALUE_STRINGVALUE: + membername = stringmember; + break; + case VALUE_BOOLVALUE: + membername = boolmember; + break; + case VALUE_STRUCTVALUE: + membername = structmember; + break; + case VALUE_LISTVALUE: + membername = listmember; + break; + } + + start_object(p); -static bool is_string_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kStringValueFullMessageName) == 0; + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + strlen(membername)); + end_membername(p); } -static bool is_bytes_value(const upb_msgdef *m) { - return strcmp(upb_msgdef_fullname(m), kBytesValueFullMessageName) == 0; +static void end_value_object(upb_json_parser *p) { + end_member(p); + end_object(p); } -static bool is_number_wrapper(const upb_msgdef *m) { - return is_double_value(m) || - is_float_value(m) || - is_int64_value(m) || - is_uint64_value(m) || - is_int32_value(m) || - is_uint32_value(m); +static void start_listvalue_object(upb_json_parser *p) { + const char *membername = "values"; + + start_object(p); + + /* Set up context for parsing value */ + start_member(p); + capture_begin(p, membername); + capture_end(p, membername + strlen(membername)); + end_membername(p); } -static bool is_string_wrapper(const upb_msgdef *m) { - return is_string_value(m) || - is_bytes_value(m); +static void end_listvalue_object(upb_json_parser *p) { + end_member(p); + end_object(p); } -static void start_wrapper_object(upb_json_parser *p) { - const char *membername = "value"; +static void start_structvalue_object(upb_json_parser *p) { + const char *membername = "fields"; start_object(p); /* Set up context for parsing value */ start_member(p); capture_begin(p, membername); - capture_end(p, membername + 5); + capture_end(p, membername + strlen(membername)); end_membername(p); } -static void end_wrapper_object(upb_json_parser *p) { +static void end_structvalue_object(upb_json_parser *p) { end_member(p); end_object(p); } @@ -15673,18 +14461,29 @@ static bool is_top_level(upb_json_parser *p) { return p->top == p->stack && p->top->f == NULL; } +static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type) { + return p->top->m != NULL && upb_msgdef_wellknowntype(p->top->m) == type; +} + +static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type) { + return p->top->f != NULL && + upb_fielddef_issubmsg(p->top->f) && + (upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(p->top->f)) + == type); +} + static bool does_number_wrapper_start(upb_json_parser *p) { return p->top->f != NULL && upb_fielddef_issubmsg(p->top->f) && - is_number_wrapper(upb_fielddef_msgsubdef(p->top->f)); + upb_msgdef_isnumberwrapper(upb_fielddef_msgsubdef(p->top->f)); } static bool does_number_wrapper_end(upb_json_parser *p) { - return p->top->m != NULL && is_number_wrapper(p->top->m); + return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m); } static bool is_number_wrapper_object(upb_json_parser *p) { - return p->top->m != NULL && is_number_wrapper(p->top->m); + return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m); } static bool does_string_wrapper_start(upb_json_parser *p) { @@ -15701,20 +14500,6 @@ static bool is_string_wrapper_object(upb_json_parser *p) { return p->top->m != NULL && is_string_wrapper(p->top->m); } -static bool does_boolean_wrapper_start(upb_json_parser *p) { - return p->top->f != NULL && - upb_fielddef_issubmsg(p->top->f) && - is_bool_value(upb_fielddef_msgsubdef(p->top->f)); -} - -static bool does_boolean_wrapper_end(upb_json_parser *p) { - return p->top->m != NULL && is_bool_value(p->top->m); -} - -static bool is_boolean_wrapper_object(upb_json_parser *p) { - return p->top->m != NULL && is_bool_value(p->top->m); -} - #define CHECK_RETURN_TOP(x) if (!(x)) goto error @@ -15736,37 +14521,44 @@ static bool is_boolean_wrapper_object(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -#line 1589 "upb/json/parser.rl" +//#line 2114 "upb/json/parser.rl" -#line 1496 "upb/json/parser.c" +//#line 1983 "upb/json/parser.c" static const char _json_actions[] = { 0, 1, 0, 1, 1, 1, 3, 1, 4, 1, 6, 1, 7, 1, 8, 1, - 9, 1, 11, 1, 13, 1, 14, 1, - 15, 1, 16, 1, 17, 1, 18, 1, - 20, 1, 22, 1, 23, 1, 24, 1, - 25, 1, 26, 1, 27, 1, 28, 2, - 4, 9, 2, 5, 6, 2, 7, 3, - 2, 7, 9, 2, 12, 10, 2, 14, - 16, 2, 15, 16, 2, 19, 2, 2, - 20, 28, 2, 21, 10, 2, 23, 28, - 2, 24, 28, 2, 25, 28, 2, 27, - 28, 3, 15, 12, 10 + 9, 1, 10, 1, 11, 1, 12, 1, + 13, 1, 21, 1, 23, 1, 24, 1, + 25, 1, 27, 1, 28, 1, 30, 1, + 32, 1, 33, 1, 34, 1, 35, 1, + 36, 1, 38, 2, 4, 9, 2, 5, + 6, 2, 7, 3, 2, 7, 9, 2, + 14, 15, 2, 16, 17, 2, 18, 19, + 2, 22, 20, 2, 26, 37, 2, 29, + 2, 2, 30, 38, 2, 31, 20, 2, + 33, 38, 2, 34, 38, 2, 35, 38, + 3, 25, 22, 20, 3, 26, 37, 38, + 4, 14, 15, 16, 17 }; -static const unsigned char _json_key_offsets[] = { +static const short _json_key_offsets[] = { 0, 0, 12, 13, 18, 23, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 43, 48, 49, 53, 58, 63, 68, 72, 76, 79, 82, 84, 88, 92, 94, 96, 101, 103, 105, 114, 120, 126, 132, - 138, 140, 149, 150, 150, 150, 155, 160, - 165, 166, 167, 168, 169, 169, 170, 171, - 172, 172, 173, 174, 175, 175, 180, 185, - 186, 190, 195, 200, 205, 209, 209, 212, - 215, 218, 221, 224, 227, 227, 227 + 138, 140, 144, 147, 149, 151, 154, 155, + 159, 161, 163, 165, 167, 168, 170, 172, + 173, 175, 177, 178, 180, 182, 183, 185, + 187, 188, 190, 192, 196, 198, 200, 201, + 202, 203, 204, 206, 211, 220, 221, 221, + 221, 226, 231, 236, 237, 238, 239, 240, + 240, 241, 242, 243, 243, 244, 245, 246, + 246, 251, 256, 257, 261, 266, 271, 276, + 280, 280, 283, 286, 289, 292, 295, 298, + 298, 298, 298, 298 }; static const char _json_trans_keys[] = { @@ -15787,18 +14579,27 @@ static const char _json_trans_keys[] = { 116, 117, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, - 97, 102, 34, 92, 34, 45, 91, 102, - 110, 116, 123, 48, 57, 34, 32, 93, - 125, 9, 13, 32, 44, 93, 9, 13, - 32, 93, 125, 9, 13, 97, 108, 115, - 101, 117, 108, 108, 114, 117, 101, 32, - 34, 125, 9, 13, 32, 34, 125, 9, - 13, 34, 32, 58, 9, 13, 32, 93, - 125, 9, 13, 32, 44, 125, 9, 13, - 32, 44, 125, 9, 13, 32, 34, 9, + 97, 102, 34, 92, 45, 48, 49, 57, + 48, 49, 57, 46, 115, 48, 57, 115, + 48, 57, 34, 46, 115, 48, 57, 48, + 57, 48, 57, 48, 57, 48, 57, 45, + 48, 57, 48, 57, 45, 48, 57, 48, + 57, 84, 48, 57, 48, 57, 58, 48, + 57, 48, 57, 58, 48, 57, 48, 57, + 43, 45, 46, 90, 48, 57, 48, 57, + 58, 48, 48, 34, 48, 57, 43, 45, + 90, 48, 57, 34, 45, 91, 102, 110, + 116, 123, 48, 57, 34, 32, 93, 125, + 9, 13, 32, 44, 93, 9, 13, 32, + 93, 125, 9, 13, 97, 108, 115, 101, + 117, 108, 108, 114, 117, 101, 32, 34, + 125, 9, 13, 32, 34, 125, 9, 13, + 34, 32, 58, 9, 13, 32, 93, 125, + 9, 13, 32, 44, 125, 9, 13, 32, + 44, 125, 9, 13, 32, 34, 9, 13, + 32, 9, 13, 32, 9, 13, 32, 9, 13, 32, 9, 13, 32, 9, 13, 32, - 9, 13, 32, 9, 13, 32, 9, 13, - 32, 9, 13, 0 + 9, 13, 0 }; static const char _json_single_lengths[] = { @@ -15807,11 +14608,16 @@ static const char _json_single_lengths[] = { 3, 3, 1, 2, 3, 3, 3, 2, 2, 1, 3, 0, 2, 2, 0, 0, 3, 2, 2, 9, 0, 0, 0, 0, - 2, 7, 1, 0, 0, 3, 3, 3, - 1, 1, 1, 1, 0, 1, 1, 1, - 0, 1, 1, 1, 0, 3, 3, 1, - 2, 3, 3, 3, 2, 0, 1, 1, - 1, 1, 1, 1, 0, 0, 0 + 2, 2, 1, 2, 0, 1, 1, 2, + 0, 0, 0, 0, 1, 0, 0, 1, + 0, 0, 1, 0, 0, 1, 0, 0, + 1, 0, 0, 4, 0, 0, 1, 1, + 1, 1, 0, 3, 7, 1, 0, 0, + 3, 3, 3, 1, 1, 1, 1, 0, + 1, 1, 1, 0, 1, 1, 1, 0, + 3, 3, 1, 2, 3, 3, 3, 2, + 0, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0 }; static const char _json_range_lengths[] = { @@ -15820,11 +14626,16 @@ static const char _json_range_lengths[] = { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 3, 3, 3, 3, - 0, 1, 0, 0, 0, 1, 1, 1, + 0, 1, 1, 0, 1, 1, 0, 1, + 1, 1, 1, 1, 0, 1, 1, 0, + 1, 1, 0, 1, 1, 0, 1, 1, + 0, 1, 1, 0, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 0, 0, 0, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 0, - 1, 1, 1, 1, 1, 0, 1, 1, - 1, 1, 1, 1, 0, 0, 0 + 1, 1, 0, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0 }; static const short _json_index_offsets[] = { @@ -15833,14 +14644,19 @@ static const short _json_index_offsets[] = { 48, 53, 58, 60, 64, 69, 74, 79, 83, 87, 90, 94, 96, 100, 104, 106, 108, 113, 116, 119, 129, 133, 137, 141, - 145, 148, 157, 159, 160, 161, 166, 171, - 176, 178, 180, 182, 184, 185, 187, 189, - 191, 192, 194, 196, 198, 199, 204, 209, - 211, 215, 220, 225, 230, 234, 235, 238, - 241, 244, 247, 250, 253, 254, 255 + 145, 148, 152, 155, 158, 160, 163, 165, + 169, 171, 173, 175, 177, 179, 181, 183, + 185, 187, 189, 191, 193, 195, 197, 199, + 201, 203, 205, 207, 212, 214, 216, 218, + 220, 222, 224, 226, 231, 240, 242, 243, + 244, 249, 254, 259, 261, 263, 265, 267, + 268, 270, 272, 274, 275, 277, 279, 281, + 282, 287, 292, 294, 298, 303, 308, 313, + 317, 318, 321, 324, 327, 330, 333, 336, + 337, 338, 339, 340 }; -static const char _json_indicies[] = { +static const unsigned char _json_indicies[] = { 0, 2, 3, 4, 5, 6, 7, 8, 0, 3, 1, 9, 1, 11, 12, 1, 11, 10, 13, 14, 12, 13, 1, 14, @@ -15859,57 +14675,77 @@ static const char _json_indicies[] = { 55, 55, 55, 55, 55, 55, 55, 56, 1, 57, 57, 57, 1, 58, 58, 58, 1, 59, 59, 59, 1, 60, 60, 60, - 1, 62, 63, 61, 64, 65, 66, 67, - 68, 69, 70, 65, 1, 71, 1, 72, - 73, 75, 76, 1, 75, 74, 77, 78, - 76, 77, 1, 78, 1, 1, 78, 74, - 79, 1, 80, 1, 81, 1, 82, 1, - 83, 84, 1, 85, 1, 86, 1, 87, - 88, 1, 89, 1, 90, 1, 91, 92, - 93, 94, 92, 1, 95, 96, 97, 95, - 1, 98, 1, 99, 100, 99, 1, 100, - 1, 1, 100, 101, 102, 103, 104, 102, - 1, 105, 106, 97, 105, 1, 106, 96, - 106, 1, 107, 108, 108, 1, 109, 109, - 1, 110, 110, 1, 111, 111, 1, 112, - 112, 1, 113, 113, 1, 1, 1, 1, - 0 + 1, 62, 63, 61, 64, 65, 66, 1, + 67, 68, 1, 69, 70, 1, 71, 1, + 70, 71, 1, 72, 1, 69, 70, 68, + 1, 73, 1, 74, 1, 75, 1, 76, + 1, 77, 1, 78, 1, 79, 1, 80, + 1, 81, 1, 82, 1, 83, 1, 84, + 1, 85, 1, 86, 1, 87, 1, 88, + 1, 89, 1, 90, 1, 91, 1, 92, + 92, 93, 94, 1, 95, 1, 96, 1, + 97, 1, 98, 1, 99, 1, 100, 1, + 101, 1, 102, 102, 103, 101, 1, 104, + 105, 106, 107, 108, 109, 110, 105, 1, + 111, 1, 112, 113, 115, 116, 1, 115, + 114, 117, 118, 116, 117, 1, 118, 1, + 1, 118, 114, 119, 1, 120, 1, 121, + 1, 122, 1, 123, 124, 1, 125, 1, + 126, 1, 127, 128, 1, 129, 1, 130, + 1, 131, 132, 133, 134, 132, 1, 135, + 136, 137, 135, 1, 138, 1, 139, 140, + 139, 1, 140, 1, 1, 140, 141, 142, + 143, 144, 142, 1, 145, 146, 137, 145, + 1, 146, 136, 146, 1, 147, 148, 148, + 1, 149, 149, 1, 150, 150, 1, 151, + 151, 1, 152, 152, 1, 153, 153, 1, + 1, 1, 1, 1, 1, 0 }; static const char _json_trans_targs[] = { - 1, 0, 2, 71, 3, 6, 10, 13, - 16, 70, 4, 3, 70, 4, 5, 7, - 8, 9, 72, 11, 12, 73, 14, 15, - 74, 17, 18, 75, 17, 18, 75, 19, - 19, 20, 21, 22, 23, 75, 22, 23, - 25, 26, 32, 76, 27, 29, 28, 30, - 31, 34, 77, 35, 34, 77, 35, 33, - 36, 37, 38, 39, 40, 34, 77, 35, - 42, 44, 45, 48, 53, 57, 61, 43, - 78, 78, 46, 45, 43, 46, 47, 49, - 50, 51, 52, 78, 54, 55, 56, 78, - 58, 59, 60, 78, 62, 63, 69, 62, - 63, 69, 64, 64, 65, 66, 67, 68, - 69, 67, 68, 78, 70, 70, 70, 70, - 70, 70 + 1, 0, 2, 106, 3, 6, 10, 13, + 16, 105, 4, 3, 105, 4, 5, 7, + 8, 9, 107, 11, 12, 108, 14, 15, + 109, 17, 18, 110, 17, 18, 110, 19, + 19, 20, 21, 22, 23, 110, 22, 23, + 25, 26, 32, 111, 27, 29, 28, 30, + 31, 34, 112, 35, 34, 112, 35, 33, + 36, 37, 38, 39, 40, 34, 112, 35, + 42, 43, 47, 43, 47, 44, 46, 45, + 113, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 74, 73, 69, + 70, 71, 72, 73, 114, 75, 68, 73, + 77, 79, 80, 83, 88, 92, 96, 78, + 115, 115, 81, 80, 78, 81, 82, 84, + 85, 86, 87, 115, 89, 90, 91, 115, + 93, 94, 95, 115, 97, 98, 104, 97, + 98, 104, 99, 99, 100, 101, 102, 103, + 104, 102, 103, 115, 105, 105, 105, 105, + 105, 105 }; static const char _json_trans_actions[] = { - 0, 0, 74, 68, 27, 0, 0, 0, - 41, 33, 17, 0, 29, 0, 0, 0, + 0, 0, 84, 78, 33, 0, 0, 0, + 47, 39, 25, 0, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 23, 89, 65, 0, 59, 25, 19, - 0, 0, 17, 21, 21, 62, 0, 0, + 0, 31, 96, 31, 0, 72, 0, 27, + 0, 0, 25, 29, 29, 29, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 5, 15, 0, 0, 47, 7, 13, - 0, 50, 9, 9, 9, 53, 56, 11, - 74, 68, 27, 0, 0, 0, 41, 33, - 45, 71, 17, 0, 29, 0, 0, 0, - 0, 0, 0, 80, 0, 0, 0, 83, - 0, 0, 0, 77, 23, 89, 65, 0, - 59, 25, 19, 0, 0, 17, 21, 21, - 62, 0, 0, 86, 0, 31, 37, 39, - 35, 43 + 0, 5, 15, 0, 0, 51, 7, 13, + 0, 54, 9, 9, 9, 57, 60, 11, + 17, 17, 17, 0, 0, 0, 19, 0, + 21, 23, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 104, 63, 104, 0, + 0, 0, 0, 0, 69, 0, 66, 66, + 84, 78, 33, 0, 0, 0, 47, 39, + 49, 81, 25, 0, 35, 0, 0, 0, + 0, 0, 0, 90, 0, 0, 0, 93, + 0, 0, 0, 87, 31, 96, 31, 0, + 72, 0, 27, 0, 0, 25, 29, 29, + 29, 0, 0, 100, 0, 37, 43, 45, + 41, 75 }; static const char _json_eof_actions[] = { @@ -15921,19 +14757,26 @@ static const char _json_eof_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 31, - 37, 39, 35, 43, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 37, 43, 45, 41, 75, 0, + 0, 0, 0, 0 }; static const int json_start = 1; static const int json_en_number_machine = 24; static const int json_en_string_machine = 33; -static const int json_en_value_machine = 41; +static const int json_en_duration_machine = 41; +static const int json_en_timestamp_machine = 48; +static const int json_en_value_machine = 76; static const int json_en_main = 1; -#line 1592 "upb/json/parser.rl" +//#line 2117 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -15956,7 +14799,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -#line 1712 "upb/json/parser.c" +//#line 2257 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -16031,118 +14874,166 @@ _match: switch ( *_acts++ ) { case 1: -#line 1503 "upb/json/parser.rl" +//#line 1988 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 2: -#line 1505 "upb/json/parser.rl" +//#line 1990 "upb/json/parser.rl" { p--; {stack[top++] = cs; cs = 24; goto _again;} } break; case 3: -#line 1509 "upb/json/parser.rl" +//#line 1994 "upb/json/parser.rl" { start_text(parser, p); } break; case 4: -#line 1510 "upb/json/parser.rl" +//#line 1995 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 5: -#line 1516 "upb/json/parser.rl" +//#line 2001 "upb/json/parser.rl" { start_hex(parser); } break; case 6: -#line 1517 "upb/json/parser.rl" +//#line 2002 "upb/json/parser.rl" { hexdigit(parser, p); } break; case 7: -#line 1518 "upb/json/parser.rl" +//#line 2003 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_hex(parser)); } break; case 8: -#line 1524 "upb/json/parser.rl" +//#line 2009 "upb/json/parser.rl" { CHECK_RETURN_TOP(escape(parser, p)); } break; case 9: -#line 1530 "upb/json/parser.rl" +//#line 2015 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 10: -#line 1533 "upb/json/parser.rl" - { {stack[top++] = cs; cs = 33; goto _again;} } +//#line 2027 "upb/json/parser.rl" + { start_duration_base(parser, p); } break; case 11: -#line 1535 "upb/json/parser.rl" - { p--; {stack[top++] = cs; cs = 41; goto _again;} } +//#line 2028 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_duration_base(parser, p)); } break; case 12: -#line 1540 "upb/json/parser.rl" - { start_member(parser); } +//#line 2030 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } break; case 13: -#line 1541 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_membername(parser)); } +//#line 2035 "upb/json/parser.rl" + { start_timestamp_base(parser, p); } break; case 14: -#line 1544 "upb/json/parser.rl" - { end_member(parser); } +//#line 2036 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); } break; case 15: -#line 1550 "upb/json/parser.rl" - { start_object(parser); } +//#line 2038 "upb/json/parser.rl" + { start_timestamp_fraction(parser, p); } break; case 16: -#line 1553 "upb/json/parser.rl" - { end_object(parser); } +//#line 2039 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); } break; case 17: -#line 1559 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_array(parser)); } +//#line 2041 "upb/json/parser.rl" + { start_timestamp_zone(parser, p); } break; case 18: -#line 1563 "upb/json/parser.rl" - { end_array(parser); } +//#line 2042 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); } break; case 19: -#line 1568 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_number(parser, p)); } +//#line 2044 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } break; case 20: -#line 1569 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_number(parser, p)); } +//#line 2049 "upb/json/parser.rl" + { + if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) { + {stack[top++] = cs; cs = 48; goto _again;} + } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) { + {stack[top++] = cs; cs = 41; goto _again;} + } else { + {stack[top++] = cs; cs = 33; goto _again;} + } + } break; case 21: -#line 1571 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_stringval(parser)); } +//#line 2060 "upb/json/parser.rl" + { p--; {stack[top++] = cs; cs = 76; goto _again;} } break; case 22: -#line 1572 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_stringval(parser)); } +//#line 2065 "upb/json/parser.rl" + { start_member(parser); } break; case 23: -#line 1574 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_bool(parser, true)); } +//#line 2066 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_membername(parser)); } break; case 24: -#line 1576 "upb/json/parser.rl" - { CHECK_RETURN_TOP(end_bool(parser, false)); } +//#line 2069 "upb/json/parser.rl" + { end_member(parser); } break; case 25: -#line 1578 "upb/json/parser.rl" - { /* null value */ } +//#line 2075 "upb/json/parser.rl" + { start_object(parser); } break; case 26: -#line 1580 "upb/json/parser.rl" - { CHECK_RETURN_TOP(start_subobject(parser)); } +//#line 2078 "upb/json/parser.rl" + { end_object(parser); } break; case 27: -#line 1581 "upb/json/parser.rl" - { end_subobject(parser); } +//#line 2084 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_array(parser)); } break; case 28: -#line 1586 "upb/json/parser.rl" +//#line 2088 "upb/json/parser.rl" + { end_array(parser); } + break; + case 29: +//#line 2093 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_number(parser, p)); } + break; + case 30: +//#line 2094 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_number(parser, p)); } + break; + case 31: +//#line 2096 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_stringval(parser)); } + break; + case 32: +//#line 2097 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_stringval(parser)); } + break; + case 33: +//#line 2099 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_bool(parser, true)); } + break; + case 34: +//#line 2101 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_bool(parser, false)); } + break; + case 35: +//#line 2103 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_null(parser)); } + break; + case 36: +//#line 2105 "upb/json/parser.rl" + { CHECK_RETURN_TOP(start_subobject_full(parser)); } + break; + case 37: +//#line 2106 "upb/json/parser.rl" + { end_subobject_full(parser); } + break; + case 38: +//#line 2111 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -#line 1898 "upb/json/parser.c" +//#line 2491 "upb/json/parser.c" } } @@ -16159,32 +15050,34 @@ _again: while ( __nacts-- > 0 ) { switch ( *__acts++ ) { case 0: -#line 1499 "upb/json/parser.rl" - { - p--; {cs = stack[--top]; goto _again;} - } +//#line 1986 "upb/json/parser.rl" + { p--; {cs = stack[--top]; goto _again;} } break; - case 20: -#line 1569 "upb/json/parser.rl" + case 26: +//#line 2078 "upb/json/parser.rl" + { end_object(parser); } + break; + case 30: +//#line 2094 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; - case 23: -#line 1574 "upb/json/parser.rl" + case 33: +//#line 2099 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, true)); } break; - case 24: -#line 1576 "upb/json/parser.rl" + case 34: +//#line 2101 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_bool(parser, false)); } break; - case 25: -#line 1578 "upb/json/parser.rl" - { /* null value */ } + case 35: +//#line 2103 "upb/json/parser.rl" + { CHECK_RETURN_TOP(end_null(parser)); } break; - case 27: -#line 1581 "upb/json/parser.rl" - { end_subobject(parser); } + case 37: +//#line 2106 "upb/json/parser.rl" + { end_subobject_full(parser); } break; -#line 1940 "upb/json/parser.c" +//#line 2535 "upb/json/parser.c" } } } @@ -16192,7 +15085,7 @@ _again: _out: {} } -#line 1614 "upb/json/parser.rl" +//#line 2139 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); @@ -16214,17 +15107,19 @@ bool end(void *closure, const void *hd) { /* Prevent compile warning on unused static constants. */ UPB_UNUSED(json_start); + UPB_UNUSED(json_en_duration_machine); UPB_UNUSED(json_en_number_machine); UPB_UNUSED(json_en_string_machine); + UPB_UNUSED(json_en_timestamp_machine); UPB_UNUSED(json_en_value_machine); UPB_UNUSED(json_en_main); parse(parser, hd, &eof_ch, 0, NULL); return parser->current_state >= -#line 1978 "upb/json/parser.c" -70 -#line 1642 "upb/json/parser.rl" +//#line 2575 "upb/json/parser.c" +105 +//#line 2169 "upb/json/parser.rl" ; } @@ -16239,13 +15134,13 @@ static void json_parser_reset(upb_json_parser *p) { /* Emit Ragel initialization of the parser. */ -#line 1995 "upb/json/parser.c" +//#line 2592 "upb/json/parser.c" { cs = json_start; top = 0; } -#line 1656 "upb/json/parser.rl" +//#line 2183 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -16398,6 +15293,7 @@ const upb_byteshandler *upb_json_parsermethod_inputhandler( #include <string.h> #include <stdint.h> +#include <time.h> struct upb_json_printer { upb_sink input_; @@ -16418,6 +15314,12 @@ struct upb_json_printer { * repeated fields and messages (maps), and the worst case is a * message->repeated field->submessage->repeated field->... nesting. */ bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2]; + + /* To print timestamp, printer needs to cache its seconds and nanos values + * and convert them when ending timestamp message. See comments of + * printer_sethandlers_timestamp for more detail. */ + int64_t seconds; + int32_t nanos; }; /* StringPiece; a pointer plus a length. */ @@ -17076,6 +15978,369 @@ void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames, upb_handlerattr_uninit(&empty_attr); } +static bool putseconds(void *closure, const void *handler_data, + int64_t seconds) { + upb_json_printer *p = closure; + p->seconds = seconds; + UPB_UNUSED(handler_data); + return true; +} + +static bool putnanos(void *closure, const void *handler_data, + int32_t nanos) { + upb_json_printer *p = closure; + p->nanos = nanos; + UPB_UNUSED(handler_data); + return true; +} + +static void *scalar_startstr_nokey(void *closure, const void *handler_data, + size_t size_hint) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(size_hint); + print_data(p, "\"", 1); + return p; +} + +static size_t putstr_nokey(void *closure, const void *handler_data, + const char *str, size_t len, + const upb_bufhandle *handle) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(handle); + print_data(p, "\"", 1); + putstring(p, str, len); + print_data(p, "\"", 1); + return len + 2; +} + +static void *startseq_nokey(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + p->depth_++; + p->first_elem_[p->depth_] = true; + print_data(p, "[", 1); + return closure; +} + +static void *startmap_nokey(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + p->depth_++; + p->first_elem_[p->depth_] = true; + print_data(p, "{", 1); + return closure; +} + +static bool putnull(void *closure, const void *handler_data, + int32_t null) { + upb_json_printer *p = closure; + print_data(p, "null", 4); + UPB_UNUSED(handler_data); + UPB_UNUSED(null); + return true; +} + +static bool printer_startdurationmsg(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + if (p->depth_ == 0) { + upb_bytessink_start(p->output_, 0, &p->subc_); + } + return true; +} + +#define UPB_DURATION_MAX_JSON_LEN 23 +#define UPB_DURATION_MAX_NANO_LEN 9 + +static bool printer_enddurationmsg(void *closure, const void *handler_data, + upb_status *s) { + upb_json_printer *p = closure; + char buffer[UPB_DURATION_MAX_JSON_LEN]; + size_t base_len; + size_t curr; + size_t i; + + memset(buffer, 0, UPB_DURATION_MAX_JSON_LEN); + + if (p->seconds < -315576000000) { + upb_status_seterrf(s, "error parsing duration: " + "minimum acceptable value is " + "-315576000000"); + return false; + } + + if (p->seconds > 315576000000) { + upb_status_seterrf(s, "error serializing duration: " + "maximum acceptable value is " + "315576000000"); + return false; + } + + _upb_snprintf(buffer, sizeof(buffer), "%ld", (long)p->seconds); + base_len = strlen(buffer); + + if (p->nanos != 0) { + char nanos_buffer[UPB_DURATION_MAX_NANO_LEN + 3]; + _upb_snprintf(nanos_buffer, sizeof(nanos_buffer), "%.9f", + p->nanos / 1000000000.0); + /* Remove trailing 0. */ + for (i = UPB_DURATION_MAX_NANO_LEN + 2; + nanos_buffer[i] == '0'; i--) { + nanos_buffer[i] = 0; + } + strcpy(buffer + base_len, nanos_buffer + 1); + } + + curr = strlen(buffer); + strcpy(buffer + curr, "s"); + + p->seconds = 0; + p->nanos = 0; + + print_data(p, "\"", 1); + print_data(p, buffer, strlen(buffer)); + print_data(p, "\"", 1); + + if (p->depth_ == 0) { + upb_bytessink_end(p->output_); + } + + UPB_UNUSED(handler_data); + return true; +} + +static bool printer_starttimestampmsg(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + if (p->depth_ == 0) { + upb_bytessink_start(p->output_, 0, &p->subc_); + } + return true; +} + +#define UPB_TIMESTAMP_MAX_JSON_LEN 31 +#define UPB_TIMESTAMP_BEFORE_NANO_LEN 19 +#define UPB_TIMESTAMP_MAX_NANO_LEN 9 + +static bool printer_endtimestampmsg(void *closure, const void *handler_data, + upb_status *s) { + upb_json_printer *p = closure; + char buffer[UPB_TIMESTAMP_MAX_JSON_LEN]; + time_t time = p->seconds; + size_t curr; + size_t i; + size_t year_length = + strftime(buffer, UPB_TIMESTAMP_MAX_JSON_LEN, "%Y", gmtime(&time)); + + if (p->seconds < -62135596800) { + upb_status_seterrf(s, "error parsing timestamp: " + "minimum acceptable value is " + "0001-01-01T00:00:00Z"); + return false; + } + + if (p->seconds > 253402300799) { + upb_status_seterrf(s, "error parsing timestamp: " + "maximum acceptable value is " + "9999-12-31T23:59:59Z"); + return false; + } + + /* strftime doesn't guarantee 4 digits for year. Prepend 0 by ourselves. */ + for (i = 0; i < 4 - year_length; i++) { + buffer[i] = '0'; + } + + strftime(buffer + (4 - year_length), UPB_TIMESTAMP_MAX_JSON_LEN, + "%Y-%m-%dT%H:%M:%S", gmtime(&time)); + if (p->nanos != 0) { + char nanos_buffer[UPB_TIMESTAMP_MAX_NANO_LEN + 3]; + _upb_snprintf(nanos_buffer, sizeof(nanos_buffer), "%.9f", + p->nanos / 1000000000.0); + /* Remove trailing 0. */ + for (i = UPB_TIMESTAMP_MAX_NANO_LEN + 2; + nanos_buffer[i] == '0'; i--) { + nanos_buffer[i] = 0; + } + strcpy(buffer + UPB_TIMESTAMP_BEFORE_NANO_LEN, nanos_buffer + 1); + } + + curr = strlen(buffer); + strcpy(buffer + curr, "Z"); + + p->seconds = 0; + p->nanos = 0; + + print_data(p, "\"", 1); + print_data(p, buffer, strlen(buffer)); + print_data(p, "\"", 1); + + if (p->depth_ == 0) { + upb_bytessink_end(p->output_); + } + + UPB_UNUSED(handler_data); + UPB_UNUSED(s); + return true; +} + +static bool printer_startmsg_noframe(void *closure, const void *handler_data) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + if (p->depth_ == 0) { + upb_bytessink_start(p->output_, 0, &p->subc_); + } + return true; +} + +static bool printer_endmsg_noframe( + void *closure, const void *handler_data, upb_status *s) { + upb_json_printer *p = closure; + UPB_UNUSED(handler_data); + UPB_UNUSED(s); + if (p->depth_ == 0) { + upb_bytessink_end(p->output_); + } + return true; +} + +/* Set up handlers for a duration submessage. */ +void printer_sethandlers_duration(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + + const upb_fielddef* seconds_field = + upb_msgdef_itof(md, UPB_DURATION_SECONDS); + const upb_fielddef* nanos_field = + upb_msgdef_itof(md, UPB_DURATION_NANOS); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartmsg(h, printer_startdurationmsg, &empty_attr); + upb_handlers_setint64(h, seconds_field, putseconds, &empty_attr); + upb_handlers_setint32(h, nanos_field, putnanos, &empty_attr); + upb_handlers_setendmsg(h, printer_enddurationmsg, &empty_attr); + + UPB_UNUSED(closure); +} + +/* Set up handlers for a timestamp submessage. Instead of printing fields + * separately, the json representation of timestamp follows RFC 3339 */ +void printer_sethandlers_timestamp(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + + const upb_fielddef* seconds_field = + upb_msgdef_itof(md, UPB_TIMESTAMP_SECONDS); + const upb_fielddef* nanos_field = + upb_msgdef_itof(md, UPB_TIMESTAMP_NANOS); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartmsg(h, printer_starttimestampmsg, &empty_attr); + upb_handlers_setint64(h, seconds_field, putseconds, &empty_attr); + upb_handlers_setint32(h, nanos_field, putnanos, &empty_attr); + upb_handlers_setendmsg(h, printer_endtimestampmsg, &empty_attr); + + UPB_UNUSED(closure); +} + +void printer_sethandlers_value(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + upb_msg_field_iter i; + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + + upb_msg_field_begin(&i, md); + for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) { + const upb_fielddef *f = upb_msg_iter_field(&i); + + switch (upb_fielddef_type(f)) { + case UPB_TYPE_ENUM: + upb_handlers_setint32(h, f, putnull, &empty_attr); + break; + case UPB_TYPE_DOUBLE: + upb_handlers_setdouble(h, f, putdouble, &empty_attr); + break; + case UPB_TYPE_STRING: + upb_handlers_setstartstr(h, f, scalar_startstr_nokey, &empty_attr); + upb_handlers_setstring(h, f, scalar_str, &empty_attr); + upb_handlers_setendstr(h, f, scalar_endstr, &empty_attr); + break; + case UPB_TYPE_BOOL: + upb_handlers_setbool(h, f, putbool, &empty_attr); + break; + case UPB_TYPE_MESSAGE: + break; + default: + UPB_ASSERT(false); + break; + } + } + + UPB_UNUSED(closure); +} + +#define WRAPPER_SETHANDLERS(wrapper, type, putmethod) \ +void printer_sethandlers_##wrapper(const void *closure, upb_handlers *h) { \ + const upb_msgdef *md = upb_handlers_msgdef(h); \ + const upb_fielddef* f = upb_msgdef_itof(md, 1); \ + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; \ + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); \ + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); \ + upb_handlers_set##type(h, f, putmethod, &empty_attr); \ + UPB_UNUSED(closure); \ +} + +WRAPPER_SETHANDLERS(doublevalue, double, putdouble) +WRAPPER_SETHANDLERS(floatvalue, float, putfloat) +WRAPPER_SETHANDLERS(int64value, int64, putint64_t) +WRAPPER_SETHANDLERS(uint64value, uint64, putuint64_t) +WRAPPER_SETHANDLERS(int32value, int32, putint32_t) +WRAPPER_SETHANDLERS(uint32value, uint32, putuint32_t) +WRAPPER_SETHANDLERS(boolvalue, bool, putbool) +WRAPPER_SETHANDLERS(stringvalue, string, putstr_nokey) +WRAPPER_SETHANDLERS(bytesvalue, string, putbytes) + +#undef WRAPPER_SETHANDLERS + +void printer_sethandlers_listvalue(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + const upb_fielddef* f = upb_msgdef_itof(md, 1); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartseq(h, f, startseq_nokey, &empty_attr); + upb_handlers_setendseq(h, f, endseq, &empty_attr); + + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + + upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr); + + UPB_UNUSED(closure); +} + +void printer_sethandlers_structvalue(const void *closure, upb_handlers *h) { + const upb_msgdef *md = upb_handlers_msgdef(h); + const upb_fielddef* f = upb_msgdef_itof(md, 1); + + upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; + + upb_handlers_setstartseq(h, f, startmap_nokey, &empty_attr); + upb_handlers_setendseq(h, f, endmap, &empty_attr); + + upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); + upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); + + upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr); + + UPB_UNUSED(closure); +} + void printer_sethandlers(const void *closure, upb_handlers *h) { const upb_msgdef *md = upb_handlers_msgdef(h); bool is_mapentry = upb_msgdef_mapentry(md); @@ -17091,6 +16356,42 @@ void printer_sethandlers(const void *closure, upb_handlers *h) { return; } + switch (upb_msgdef_wellknowntype(md)) { + case UPB_WELLKNOWN_UNSPECIFIED: + break; + case UPB_WELLKNOWN_DURATION: + printer_sethandlers_duration(closure, h); + return; + case UPB_WELLKNOWN_TIMESTAMP: + printer_sethandlers_timestamp(closure, h); + return; + case UPB_WELLKNOWN_VALUE: + printer_sethandlers_value(closure, h); + return; + case UPB_WELLKNOWN_LISTVALUE: + printer_sethandlers_listvalue(closure, h); + return; + case UPB_WELLKNOWN_STRUCT: + printer_sethandlers_structvalue(closure, h); + return; +#define WRAPPER(wellknowntype, name) \ + case wellknowntype: \ + printer_sethandlers_##name(closure, h); \ + return; \ + + WRAPPER(UPB_WELLKNOWN_DOUBLEVALUE, doublevalue); + WRAPPER(UPB_WELLKNOWN_FLOATVALUE, floatvalue); + WRAPPER(UPB_WELLKNOWN_INT64VALUE, int64value); + WRAPPER(UPB_WELLKNOWN_UINT64VALUE, uint64value); + WRAPPER(UPB_WELLKNOWN_INT32VALUE, int32value); + WRAPPER(UPB_WELLKNOWN_UINT32VALUE, uint32value); + WRAPPER(UPB_WELLKNOWN_BOOLVALUE, boolvalue); + WRAPPER(UPB_WELLKNOWN_STRINGVALUE, stringvalue); + WRAPPER(UPB_WELLKNOWN_BYTESVALUE, bytesvalue); + +#undef WRAPPER + } + upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); @@ -17198,6 +16499,8 @@ upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h, p->output_ = output; json_printer_reset(p); upb_sink_reset(&p->input_, h, p); + p->seconds = 0; + p->nanos = 0; /* If this fails, increase the value in printer.h. */ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <= @@ -17215,3 +16518,8 @@ const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, return upb_handlers_newfrozen( md, owner, printer_sethandlers, &preserve_fieldnames); } + +#undef UPB_SIZE +#undef UPB_FIELD_AT +#undef UPB_READ_ONEOF +#undef UPB_WRITE_ONEOF diff --git a/php/ext/google/protobuf/upb.h b/php/ext/google/protobuf/upb.h index 180f4715..0670a812 100644 --- a/php/ext/google/protobuf/upb.h +++ b/php/ext/google/protobuf/upb.h @@ -6,35 +6,40 @@ #define NDEBUG #endif -/* -** upb_decode: parsing into a upb_msg using a upb_msglayout. -*/ +#if UINTPTR_MAX == 0xffffffff +#define UPB_SIZE(size32, size64) size32 +#else +#define UPB_SIZE(size32, size64) size64 +#endif -#ifndef UPB_DECODE_H_ -#define UPB_DECODE_H_ +#define UPB_FIELD_AT(msg, fieldtype, offset) \ + *(fieldtype*)((const char*)(msg) + offset) + +#define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \ + UPB_FIELD_AT(msg, int, case_offset) == case_val \ + ? UPB_FIELD_AT(msg, fieldtype, offset) \ + : default +#define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \ + UPB_FIELD_AT(msg, int, case_offset) = case_val; \ + UPB_FIELD_AT(msg, fieldtype, offset) = value; /* ** upb::Message is a representation for protobuf messages. ** ** However it differs from other common representations like ** google::protobuf::Message in one key way: it does not prescribe any ** ownership between messages and submessages, and it relies on the -** client to delete each message/submessage/array/map at the appropriate -** time. +** client to ensure that each submessage/array/map outlives its parent. +** +** All messages, arrays, and maps live in an Arena. If the entire message +** tree is in the same arena, ensuring proper lifetimes is simple. However +** the client can mix arenas as long as they ensure that there are no +** dangling pointers. ** ** A client can access a upb::Message without knowing anything about ** ownership semantics, but to create or mutate a message a user needs ** to implement the memory management themselves. ** -** Currently all messages, arrays, and maps store a upb_alloc* internally. -** Mutating operations use this when they require dynamically-allocated -** memory. We could potentially eliminate this size overhead later by -** letting the user flip a bit on the factory that prevents this from -** being stored. The user would then need to use separate functions where -** the upb_alloc* is passed explicitly. However for handlers to populate -** such structures, they would need a place to store this upb_alloc* during -** parsing; upb_handlers don't currently have a good way to accommodate this. -** ** TODO: UTF-8 checking? **/ @@ -2002,6 +2007,31 @@ typedef enum { UPB_SYNTAX_PROTO3 = 3 } upb_syntax_t; +/* All the different kind of well known type messages. For simplicity of check, + * number wrappers and string wrappers are grouped together. Make sure the + * order and merber of these groups are not changed. + */ +typedef enum { + UPB_WELLKNOWN_UNSPECIFIED, + UPB_WELLKNOWN_DURATION, + UPB_WELLKNOWN_TIMESTAMP, + /* number wrappers */ + UPB_WELLKNOWN_DOUBLEVALUE, + UPB_WELLKNOWN_FLOATVALUE, + UPB_WELLKNOWN_INT64VALUE, + UPB_WELLKNOWN_UINT64VALUE, + UPB_WELLKNOWN_INT32VALUE, + UPB_WELLKNOWN_UINT32VALUE, + /* string wrappers */ + UPB_WELLKNOWN_STRINGVALUE, + UPB_WELLKNOWN_BYTESVALUE, + UPB_WELLKNOWN_BOOLVALUE, + UPB_WELLKNOWN_VALUE, + UPB_WELLKNOWN_LISTVALUE, + UPB_WELLKNOWN_STRUCT +} upb_wellknowntype_t; + + /* Maps descriptor type -> upb field type. */ extern const uint8_t upb_desctype_to_fieldtype[]; @@ -2386,6 +2416,14 @@ typedef upb_strtable_iter upb_msg_oneof_iter; #define UPB_MAPENTRY_KEY 1 #define UPB_MAPENTRY_VALUE 2 +/* Well-known field tag numbers for timestamp messages. */ +#define UPB_DURATION_SECONDS 1 +#define UPB_DURATION_NANOS 2 + +/* Well-known field tag numbers for duration messages. */ +#define UPB_TIMESTAMP_SECONDS 1 +#define UPB_TIMESTAMP_NANOS 2 + #ifdef __cplusplus /* Structure that describes a single .proto message type. @@ -2500,6 +2538,13 @@ class upb::MessageDef { void setmapentry(bool map_entry); bool mapentry() const; + /* Return the type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for + * non-well-known message. */ + upb_wellknowntype_t wellknowntype() const; + + /* Whether is a number wrapper. */ + bool isnumberwrapper() const; + /* Iteration over fields. The order is undefined. */ class field_iterator : public std::iterator<std::forward_iterator_tag, FieldDef*> { @@ -2641,6 +2686,8 @@ bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s); void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry); bool upb_msgdef_mapentry(const upb_msgdef *m); +upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m); +bool upb_msgdef_isnumberwrapper(const upb_msgdef *m); bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax); /* Field lookup in a couple of different variations: @@ -3580,6 +3627,12 @@ inline void MessageDef::setmapentry(bool map_entry) { inline bool MessageDef::mapentry() const { return upb_msgdef_mapentry(this); } +inline upb_wellknowntype_t MessageDef::wellknowntype() const { + return upb_msgdef_wellknowntype(this); +} +inline bool MessageDef::isnumberwrapper() const { + return upb_msgdef_isnumberwrapper(this); +} inline MessageDef::field_iterator MessageDef::field_begin() { return field_iterator(this); } @@ -4707,6 +4760,34 @@ UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) { uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f); uint32_t upb_handlers_selectorcount(const upb_fielddef *f); + +/** Message handlers ******************************************************************/ + +/* These are the handlers used internally by upb_msgfactory_getmergehandlers(). + * They write scalar data to a known offset from the message pointer. + * + * These would be trivial for anyone to implement themselves, but it's better + * to use these because some JITs will recognize and specialize these instead + * of actually calling the function. */ + +/* Sets a handler for the given primitive field that will write the data at the + * given offset. If hasbit > 0, also sets a hasbit at the given bit offset + * (addressing each byte low to high). */ +bool upb_msg_setscalarhandler(upb_handlers *h, + const upb_fielddef *f, + size_t offset, + int32_t hasbit); + +/* If the given handler is a msghandlers_primitive field, returns true and sets + * *type, *offset and *hasbit. Otherwise returns false. */ +bool upb_msg_getscalarhandlerdata(const upb_handlers *h, + upb_selector_t s, + upb_fieldtype_t *type, + size_t *offset, + int32_t *hasbit); + + + UPB_END_EXTERN_C /* @@ -6391,21 +6472,14 @@ namespace upb { class Array; class Map; class MapIterator; -class MessageFactory; class MessageLayout; -class Visitor; -class VisitorPlan; } #endif -UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory) -UPB_DECLARE_TYPE(upb::MessageLayout, upb_msglayout) UPB_DECLARE_TYPE(upb::Array, upb_array) UPB_DECLARE_TYPE(upb::Map, upb_map) UPB_DECLARE_TYPE(upb::MapIterator, upb_mapiter) -UPB_DECLARE_TYPE(upb::Visitor, upb_visitor) -UPB_DECLARE_TYPE(upb::VisitorPlan, upb_visitorplan) /* TODO(haberman): C++ accessors */ @@ -6416,53 +6490,28 @@ typedef void upb_msg; /** upb_msglayout *************************************************************/ -/* upb_msglayout represents the memory layout of a given upb_msgdef. You get - * instances of this from a upb_msgfactory, and the factory always owns the - * msglayout. */ - - -/** upb_visitor ***************************************************************/ - -/* upb_visitor will visit all the fields of a message and its submessages. It - * uses a upb_visitorplan which you can obtain from a upb_msgfactory. */ - -upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp, - upb_sink *output); -bool upb_visitor_visitmsg(upb_visitor *v, const upb_msg *msg); +/* upb_msglayout represents the memory layout of a given upb_msgdef. The + * members are public so generated code can initialize them, but users MUST NOT + * read or write any of its members. */ +typedef struct { + uint32_t number; + uint16_t offset; + int16_t presence; /* If >0, hasbit_index+1. If <0, oneof_index+1. */ + uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */ + uint8_t descriptortype; + uint8_t label; +} upb_msglayout_field; -/** upb_msgfactory ************************************************************/ - -/* A upb_msgfactory contains a cache of upb_msglayout, upb_handlers, and - * upb_visitorplan objects. These are the objects necessary to represent, - * populate, and and visit upb_msg objects. - * - * These caches are all populated by upb_msgdef, and lazily created on demand. - */ - -/* Creates and destroys a msgfactory, respectively. The messages for this - * msgfactory must come from |symtab| (which should outlive the msgfactory). */ -upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab); -void upb_msgfactory_free(upb_msgfactory *f); - -const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f); - -/* The functions to get cached objects, lazily creating them on demand. These - * all require: - * - * - m is in upb_msgfactory_symtab(f) - * - upb_msgdef_mapentry(m) == false (since map messages can't have layouts). - * - * The returned objects will live for as long as the msgfactory does. - * - * TODO(haberman): consider making this thread-safe and take a const - * upb_msgfactory. */ -const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, - const upb_msgdef *m); -const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f, - const upb_msgdef *m); -const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f, - const upb_handlers *h); +typedef struct upb_msglayout { + const struct upb_msglayout *const* submsgs; + const upb_msglayout_field *fields; + /* Must be aligned to sizeof(void*). Doesn't include internal members like + * unknown fields, extension dict, pointer to msglayout, etc. */ + uint16_t size; + uint16_t field_count; + bool extendable; +} upb_msglayout; /** upb_stringview ************************************************************/ @@ -6538,52 +6587,16 @@ UPB_INLINE upb_msgval upb_msgval_makestr(const char *data, size_t size) { /** upb_msg *******************************************************************/ /* A upb_msg represents a protobuf message. It always corresponds to a specific - * upb_msglayout, which describes how it is laid out in memory. - * - * The message will have a fixed size, as returned by upb_msg_sizeof(), which - * will be used to store fixed-length fields. The upb_msg may also allocate - * dynamic memory internally to store data such as: - * - * - extensions - * - unknown fields - */ + * upb_msglayout, which describes how it is laid out in memory. */ -/* Returns the size of a message given this layout. */ -size_t upb_msg_sizeof(const upb_msglayout *l); +/* Creates a new message of the given type/layout in this arena. */ +upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a); -/* upb_msg_init() / upb_msg_uninit() allow the user to use a pre-allocated - * block of memory as a message. The block's size should be upb_msg_sizeof(). - * upb_msg_uninit() must be called to release internally-allocated memory - * unless the allocator is an arena that does not require freeing. - * - * Please note that upb_msg_init() may return a value that is different than - * |msg|, so you must assign the return value and not cast your memory block - * to upb_msg* directly! - * - * Please note that upb_msg_uninit() does *not* free any submessages, maps, - * or arrays referred to by this message's fields. You must free them manually - * yourself. - * - * upb_msg_uninit returns the original memory block, which may be useful if - * you dynamically allocated it (though upb_msg_new() would normally be more - * appropriate in this case). */ -upb_msg *upb_msg_init(void *msg, const upb_msglayout *l, upb_alloc *a); -void *upb_msg_uninit(upb_msg *msg, const upb_msglayout *l); - -/* Like upb_msg_init() / upb_msg_uninit(), except the message's memory is - * allocated / freed from the given upb_alloc. */ -upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a); -void upb_msg_free(upb_msg *msg, const upb_msglayout *l); - -/* Returns the upb_alloc for the given message. - * TODO(haberman): get rid of this? Not sure we want to be storing this - * for every message. */ -upb_alloc *upb_msg_alloc(const upb_msg *msg); - -/* Packs the tree of messages rooted at "msg" into a single hunk of memory, - * allocated from the given allocator. */ -void *upb_msg_pack(const upb_msg *msg, const upb_msglayout *l, - void *p, size_t *ofs, size_t size); +/* Returns the arena for the given message. */ +upb_arena *upb_msg_arena(const upb_msg *msg); + +void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len); +const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); /* Read-only message API. Can be safely called by anyone. */ @@ -6637,16 +6650,12 @@ bool upb_msg_clearfield(upb_msg *msg, * semantics are the same as upb_msg. A upb_array allocates dynamic * memory internally for the array elements. */ -size_t upb_array_sizeof(upb_fieldtype_t type); -void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *a); -void upb_array_uninit(upb_array *arr); -upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a); -void upb_array_free(upb_array *arr); +upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a); +upb_fieldtype_t upb_array_type(const upb_array *arr); /* Read-only interface. Safe for anyone to call. */ size_t upb_array_size(const upb_array *arr); -upb_fieldtype_t upb_array_type(const upb_array *arr); upb_msgval upb_array_get(const upb_array *arr, size_t i); /* Write interface. May only be called by the message's owner who can enforce @@ -6663,12 +6672,8 @@ bool upb_array_set(upb_array *arr, size_t i, upb_msgval val); * So you must ensure that any string or message values outlive the map, and you * must delete them manually when they are no longer required. */ -size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype); -bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype, - upb_alloc *a); -void upb_map_uninit(upb_map *map); -upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, upb_alloc *a); -void upb_map_free(upb_map *map); +upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, + upb_arena *a); /* Read-only interface. Safe for anyone to call. */ @@ -6712,86 +6717,32 @@ upb_msgval upb_mapiter_value(const upb_mapiter *i); void upb_mapiter_setdone(upb_mapiter *i); bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2); +UPB_END_EXTERN_C -/** Handlers ******************************************************************/ - -/* These are the handlers used internally by upb_msgfactory_getmergehandlers(). - * They write scalar data to a known offset from the message pointer. +#endif /* UPB_MSG_H_ */ +/* This file was generated by upbc (the upb compiler) from the input + * file: * - * These would be trivial for anyone to implement themselves, but it's better - * to use these because some JITs will recognize and specialize these instead - * of actually calling the function. */ - -/* Sets a handler for the given primitive field that will write the data at the - * given offset. If hasbit > 0, also sets a hasbit at the given bit offset - * (addressing each byte low to high). */ -bool upb_msg_setscalarhandler(upb_handlers *h, - const upb_fielddef *f, - size_t offset, - int32_t hasbit); - -/* If the given handler is a msghandlers_primitive field, returns true and sets - * *type, *offset and *hasbit. Otherwise returns false. */ -bool upb_msg_getscalarhandlerdata(const upb_handlers *h, - upb_selector_t s, - upb_fieldtype_t *type, - size_t *offset, - int32_t *hasbit); - - -/** Interfaces for generated code *********************************************/ - -#define UPB_NOT_IN_ONEOF UINT16_MAX -#define UPB_NO_HASBIT UINT16_MAX -#define UPB_NO_SUBMSG UINT16_MAX - -typedef struct { - uint32_t number; - uint32_t offset; /* If in a oneof, offset of default in default_msg below. */ - uint16_t hasbit; /* UPB_NO_HASBIT if no hasbit. */ - uint16_t oneof_index; /* UPB_NOT_IN_ONEOF if not in a oneof. */ - uint16_t submsg_index; /* UPB_NO_SUBMSG if no submsg. */ - uint8_t descriptortype; - uint8_t label; -} upb_msglayout_fieldinit_v1; + * google/protobuf/descriptor.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ -typedef struct { - uint32_t data_offset; - uint32_t case_offset; -} upb_msglayout_oneofinit_v1; - -typedef struct upb_msglayout_msginit_v1 { - const struct upb_msglayout_msginit_v1 *const* submsgs; - const upb_msglayout_fieldinit_v1 *fields; - const upb_msglayout_oneofinit_v1 *oneofs; - void *default_msg; - /* Must be aligned to sizeof(void*). Doesn't include internal members like - * unknown fields, extension dict, pointer to msglayout, etc. */ - uint32_t size; - uint16_t field_count; - uint16_t oneof_count; - bool extendable; - bool is_proto2; -} upb_msglayout_msginit_v1; +#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ +#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -#define UPB_ALIGN_UP_TO(val, align) ((val + (align - 1)) & -align) -#define UPB_ALIGNED_SIZEOF(type) UPB_ALIGN_UP_TO(sizeof(type), sizeof(void*)) -/* Initialize/uninitialize a msglayout from a msginit. If upb uses v1 - * internally, this will not allocate any memory. Should only be used by - * generated code. */ -upb_msglayout *upb_msglayout_frominit_v1( - const upb_msglayout_msginit_v1 *init, upb_alloc *a); -void upb_msglayout_uninit_v1(upb_msglayout *layout, upb_alloc *a); +/* +** upb_decode: parsing into a upb_msg using a upb_msglayout. +*/ -UPB_END_EXTERN_C +#ifndef UPB_DECODE_H_ +#define UPB_DECODE_H_ -#endif /* UPB_MSG_H_ */ UPB_BEGIN_EXTERN_C -bool upb_decode(upb_stringview buf, void *msg, - const upb_msglayout_msginit_v1 *l, upb_env *env); +bool upb_decode(upb_stringview buf, upb_msg *msg, const upb_msglayout *l); UPB_END_EXTERN_C @@ -6806,80 +6757,69 @@ UPB_END_EXTERN_C UPB_BEGIN_EXTERN_C -char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *l, - upb_env *env, size_t *size); +char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena, + size_t *size); UPB_END_EXTERN_C #endif /* UPB_ENCODE_H_ */ -/* This file was generated by upbc (the upb compiler) from the input - * file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. */ - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ - - UPB_BEGIN_EXTERN_C struct google_protobuf_FileDescriptorSet; -typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; struct google_protobuf_FileDescriptorProto; -typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; struct google_protobuf_DescriptorProto; -typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; struct google_protobuf_DescriptorProto_ExtensionRange; -typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; struct google_protobuf_DescriptorProto_ReservedRange; -typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; struct google_protobuf_ExtensionRangeOptions; -typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; struct google_protobuf_FieldDescriptorProto; -typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; struct google_protobuf_OneofDescriptorProto; -typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; struct google_protobuf_EnumDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; struct google_protobuf_EnumDescriptorProto_EnumReservedRange; -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; struct google_protobuf_EnumValueDescriptorProto; -typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; struct google_protobuf_ServiceDescriptorProto; -typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; struct google_protobuf_MethodDescriptorProto; -typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; struct google_protobuf_FileOptions; -typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; struct google_protobuf_MessageOptions; -typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; struct google_protobuf_FieldOptions; -typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; struct google_protobuf_OneofOptions; -typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; struct google_protobuf_EnumOptions; -typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; struct google_protobuf_EnumValueOptions; -typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; struct google_protobuf_ServiceOptions; -typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; struct google_protobuf_MethodOptions; -typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; struct google_protobuf_UninterpretedOption; -typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; struct google_protobuf_UninterpretedOption_NamePart; -typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; struct google_protobuf_SourceCodeInfo; -typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; struct google_protobuf_SourceCodeInfo_Location; -typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; struct google_protobuf_GeneratedCodeInfo; -typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; struct google_protobuf_GeneratedCodeInfo_Annotation; +typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; +typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; +typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; +typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; +typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; +typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; +typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; +typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; +typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; +typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; +typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; +typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; +typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; +typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; +typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; +typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; +typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; +typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; +typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; +typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; +typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; +typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; +typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; +typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; + /* Enums */ typedef enum { @@ -6933,576 +6873,712 @@ typedef enum { google_protobuf_MethodOptions_IDEMPOTENT = 2 } google_protobuf_MethodOptions_IdempotencyLevel; -/* google_protobuf_FileDescriptorSet */ -extern const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorSet_msginit; -google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_env *env); -google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_FileDescriptorSet_serialize(google_protobuf_FileDescriptorSet *msg, upb_env *env, size_t *len); -void google_protobuf_FileDescriptorSet_free(google_protobuf_FileDescriptorSet *msg, upb_env *env); - -/* getters. */ -const upb_array* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg); - -/* setters. */ -void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileDescriptorSet *msg, upb_array* value); - - -/* google_protobuf_FileDescriptorProto */ -extern const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorProto_msginit; -google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_env *env); -google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_FileDescriptorProto_serialize(google_protobuf_FileDescriptorProto *msg, upb_env *env, size_t *len); -void google_protobuf_FileDescriptorProto_free(google_protobuf_FileDescriptorProto *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg); -upb_stringview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg); -const upb_array* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg); -const upb_array* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg); -const upb_array* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg); -const upb_array* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg); -const upb_array* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg); -const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg); -const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg); -const upb_array* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg); -const upb_array* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg); -upb_stringview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg); - -/* setters. */ -void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_stringview value); -void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_stringview value); -void google_protobuf_FileDescriptorProto_set_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value); -void google_protobuf_FileDescriptorProto_set_message_type(google_protobuf_FileDescriptorProto *msg, upb_array* value); -void google_protobuf_FileDescriptorProto_set_enum_type(google_protobuf_FileDescriptorProto *msg, upb_array* value); -void google_protobuf_FileDescriptorProto_set_service(google_protobuf_FileDescriptorProto *msg, upb_array* value); -void google_protobuf_FileDescriptorProto_set_extension(google_protobuf_FileDescriptorProto *msg, upb_array* value); -void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value); -void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value); -void google_protobuf_FileDescriptorProto_set_public_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value); -void google_protobuf_FileDescriptorProto_set_weak_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value); -void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_stringview value); - - -/* google_protobuf_DescriptorProto */ -extern const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_msginit; -google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_env *env); -google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_DescriptorProto_serialize(google_protobuf_DescriptorProto *msg, upb_env *env, size_t *len); -void google_protobuf_DescriptorProto_free(google_protobuf_DescriptorProto *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg); -const upb_array* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg); -const upb_array* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg); -const upb_array* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg); -const upb_array* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg); -const upb_array* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg); -const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg); -const upb_array* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg); -const upb_array* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg); -const upb_array* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg); - -/* setters. */ -void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_stringview value); -void google_protobuf_DescriptorProto_set_field(google_protobuf_DescriptorProto *msg, upb_array* value); -void google_protobuf_DescriptorProto_set_nested_type(google_protobuf_DescriptorProto *msg, upb_array* value); -void google_protobuf_DescriptorProto_set_enum_type(google_protobuf_DescriptorProto *msg, upb_array* value); -void google_protobuf_DescriptorProto_set_extension_range(google_protobuf_DescriptorProto *msg, upb_array* value); -void google_protobuf_DescriptorProto_set_extension(google_protobuf_DescriptorProto *msg, upb_array* value); -void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value); -void google_protobuf_DescriptorProto_set_oneof_decl(google_protobuf_DescriptorProto *msg, upb_array* value); -void google_protobuf_DescriptorProto_set_reserved_range(google_protobuf_DescriptorProto *msg, upb_array* value); -void google_protobuf_DescriptorProto_set_reserved_name(google_protobuf_DescriptorProto *msg, upb_array* value); - - -/* google_protobuf_DescriptorProto_ExtensionRange */ -extern const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ExtensionRange_msginit; -google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_env *env); -google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_DescriptorProto_ExtensionRange_serialize(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_env *env, size_t *len); -void google_protobuf_DescriptorProto_ExtensionRange_free(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_env *env); - -/* getters. */ -int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg); -int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg); -const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg); - -/* setters. */ -void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value); -void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value); -void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value); - - -/* google_protobuf_DescriptorProto_ReservedRange */ -extern const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ReservedRange_msginit; -google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_env *env); -google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_DescriptorProto_ReservedRange_serialize(google_protobuf_DescriptorProto_ReservedRange *msg, upb_env *env, size_t *len); -void google_protobuf_DescriptorProto_ReservedRange_free(google_protobuf_DescriptorProto_ReservedRange *msg, upb_env *env); - -/* getters. */ -int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg); -int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg); - -/* setters. */ -void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value); -void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value); - - -/* google_protobuf_ExtensionRangeOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_ExtensionRangeOptions_msginit; -google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_env *env); -google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_ExtensionRangeOptions_serialize(google_protobuf_ExtensionRangeOptions *msg, upb_env *env, size_t *len); -void google_protobuf_ExtensionRangeOptions_free(google_protobuf_ExtensionRangeOptions *msg, upb_env *env); - -/* getters. */ -const upb_array* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg); - -/* setters. */ -void google_protobuf_ExtensionRangeOptions_set_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_array* value); - - -/* google_protobuf_FieldDescriptorProto */ -extern const upb_msglayout_msginit_v1 google_protobuf_FieldDescriptorProto_msginit; -google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_env *env); -google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_FieldDescriptorProto_serialize(google_protobuf_FieldDescriptorProto *msg, upb_env *env, size_t *len); -void google_protobuf_FieldDescriptorProto_free(google_protobuf_FieldDescriptorProto *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg); -upb_stringview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg); -int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg); -google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg); -google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg); -upb_stringview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg); -upb_stringview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg); -const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg); -int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg); -upb_stringview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg); - -/* setters. */ -void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); -void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); -void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value); -void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value); -void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value); -void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); -void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); -void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value); -void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value); -void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value); - - -/* google_protobuf_OneofDescriptorProto */ -extern const upb_msglayout_msginit_v1 google_protobuf_OneofDescriptorProto_msginit; -google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_env *env); -google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_OneofDescriptorProto_serialize(google_protobuf_OneofDescriptorProto *msg, upb_env *env, size_t *len); -void google_protobuf_OneofDescriptorProto_free(google_protobuf_OneofDescriptorProto *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg); -const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg); - -/* setters. */ -void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_stringview value); -void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value); - - -/* google_protobuf_EnumDescriptorProto */ -extern const upb_msglayout_msginit_v1 google_protobuf_EnumDescriptorProto_msginit; -google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_env *env); -google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_EnumDescriptorProto_serialize(google_protobuf_EnumDescriptorProto *msg, upb_env *env, size_t *len); -void google_protobuf_EnumDescriptorProto_free(google_protobuf_EnumDescriptorProto *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg); -const upb_array* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg); -const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg); -const upb_array* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg); -const upb_array* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg); - -/* setters. */ -void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_stringview value); -void google_protobuf_EnumDescriptorProto_set_value(google_protobuf_EnumDescriptorProto *msg, upb_array* value); -void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value); -void google_protobuf_EnumDescriptorProto_set_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_array* value); -void google_protobuf_EnumDescriptorProto_set_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_array* value); - - -/* google_protobuf_EnumDescriptorProto_EnumReservedRange */ -extern const upb_msglayout_msginit_v1 google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; -google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_env *env); -google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_env *env, size_t *len); -void google_protobuf_EnumDescriptorProto_EnumReservedRange_free(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_env *env); - -/* getters. */ -int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg); -int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg); - -/* setters. */ -void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value); -void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value); - - -/* google_protobuf_EnumValueDescriptorProto */ -extern const upb_msglayout_msginit_v1 google_protobuf_EnumValueDescriptorProto_msginit; -google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_env *env); -google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_EnumValueDescriptorProto_serialize(google_protobuf_EnumValueDescriptorProto *msg, upb_env *env, size_t *len); -void google_protobuf_EnumValueDescriptorProto_free(google_protobuf_EnumValueDescriptorProto *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg); -int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg); -const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg); - -/* setters. */ -void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_stringview value); -void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value); -void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value); - - -/* google_protobuf_ServiceDescriptorProto */ -extern const upb_msglayout_msginit_v1 google_protobuf_ServiceDescriptorProto_msginit; -google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_env *env); -google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_ServiceDescriptorProto_serialize(google_protobuf_ServiceDescriptorProto *msg, upb_env *env, size_t *len); -void google_protobuf_ServiceDescriptorProto_free(google_protobuf_ServiceDescriptorProto *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg); -const upb_array* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg); -const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg); - -/* setters. */ -void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_stringview value); -void google_protobuf_ServiceDescriptorProto_set_method(google_protobuf_ServiceDescriptorProto *msg, upb_array* value); -void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value); - - -/* google_protobuf_MethodDescriptorProto */ -extern const upb_msglayout_msginit_v1 google_protobuf_MethodDescriptorProto_msginit; -google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_env *env); -google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_MethodDescriptorProto_serialize(google_protobuf_MethodDescriptorProto *msg, upb_env *env, size_t *len); -void google_protobuf_MethodDescriptorProto_free(google_protobuf_MethodDescriptorProto *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg); -upb_stringview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg); -upb_stringview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg); -const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg); -bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg); -bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg); - -/* setters. */ -void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_stringview value); -void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value); -void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value); -void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value); -void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value); -void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value); - - -/* google_protobuf_FileOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_FileOptions_msginit; -google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_env *env); -google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_FileOptions_serialize(google_protobuf_FileOptions *msg, upb_env *env, size_t *len); -void google_protobuf_FileOptions_free(google_protobuf_FileOptions *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg); -upb_stringview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg); -google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg); -upb_stringview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg); -upb_stringview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg); -upb_stringview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg); -upb_stringview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg); -upb_stringview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg); -upb_stringview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg); -bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg); -const upb_array* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg); - -/* setters. */ -void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_stringview value); -void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_stringview value); -void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value); -void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_stringview value); -void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value); -void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_stringview value); -void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_stringview value); -void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value); -void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_stringview value); -void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value); -void google_protobuf_FileOptions_set_uninterpreted_option(google_protobuf_FileOptions *msg, upb_array* value); - - -/* google_protobuf_MessageOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_MessageOptions_msginit; -google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_env *env); -google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_MessageOptions_serialize(google_protobuf_MessageOptions *msg, upb_env *env, size_t *len); -void google_protobuf_MessageOptions_free(google_protobuf_MessageOptions *msg, upb_env *env); - -/* getters. */ -bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg); -bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg); -bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg); -bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg); -const upb_array* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg); - -/* setters. */ -void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value); -void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value); -void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value); -void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value); -void google_protobuf_MessageOptions_set_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_array* value); - - -/* google_protobuf_FieldOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_FieldOptions_msginit; -google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_env *env); -google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_FieldOptions_serialize(google_protobuf_FieldOptions *msg, upb_env *env, size_t *len); -void google_protobuf_FieldOptions_free(google_protobuf_FieldOptions *msg, upb_env *env); - -/* getters. */ -google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg); -bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg); -bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg); -bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg); -google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg); -bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg); -const upb_array* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg); - -/* setters. */ -void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value); -void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value); -void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value); -void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value); -void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value); -void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value); -void google_protobuf_FieldOptions_set_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_array* value); - - -/* google_protobuf_OneofOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_OneofOptions_msginit; -google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_env *env); -google_protobuf_OneofOptions *google_protobuf_OneofOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_OneofOptions_serialize(google_protobuf_OneofOptions *msg, upb_env *env, size_t *len); -void google_protobuf_OneofOptions_free(google_protobuf_OneofOptions *msg, upb_env *env); - -/* getters. */ -const upb_array* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg); - -/* setters. */ -void google_protobuf_OneofOptions_set_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_array* value); - - -/* google_protobuf_EnumOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_EnumOptions_msginit; -google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_env *env); -google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_EnumOptions_serialize(google_protobuf_EnumOptions *msg, upb_env *env, size_t *len); -void google_protobuf_EnumOptions_free(google_protobuf_EnumOptions *msg, upb_env *env); - -/* getters. */ -bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg); -bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg); -const upb_array* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg); - -/* setters. */ -void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value); -void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value); -void google_protobuf_EnumOptions_set_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_array* value); - - -/* google_protobuf_EnumValueOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_EnumValueOptions_msginit; -google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_env *env); -google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_EnumValueOptions_serialize(google_protobuf_EnumValueOptions *msg, upb_env *env, size_t *len); -void google_protobuf_EnumValueOptions_free(google_protobuf_EnumValueOptions *msg, upb_env *env); - -/* getters. */ -bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg); -const upb_array* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg); - -/* setters. */ -void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value); -void google_protobuf_EnumValueOptions_set_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_array* value); - - -/* google_protobuf_ServiceOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_ServiceOptions_msginit; -google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_env *env); -google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_ServiceOptions_serialize(google_protobuf_ServiceOptions *msg, upb_env *env, size_t *len); -void google_protobuf_ServiceOptions_free(google_protobuf_ServiceOptions *msg, upb_env *env); - -/* getters. */ -bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg); -const upb_array* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg); - -/* setters. */ -void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value); -void google_protobuf_ServiceOptions_set_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_array* value); - - -/* google_protobuf_MethodOptions */ -extern const upb_msglayout_msginit_v1 google_protobuf_MethodOptions_msginit; -google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_env *env); -google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_MethodOptions_serialize(google_protobuf_MethodOptions *msg, upb_env *env, size_t *len); -void google_protobuf_MethodOptions_free(google_protobuf_MethodOptions *msg, upb_env *env); - -/* getters. */ -bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg); -google_protobuf_MethodOptions_IdempotencyLevel google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg); -const upb_array* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg); - -/* setters. */ -void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value); -void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, google_protobuf_MethodOptions_IdempotencyLevel value); -void google_protobuf_MethodOptions_set_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_array* value); - - -/* google_protobuf_UninterpretedOption */ -extern const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_msginit; -google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_env *env); -google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_UninterpretedOption_serialize(google_protobuf_UninterpretedOption *msg, upb_env *env, size_t *len); -void google_protobuf_UninterpretedOption_free(google_protobuf_UninterpretedOption *msg, upb_env *env); - -/* getters. */ -const upb_array* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg); -upb_stringview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg); -uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg); -int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg); -double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg); -upb_stringview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg); -upb_stringview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg); - -/* setters. */ -void google_protobuf_UninterpretedOption_set_name(google_protobuf_UninterpretedOption *msg, upb_array* value); -void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_stringview value); -void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value); -void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value); -void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value); -void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_stringview value); -void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_stringview value); - - -/* google_protobuf_UninterpretedOption_NamePart */ -extern const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_NamePart_msginit; -google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_env *env); -google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_UninterpretedOption_NamePart_serialize(google_protobuf_UninterpretedOption_NamePart *msg, upb_env *env, size_t *len); -void google_protobuf_UninterpretedOption_NamePart_free(google_protobuf_UninterpretedOption_NamePart *msg, upb_env *env); - -/* getters. */ -upb_stringview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg); -bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg); - -/* setters. */ -void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_stringview value); -void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value); - - -/* google_protobuf_SourceCodeInfo */ -extern const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_msginit; -google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_env *env); -google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_SourceCodeInfo_serialize(google_protobuf_SourceCodeInfo *msg, upb_env *env, size_t *len); -void google_protobuf_SourceCodeInfo_free(google_protobuf_SourceCodeInfo *msg, upb_env *env); - -/* getters. */ -const upb_array* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg); - -/* setters. */ -void google_protobuf_SourceCodeInfo_set_location(google_protobuf_SourceCodeInfo *msg, upb_array* value); - - -/* google_protobuf_SourceCodeInfo_Location */ -extern const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_Location_msginit; -google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_env *env); -google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_SourceCodeInfo_Location_serialize(google_protobuf_SourceCodeInfo_Location *msg, upb_env *env, size_t *len); -void google_protobuf_SourceCodeInfo_Location_free(google_protobuf_SourceCodeInfo_Location *msg, upb_env *env); - -/* getters. */ -const upb_array* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg); -const upb_array* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg); -upb_stringview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg); -upb_stringview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg); -const upb_array* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg); - -/* setters. */ -void google_protobuf_SourceCodeInfo_Location_set_path(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value); -void google_protobuf_SourceCodeInfo_Location_set_span(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value); -void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value); -void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value); -void google_protobuf_SourceCodeInfo_Location_set_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value); - - -/* google_protobuf_GeneratedCodeInfo */ -extern const upb_msglayout_msginit_v1 google_protobuf_GeneratedCodeInfo_msginit; -google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_env *env); -google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_GeneratedCodeInfo_serialize(google_protobuf_GeneratedCodeInfo *msg, upb_env *env, size_t *len); -void google_protobuf_GeneratedCodeInfo_free(google_protobuf_GeneratedCodeInfo *msg, upb_env *env); - -/* getters. */ -const upb_array* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg); - -/* setters. */ -void google_protobuf_GeneratedCodeInfo_set_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_array* value); - - -/* google_protobuf_GeneratedCodeInfo_Annotation */ -extern const upb_msglayout_msginit_v1 google_protobuf_GeneratedCodeInfo_Annotation_msginit; -google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_env *env); -google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parsenew(upb_stringview buf, upb_env *env); -char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_env *env, size_t *len); -void google_protobuf_GeneratedCodeInfo_Annotation_free(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_env *env); - -/* getters. */ -const upb_array* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg); -upb_stringview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg); -int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg); -int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg); - -/* setters. */ -void google_protobuf_GeneratedCodeInfo_Annotation_set_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_array* value); -void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_stringview value); -void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value); -void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value); +/* google.protobuf.FileDescriptorSet */ + +extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit; +UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena); +} +UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FileDescriptorSet_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileDescriptorSet *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.FileDescriptorProto */ + +extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit; +UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FileDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(40, 80)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(44, 88)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(48, 96)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(52, 104)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(56, 112)); } +UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FileOptions*, UPB_SIZE(32, 64)); } +UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_SourceCodeInfo*, UPB_SIZE(36, 72)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(60, 120)); } +UPB_INLINE const upb_array* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(64, 128)); } +UPB_INLINE upb_stringview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)); } + +UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(40, 80)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_message_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(44, 88)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_enum_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(48, 96)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_service(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(52, 104)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_extension(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(56, 112)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { UPB_FIELD_AT(msg, google_protobuf_FileOptions*, UPB_SIZE(32, 64)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { UPB_FIELD_AT(msg, google_protobuf_SourceCodeInfo*, UPB_SIZE(36, 72)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_public_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(60, 120)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_weak_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(64, 128)) = value; } +UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)) = value; } + + +/* google.protobuf.DescriptorProto */ + +extern const upb_msglayout google_protobuf_DescriptorProto_msginit; +UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(32, 64)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(36, 72)); } +UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MessageOptions*, UPB_SIZE(16, 32)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(40, 80)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(44, 88)); } +UPB_INLINE const upb_array* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(48, 96)); } + +UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_field(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_nested_type(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_enum_type(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_extension_range(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(32, 64)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_extension(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(36, 72)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { UPB_FIELD_AT(msg, google_protobuf_MessageOptions*, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_oneof_decl(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(40, 80)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_reserved_range(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(44, 88)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_set_reserved_name(google_protobuf_DescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(48, 96)) = value; } + + +/* google.protobuf.DescriptorProto.ExtensionRange */ + +extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit; +UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); +} +UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len); +} + +UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } +UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)); } + +UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { UPB_FIELD_AT(msg, google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)) = value; } + + +/* google.protobuf.DescriptorProto.ReservedRange */ + +extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit; +UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); +} +UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len); +} + +UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } + +UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } + + +/* google.protobuf.ExtensionRangeOptions */ + +extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit; +UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); +} +UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_ExtensionRangeOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.FieldDescriptorProto */ + +extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit; +UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FieldDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)); } +UPB_INLINE google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Label, UPB_SIZE(8, 8)); } +UPB_INLINE google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Type, UPB_SIZE(16, 16)); } +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)); } +UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FieldOptions*, UPB_SIZE(72, 112)); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)); } +UPB_INLINE upb_stringview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)); } + +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value) { UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Label, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value) { UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Type, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions*, UPB_SIZE(72, 112)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)) = value; } +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)) = value; } + + +/* google.protobuf.OneofDescriptorProto */ + +extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit; +UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_OneofDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_OneofOptions*, UPB_SIZE(16, 32)); } + +UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { UPB_FIELD_AT(msg, google_protobuf_OneofOptions*, UPB_SIZE(16, 32)) = value; } + + +/* google.protobuf.EnumDescriptorProto */ + +extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit; +UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } +UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumOptions*, UPB_SIZE(16, 32)); } +UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } +UPB_INLINE const upb_array* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } + +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_value(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { UPB_FIELD_AT(msg, google_protobuf_EnumOptions*, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } + + +/* google.protobuf.EnumDescriptorProto.EnumReservedRange */ + +extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; +UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); +} +UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len); +} + +UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } + +UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } + + +/* google.protobuf.EnumValueDescriptorProto */ + +extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit; +UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumValueDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumValueOptions*, UPB_SIZE(16, 32)); } + +UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { UPB_FIELD_AT(msg, google_protobuf_EnumValueOptions*, UPB_SIZE(16, 32)) = value; } + + +/* google.protobuf.ServiceDescriptorProto */ + +extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit; +UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_ServiceDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE const upb_array* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 40)); } +UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ServiceOptions*, UPB_SIZE(16, 32)); } + +UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_method(google_protobuf_ServiceDescriptorProto *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 40)) = value; } +UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { UPB_FIELD_AT(msg, google_protobuf_ServiceOptions*, UPB_SIZE(16, 32)) = value; } + + +/* google.protobuf.MethodDescriptorProto */ + +extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit; +UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); +} +UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_MethodDescriptorProto_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } +UPB_INLINE upb_stringview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)); } +UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MethodOptions*, UPB_SIZE(32, 64)); } +UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } + +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(24, 48)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { UPB_FIELD_AT(msg, google_protobuf_MethodOptions*, UPB_SIZE(32, 64)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } + + +/* google.protobuf.FileOptions */ + +extern const upb_msglayout google_protobuf_FileOptions_msginit; +UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FileOptions_msginit, arena); +} +UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FileOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } +UPB_INLINE google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FileOptions_OptimizeMode, UPB_SIZE(8, 8)); } +UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } +UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)); } +UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)); } +UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)); } +UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)); } +UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)); } +UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)); } +UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(72, 112)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(80, 128)); } +UPB_INLINE upb_stringview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(88, 144)); } +UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); } +UPB_INLINE const upb_array* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(96, 160)); } + +UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value) { UPB_FIELD_AT(msg, google_protobuf_FileOptions_OptimizeMode, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(56, 80)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(64, 96)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(72, 112)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(80, 128)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(88, 144)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value; } +UPB_INLINE void google_protobuf_FileOptions_set_uninterpreted_option(google_protobuf_FileOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(96, 160)) = value; } + + +/* google.protobuf.MessageOptions */ + +extern const upb_msglayout google_protobuf_MessageOptions_msginit; +UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_MessageOptions_msginit, arena); +} +UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_MessageOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len); +} + +UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } +UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)); } +UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)); } +UPB_INLINE const upb_array* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(8, 8)); } + +UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } +UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)) = value; } +UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_MessageOptions_set_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(8, 8)) = value; } + + +/* google.protobuf.FieldOptions */ + +extern const upb_msglayout google_protobuf_FieldOptions_msginit; +UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_FieldOptions_msginit, arena); +} +UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_FieldOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len); +} + +UPB_INLINE google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldOptions_CType, UPB_SIZE(8, 8)); } +UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); } +UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)); } +UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)); } +UPB_INLINE google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldOptions_JSType, UPB_SIZE(16, 16)); } +UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)); } +UPB_INLINE const upb_array* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 32)); } + +UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions_CType, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value) { UPB_FIELD_AT(msg, google_protobuf_FieldOptions_JSType, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)) = value; } +UPB_INLINE void google_protobuf_FieldOptions_set_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 32)) = value; } + + +/* google.protobuf.OneofOptions */ + +extern const upb_msglayout google_protobuf_OneofOptions_msginit; +UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_OneofOptions_msginit, arena); +} +UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_OneofOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_OneofOptions_set_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.EnumOptions */ + +extern const upb_msglayout google_protobuf_EnumOptions_msginit; +UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumOptions_msginit, arena); +} +UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len); +} + +UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); } +UPB_INLINE const upb_array* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } + +UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; } +UPB_INLINE void google_protobuf_EnumOptions_set_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } + + +/* google.protobuf.EnumValueOptions */ + +extern const upb_msglayout google_protobuf_EnumValueOptions_msginit; +UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); +} +UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_EnumValueOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len); +} + +UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE const upb_array* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } + +UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_EnumValueOptions_set_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } + + +/* google.protobuf.ServiceOptions */ + +extern const upb_msglayout google_protobuf_ServiceOptions_msginit; +UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena); +} +UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_ServiceOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len); +} + +UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } +UPB_INLINE const upb_array* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(4, 8)); } + +UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } +UPB_INLINE void google_protobuf_ServiceOptions_set_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(4, 8)) = value; } + + +/* google.protobuf.MethodOptions */ + +extern const upb_msglayout google_protobuf_MethodOptions_msginit; +UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_MethodOptions_msginit, arena); +} +UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_MethodOptions_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len); +} + +UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); } +UPB_INLINE google_protobuf_MethodOptions_IdempotencyLevel google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_MethodOptions_IdempotencyLevel, UPB_SIZE(8, 8)); } +UPB_INLINE const upb_array* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(20, 24)); } + +UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, google_protobuf_MethodOptions_IdempotencyLevel value) { UPB_FIELD_AT(msg, google_protobuf_MethodOptions_IdempotencyLevel, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_MethodOptions_set_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(20, 24)) = value; } + + +/* google.protobuf.UninterpretedOption */ + +extern const upb_msglayout google_protobuf_UninterpretedOption_msginit; +UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); +} +UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_UninterpretedOption_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(56, 80)); } +UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)); } +UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)); } +UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)); } +UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)); } +UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)); } +UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)); } + +UPB_INLINE void google_protobuf_UninterpretedOption_set_name(google_protobuf_UninterpretedOption *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(56, 80)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(32, 32)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(40, 48)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(48, 64)) = value; } + + +/* google.protobuf.UninterpretedOption.NamePart */ + +extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit; +UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); +} +UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_UninterpretedOption_NamePart_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len); +} + +UPB_INLINE upb_stringview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); } + +UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; } + + +/* google.protobuf.SourceCodeInfo */ + +extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit; +UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); +} +UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_SourceCodeInfo_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_SourceCodeInfo_set_location(google_protobuf_SourceCodeInfo *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.SourceCodeInfo.Location */ + +extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit; +UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); +} +UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_SourceCodeInfo_Location_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 48)); } +UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(28, 56)); } +UPB_INLINE upb_stringview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)); } +UPB_INLINE upb_stringview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)); } +UPB_INLINE const upb_array* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(32, 64)); } + +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_path(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 48)) = value; } +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_span(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(28, 56)) = value; } +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(8, 16)) = value; } +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 32)) = value; } +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(32, 64)) = value; } + + +/* google.protobuf.GeneratedCodeInfo */ + +extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit; +UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena); +} +UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_GeneratedCodeInfo_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(0, 0)); } + +UPB_INLINE void google_protobuf_GeneratedCodeInfo_set_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(0, 0)) = value; } + + +/* google.protobuf.GeneratedCodeInfo.Annotation */ + +extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit; +UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) { + return upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); +} +UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parsenew(upb_stringview buf, upb_arena *arena) { + google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); + return (ret && upb_decode(buf, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit)) ? ret : NULL; +} +UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) { + return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len); +} + +UPB_INLINE const upb_array* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, const upb_array*, UPB_SIZE(24, 32)); } +UPB_INLINE upb_stringview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 16)); } +UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); } +UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); } + +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_array* value) { UPB_FIELD_AT(msg, upb_array*, UPB_SIZE(24, 32)) = value; } +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_stringview value) { UPB_FIELD_AT(msg, upb_stringview, UPB_SIZE(16, 16)) = value; } +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value; } +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; } UPB_END_EXTERN_C + #endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */ /* ** structs.int.h: structures definitions that are internal to upb. @@ -7517,7 +7593,7 @@ struct upb_array { void *data; /* Each element is element_size. */ size_t len; /* Measured in elements. */ size_t size; /* Measured in elements. */ - upb_alloc *alloc; + upb_arena *arena; }; #endif /* UPB_STRUCTS_H_ */ @@ -7638,6 +7714,10 @@ struct upb_msgdef { /* Whether this message has proto2 or proto3 semantics. */ upb_syntax_t syntax; + /* Type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for + * non-well-known message. */ + upb_wellknowntype_t well_known_type; + /* TODO(haberman): proper extension ranges (there can be multiple). */ }; @@ -7646,10 +7726,11 @@ extern const struct upb_refcounted_vtbl upb_msgdef_vtbl; /* TODO: also support static initialization of the oneofs table. This will be * needed if we compile in descriptors that contain oneofs. */ #define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \ - map_entry, syntax, refs, ref2s) \ + map_entry, syntax, well_known_type, refs, ref2s) \ { \ UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \ - selector_count, submsg_field_count, itof, ntof, map_entry, syntax \ + selector_count, submsg_field_count, itof, ntof, map_entry, syntax, \ + well_known_type \ } @@ -7712,6 +7793,44 @@ struct upb_filedef { extern const struct upb_refcounted_vtbl upb_filedef_vtbl; #endif /* UPB_STATICINIT_H_ */ + + +#ifndef UPB_MSGFACTORY_H_ +#define UPB_MSGFACTORY_H_ + +UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory) + +/** upb_msgfactory ************************************************************/ + +/* A upb_msgfactory contains a cache of upb_msglayout, upb_handlers, and + * upb_visitorplan objects. These are the objects necessary to represent, + * populate, and and visit upb_msg objects. + * + * These caches are all populated by upb_msgdef, and lazily created on demand. + */ + +/* Creates and destroys a msgfactory, respectively. The messages for this + * msgfactory must come from |symtab| (which should outlive the msgfactory). */ +upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab); +void upb_msgfactory_free(upb_msgfactory *f); + +const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f); + +/* The functions to get cached objects, lazily creating them on demand. These + * all require: + * + * - m is in upb_msgfactory_symtab(f) + * - upb_msgdef_mapentry(m) == false (since map messages can't have layouts). + * + * The returned objects will live for as long as the msgfactory does. + * + * TODO(haberman): consider making this thread-safe and take a const + * upb_msgfactory. */ +const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, + const upb_msgdef *m); + + +#endif /* UPB_MSGFACTORY_H_ */ /* ** upb::descriptor::Reader (upb_descreader) ** @@ -9448,7 +9567,7 @@ UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, * constructed. This hint may be an overestimate for some build configurations. * But if the parser library is upgraded without recompiling the application, * it may be an underestimate. */ -#define UPB_JSON_PARSER_SIZE 4112 +#define UPB_JSON_PARSER_SIZE 4160 #ifdef __cplusplus @@ -9562,7 +9681,7 @@ UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer) /* upb::json::Printer *********************************************************/ -#define UPB_JSON_PRINTER_SIZE 176 +#define UPB_JSON_PRINTER_SIZE 192 #ifdef __cplusplus @@ -9623,3 +9742,8 @@ inline reffed_ptr<const Handlers> Printer::NewHandlers( #endif #endif /* UPB_JSON_TYPED_PRINTER_H_ */ + +#undef UPB_SIZE +#undef UPB_FIELD_AT +#undef UPB_READ_ONEOF +#undef UPB_WRITE_ONEOF diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index ec0bf6bd..7b5cc7d1 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -438,8 +438,8 @@ class GPBUtil $nanoseconds = intval($nanoseconds); // remove the nanoseconds and preceding period from the timestamp - $date = substr($timestamp, 0, $periodIndex - 1); - $timezone = substr($timestamp, $periodIndex + $nanosecondsLength); + $date = substr($timestamp, 0, $periodIndex); + $timezone = substr($timestamp, $periodIndex + $nanosecondsLength + 1); $timestamp = $date.$timezone; } } diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 8ff141ca..147aaab8 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -1157,9 +1157,17 @@ class Message public function parseFromJsonStream($input) { $array = json_decode($input->getData(), true, 512, JSON_BIGINT_AS_STRING); + if ($this instanceof \Google\Protobuf\ListValue) { + $array = ["values"=>$array]; + } if (is_null($array)) { - throw new GPBDecodeException( - "Cannot decode json string."); + if ($this instanceof \Google\Protobuf\Value) { + $this->setNullValue(\Google\Protobuf\NullValue::NULL_VALUE); + return; + } else { + throw new GPBDecodeException( + "Cannot decode json string: " . $input->getData()); + } } try { $this->mergeFromJsonArray($array); diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 870dacab..fdd142f4 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -20,6 +20,9 @@ use Google\Protobuf\UInt64Value; use Google\Protobuf\BoolValue; use Google\Protobuf\StringValue; use Google\Protobuf\BytesValue; +use Google\Protobuf\Value; +use Google\Protobuf\ListValue; +use Google\Protobuf\Struct; class EncodeDecodeTest extends TestBase { @@ -40,6 +43,13 @@ class EncodeDecodeTest extends TestBase $this->assertEquals(false, $m->getValue()); } + public function testEncodeTopLevelBoolValue() + { + $m = new BoolValue(); + $m->setValue(true); + $this->assertSame("true", $m->serializeToJsonString()); + } + public function testDecodeTopLevelDoubleValue() { $m = new DoubleValue(); @@ -47,6 +57,13 @@ class EncodeDecodeTest extends TestBase $this->assertEquals(1.5, $m->getValue()); } + public function testEncodeTopLevelDoubleValue() + { + $m = new DoubleValue(); + $m->setValue(1.5); + $this->assertSame("1.5", $m->serializeToJsonString()); + } + public function testDecodeTopLevelFloatValue() { $m = new FloatValue(); @@ -54,6 +71,13 @@ class EncodeDecodeTest extends TestBase $this->assertEquals(1.5, $m->getValue()); } + public function testEncodeTopLevelFloatValue() + { + $m = new FloatValue(); + $m->setValue(1.5); + $this->assertSame("1.5", $m->serializeToJsonString()); + } + public function testDecodeTopLevelInt32Value() { $m = new Int32Value(); @@ -61,6 +85,13 @@ class EncodeDecodeTest extends TestBase $this->assertEquals(1, $m->getValue()); } + public function testEncodeTopLevelInt32Value() + { + $m = new Int32Value(); + $m->setValue(1); + $this->assertSame("1", $m->serializeToJsonString()); + } + public function testDecodeTopLevelUInt32Value() { $m = new UInt32Value(); @@ -68,6 +99,13 @@ class EncodeDecodeTest extends TestBase $this->assertEquals(1, $m->getValue()); } + public function testEncodeTopLevelUInt32Value() + { + $m = new UInt32Value(); + $m->setValue(1); + $this->assertSame("1", $m->serializeToJsonString()); + } + public function testDecodeTopLevelInt64Value() { $m = new Int64Value(); @@ -75,6 +113,13 @@ class EncodeDecodeTest extends TestBase $this->assertEquals(1, $m->getValue()); } + # public function testEncodeTopLevelInt64Value() + # { + # $m = new Int64Value(); + # $m->setValue(1); + # $this->assertSame("\"1\"", $m->serializeToJsonString()); + # } + public function testDecodeTopLevelUInt64Value() { $m = new UInt64Value(); @@ -82,6 +127,13 @@ class EncodeDecodeTest extends TestBase $this->assertEquals(1, $m->getValue()); } + # public function testEncodeTopLevelUInt64Value() + # { + # $m = new UInt64Value(); + # $m->setValue(1); + # $this->assertSame("\"1\"", $m->serializeToJsonString()); + # } + public function testDecodeTopLevelStringValue() { $m = new StringValue(); @@ -89,6 +141,13 @@ class EncodeDecodeTest extends TestBase $this->assertSame("a", $m->getValue()); } + public function testEncodeTopLevelStringValue() + { + $m = new StringValue(); + $m->setValue("a"); + $this->assertSame("\"a\"", $m->serializeToJsonString()); + } + public function testDecodeTopLevelBytesValue() { $m = new BytesValue(); @@ -96,6 +155,13 @@ class EncodeDecodeTest extends TestBase $this->assertSame("a", $m->getValue()); } + public function testEncodeTopLevelBytesValue() + { + $m = new BytesValue(); + $m->setValue("a"); + $this->assertSame("\"YQ==\"", $m->serializeToJsonString()); + } + public function testEncode() { $from = new TestMessage(); @@ -603,4 +669,120 @@ class EncodeDecodeTest extends TestBase $to->mergeFromJsonString($data); $this->expectFields($to); } + + public function testDecodeDuration() + { + $m = new Google\Protobuf\Duration(); + $m->mergeFromJsonString("\"1234.5678s\""); + $this->assertEquals(1234, $m->getSeconds()); + $this->assertEquals(567800000, $m->getNanos()); + } + + public function testEncodeDuration() + { + $m = new Google\Protobuf\Duration(); + $m->setSeconds(1234); + $m->setNanos(999999999); + $this->assertEquals("\"1234.999999999s\"", $m->serializeToJsonString()); + } + + public function testDecodeTimestamp() + { + $m = new Google\Protobuf\Timestamp(); + $m->mergeFromJsonString("\"2000-01-01T00:00:00.123456789Z\""); + $this->assertEquals(946684800, $m->getSeconds()); + $this->assertEquals(123456789, $m->getNanos()); + } + + public function testEncodeTimestamp() + { + $m = new Google\Protobuf\Timestamp(); + $m->setSeconds(946684800); + $m->setNanos(123456789); + $this->assertEquals("\"2000-01-01T00:00:00.123456789Z\"", + $m->serializeToJsonString()); + } + + public function testDecodeTopLevelValue() + { + $m = new Value(); + $m->mergeFromJsonString("\"a\""); + $this->assertSame("a", $m->getStringValue()); + + $m = new Value(); + $m->mergeFromJsonString("1.5"); + $this->assertSame(1.5, $m->getNumberValue()); + + $m = new Value(); + $m->mergeFromJsonString("true"); + $this->assertSame(true, $m->getBoolValue()); + + $m = new Value(); + $m->mergeFromJsonString("null"); + $this->assertSame("null_value", $m->getKind()); + + $m = new Value(); + $m->mergeFromJsonString("[1]"); + $this->assertSame("list_value", $m->getKind()); + + $m = new Value(); + $m->mergeFromJsonString("{\"a\":1}"); + $this->assertSame("struct_value", $m->getKind()); + } + + public function testEncodeTopLevelValue() + { + $m = new Value(); + $m->setStringValue("a"); + $this->assertSame("\"a\"", $m->serializeToJsonString()); + + $m = new Value(); + $m->setNumberValue(1.5); + $this->assertSame("1.5", $m->serializeToJsonString()); + + $m = new Value(); + $m->setBoolValue(true); + $this->assertSame("true", $m->serializeToJsonString()); + + $m = new Value(); + $m->setNullValue(0); + $this->assertSame("null", $m->serializeToJsonString()); + } + + public function testDecodeTopLevelListValue() + { + $m = new ListValue(); + $m->mergeFromJsonString("[1]"); + $this->assertSame(1.0, $m->getValues()[0]->getNumberValue()); + } + + public function testEncodeTopLevelListValue() + { + $m = new ListValue(); + $arr = $m->getValues(); + $sub = new Value(); + $sub->setNumberValue(1.5); + $arr[] = $sub; + $this->assertSame("[1.5]", $m->serializeToJsonString()); + } + + public function testDecodeTopLevelStruct() + { + $m = new Struct(); + $m->mergeFromJsonString("{\"a\":{\"b\":1}}"); + $this->assertSame(1.0, $m->getFields()["a"] + ->getStructValue() + ->getFields()["b"]->getNumberValue()); + } + + public function testEncodeTopLevelStruct() + { + $m = new Struct(); + $map = $m->getFields(); + $sub = new Value(); + $sub->setNumberValue(1.5); + $map["a"] = $sub; + $this->assertSame("{\"a\":1.5}", $m->serializeToJsonString()); + } + } diff --git a/src/google/protobuf/compiler/csharp/csharp_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_enum_field.cc index 9ceffa8c..df599614 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_enum_field.cc @@ -47,8 +47,8 @@ namespace compiler { namespace csharp { EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, const Options *options) - : PrimitiveFieldGenerator(descriptor, fieldOrdinal, options) { + int presenceIndex, const Options *options) + : PrimitiveFieldGenerator(descriptor, presenceIndex, options) { } EnumFieldGenerator::~EnumFieldGenerator() { @@ -56,7 +56,7 @@ EnumFieldGenerator::~EnumFieldGenerator() { void EnumFieldGenerator::GenerateParsingCode(io::Printer* printer) { printer->Print(variables_, - "$name$_ = ($type_name$) input.ReadEnum();\n"); + "$property_name$ = ($type_name$) input.ReadEnum();\n"); } void EnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) { @@ -82,8 +82,8 @@ void EnumFieldGenerator::GenerateCodecCode(io::Printer* printer) { } EnumOneofFieldGenerator::EnumOneofFieldGenerator( - const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options) - : PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal, options) { + const FieldDescriptor* descriptor, int presenceIndex, const Options *options) + : PrimitiveOneofFieldGenerator(descriptor, presenceIndex, options) { } EnumOneofFieldGenerator::~EnumOneofFieldGenerator() { diff --git a/src/google/protobuf/compiler/csharp/csharp_enum_field.h b/src/google/protobuf/compiler/csharp/csharp_enum_field.h index 631632bc..bfb9bc81 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_enum_field.h @@ -44,7 +44,7 @@ namespace csharp { class EnumFieldGenerator : public PrimitiveFieldGenerator { public: EnumFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~EnumFieldGenerator(); @@ -60,7 +60,7 @@ class EnumFieldGenerator : public PrimitiveFieldGenerator { class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator { public: EnumOneofFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~EnumOneofFieldGenerator(); diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index 7e737e47..f8808264 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -57,6 +57,9 @@ void FieldGeneratorBase::SetCommonFieldVariables( // repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which // never effects the tag size. int tag_size = internal::WireFormat::TagSize(descriptor_->number(), descriptor_->type()); + if (descriptor_->type() == FieldDescriptor::TYPE_GROUP) { + tag_size /= 2; + } uint tag = internal::WireFormat::MakeTag(descriptor_); uint8 tag_array[5]; io::CodedOutputStream::WriteTagToArray(tag, tag_array); @@ -75,34 +78,52 @@ void FieldGeneratorBase::SetCommonFieldVariables( (*variables)["name"] = name(); (*variables)["descriptor_name"] = descriptor_->name(); (*variables)["default_value"] = default_value(); - if (has_default_value()) { + (*variables)["capitalized_type_name"] = capitalized_type_name(); + (*variables)["number"] = number(); + if (has_default_value() && !IsProto2(descriptor_->file())) { (*variables)["name_def_message"] = (*variables)["name"] + "_ = " + (*variables)["default_value"]; } else { (*variables)["name_def_message"] = (*variables)["name"] + "_"; } - (*variables)["capitalized_type_name"] = capitalized_type_name(); - (*variables)["number"] = number(); - (*variables)["has_property_check"] = - (*variables)["property_name"] + " != " + (*variables)["default_value"]; - (*variables)["other_has_property_check"] = "other." + - (*variables)["property_name"] + " != " + (*variables)["default_value"]; + if (IsProto2(descriptor_->file())) { + (*variables)["has_property_check"] = "Has" + (*variables)["property_name"]; + (*variables)["other_has_property_check"] = "other.Has" + (*variables)["property_name"]; + (*variables)["has_not_property_check"] = "!" + (*variables)["has_property_check"]; + (*variables)["other_has_not_property_check"] = "!" + (*variables)["other_has_property_check"]; + if (presenceIndex_ != -1) { + string hasBitsNumber = SimpleItoa(presenceIndex_ / 32); + string hasBitsMask = SimpleItoa(1 << (presenceIndex_ % 32)); + (*variables)["has_field_check"] = "(_hasBits" + hasBitsNumber + " & " + hasBitsMask + ") != 0"; + (*variables)["set_has_field"] = "_hasBits" + hasBitsNumber + " |= " + hasBitsMask; + (*variables)["clear_has_field"] = "_hasBits" + hasBitsNumber + " &= ~" + hasBitsMask; + } + } else { + (*variables)["has_property_check"] = + (*variables)["property_name"] + " != " + (*variables)["default_value"]; + (*variables)["other_has_property_check"] = "other." + + (*variables)["property_name"] + " != " + (*variables)["default_value"]; + } } void FieldGeneratorBase::SetCommonOneofFieldVariables( std::map<string, string>* variables) { (*variables)["oneof_name"] = oneof_name(); - (*variables)["has_property_check"] = - oneof_name() + "Case_ == " + oneof_property_name() + - "OneofCase." + property_name(); + if (IsProto2(descriptor_->file())) { + (*variables)["has_property_check"] = "Has" + property_name(); + } else { + (*variables)["has_property_check"] = + oneof_name() + "Case_ == " + oneof_property_name() + + "OneofCase." + property_name(); + } (*variables)["oneof_property_name"] = oneof_property_name(); } FieldGeneratorBase::FieldGeneratorBase(const FieldDescriptor* descriptor, - int fieldOrdinal, const Options* options) + int presenceIndex, const Options* options) : SourceGeneratorBase(descriptor->file(), options), descriptor_(descriptor), - fieldOrdinal_(fieldOrdinal) { + presenceIndex_(presenceIndex) { SetCommonFieldVariables(&variables_); } @@ -251,36 +272,6 @@ bool FieldGeneratorBase::has_default_value() { } } -bool FieldGeneratorBase::is_nullable_type() { - switch (descriptor_->type()) { - case FieldDescriptor::TYPE_ENUM: - case FieldDescriptor::TYPE_DOUBLE: - case FieldDescriptor::TYPE_FLOAT: - case FieldDescriptor::TYPE_INT64: - case FieldDescriptor::TYPE_UINT64: - case FieldDescriptor::TYPE_INT32: - case FieldDescriptor::TYPE_FIXED64: - case FieldDescriptor::TYPE_FIXED32: - case FieldDescriptor::TYPE_BOOL: - case FieldDescriptor::TYPE_UINT32: - case FieldDescriptor::TYPE_SFIXED32: - case FieldDescriptor::TYPE_SFIXED64: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_SINT64: - return false; - - case FieldDescriptor::TYPE_MESSAGE: - case FieldDescriptor::TYPE_GROUP: - case FieldDescriptor::TYPE_STRING: - case FieldDescriptor::TYPE_BYTES: - return true; - - default: - GOOGLE_LOG(FATAL)<< "Unknown field type."; - return true; - } -} - bool AllPrintableAscii(const std::string& text) { for(int i = 0; i < text.size(); i++) { if (text[i] < 0x20 || text[i] > 0x7e) { @@ -290,14 +281,18 @@ bool AllPrintableAscii(const std::string& text) { return true; } -std::string FieldGeneratorBase::GetStringDefaultValueInternal() { - // No other default values needed for proto3... - return "\"\""; +std::string FieldGeneratorBase::GetStringDefaultValueInternal(const FieldDescriptor* descriptor) { + if (descriptor->default_value_string().empty()) + return "\"\""; + else + return "global::System.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(\" +" + StringToBase64(descriptor->default_value_string()) + " +\"))"; } -std::string FieldGeneratorBase::GetBytesDefaultValueInternal() { - // No other default values needed for proto3... - return "pb::ByteString.Empty"; +std::string FieldGeneratorBase::GetBytesDefaultValueInternal(const FieldDescriptor* descriptor) { + if (descriptor->default_value_string().empty()) + return "pb::ByteString.Empty"; + else + return "pb::ByteString.FromBase64(\"" + StringToBase64(descriptor->default_value_string()) + "\")"; } std::string FieldGeneratorBase::default_value() { @@ -307,9 +302,13 @@ std::string FieldGeneratorBase::default_value() { std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) { switch (descriptor->type()) { case FieldDescriptor::TYPE_ENUM: - // All proto3 enums have a default value of 0, and there's an implicit conversion from the constant 0 to - // any C# enum. This means we don't need to work out what we actually mapped the enum value name to. - return "0"; + if (IsProto2(descriptor_->file())) { + return GetClassName(descriptor->default_value_enum()->type()) + "." + + GetEnumValueName(descriptor->default_value_enum()->type()->name(), descriptor->default_value_enum()->name()); + } + else { + return "0"; + } case FieldDescriptor::TYPE_MESSAGE: case FieldDescriptor::TYPE_GROUP: if (IsWrapperType(descriptor)) { @@ -357,9 +356,9 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) return "false"; } case FieldDescriptor::TYPE_STRING: - return GetStringDefaultValueInternal(); + return GetStringDefaultValueInternal(descriptor); case FieldDescriptor::TYPE_BYTES: - return GetBytesDefaultValueInternal(); + return GetBytesDefaultValueInternal(descriptor); case FieldDescriptor::TYPE_UINT32: return SimpleItoa(descriptor->default_value_uint32()); case FieldDescriptor::TYPE_SFIXED32: diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index 62c25517..7eee6bf1 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -47,7 +47,7 @@ namespace csharp { class FieldGeneratorBase : public SourceGeneratorBase { public: FieldGeneratorBase(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options* options); ~FieldGeneratorBase(); @@ -67,7 +67,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { protected: const FieldDescriptor* descriptor_; - const int fieldOrdinal_; + const int presenceIndex_; std::map<string, string> variables_; void AddDeprecatedFlag(io::Printer* printer); @@ -84,7 +84,6 @@ class FieldGeneratorBase : public SourceGeneratorBase { std::string type_name(); std::string type_name(const FieldDescriptor* descriptor); bool has_default_value(); - bool is_nullable_type(); std::string default_value(); std::string default_value(const FieldDescriptor* descriptor); std::string number(); @@ -92,8 +91,8 @@ class FieldGeneratorBase : public SourceGeneratorBase { private: void SetCommonFieldVariables(std::map<string, string>* variables); - std::string GetStringDefaultValueInternal(); - std::string GetBytesDefaultValueInternal(); + std::string GetStringDefaultValueInternal(const FieldDescriptor* descriptor); + std::string GetBytesDefaultValueInternal(const FieldDescriptor* descriptor); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorBase); }; diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.cc b/src/google/protobuf/compiler/csharp/csharp_generator.cc index 0c93fc29..c0597fe4 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator.cc @@ -65,11 +65,11 @@ bool Generator::Generate( std::vector<std::pair<string, string> > options; ParseGeneratorParameter(parameter, &options); - // We only support proto3 - but we make an exception for descriptor.proto. + // We only support proto3 - but we make an exception for descriptor.proto. if (file->syntax() != FileDescriptor::SYNTAX_PROTO3 && !IsDescriptorProto(file)) { - *error = "C# code generation only supports proto3 syntax"; + *error = "C# code generation only supports proto3 syntax"; return false; - } + } struct Options cli_options; diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 04b61074..dace4100 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -36,6 +36,7 @@ #include <google/protobuf/stubs/hash.h> #include <limits> #include <vector> +#include <sstream> #include <google/protobuf/compiler/csharp/csharp_helpers.h> #include <google/protobuf/compiler/csharp/csharp_names.h> @@ -452,55 +453,89 @@ std::string FileDescriptorToBase64(const FileDescriptor* descriptor) { } FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options* options) { switch (descriptor->type()) { case FieldDescriptor::TYPE_GROUP: case FieldDescriptor::TYPE_MESSAGE: if (descriptor->is_repeated()) { if (descriptor->is_map()) { - return new MapFieldGenerator(descriptor, fieldOrdinal, options); + return new MapFieldGenerator(descriptor, presenceIndex, options); } else { - return new RepeatedMessageFieldGenerator(descriptor, fieldOrdinal, options); + return new RepeatedMessageFieldGenerator(descriptor, presenceIndex, options); } } else { if (IsWrapperType(descriptor)) { if (descriptor->containing_oneof()) { - return new WrapperOneofFieldGenerator(descriptor, fieldOrdinal, options); + return new WrapperOneofFieldGenerator(descriptor, presenceIndex, options); } else { - return new WrapperFieldGenerator(descriptor, fieldOrdinal, options); + return new WrapperFieldGenerator(descriptor, presenceIndex, options); } } else { if (descriptor->containing_oneof()) { - return new MessageOneofFieldGenerator(descriptor, fieldOrdinal, options); + return new MessageOneofFieldGenerator(descriptor, presenceIndex, options); } else { - return new MessageFieldGenerator(descriptor, fieldOrdinal, options); + return new MessageFieldGenerator(descriptor, presenceIndex, options); } } } case FieldDescriptor::TYPE_ENUM: if (descriptor->is_repeated()) { - return new RepeatedEnumFieldGenerator(descriptor, fieldOrdinal, options); + return new RepeatedEnumFieldGenerator(descriptor, presenceIndex, options); } else { if (descriptor->containing_oneof()) { - return new EnumOneofFieldGenerator(descriptor, fieldOrdinal, options); + return new EnumOneofFieldGenerator(descriptor, presenceIndex, options); } else { - return new EnumFieldGenerator(descriptor, fieldOrdinal, options); + return new EnumFieldGenerator(descriptor, presenceIndex, options); } } default: if (descriptor->is_repeated()) { - return new RepeatedPrimitiveFieldGenerator(descriptor, fieldOrdinal, options); + return new RepeatedPrimitiveFieldGenerator(descriptor, presenceIndex, options); } else { if (descriptor->containing_oneof()) { - return new PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal, options); + return new PrimitiveOneofFieldGenerator(descriptor, presenceIndex, options); } else { - return new PrimitiveFieldGenerator(descriptor, fieldOrdinal, options); + return new PrimitiveFieldGenerator(descriptor, presenceIndex, options); } } } } +bool IsNullable(const FieldDescriptor* descriptor) { + if (descriptor->is_repeated()) { + return true; + } + + switch (descriptor->type()) { + case FieldDescriptor::TYPE_ENUM: + case FieldDescriptor::TYPE_DOUBLE: + case FieldDescriptor::TYPE_FLOAT: + case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_UINT64: + case FieldDescriptor::TYPE_INT32: + case FieldDescriptor::TYPE_FIXED64: + case FieldDescriptor::TYPE_FIXED32: + case FieldDescriptor::TYPE_BOOL: + case FieldDescriptor::TYPE_UINT32: + case FieldDescriptor::TYPE_SFIXED32: + case FieldDescriptor::TYPE_SFIXED64: + case FieldDescriptor::TYPE_SINT32: + case FieldDescriptor::TYPE_SINT64: + return false; + + case FieldDescriptor::TYPE_MESSAGE: + case FieldDescriptor::TYPE_GROUP: + case FieldDescriptor::TYPE_STRING: + case FieldDescriptor::TYPE_BYTES: + return true; + + default: + GOOGLE_LOG(FATAL) << "Unknown field type."; + return true; + } +} + } // namespace csharp } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index ec0b1c77..5b9f90e0 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -107,9 +107,11 @@ std::string StringToBase64(const std::string& input); std::string FileDescriptorToBase64(const FileDescriptor* descriptor); FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options* options); +bool IsNullable(const FieldDescriptor* descriptor); + // Determines whether the given message is a map entry message, // i.e. one implicitly created by protoc due to a map<key, value> field. inline bool IsMapEntryMessage(const Descriptor* descriptor) { @@ -144,6 +146,10 @@ inline bool IsWrapperType(const FieldDescriptor* descriptor) { descriptor->message_type()->file()->name() == "google/protobuf/wrappers.proto"; } +inline bool IsProto2(const FileDescriptor* descriptor) { + return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2; +} + } // namespace csharp } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index d58514ce..125bdf1d 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -48,9 +48,9 @@ namespace compiler { namespace csharp { MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options* options) - : FieldGeneratorBase(descriptor, fieldOrdinal, options) { + : FieldGeneratorBase(descriptor, presenceIndex, options) { } MapFieldGenerator::~MapFieldGenerator() { diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.h b/src/google/protobuf/compiler/csharp/csharp_map_field.h index 84a33a03..91c99bd0 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.h @@ -44,7 +44,7 @@ namespace csharp { class MapFieldGenerator : public FieldGeneratorBase { public: MapFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options* options); ~MapFieldGenerator(); diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 8a4307f1..1daae6f5 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -61,20 +61,27 @@ bool CompareFieldNumbers(const FieldDescriptor* d1, const FieldDescriptor* d2) { MessageGenerator::MessageGenerator(const Descriptor* descriptor, const Options* options) : SourceGeneratorBase(descriptor->file(), options), - descriptor_(descriptor) { - - // sorted field names - for (int i = 0; i < descriptor_->field_count(); i++) { - field_names_.push_back(descriptor_->field(i)->name()); - } - std::sort(field_names_.begin(), field_names_.end()); - + descriptor_(descriptor), + has_bit_field_count_(0) { // fields by number for (int i = 0; i < descriptor_->field_count(); i++) { fields_by_number_.push_back(descriptor_->field(i)); } std::sort(fields_by_number_.begin(), fields_by_number_.end(), CompareFieldNumbers); + + if (IsProto2(descriptor_->file())) { + int primitiveCount = 0; + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + if (!IsNullable(field)) { + primitiveCount++; + if (has_bit_field_count_ == 0 || (primitiveCount % 32) == 0) { + has_bit_field_count_++; + } + } + } + } } MessageGenerator::~MessageGenerator() { @@ -88,10 +95,6 @@ std::string MessageGenerator::full_class_name() { return GetClassName(descriptor_); } -const std::vector<std::string>& MessageGenerator::field_names() { - return field_names_; -} - const std::vector<const FieldDescriptor*>& MessageGenerator::fields_by_number() { return fields_by_number_; } @@ -123,6 +126,12 @@ void MessageGenerator::Generate(io::Printer* printer) { printer->Print( "private pb::UnknownFieldSet _unknownFields;\n"); + for (int i = 0; i < has_bit_field_count_; i++) { + // don't use arrays since all arrays are heap allocated, saving allocations + // use ints instead of bytes since bytes lack bitwise operators, saving casts + printer->Print("private int _hasBits$i$;\n", "i", SimpleItoa(i)); + } + WriteGeneratedCodeAttributes(printer); printer->Print( @@ -288,6 +297,9 @@ void MessageGenerator::GenerateCloningCode(io::Printer* printer) { vars, "public $class_name$($class_name$ other) : this() {\n"); printer->Indent(); + for (int i = 0; i < has_bit_field_count_; i++) { + printer->Print("_hasBits$i$ = other._hasBits$i$;\n", "i", SimpleItoa(i)); + } // Clone non-oneof fields first for (int i = 0; i < descriptor_->field_count(); i++) { if (!descriptor_->field(i)->containing_oneof()) { @@ -559,19 +571,29 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { printer->Print("}\n\n"); // method } -int MessageGenerator::GetFieldOrdinal(const FieldDescriptor* descriptor) { - for (int i = 0; i < field_names().size(); i++) { - if (field_names()[i] == descriptor->name()) { - return i; +// it's a waste of space to track presence for all values, so we only track them if they're not nullable +int MessageGenerator::GetPresenceIndex(const FieldDescriptor* descriptor) { + if (IsNullable(descriptor) || !IsProto2(descriptor_->file())) { + return -1; + } + + int index = 0; + for (int i = 0; i < fields_by_number().size(); i++) { + const FieldDescriptor* field = fields_by_number()[i]; + if (field == descriptor) { + return index; + } + if (!IsNullable(field)) { + index++; } } - GOOGLE_LOG(DFATAL)<< "Could not find ordinal for field " << descriptor->name(); + GOOGLE_LOG(DFATAL)<< "Could not find presence index for field " << descriptor->name(); return -1; } FieldGeneratorBase* MessageGenerator::CreateFieldGeneratorInternal( const FieldDescriptor* descriptor) { - return CreateFieldGenerator(descriptor, GetFieldOrdinal(descriptor), this->options()); + return CreateFieldGenerator(descriptor, GetPresenceIndex(descriptor), this->options()); } } // namespace csharp diff --git a/src/google/protobuf/compiler/csharp/csharp_message.h b/src/google/protobuf/compiler/csharp/csharp_message.h index e7f3b4d0..b20bec3d 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.h +++ b/src/google/protobuf/compiler/csharp/csharp_message.h @@ -57,13 +57,13 @@ class MessageGenerator : public SourceGeneratorBase { private: const Descriptor* descriptor_; - std::vector<std::string> field_names_; std::vector<const FieldDescriptor*> fields_by_number_; + int has_bit_field_count_; void GenerateMessageSerializationMethods(io::Printer* printer); void GenerateMergingMethods(io::Printer* printer); - int GetFieldOrdinal(const FieldDescriptor* descriptor); + int GetPresenceIndex(const FieldDescriptor* descriptor); FieldGeneratorBase* CreateFieldGeneratorInternal( const FieldDescriptor* descriptor); @@ -74,9 +74,6 @@ class MessageGenerator : public SourceGeneratorBase { std::string class_name(); std::string full_class_name(); - // field names sorted alphabetically - const std::vector<std::string>& field_names(); - // field descriptors sorted by number const std::vector<const FieldDescriptor*>& fields_by_number(); diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_message_field.cc index cf1b4dbf..16714603 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.cc @@ -49,11 +49,13 @@ namespace compiler { namespace csharp { MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options) - : FieldGeneratorBase(descriptor, fieldOrdinal, options) { - variables_["has_property_check"] = name() + "_ != null"; - variables_["has_not_property_check"] = name() + "_ == null"; + : FieldGeneratorBase(descriptor, presenceIndex, options) { + if (!IsProto2(descriptor_->file())) { + variables_["has_property_check"] = name() + "_ != null"; + variables_["has_not_property_check"] = name() + "_ == null"; + } } MessageFieldGenerator::~MessageFieldGenerator() { @@ -74,6 +76,26 @@ void MessageFieldGenerator::GenerateMembers(io::Printer* printer) { " $name$_ = value;\n" " }\n" "}\n"); + if (IsProto2(descriptor_->file())) { + printer->Print( + variables_, + "/// <summary>Gets whether the $descriptor_name$ field is set</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ bool Has$property_name$ {\n" + " get { return $name$_ != null; }\n" + "}\n"); + printer->Print( + variables_, + "/// <summary>Clears the value of the $descriptor_name$ field</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ void Clear$property_name$() {\n" + " $name$_ = null;\n" + "}\n"); + } } void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) { @@ -81,7 +103,7 @@ void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) { variables_, "if (other.$has_property_check$) {\n" " if ($has_not_property_check$) {\n" - " $name$_ = new $type_name$();\n" + " $property_name$ = new $type_name$();\n" " }\n" " $property_name$.MergeFrom(other.$property_name$);\n" "}\n"); @@ -91,10 +113,9 @@ void MessageFieldGenerator::GenerateParsingCode(io::Printer* printer) { printer->Print( variables_, "if ($has_not_property_check$) {\n" - " $name$_ = new $type_name$();\n" + " $property_name$ = new $type_name$();\n" "}\n" - // TODO(jonskeet): Do we really need merging behaviour like this? - "input.ReadMessage($name$_);\n"); // No need to support TYPE_GROUP... + "input.ReadMessage($property_name$);\n"); } void MessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) { @@ -130,7 +151,6 @@ void MessageFieldGenerator::WriteToString(io::Printer* printer) { variables_, "PrintField(\"$field_name$\", has$property_name$, $name$_, writer);\n"); } - void MessageFieldGenerator::GenerateCloningCode(io::Printer* printer) { printer->Print(variables_, "$name$_ = other.$has_property_check$ ? other.$name$_.Clone() : null;\n"); @@ -147,9 +167,9 @@ void MessageFieldGenerator::GenerateCodecCode(io::Printer* printer) { MessageOneofFieldGenerator::MessageOneofFieldGenerator( const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options) - : MessageFieldGenerator(descriptor, fieldOrdinal, options) { + : MessageFieldGenerator(descriptor, presenceIndex, options) { SetCommonOneofFieldVariables(&variables_); } @@ -169,6 +189,28 @@ void MessageOneofFieldGenerator::GenerateMembers(io::Printer* printer) { " $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$property_name$;\n" " }\n" "}\n"); + if (IsProto2(descriptor_->file())) { + printer->Print( + variables_, + "/// <summary>Gets whether the \"$descriptor_name$\" field is set</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ bool Has$property_name$ {\n" + " get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$property_name$; }\n" + "}\n"); + printer->Print( + variables_, + "/// <summary> Clears the value of the oneof if it's currently set to \"$descriptor_name$\" </summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ void Clear$property_name$() {\n" + " if ($has_property_check$) {\n" + " Clear$oneof_property_name$();\n" + " }\n" + "}\n"); + } } void MessageOneofFieldGenerator::GenerateMergingCode(io::Printer* printer) { @@ -187,7 +229,7 @@ void MessageOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) { "if ($has_property_check$) {\n" " subBuilder.MergeFrom($property_name$);\n" "}\n" - "input.ReadMessage(subBuilder);\n" // No support of TYPE_GROUP + "input.ReadMessage(subBuilder);\n" "$property_name$ = subBuilder;\n"); } diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.h b/src/google/protobuf/compiler/csharp/csharp_message_field.h index c41ee88a..104fb027 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.h @@ -44,7 +44,7 @@ namespace csharp { class MessageFieldGenerator : public FieldGeneratorBase { public: MessageFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~MessageFieldGenerator(); @@ -68,7 +68,7 @@ class MessageFieldGenerator : public FieldGeneratorBase { class MessageOneofFieldGenerator : public MessageFieldGenerator { public: MessageOneofFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~MessageOneofFieldGenerator(); diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc index c3003e3d..b83468d3 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc @@ -49,12 +49,12 @@ namespace compiler { namespace csharp { PrimitiveFieldGenerator::PrimitiveFieldGenerator( - const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options) - : FieldGeneratorBase(descriptor, fieldOrdinal, options) { + const FieldDescriptor* descriptor, int presenceIndex, const Options *options) + : FieldGeneratorBase(descriptor, presenceIndex, options) { // TODO(jonskeet): Make this cleaner... is_value_type = descriptor->type() != FieldDescriptor::TYPE_STRING && descriptor->type() != FieldDescriptor::TYPE_BYTES; - if (!is_value_type) { + if (!is_value_type && !IsProto2(descriptor_->file())) { variables_["has_property_check"] = variables_["property_name"] + ".Length != 0"; variables_["other_has_property_check"] = "other." + variables_["property_name"] + ".Length != 0"; } @@ -67,16 +67,44 @@ void PrimitiveFieldGenerator::GenerateMembers(io::Printer* printer) { // TODO(jonskeet): Work out whether we want to prevent the fields from ever being // null, or whether we just handle it, in the cases of bytes and string. // (Basically, should null-handling code be in the getter or the setter?) + if (IsProto2(descriptor_->file())) { + printer->Print( + variables_, + "private readonly static $type_name$ $property_name$DefaultValue = $default_value$;\n\n"); + } + printer->Print( variables_, "private $type_name$ $name_def_message$;\n"); + WritePropertyDocComment(printer, descriptor_); AddPublicMemberAttributes(printer); - printer->Print( - variables_, - "$access_level$ $type_name$ $property_name$ {\n" - " get { return $name$_; }\n" - " set {\n"); + if (IsProto2(descriptor_->file())) { + if (presenceIndex_ == -1) { + printer->Print( + variables_, + "$access_level$ $type_name$ $property_name$ {\n" + " get { return $name$_ ?? $property_name$DefaultValue; }\n" + " set {\n"); + } else { + printer->Print( + variables_, + "$access_level$ $type_name$ $property_name$ {\n" + " get { if ($has_field_check$) { return $name$_; } else { return $property_name$DefaultValue; } }\n" + " set {\n"); + } + } else { + printer->Print( + variables_, + "$access_level$ $type_name$ $property_name$ {\n" + " get { return $name$_; }\n" + " set {\n"); + } + if (presenceIndex_ != -1) { + printer->Print( + variables_, + " $set_has_field$;\n"); + } if (is_value_type) { printer->Print( variables_, @@ -89,6 +117,36 @@ void PrimitiveFieldGenerator::GenerateMembers(io::Printer* printer) { printer->Print( " }\n" "}\n"); + if (IsProto2(descriptor_->file())) { + printer->Print(variables_, "/// <summary>Gets whether the \"$descriptor_name$\" field is set</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ bool Has$property_name$ {\n" + " get { return "); + if (IsNullable(descriptor_)) { + printer->Print( + variables_, + "$name$_ != null; }\n}\n"); + } else { + printer->Print( + variables_, + "$has_field_check$; }\n}\n"); + } + } + if (IsProto2(descriptor_->file())) { + printer->Print(variables_, "/// <summary>Clears the value of the \"$descriptor_name$\" field</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ void Clear$property_name$() {\n"); + if (IsNullable(descriptor_)) { + printer->Print(variables_, " $name$_ = null;\n"); + } else { + printer->Print(variables_, " $clear_has_field$;\n"); + } + printer->Print("}\n"); + } } void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) { @@ -172,8 +230,8 @@ void PrimitiveFieldGenerator::GenerateCodecCode(io::Printer* printer) { } PrimitiveOneofFieldGenerator::PrimitiveOneofFieldGenerator( - const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options) - : PrimitiveFieldGenerator(descriptor, fieldOrdinal, options) { + const FieldDescriptor* descriptor, int presenceIndex, const Options *options) + : PrimitiveFieldGenerator(descriptor, presenceIndex, options) { SetCommonOneofFieldVariables(&variables_); } @@ -188,20 +246,42 @@ void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) { "$access_level$ $type_name$ $property_name$ {\n" " get { return $has_property_check$ ? ($type_name$) $oneof_name$_ : $default_value$; }\n" " set {\n"); - if (is_value_type) { - printer->Print( - variables_, - " $oneof_name$_ = value;\n"); - } else { - printer->Print( - variables_, - " $oneof_name$_ = pb::ProtoPreconditions.CheckNotNull(value, \"value\");\n"); - } + if (is_value_type) { printer->Print( variables_, - " $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n" + " $oneof_name$_ = value;\n"); + } else { + printer->Print( + variables_, + " $oneof_name$_ = pb::ProtoPreconditions.CheckNotNull(value, \"value\");\n"); + } + printer->Print( + variables_, + " $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n" + " }\n" + "}\n"); + if (IsProto2(descriptor_->file())) { + printer->Print( + variables_, + "/// <summary>Gets whether the \"$descriptor_name$\" field is set</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ bool Has$property_name$ {\n" + " get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$property_name$; }\n" + "}\n"); + printer->Print( + variables_, + "/// <summary> Clears the value of the oneof if it's currently set to \"$descriptor_name$\" </summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ void Clear$property_name$() {\n" + " if ($has_property_check$) {\n" + " Clear$oneof_property_name$();\n" " }\n" "}\n"); + } } void PrimitiveOneofFieldGenerator::GenerateMergingCode(io::Printer* printer) { diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h index ca7b8b3d..010ceb21 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h @@ -46,7 +46,7 @@ struct Options; class PrimitiveFieldGenerator : public FieldGeneratorBase { public: PrimitiveFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~PrimitiveFieldGenerator(); @@ -72,7 +72,7 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase { class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator { public: PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~PrimitiveOneofFieldGenerator(); diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc index 683c4b0b..a69e97b2 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc @@ -48,8 +48,8 @@ namespace compiler { namespace csharp { RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator( - const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options) - : FieldGeneratorBase(descriptor, fieldOrdinal, options) { + const FieldDescriptor* descriptor, int presenceIndex, const Options *options) + : FieldGeneratorBase(descriptor, presenceIndex, options) { } RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h index 819b5832..58252225 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h @@ -46,7 +46,7 @@ namespace csharp { class RepeatedEnumFieldGenerator : public FieldGeneratorBase { public: RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~RepeatedEnumFieldGenerator(); diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc index 90af569c..d4216597 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc @@ -49,8 +49,8 @@ namespace compiler { namespace csharp { RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator( - const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options) - : FieldGeneratorBase(descriptor, fieldOrdinal, options) { + const FieldDescriptor* descriptor, int presenceIndex, const Options *options) + : FieldGeneratorBase(descriptor, presenceIndex, options) { } RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() { @@ -67,11 +67,11 @@ void RepeatedMessageFieldGenerator::GenerateMembers(io::Printer* printer) { // function, but it doesn't seem worth it for just this. if (IsWrapperType(descriptor_)) { std::unique_ptr<FieldGeneratorBase> single_generator( - new WrapperFieldGenerator(descriptor_, fieldOrdinal_, this->options())); + new WrapperFieldGenerator(descriptor_, presenceIndex_, this->options())); single_generator->GenerateCodecCode(printer); } else { std::unique_ptr<FieldGeneratorBase> single_generator( - new MessageFieldGenerator(descriptor_, fieldOrdinal_, this->options())); + new MessageFieldGenerator(descriptor_, presenceIndex_, this->options())); single_generator->GenerateCodecCode(printer); } printer->Print(";\n"); diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h index 6e33648b..ebc760fa 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h @@ -46,7 +46,7 @@ struct Options; class RepeatedMessageFieldGenerator : public FieldGeneratorBase { public: RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~RepeatedMessageFieldGenerator(); diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc index cd91506f..bc25627f 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc @@ -48,8 +48,8 @@ namespace compiler { namespace csharp { RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator( - const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options) - : FieldGeneratorBase(descriptor, fieldOrdinal, options) { + const FieldDescriptor* descriptor, int presenceIndex, const Options *options) + : FieldGeneratorBase(descriptor, presenceIndex, options) { } RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() { diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h index a59348a9..340688eb 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h @@ -43,7 +43,7 @@ namespace csharp { class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase { public: - RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options); + RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, int presenceIndex, const Options *options); ~RepeatedPrimitiveFieldGenerator(); virtual void GenerateCloningCode(io::Printer* printer); diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc index 047edf73..1dcbf97b 100644 --- a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc @@ -48,8 +48,8 @@ namespace compiler { namespace csharp { WrapperFieldGenerator::WrapperFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, const Options *options) - : FieldGeneratorBase(descriptor, fieldOrdinal, options) { + int presenceIndex, const Options *options) + : FieldGeneratorBase(descriptor, presenceIndex, options) { variables_["has_property_check"] = name() + "_ != null"; variables_["has_not_property_check"] = name() + "_ == null"; const FieldDescriptor* wrapped_field = descriptor->message_type()->field(0); @@ -81,7 +81,27 @@ void WrapperFieldGenerator::GenerateMembers(io::Printer* printer) { " set {\n" " $name$_ = value;\n" " }\n" - "}\n"); + "}\n\n"); + if (IsProto2(descriptor_->file())) { + printer->Print( + variables_, + "/// <summary>Gets whether the $descriptor_name$ field is set</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ bool Has$property_name$ {\n" + " get { return $name$_ != null; }\n" + "}\n\n"); + printer->Print( + variables_, + "/// <summary>Clears the value of the $descriptor_name$ field</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ void Clear$property_name$() {\n" + " $name$_ = null;\n" + "}\n"); + } } void WrapperFieldGenerator::GenerateMergingCode(io::Printer* printer) { @@ -163,8 +183,8 @@ void WrapperFieldGenerator::GenerateCodecCode(io::Printer* printer) { } WrapperOneofFieldGenerator::WrapperOneofFieldGenerator( - const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options) - : WrapperFieldGenerator(descriptor, fieldOrdinal, options) { + const FieldDescriptor* descriptor, int presenceIndex, const Options *options) + : WrapperFieldGenerator(descriptor, presenceIndex, options) { SetCommonOneofFieldVariables(&variables_); } @@ -189,6 +209,28 @@ void WrapperOneofFieldGenerator::GenerateMembers(io::Printer* printer) { " $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$property_name$;\n" " }\n" "}\n"); + if (IsProto2(descriptor_->file())) { + printer->Print( + variables_, + "/// <summary>Gets whether the \"$descriptor_name$\" field is set</summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ bool Has$property_name$ {\n" + " get { return $oneof_name$Case_ == $oneof_property_name$OneofCase.$property_name$; }\n" + "}\n"); + printer->Print( + variables_, + "/// <summary> Clears the value of the oneof if it's currently set to \"$descriptor_name$\" </summary>\n"); + AddPublicMemberAttributes(printer); + printer->Print( + variables_, + "$access_level$ void Clear$property_name$() {\n" + " if ($has_property_check$) {\n" + " Clear$oneof_property_name$();\n" + " }\n" + "}\n"); + } } void WrapperOneofFieldGenerator::GenerateMergingCode(io::Printer* printer) { diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h index 452531fb..08cae548 100644 --- a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h @@ -46,7 +46,7 @@ struct Options; class WrapperFieldGenerator : public FieldGeneratorBase { public: WrapperFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~WrapperFieldGenerator(); @@ -70,7 +70,7 @@ class WrapperFieldGenerator : public FieldGeneratorBase { class WrapperOneofFieldGenerator : public WrapperFieldGenerator { public: WrapperOneofFieldGenerator(const FieldDescriptor* descriptor, - int fieldOrdinal, + int presenceIndex, const Options *options); ~WrapperOneofFieldGenerator(); @@ -128,7 +128,7 @@ use_java() { esac MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository - MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY" + MVN="$MVN -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY" which java java -version |