diff options
105 files changed, 5234 insertions, 2945 deletions
@@ -22,7 +22,6 @@ load( "protobuf", "cc_proto_library", "py_proto_library", - "internal_copied_filegroup", "internal_protobuf_py_tests", ) @@ -484,25 +483,7 @@ java_library( # Python support ################################################################################ -# Hack: -# protoc generated files contain imports like: -# "from google.protobuf.xxx import yyy" -# However, the sources files of the python runtime are not directly under -# "google/protobuf" (they are under python/google/protobuf). We workaround -# this by copying runtime source files into the desired location to workaround -# the import issue. Ideally py_library should support something similiar to the -# "include" attribute in cc_library to inject the PYTHON_PATH for all libraries -# that depend on the target. -# -# If you use python protobuf as a third_party library in your bazel managed -# project: -# 1) Please import the whole package to //google/protobuf in your -# project. Otherwise, bazel disallows generated files out of the current -# package, thus we won't be able to copy protobuf runtime files into -# //google/protobuf/. -# 2) The runtime also requires "six" for Python2/3 compatibility, please see the -# WORKSPACE file and bind "six" to your workspace as well. -internal_copied_filegroup( +py_library( name = "python_srcs", srcs = glob( [ @@ -514,7 +495,7 @@ internal_copied_filegroup( "python/google/protobuf/internal/test_util.py", ], ), - include = "python", + imports = ["python"], ) cc_binary( @@ -527,7 +508,7 @@ cc_binary( linkstatic = 1, deps = select({ "//conditions:default": [], - ":use_fast_cpp_protos": ["//util/python:python_headers"], + ":use_fast_cpp_protos": ["//external:python_headers"], }), ) @@ -553,7 +534,7 @@ cc_binary( ":protobuf", ] + select({ "//conditions:default": [], - ":use_fast_cpp_protos": ["//util/python:python_headers"], + ":use_fast_cpp_protos": ["//external:python_headers"], }), ) @@ -584,23 +565,14 @@ py_proto_library( }), default_runtime = "", protoc = ":protoc", - py_extra_srcs = [":python_srcs"], - py_libs = ["//external:six"], + py_libs = [ + ":python_srcs", + "//external:six" + ], srcs_version = "PY2AND3", visibility = ["//visibility:public"], ) -internal_copied_filegroup( - name = "python_test_srcs", - srcs = glob( - [ - "python/google/protobuf/internal/*_test.py", - "python/google/protobuf/internal/test_util.py", - ], - ), - include = "python", -) - py_proto_library( name = "python_common_test_protos", srcs = LITE_TEST_PROTOS + TEST_PROTOS, @@ -624,7 +596,13 @@ py_proto_library( py_library( name = "python_tests", - srcs = [":python_test_srcs"], + srcs = glob( + [ + "python/google/protobuf/internal/*_test.py", + "python/google/protobuf/internal/test_util.py", + ], + ), + imports = ["python"], srcs_version = "PY2AND3", deps = [ ":protobuf_python", diff --git a/Makefile.am b/Makefile.am index fbd27fc5..3e21db89 100644 --- a/Makefile.am +++ b/Makefile.am @@ -653,7 +653,6 @@ ruby_EXTRA_DIST= \ ruby/tests/repeated_field_test.rb \ ruby/tests/stress.rb \ ruby/tests/generated_code.proto \ - ruby/tests/generated_code.rb \ ruby/tests/generated_code_test.rb \ ruby/travis-test.sh @@ -1,28 +1,33 @@ new_http_archive( - name = "gmock_archive", - url = "https://googlemock.googlecode.com/files/gmock-1.7.0.zip", - sha256 = "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b", - build_file = "gmock.BUILD", + name = "gmock_archive", + url = "https://googlemock.googlecode.com/files/gmock-1.7.0.zip", + sha256 = "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b", + build_file = "gmock.BUILD", ) new_http_archive( - name = "six_archive", - url = "https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55", - sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a", - build_file = "six.BUILD", + name = "six_archive", + url = "https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55", + sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a", + build_file = "six.BUILD", ) bind( - name = "gtest", - actual = "@gmock_archive//:gtest", + name = "python_headers", + actual = "//util/python:python_headers", ) bind( - name = "gtest_main", - actual = "@gmock_archive//:gtest_main", + name = "gtest", + actual = "@gmock_archive//:gtest", ) bind( - name = "six", - actual = "@six_archive//:six", + name = "gtest_main", + actual = "@gmock_archive//:gtest_main", +) + +bind( + name = "six", + actual = "@six_archive//:six", ) diff --git a/conformance/conformance_ruby.rb b/conformance/conformance_ruby.rb index cd065673..c716facd 100755 --- a/conformance/conformance_ruby.rb +++ b/conformance/conformance_ruby.rb @@ -51,7 +51,12 @@ def do_test(request) end when :json_payload - test_message = Conformance::TestAllTypes.decode_json(request.json_payload) + begin + test_message = Conformance::TestAllTypes.decode_json(request.json_payload) + rescue Google::Protobuf::ParseError => err + response.parse_error = err.message.encode('utf-8') + return response + end when nil fail "Request didn't have payload" @@ -66,6 +71,9 @@ def do_test(request) when :JSON response.json_payload = test_message.to_json + + when nil + fail "Request didn't have requested output format" end rescue StandardError => err response.runtime_error = err.message.encode('utf-8') @@ -96,8 +104,8 @@ def do_test_io STDOUT.flush if $verbose - STDERR.puts("conformance-cpp: request={request.to_json}, " \ - "response={response.to_json}\n") + STDERR.puts("conformance_ruby: request=#{request.to_json}, " \ + "response=#{response.to_json}\n") end $test_count += 1 @@ -107,7 +115,7 @@ end loop do unless do_test_io - STDERR.puts('conformance-cpp: received EOF from test runner ' \ + STDERR.puts('conformance_ruby: received EOF from test runner ' \ "after #{$test_count} tests, exiting") break end diff --git a/conformance/failure_list_ruby.txt b/conformance/failure_list_ruby.txt index 1b2e7d94..ade0ff4c 100644 --- a/conformance/failure_list_ruby.txt +++ b/conformance/failure_list_ruby.txt @@ -1,18 +1,12 @@ -# Many of the JSON tests are failing due to a simple bug: -# fields are not camel-cased at all right now. Once this -# is fixed, this list should grow a lot shorter. - DurationProtoInputTooLarge.JsonOutput DurationProtoInputTooSmall.JsonOutput FieldMaskNumbersDontRoundTrip.JsonOutput FieldMaskPathsDontRoundTrip.JsonOutput FieldMaskTooManyUnderscore.JsonOutput -JsonInput.AllFieldAcceptNull.JsonOutput -JsonInput.AllFieldAcceptNull.ProtobufOutput JsonInput.Any.JsonOutput +JsonInput.Any.ProtobufOutput JsonInput.AnyNested.JsonOutput JsonInput.AnyNested.ProtobufOutput -JsonInput.Any.ProtobufOutput JsonInput.AnyUnorderedTypeTag.JsonOutput JsonInput.AnyUnorderedTypeTag.ProtobufOutput JsonInput.AnyWithDuration.JsonOutput @@ -29,31 +23,9 @@ JsonInput.AnyWithValueForInteger.JsonOutput JsonInput.AnyWithValueForInteger.ProtobufOutput JsonInput.AnyWithValueForJsonObject.JsonOutput JsonInput.AnyWithValueForJsonObject.ProtobufOutput -JsonInput.BoolFieldAllCapitalFalse -JsonInput.BoolFieldAllCapitalTrue -JsonInput.BoolFieldCamelCaseFalse -JsonInput.BoolFieldCamelCaseTrue -JsonInput.BoolFieldDoubleQuotedFalse -JsonInput.BoolFieldDoubleQuotedTrue -JsonInput.BoolFieldFalse.JsonOutput -JsonInput.BoolFieldFalse.ProtobufOutput JsonInput.BoolFieldIntegerOne JsonInput.BoolFieldIntegerZero -JsonInput.BoolFieldTrue.JsonOutput -JsonInput.BoolFieldTrue.ProtobufOutput -JsonInput.BoolMapEscapedKey.JsonOutput -JsonInput.BoolMapEscapedKey.ProtobufOutput -JsonInput.BoolMapField.JsonOutput -JsonInput.BoolMapFieldKeyNotQuoted -JsonInput.BoolMapField.ProtobufOutput -JsonInput.BytesFieldInvalidBase64Characters -JsonInput.BytesField.JsonOutput -JsonInput.BytesFieldNoPadding -JsonInput.BytesField.ProtobufOutput -JsonInput.BytesRepeatedField.JsonOutput -JsonInput.BytesRepeatedField.ProtobufOutput JsonInput.DoubleFieldInfinity.JsonOutput -JsonInput.DoubleFieldInfinityNotQuoted JsonInput.DoubleFieldInfinity.ProtobufOutput JsonInput.DoubleFieldMaxNegativeValue.JsonOutput JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput @@ -64,136 +36,74 @@ JsonInput.DoubleFieldMinNegativeValue.ProtobufOutput JsonInput.DoubleFieldMinPositiveValue.JsonOutput JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput JsonInput.DoubleFieldNan.JsonOutput -JsonInput.DoubleFieldNanNotQuoted JsonInput.DoubleFieldNan.ProtobufOutput JsonInput.DoubleFieldNegativeInfinity.JsonOutput -JsonInput.DoubleFieldNegativeInfinityNotQuoted JsonInput.DoubleFieldNegativeInfinity.ProtobufOutput JsonInput.DoubleFieldQuotedValue.JsonOutput JsonInput.DoubleFieldQuotedValue.ProtobufOutput -JsonInput.DoubleFieldTooLarge -JsonInput.DoubleFieldTooSmall JsonInput.DurationHas3FractionalDigits.Validator JsonInput.DurationHas6FractionalDigits.Validator JsonInput.DurationHas9FractionalDigits.Validator JsonInput.DurationHasZeroFractionalDigit.Validator -JsonInput.DurationJsonInputTooLarge -JsonInput.DurationJsonInputTooSmall JsonInput.DurationMaxValue.JsonOutput JsonInput.DurationMaxValue.ProtobufOutput JsonInput.DurationMinValue.JsonOutput JsonInput.DurationMinValue.ProtobufOutput -JsonInput.DurationMissingS JsonInput.DurationRepeatedValue.JsonOutput JsonInput.DurationRepeatedValue.ProtobufOutput -JsonInput.EnumField.JsonOutput -JsonInput.EnumFieldNotQuoted JsonInput.EnumFieldNumericValueNonZero.JsonOutput JsonInput.EnumFieldNumericValueNonZero.ProtobufOutput JsonInput.EnumFieldNumericValueZero.JsonOutput JsonInput.EnumFieldNumericValueZero.ProtobufOutput -JsonInput.EnumField.ProtobufOutput JsonInput.EnumFieldUnknownValue.Validator -JsonInput.EnumRepeatedField.JsonOutput -JsonInput.EnumRepeatedField.ProtobufOutput -JsonInput.FieldMaskInvalidCharacter JsonInput.FieldMask.JsonOutput JsonInput.FieldMask.ProtobufOutput -JsonInput.FieldNameDuplicate -JsonInput.FieldNameDuplicateDifferentCasing1 -JsonInput.FieldNameDuplicateDifferentCasing2 -JsonInput.FieldNameEscaped.JsonOutput -JsonInput.FieldNameInLowerCamelCase.Validator JsonInput.FieldNameInSnakeCase.JsonOutput -JsonInput.FieldNameInSnakeCase.ProtobufOutput -JsonInput.FieldNameNotQuoted JsonInput.FieldNameWithMixedCases.JsonOutput JsonInput.FieldNameWithMixedCases.ProtobufOutput JsonInput.FieldNameWithMixedCases.Validator -JsonInput.FieldNameWithNumbers.JsonOutput -JsonInput.FieldNameWithNumbers.ProtobufOutput -JsonInput.FieldNameWithNumbers.Validator JsonInput.FloatFieldInfinity.JsonOutput -JsonInput.FloatFieldInfinityNotQuoted JsonInput.FloatFieldInfinity.ProtobufOutput -JsonInput.FloatFieldMaxNegativeValue.JsonOutput -JsonInput.FloatFieldMaxNegativeValue.ProtobufOutput -JsonInput.FloatFieldMaxPositiveValue.JsonOutput -JsonInput.FloatFieldMaxPositiveValue.ProtobufOutput -JsonInput.FloatFieldMinNegativeValue.JsonOutput -JsonInput.FloatFieldMinNegativeValue.ProtobufOutput -JsonInput.FloatFieldMinPositiveValue.JsonOutput -JsonInput.FloatFieldMinPositiveValue.ProtobufOutput JsonInput.FloatFieldNan.JsonOutput -JsonInput.FloatFieldNanNotQuoted JsonInput.FloatFieldNan.ProtobufOutput JsonInput.FloatFieldNegativeInfinity.JsonOutput -JsonInput.FloatFieldNegativeInfinityNotQuoted JsonInput.FloatFieldNegativeInfinity.ProtobufOutput JsonInput.FloatFieldQuotedValue.JsonOutput JsonInput.FloatFieldQuotedValue.ProtobufOutput JsonInput.FloatFieldTooLarge JsonInput.FloatFieldTooSmall -JsonInput.HelloWorld.JsonOutput -JsonInput.HelloWorld.ProtobufOutput JsonInput.Int32FieldExponentialFormat.JsonOutput JsonInput.Int32FieldExponentialFormat.ProtobufOutput JsonInput.Int32FieldFloatTrailingZero.JsonOutput JsonInput.Int32FieldFloatTrailingZero.ProtobufOutput -JsonInput.Int32FieldLeadingSpace -JsonInput.Int32FieldLeadingZero JsonInput.Int32FieldMaxFloatValue.JsonOutput JsonInput.Int32FieldMaxFloatValue.ProtobufOutput -JsonInput.Int32FieldMaxValue.JsonOutput -JsonInput.Int32FieldMaxValue.ProtobufOutput JsonInput.Int32FieldMinFloatValue.JsonOutput JsonInput.Int32FieldMinFloatValue.ProtobufOutput JsonInput.Int32FieldMinValue.JsonOutput -JsonInput.Int32FieldMinValue.ProtobufOutput -JsonInput.Int32FieldNegativeWithLeadingZero -JsonInput.Int32FieldNotInteger -JsonInput.Int32FieldNotNumber -JsonInput.Int32FieldPlusSign -JsonInput.Int32FieldStringValueEscaped.JsonOutput -JsonInput.Int32FieldStringValueEscaped.ProtobufOutput JsonInput.Int32FieldStringValue.JsonOutput JsonInput.Int32FieldStringValue.ProtobufOutput -JsonInput.Int32FieldTooLarge -JsonInput.Int32FieldTooSmall -JsonInput.Int32FieldTrailingSpace +JsonInput.Int32FieldStringValueEscaped.JsonOutput +JsonInput.Int32FieldStringValueEscaped.ProtobufOutput JsonInput.Int32MapEscapedKey.JsonOutput JsonInput.Int32MapEscapedKey.ProtobufOutput JsonInput.Int32MapField.JsonOutput -JsonInput.Int32MapFieldKeyNotQuoted JsonInput.Int32MapField.ProtobufOutput JsonInput.Int64FieldBeString.Validator JsonInput.Int64FieldMaxValue.JsonOutput -JsonInput.Int64FieldMaxValueNotQuoted.JsonOutput -JsonInput.Int64FieldMaxValueNotQuoted.ProtobufOutput JsonInput.Int64FieldMaxValue.ProtobufOutput JsonInput.Int64FieldMinValue.JsonOutput -JsonInput.Int64FieldMinValueNotQuoted.JsonOutput -JsonInput.Int64FieldMinValueNotQuoted.ProtobufOutput JsonInput.Int64FieldMinValue.ProtobufOutput -JsonInput.Int64FieldNotInteger -JsonInput.Int64FieldNotNumber -JsonInput.Int64FieldTooLarge -JsonInput.Int64FieldTooSmall JsonInput.Int64MapEscapedKey.JsonOutput JsonInput.Int64MapEscapedKey.ProtobufOutput JsonInput.Int64MapField.JsonOutput -JsonInput.Int64MapFieldKeyNotQuoted JsonInput.Int64MapField.ProtobufOutput -JsonInput.JsonWithComments -JsonInput.MapFieldKeyIsNull -JsonInput.MapFieldValueIsNull JsonInput.MessageField.JsonOutput JsonInput.MessageField.ProtobufOutput JsonInput.MessageMapField.JsonOutput JsonInput.MessageMapField.ProtobufOutput JsonInput.MessageRepeatedField.JsonOutput JsonInput.MessageRepeatedField.ProtobufOutput -JsonInput.OneofFieldDuplicate JsonInput.OptionalBoolWrapper.JsonOutput JsonInput.OptionalBoolWrapper.ProtobufOutput JsonInput.OptionalBytesWrapper.JsonOutput @@ -215,6 +125,7 @@ JsonInput.OptionalUint64Wrapper.ProtobufOutput JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput JsonInput.OriginalProtoFieldName.JsonOutput +JsonInput.OriginalProtoFieldName.ProtobufOutput JsonInput.PrimitiveRepeatedField.JsonOutput JsonInput.PrimitiveRepeatedField.ProtobufOutput JsonInput.RepeatedBoolWrapper.JsonOutput @@ -223,18 +134,7 @@ JsonInput.RepeatedBytesWrapper.JsonOutput JsonInput.RepeatedBytesWrapper.ProtobufOutput JsonInput.RepeatedDoubleWrapper.JsonOutput JsonInput.RepeatedDoubleWrapper.ProtobufOutput -JsonInput.RepeatedFieldMessageElementIsNull -JsonInput.RepeatedFieldPrimitiveElementIsNull -JsonInput.RepeatedFieldTrailingComma -JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool -JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotMessage -JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotString -JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotBool -JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotInt -JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotString -JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt -JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotMessage JsonInput.RepeatedFloatWrapper.JsonOutput JsonInput.RepeatedFloatWrapper.ProtobufOutput JsonInput.RepeatedInt32Wrapper.JsonOutput @@ -247,39 +147,18 @@ JsonInput.RepeatedUint32Wrapper.JsonOutput JsonInput.RepeatedUint32Wrapper.ProtobufOutput JsonInput.RepeatedUint64Wrapper.JsonOutput JsonInput.RepeatedUint64Wrapper.ProtobufOutput -JsonInput.StringFieldEscape.JsonOutput -JsonInput.StringFieldEscape.ProtobufOutput -JsonInput.StringFieldInvalidEscape -JsonInput.StringField.JsonOutput JsonInput.StringFieldNotAString -JsonInput.StringField.ProtobufOutput JsonInput.StringFieldSurrogateInWrongOrder JsonInput.StringFieldSurrogatePair.JsonOutput JsonInput.StringFieldSurrogatePair.ProtobufOutput -JsonInput.StringFieldUnicodeEscape.JsonOutput -JsonInput.StringFieldUnicodeEscape.ProtobufOutput -JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.JsonOutput -JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.ProtobufOutput -JsonInput.StringFieldUnicode.JsonOutput -JsonInput.StringFieldUnicode.ProtobufOutput JsonInput.StringFieldUnpairedHighSurrogate JsonInput.StringFieldUnpairedLowSurrogate -JsonInput.StringFieldUnterminatedEscape -JsonInput.StringFieldUppercaseEscapeLetter -JsonInput.StringRepeatedField.JsonOutput -JsonInput.StringRepeatedField.ProtobufOutput JsonInput.Struct.JsonOutput JsonInput.Struct.ProtobufOutput JsonInput.TimestampHas3FractionalDigits.Validator JsonInput.TimestampHas6FractionalDigits.Validator JsonInput.TimestampHas9FractionalDigits.Validator JsonInput.TimestampHasZeroFractionalDigit.Validator -JsonInput.TimestampJsonInputLowercaseT -JsonInput.TimestampJsonInputLowercaseZ -JsonInput.TimestampJsonInputMissingT -JsonInput.TimestampJsonInputMissingZ -JsonInput.TimestampJsonInputTooLarge -JsonInput.TimestampJsonInputTooSmall JsonInput.TimestampMaxValue.JsonOutput JsonInput.TimestampMaxValue.ProtobufOutput JsonInput.TimestampMinValue.JsonOutput @@ -291,27 +170,14 @@ JsonInput.TimestampWithNegativeOffset.ProtobufOutput JsonInput.TimestampWithPositiveOffset.JsonOutput JsonInput.TimestampWithPositiveOffset.ProtobufOutput JsonInput.TimestampZeroNormalized.Validator -JsonInput.TrailingCommaInAnObject JsonInput.Uint32FieldMaxFloatValue.JsonOutput JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput -JsonInput.Uint32FieldMaxValue.JsonOutput -JsonInput.Uint32FieldMaxValue.ProtobufOutput -JsonInput.Uint32FieldNotInteger -JsonInput.Uint32FieldNotNumber -JsonInput.Uint32FieldTooLarge JsonInput.Uint32MapField.JsonOutput -JsonInput.Uint32MapFieldKeyNotQuoted JsonInput.Uint32MapField.ProtobufOutput JsonInput.Uint64FieldBeString.Validator JsonInput.Uint64FieldMaxValue.JsonOutput -JsonInput.Uint64FieldMaxValueNotQuoted.JsonOutput -JsonInput.Uint64FieldMaxValueNotQuoted.ProtobufOutput JsonInput.Uint64FieldMaxValue.ProtobufOutput -JsonInput.Uint64FieldNotInteger -JsonInput.Uint64FieldNotNumber -JsonInput.Uint64FieldTooLarge JsonInput.Uint64MapField.JsonOutput -JsonInput.Uint64MapFieldKeyNotQuoted JsonInput.Uint64MapField.ProtobufOutput JsonInput.ValueAcceptBool.JsonOutput JsonInput.ValueAcceptBool.ProtobufOutput @@ -327,8 +193,6 @@ JsonInput.ValueAcceptObject.JsonOutput JsonInput.ValueAcceptObject.ProtobufOutput JsonInput.ValueAcceptString.JsonOutput JsonInput.ValueAcceptString.ProtobufOutput -JsonInput.WrapperTypesWithNullValue.JsonOutput -JsonInput.WrapperTypesWithNullValue.ProtobufOutput ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput diff --git a/csharp/.gitignore b/csharp/.gitignore index 07ea90ac..c88f741e 100644 --- a/csharp/.gitignore +++ b/csharp/.gitignore @@ -33,3 +33,4 @@ mono/.libs mono/*.exe mono/*.dll lib/protoc.exe +*.ncrunch* diff --git a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs index 0e7cf04e..c0a9ffd1 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs @@ -572,5 +572,27 @@ namespace Google.Protobuf Assert.Throws<ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 0, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 1, 0));
}
+
+ [Test]
+ public void Dispose_DisposesUnderlyingStream()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanRead);
+ using (var cis = new CodedInputStream(memoryStream))
+ {
+ }
+ Assert.IsFalse(memoryStream.CanRead); // Disposed
+ }
+
+ [Test]
+ public void Dispose_WithLeaveOpen()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanRead);
+ using (var cis = new CodedInputStream(memoryStream, true))
+ {
+ }
+ Assert.IsTrue(memoryStream.CanRead); // We left the stream open
+ }
}
}
\ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 3297fe87..48bf6d60 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -387,5 +387,33 @@ namespace Google.Protobuf Assert.IsTrue(cin.IsAtEnd);
}
}
+
+ [Test]
+ public void Dispose_DisposesUnderlyingStream()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanWrite);
+ using (var cos = new CodedOutputStream(memoryStream))
+ {
+ cos.WriteRawByte(0);
+ Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
+ }
+ Assert.AreEqual(1, memoryStream.ToArray().Length); // Flushed data from CodedOutputStream to MemoryStream
+ Assert.IsFalse(memoryStream.CanWrite); // Disposed
+ }
+
+ [Test]
+ public void Dispose_WithLeaveOpen()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanWrite);
+ using (var cos = new CodedOutputStream(memoryStream, true))
+ {
+ cos.WriteRawByte(0);
+ Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
+ }
+ Assert.AreEqual(1, memoryStream.Position); // Flushed data from CodedOutputStream to MemoryStream
+ Assert.IsTrue(memoryStream.CanWrite); // We left the stream open
+ }
}
}
\ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs index 67069954..5c2a052b 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs @@ -710,5 +710,14 @@ namespace Google.Protobuf Assert.AreEqual("{ \"singleForeignMessage\": { \"c\": 16, \"@cInHex\": \"10\" } }", message.ToString());
Assert.AreEqual("{ \"singleForeignMessage\": { \"c\": 16 } }", JsonFormatter.Default.Format(message));
}
+
+ [Test]
+ public void CustomDiagnosticMessage_DirectToTextWriterCall()
+ {
+ var message = new ForeignMessage { C = 31 };
+ var writer = new StringWriter();
+ JsonFormatter.Default.Format(message, writer);
+ Assert.AreEqual("{ \"c\": 31 }", writer.ToString());
+ }
}
}
diff --git a/csharp/src/Google.Protobuf.sln b/csharp/src/Google.Protobuf.sln index 69ce9a47..72d87f76 100644 --- a/csharp/src/Google.Protobuf.sln +++ b/csharp/src/Google.Protobuf.sln @@ -1,7 +1,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.31101.0
-MinimumVisualStudioVersion = 10.0.40219.1
+# Visual Studio 2015
+VisualStudioVersion = 14.0.24720.0
+MinimumVisualStudioVersion = 14.0.24720.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf", "Google.Protobuf\Google.Protobuf.csproj", "{6908BDCE-D925-43F3-94AC-A531E6DF2591}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Test", "Google.Protobuf.Test\Google.Protobuf.Test.csproj", "{DD01ED24-3750-4567-9A23-1DB676A15610}"
diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs index 1c02d951..ce6856d6 100644 --- a/csharp/src/Google.Protobuf/CodedInputStream.cs +++ b/csharp/src/Google.Protobuf/CodedInputStream.cs @@ -51,9 +51,15 @@ namespace Google.Protobuf /// and <see cref="MapField{TKey, TValue}"/> to serialize such fields.
/// </para>
/// </remarks>
- public sealed class CodedInputStream
+ public sealed class CodedInputStream : IDisposable
{
/// <summary>
+ /// Whether to leave the underlying stream open when disposing of this stream.
+ /// This is always true when there's no stream.
+ /// </summary>
+ private readonly bool leaveOpen;
+
+ /// <summary>
/// Buffer of data read from the stream or provided at construction time.
/// </summary>
private readonly byte[] buffer;
@@ -120,7 +126,7 @@ namespace Google.Protobuf }
/// <summary>
- /// Creates a new CodedInputStream that reads from the given byte array slice.
+ /// Creates a new <see cref="CodedInputStream"/> that reads from the given byte array slice.
/// </summary>
public CodedInputStream(byte[] buffer, int offset, int length)
: this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), offset, offset + length)
@@ -136,14 +142,28 @@ namespace Google.Protobuf }
/// <summary>
- /// Creates a new CodedInputStream reading data from the given stream.
+ /// Creates a new <see cref="CodedInputStream"/> reading data from the given stream, which will be disposed
+ /// when the returned object is disposed.
/// </summary>
- public CodedInputStream(Stream input) : this(input, new byte[BufferSize], 0, 0)
+ /// <param name="input">The stream to read from.</param>
+ public CodedInputStream(Stream input) : this(input, false)
{
- ProtoPreconditions.CheckNotNull(input, "input");
}
/// <summary>
+ /// Creates a new <see cref="CodedInputStream"/> reading data from the given stream.
+ /// </summary>
+ /// <param name="input">The stream to read from.</param>
+ /// <param name="leaveOpen"><c>true</c> to leave <paramref name="input"/> open when the returned
+ /// <c cref="CodedInputStream"/> is disposed; <c>false</c> to dispose of the given stream when the
+ /// returned object is disposed.</param>
+ public CodedInputStream(Stream input, bool leaveOpen)
+ : this(ProtoPreconditions.CheckNotNull(input, "input"), new byte[BufferSize], 0, 0)
+ {
+ this.leaveOpen = leaveOpen;
+ }
+
+ /// <summary>
/// Creates a new CodedInputStream reading data from the given
/// stream and buffer, using the default limits.
/// </summary>
@@ -246,6 +266,22 @@ namespace Google.Protobuf /// </value>
public int RecursionLimit { get { return recursionLimit; } }
+ /// <summary>
+ /// Disposes of this instance, potentially closing any underlying stream.
+ /// </summary>
+ /// <remarks>
+ /// As there is no flushing to perform here, disposing of a <see cref="CodedInputStream"/> which
+ /// was constructed with the <c>leaveOpen</c> option parameter set to <c>true</c> (or one which
+ /// was constructed to read from a byte array) has no effect.
+ /// </remarks>
+ public void Dispose()
+ {
+ if (!leaveOpen)
+ {
+ input.Dispose();
+ }
+ }
+
#region Validation
/// <summary>
/// Verifies that the last call to ReadTag() returned tag 0 - in other words,
diff --git a/csharp/src/Google.Protobuf/CodedOutputStream.cs b/csharp/src/Google.Protobuf/CodedOutputStream.cs index d6355f03..6211aac3 100644 --- a/csharp/src/Google.Protobuf/CodedOutputStream.cs +++ b/csharp/src/Google.Protobuf/CodedOutputStream.cs @@ -55,7 +55,7 @@ namespace Google.Protobuf /// and <c>MapField<TKey, TValue></c> to serialize such fields.
/// </para>
/// </remarks>
- public sealed partial class CodedOutputStream
+ public sealed partial class CodedOutputStream : IDisposable
{
// "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.)
internal static readonly Encoding Utf8Encoding = Encoding.UTF8;
@@ -65,6 +65,7 @@ namespace Google.Protobuf /// </summary>
public static readonly int DefaultBufferSize = 4096;
+ private readonly bool leaveOpen;
private readonly byte[] buffer;
private readonly int limit;
private int position;
@@ -91,20 +92,44 @@ namespace Google.Protobuf this.buffer = buffer;
this.position = offset;
this.limit = offset + length;
+ leaveOpen = true; // Simple way of avoiding trying to dispose of a null reference
}
- private CodedOutputStream(Stream output, byte[] buffer)
+ private CodedOutputStream(Stream output, byte[] buffer, bool leaveOpen)
{
- this.output = output;
+ this.output = ProtoPreconditions.CheckNotNull(output, nameof(output));
this.buffer = buffer;
this.position = 0;
this.limit = buffer.Length;
+ this.leaveOpen = leaveOpen;
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="CodedOutputStream" /> which write to the given stream, and disposes of that
+ /// stream when the returned <c>CodedOutputStream</c> is disposed.
+ /// </summary>
+ /// <param name="output">The stream to write to. It will be disposed when the returned <c>CodedOutputStream is disposed.</c></param>
+ public CodedOutputStream(Stream output) : this(output, DefaultBufferSize, false)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new CodedOutputStream which write to the given stream and uses
+ /// the specified buffer size.
+ /// </summary>
+ /// <param name="output">The stream to write to. It will be disposed when the returned <c>CodedOutputStream is disposed.</c></param>
+ /// <param name="bufferSize">The size of buffer to use internally.</param>
+ public CodedOutputStream(Stream output, int bufferSize) : this(output, new byte[bufferSize], false)
+ {
}
/// <summary>
/// Creates a new CodedOutputStream which write to the given stream.
/// </summary>
- public CodedOutputStream(Stream output) : this(output, DefaultBufferSize)
+ /// <param name="output">The stream to write to.</param>
+ /// <param name="leaveOpen">If <c>true</c>, <paramref name="output"/> is left open when the returned <c>CodedOutputStream</c> is disposed;
+ /// if <c>false</c>, the provided stream is disposed as well.</param>
+ public CodedOutputStream(Stream output, bool leaveOpen) : this(output, DefaultBufferSize, leaveOpen)
{
}
@@ -112,9 +137,13 @@ namespace Google.Protobuf /// Creates a new CodedOutputStream which write to the given stream and uses
/// the specified buffer size.
/// </summary>
- public CodedOutputStream(Stream output, int bufferSize) : this(output, new byte[bufferSize])
+ /// <param name="output">The stream to write to.</param>
+ /// <param name="bufferSize">The size of buffer to use internally.</param>
+ /// <param name="leaveOpen">If <c>true</c>, <paramref name="output"/> is left open when the returned <c>CodedOutputStream</c> is disposed;
+ /// if <c>false</c>, the provided stream is disposed as well.</param>
+ public CodedOutputStream(Stream output, int bufferSize, bool leaveOpen) : this(output, new byte[bufferSize], leaveOpen)
{
- }
+ }
#endregion
/// <summary>
@@ -660,6 +689,30 @@ namespace Google.Protobuf }
/// <summary>
+ /// Flushes any buffered data and optionally closes the underlying stream, if any.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// By default, any underlying stream is closed by this method. To configure this behaviour,
+ /// use a constructor overload with a <c>leaveOpen</c> parameter. If this instance does not
+ /// have an underlying stream, this method does nothing.
+ /// </para>
+ /// <para>
+ /// For the sake of efficiency, calling this method does not prevent future write calls - but
+ /// if a later write ends up writing to a stream which has been disposed, that is likely to
+ /// fail. It is recommend that you not call any other methods after this.
+ /// </para>
+ /// </remarks>
+ public void Dispose()
+ {
+ Flush();
+ if (!leaveOpen)
+ {
+ output.Dispose();
+ }
+ }
+
+ /// <summary>
/// Flushes any buffered data to the underlying stream (if there is one).
/// </summary>
public void Flush()
@@ -705,4 +758,4 @@ namespace Google.Protobuf }
}
}
-}
\ No newline at end of file +}
diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index 90a5ff1a..993a89d7 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -34,6 +34,7 @@ using Google.Protobuf.Reflection; using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using Google.Protobuf.Compatibility; @@ -474,9 +475,9 @@ namespace Google.Protobuf.Collections /// </summary> public override string ToString() { - var builder = new StringBuilder(); - JsonFormatter.Default.WriteDictionary(builder, this); - return builder.ToString(); + var writer = new StringWriter(); + JsonFormatter.Default.WriteDictionary(writer, this); + return writer.ToString(); } #region IDictionary explicit interface implementation diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs index 1cde03bc..d1db856c 100644 --- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs +++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs @@ -33,6 +33,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Text; namespace Google.Protobuf.Collections @@ -474,9 +475,9 @@ namespace Google.Protobuf.Collections /// </summary> public override string ToString() { - var builder = new StringBuilder(); - JsonFormatter.Default.WriteList(builder, this); - return builder.ToString(); + var writer = new StringWriter(); + JsonFormatter.Default.WriteList(writer, this); + return writer.ToString(); } /// <summary> diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index 60f61fc8..eb959c9f 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -36,6 +36,7 @@ using System.Globalization; using System.Text; using Google.Protobuf.Reflection; using Google.Protobuf.WellKnownTypes; +using System.IO; using System.Linq; using System.Collections.Generic; @@ -141,17 +142,30 @@ namespace Google.Protobuf /// <returns>The formatted message.</returns> public string Format(IMessage message) { + var writer = new StringWriter(); + Format(message, writer); + return writer.ToString(); + } + + /// <summary> + /// Formats the specified message as JSON. + /// </summary> + /// <param name="message">The message to format.</param> + /// <param name="writer">The TextWriter to write the formatted message to.</param> + /// <returns>The formatted message.</returns> + public void Format(IMessage message, TextWriter writer) + { ProtoPreconditions.CheckNotNull(message, nameof(message)); - StringBuilder builder = new StringBuilder(); + ProtoPreconditions.CheckNotNull(writer, nameof(writer)); + if (message.Descriptor.IsWellKnownType) { - WriteWellKnownTypeValue(builder, message.Descriptor, message); + WriteWellKnownTypeValue(writer, message.Descriptor, message); } else { - WriteMessage(builder, message); + WriteMessage(writer, message); } - return builder.ToString(); } /// <summary> @@ -177,11 +191,11 @@ namespace Google.Protobuf return diagnosticFormatter.Format(message); } - private void WriteMessage(StringBuilder builder, IMessage message) + private void WriteMessage(TextWriter writer, IMessage message) { if (message == null) { - WriteNull(builder); + WriteNull(writer); return; } if (DiagnosticOnly) @@ -189,16 +203,16 @@ namespace Google.Protobuf ICustomDiagnosticMessage customDiagnosticMessage = message as ICustomDiagnosticMessage; if (customDiagnosticMessage != null) { - builder.Append(customDiagnosticMessage.ToDiagnosticString()); + writer.Write(customDiagnosticMessage.ToDiagnosticString()); return; } } - builder.Append("{ "); - bool writtenFields = WriteMessageFields(builder, message, false); - builder.Append(writtenFields ? " }" : "}"); + writer.Write("{ "); + bool writtenFields = WriteMessageFields(writer, message, false); + writer.Write(writtenFields ? " }" : "}"); } - private bool WriteMessageFields(StringBuilder builder, IMessage message, bool assumeFirstFieldWritten) + private bool WriteMessageFields(TextWriter writer, IMessage message, bool assumeFirstFieldWritten) { var fields = message.Descriptor.Fields; bool first = !assumeFirstFieldWritten; @@ -221,11 +235,11 @@ namespace Google.Protobuf // Okay, all tests complete: let's write the field value... if (!first) { - builder.Append(PropertySeparator); + writer.Write(PropertySeparator); } - WriteString(builder, ToCamelCase(accessor.Descriptor.Name)); - builder.Append(NameValueSeparator); - WriteValue(builder, value); + WriteString(writer, ToCamelCase(accessor.Descriptor.Name)); + writer.Write(NameValueSeparator); + WriteValue(writer, value); first = false; } return !first; @@ -309,9 +323,9 @@ namespace Google.Protobuf return result.ToString(); } - private static void WriteNull(StringBuilder builder) + private static void WriteNull(TextWriter writer) { - builder.Append("null"); + writer.Write("null"); } private static bool IsDefaultValue(IFieldAccessor accessor, object value) @@ -361,56 +375,56 @@ namespace Google.Protobuf } } - private void WriteValue(StringBuilder builder, object value) + private void WriteValue(TextWriter writer, object value) { if (value == null) { - WriteNull(builder); + WriteNull(writer); } else if (value is bool) { - builder.Append((bool) value ? "true" : "false"); + writer.Write((bool)value ? "true" : "false"); } else if (value is ByteString) { // Nothing in Base64 needs escaping - builder.Append('"'); - builder.Append(((ByteString) value).ToBase64()); - builder.Append('"'); + writer.Write('"'); + writer.Write(((ByteString)value).ToBase64()); + writer.Write('"'); } else if (value is string) { - WriteString(builder, (string) value); + WriteString(writer, (string)value); } else if (value is IDictionary) { - WriteDictionary(builder, (IDictionary) value); + WriteDictionary(writer, (IDictionary)value); } else if (value is IList) { - WriteList(builder, (IList) value); + WriteList(writer, (IList)value); } else if (value is int || value is uint) { IFormattable formattable = (IFormattable) value; - builder.Append(formattable.ToString("d", CultureInfo.InvariantCulture)); + writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture)); } else if (value is long || value is ulong) { - builder.Append('"'); + writer.Write('"'); IFormattable formattable = (IFormattable) value; - builder.Append(formattable.ToString("d", CultureInfo.InvariantCulture)); - builder.Append('"'); + writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture)); + writer.Write('"'); } else if (value is System.Enum) { if (System.Enum.IsDefined(value.GetType(), value)) { - WriteString(builder, value.ToString()); + WriteString(writer, value.ToString()); } else { - WriteValue(builder, (int) value); + WriteValue(writer, (int)value); } } else if (value is float || value is double) @@ -418,13 +432,13 @@ namespace Google.Protobuf string text = ((IFormattable) value).ToString("r", CultureInfo.InvariantCulture); if (text == "NaN" || text == "Infinity" || text == "-Infinity") { - builder.Append('"'); - builder.Append(text); - builder.Append('"'); + writer.Write('"'); + writer.Write(text); + writer.Write('"'); } else { - builder.Append(text); + writer.Write(text); } } else if (value is IMessage) @@ -432,11 +446,11 @@ namespace Google.Protobuf IMessage message = (IMessage) value; if (message.Descriptor.IsWellKnownType) { - WriteWellKnownTypeValue(builder, message.Descriptor, value); + WriteWellKnownTypeValue(writer, message.Descriptor, value); } else { - WriteMessage(builder, (IMessage) value); + WriteMessage(writer, (IMessage)value); } } else @@ -451,13 +465,13 @@ namespace Google.Protobuf /// values are using the embedded well-known types, in order to allow for dynamic messages /// in the future. /// </summary> - private void WriteWellKnownTypeValue(StringBuilder builder, MessageDescriptor descriptor, object value) + private void WriteWellKnownTypeValue(TextWriter writer, MessageDescriptor descriptor, object value) { // Currently, we can never actually get here, because null values are always handled by the caller. But if we *could*, // this would do the right thing. if (value == null) { - WriteNull(builder); + WriteNull(writer); return; } // For wrapper types, the value will either be the (possibly boxed) "native" value, @@ -472,49 +486,49 @@ namespace Google.Protobuf var message = (IMessage) value; value = message.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.GetValue(message); } - WriteValue(builder, value); + WriteValue(writer, value); return; } if (descriptor.FullName == Timestamp.Descriptor.FullName) { - WriteTimestamp(builder, (IMessage) value); + WriteTimestamp(writer, (IMessage)value); return; } if (descriptor.FullName == Duration.Descriptor.FullName) { - WriteDuration(builder, (IMessage) value); + WriteDuration(writer, (IMessage)value); return; } if (descriptor.FullName == FieldMask.Descriptor.FullName) { - WriteFieldMask(builder, (IMessage) value); + WriteFieldMask(writer, (IMessage)value); return; } if (descriptor.FullName == Struct.Descriptor.FullName) { - WriteStruct(builder, (IMessage) value); + WriteStruct(writer, (IMessage)value); return; } if (descriptor.FullName == ListValue.Descriptor.FullName) { var fieldAccessor = descriptor.Fields[ListValue.ValuesFieldNumber].Accessor; - WriteList(builder, (IList) fieldAccessor.GetValue((IMessage) value)); + WriteList(writer, (IList)fieldAccessor.GetValue((IMessage)value)); return; } if (descriptor.FullName == Value.Descriptor.FullName) { - WriteStructFieldValue(builder, (IMessage) value); + WriteStructFieldValue(writer, (IMessage)value); return; } if (descriptor.FullName == Any.Descriptor.FullName) { - WriteAny(builder, (IMessage) value); + WriteAny(writer, (IMessage)value); return; } - WriteMessage(builder, (IMessage) value); + WriteMessage(writer, (IMessage)value); } - private void WriteTimestamp(StringBuilder builder, IMessage value) + private void WriteTimestamp(TextWriter writer, IMessage value) { // TODO: In the common case where this *is* using the built-in Timestamp type, we could // avoid all the reflection at this point, by casting to Timestamp. In the interests of @@ -522,28 +536,28 @@ namespace Google.Protobuf // it still works in that case. int nanos = (int) value.Descriptor.Fields[Timestamp.NanosFieldNumber].Accessor.GetValue(value); long seconds = (long) value.Descriptor.Fields[Timestamp.SecondsFieldNumber].Accessor.GetValue(value); - builder.Append(Timestamp.ToJson(seconds, nanos, DiagnosticOnly)); + writer.Write(Timestamp.ToJson(seconds, nanos, DiagnosticOnly)); } - private void WriteDuration(StringBuilder builder, IMessage value) + private void WriteDuration(TextWriter writer, IMessage value) { // TODO: Same as for WriteTimestamp int nanos = (int) value.Descriptor.Fields[Duration.NanosFieldNumber].Accessor.GetValue(value); long seconds = (long) value.Descriptor.Fields[Duration.SecondsFieldNumber].Accessor.GetValue(value); - builder.Append(Duration.ToJson(seconds, nanos, DiagnosticOnly)); + writer.Write(Duration.ToJson(seconds, nanos, DiagnosticOnly)); } - private void WriteFieldMask(StringBuilder builder, IMessage value) + private void WriteFieldMask(TextWriter writer, IMessage value) { var paths = (IList<string>) value.Descriptor.Fields[FieldMask.PathsFieldNumber].Accessor.GetValue(value); - builder.Append(FieldMask.ToJson(paths, DiagnosticOnly)); + writer.Write(FieldMask.ToJson(paths, DiagnosticOnly)); } - private void WriteAny(StringBuilder builder, IMessage value) + private void WriteAny(TextWriter writer, IMessage value) { if (DiagnosticOnly) { - WriteDiagnosticOnlyAny(builder, value); + WriteDiagnosticOnlyAny(writer, value); return; } @@ -556,40 +570,40 @@ namespace Google.Protobuf throw new InvalidOperationException($"Type registry has no descriptor for type name '{typeName}'"); } IMessage message = descriptor.Parser.ParseFrom(data); - builder.Append("{ "); - WriteString(builder, AnyTypeUrlField); - builder.Append(NameValueSeparator); - WriteString(builder, typeUrl); + writer.Write("{ "); + WriteString(writer, AnyTypeUrlField); + writer.Write(NameValueSeparator); + WriteString(writer, typeUrl); if (descriptor.IsWellKnownType) { - builder.Append(PropertySeparator); - WriteString(builder, AnyWellKnownTypeValueField); - builder.Append(NameValueSeparator); - WriteWellKnownTypeValue(builder, descriptor, message); + writer.Write(PropertySeparator); + WriteString(writer, AnyWellKnownTypeValueField); + writer.Write(NameValueSeparator); + WriteWellKnownTypeValue(writer, descriptor, message); } else { - WriteMessageFields(builder, message, true); + WriteMessageFields(writer, message, true); } - builder.Append(" }"); + writer.Write(" }"); } - private void WriteDiagnosticOnlyAny(StringBuilder builder, IMessage value) + private void WriteDiagnosticOnlyAny(TextWriter writer, IMessage value) { string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); - builder.Append("{ "); - WriteString(builder, AnyTypeUrlField); - builder.Append(NameValueSeparator); - WriteString(builder, typeUrl); - builder.Append(PropertySeparator); - WriteString(builder, AnyDiagnosticValueField); - builder.Append(NameValueSeparator); - builder.Append('"'); - builder.Append(data.ToBase64()); - builder.Append('"'); - builder.Append(" }"); + writer.Write("{ "); + WriteString(writer, AnyTypeUrlField); + writer.Write(NameValueSeparator); + WriteString(writer, typeUrl); + writer.Write(PropertySeparator); + WriteString(writer, AnyDiagnosticValueField); + writer.Write(NameValueSeparator); + writer.Write('"'); + writer.Write(data.ToBase64()); + writer.Write('"'); + writer.Write(" }"); } internal static string GetTypeName(String typeUrl) @@ -602,9 +616,9 @@ namespace Google.Protobuf return parts[1]; } - private void WriteStruct(StringBuilder builder, IMessage message) + private void WriteStruct(TextWriter writer, IMessage message) { - builder.Append("{ "); + writer.Write("{ "); IDictionary fields = (IDictionary) message.Descriptor.Fields[Struct.FieldsFieldNumber].Accessor.GetValue(message); bool first = true; foreach (DictionaryEntry entry in fields) @@ -618,17 +632,17 @@ namespace Google.Protobuf if (!first) { - builder.Append(PropertySeparator); + writer.Write(PropertySeparator); } - WriteString(builder, key); - builder.Append(NameValueSeparator); - WriteStructFieldValue(builder, value); + WriteString(writer, key); + writer.Write(NameValueSeparator); + WriteStructFieldValue(writer, value); first = false; } - builder.Append(first ? "}" : " }"); + writer.Write(first ? "}" : " }"); } - private void WriteStructFieldValue(StringBuilder builder, IMessage message) + private void WriteStructFieldValue(TextWriter writer, IMessage message) { var specifiedField = message.Descriptor.Oneofs[0].Accessor.GetCaseFieldDescriptor(message); if (specifiedField == null) @@ -643,48 +657,48 @@ namespace Google.Protobuf case Value.BoolValueFieldNumber: case Value.StringValueFieldNumber: case Value.NumberValueFieldNumber: - WriteValue(builder, value); + WriteValue(writer, value); return; case Value.StructValueFieldNumber: case Value.ListValueFieldNumber: // Structs and ListValues are nested messages, and already well-known types. var nestedMessage = (IMessage) specifiedField.Accessor.GetValue(message); - WriteWellKnownTypeValue(builder, nestedMessage.Descriptor, nestedMessage); + WriteWellKnownTypeValue(writer, nestedMessage.Descriptor, nestedMessage); return; case Value.NullValueFieldNumber: - WriteNull(builder); + WriteNull(writer); return; default: throw new InvalidOperationException("Unexpected case in struct field: " + specifiedField.FieldNumber); } } - internal void WriteList(StringBuilder builder, IList list) + internal void WriteList(TextWriter writer, IList list) { - builder.Append("[ "); + writer.Write("[ "); bool first = true; foreach (var value in list) { if (!first) { - builder.Append(PropertySeparator); + writer.Write(PropertySeparator); } - WriteValue(builder, value); + WriteValue(writer, value); first = false; } - builder.Append(first ? "]" : " ]"); + writer.Write(first ? "]" : " ]"); } - internal void WriteDictionary(StringBuilder builder, IDictionary dictionary) + internal void WriteDictionary(TextWriter writer, IDictionary dictionary) { - builder.Append("{ "); + writer.Write("{ "); bool first = true; // This will box each pair. Could use IDictionaryEnumerator, but that's ugly in terms of disposal. foreach (DictionaryEntry pair in dictionary) { if (!first) { - builder.Append(PropertySeparator); + writer.Write(PropertySeparator); } string keyText; if (pair.Key is string) @@ -707,12 +721,12 @@ namespace Google.Protobuf } throw new ArgumentException("Unhandled dictionary key type: " + pair.Key.GetType()); } - WriteString(builder, keyText); - builder.Append(NameValueSeparator); - WriteValue(builder, pair.Value); + WriteString(writer, keyText); + writer.Write(NameValueSeparator); + WriteValue(writer, pair.Value); first = false; } - builder.Append(first ? "}" : " }"); + writer.Write(first ? "}" : " }"); } /// <summary> @@ -735,15 +749,15 @@ namespace Google.Protobuf /// <remarks> /// Other than surrogate pair handling, this code is mostly taken from src/google/protobuf/util/internal/json_escaping.cc. /// </remarks> - internal static void WriteString(StringBuilder builder, string text) + internal static void WriteString(TextWriter writer, string text) { - builder.Append('"'); + writer.Write('"'); for (int i = 0; i < text.Length; i++) { char c = text[i]; if (c < 0xa0) { - builder.Append(CommonRepresentations[c]); + writer.Write(CommonRepresentations[c]); continue; } if (char.IsHighSurrogate(c)) @@ -755,8 +769,8 @@ namespace Google.Protobuf { throw new ArgumentException("String contains low surrogate not followed by high surrogate"); } - HexEncodeUtf16CodeUnit(builder, c); - HexEncodeUtf16CodeUnit(builder, text[i]); + HexEncodeUtf16CodeUnit(writer, c); + HexEncodeUtf16CodeUnit(writer, text[i]); continue; } else if (char.IsLowSurrogate(c)) @@ -777,7 +791,7 @@ namespace Google.Protobuf case 0x070f: // Syriac abbreviation mark case 0x17b4: // Khmer vowel inherent Aq case 0x17b5: // Khmer vowel inherent Aa - HexEncodeUtf16CodeUnit(builder, c); + HexEncodeUtf16CodeUnit(writer, c); break; default: @@ -787,27 +801,27 @@ namespace Google.Protobuf (c >= 0x2060 && c <= 0x2064) || // Invisible etc. (c >= 0x206a && c <= 0x206f)) { - HexEncodeUtf16CodeUnit(builder, c); + HexEncodeUtf16CodeUnit(writer, c); } else { // No handling of surrogates here - that's done earlier - builder.Append(c); + writer.Write(c); } break; } } - builder.Append('"'); + writer.Write('"'); } private const string Hex = "0123456789abcdef"; - private static void HexEncodeUtf16CodeUnit(StringBuilder builder, char c) + private static void HexEncodeUtf16CodeUnit(TextWriter writer, char c) { - builder.Append("\\u"); - builder.Append(Hex[(c >> 12) & 0xf]); - builder.Append(Hex[(c >> 8) & 0xf]); - builder.Append(Hex[(c >> 4) & 0xf]); - builder.Append(Hex[(c >> 0) & 0xf]); + writer.Write("\\u"); + writer.Write(Hex[(c >> 12) & 0xf]); + writer.Write(Hex[(c >> 8) & 0xf]); + writer.Write(Hex[(c >> 4) & 0xf]); + writer.Write(Hex[(c >> 0) & 0xf]); } /// <summary> diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs index df1292dc..4bd62cf3 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs @@ -33,6 +33,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; @@ -57,19 +58,19 @@ namespace Google.Protobuf.WellKnownTypes var firstInvalid = paths.FirstOrDefault(p => !ValidatePath(p)); if (firstInvalid == null) { - var builder = new StringBuilder(); - JsonFormatter.WriteString(builder, string.Join(",", paths.Select(JsonFormatter.ToCamelCase))); - return builder.ToString(); + var writer = new StringWriter(); + JsonFormatter.WriteString(writer, string.Join(",", paths.Select(JsonFormatter.ToCamelCase))); + return writer.ToString(); } else { if (diagnosticOnly) { - var builder = new StringBuilder(); - builder.Append("{ \"@warning\": \"Invalid FieldMask\", \"paths\": "); - JsonFormatter.Default.WriteList(builder, (IList) paths); - builder.Append(" }"); - return builder.ToString(); + var writer = new StringWriter(); + writer.Write("{ \"@warning\": \"Invalid FieldMask\", \"paths\": "); + JsonFormatter.Default.WriteList(writer, (IList)paths); + writer.Write(" }"); + return writer.ToString(); } else { diff --git a/js/README.md b/js/README.md index fc144a3d..15d48c87 100644 --- a/js/README.md +++ b/js/README.md @@ -1,14 +1,159 @@ -This directory contains Protocol Buffer support for JavaScript. This code works -in browsers and in Node.js. +Protocol Buffers - Google's data interchange format +=================================================== -The packaging work for this is still in-progress. For now you can just run the -tests. First you need to build the main C++ distribution because the code -generator for JavaScript is written in C++: +[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf) - $ ./autogen.sh - $ ./configure - $ make +Copyright 2008 Google Inc. -Then you can run the JavaScript tests in this directory: +This directory contains the JavaScript Protocol Buffers runtime library. - $ cd js && gulp test +The library is currently compatible with: + +1. CommonJS-style imports (eg. `var protos = require('my-protos');`) +2. Closure-style imports (eg. `goog.require('my.package.MyProto');`) + +Support for ES6-style imports is not implemented yet. Browsers can +be supported by using Browserify, webpack, Closure Compiler, etc. to +resolve imports at compile time. + +To use Protocol Buffers with JavaScript, you need two main components: + +1. The protobuf runtime library. You can install this with + `npm install google-protobuf`, or use the files in this directory. +2. The Protocol Compiler `protoc`. This translates `.proto` files + into `.js` files. The compiler is not currently available via + npm, but you can download a pre-built binary + [on GitHub](https://github.com/google/protobuf/releases) + (look for the `protoc-*.zip` files under **Downloads**). + + +Setup +===== + +First, obtain the Protocol Compiler. The easiest way is to download +a pre-built binary from [https://github.com/google/protobuf/releases](https://github.com/google/protobuf/releases). + +If you want, you can compile `protoc` from source instead. To do this +follow the instructions in [the top-level +README](https://github.com/google/protobuf/blob/master/src/README.md). + +Once you have `protoc` compiled, you can run the tests by typing: + + $ cd js + $ npm install + $ npm test + + # If your protoc is somewhere else than ../src/protoc, instead do this. + # But make sure your protoc is the same version as this (or compatible)! + $ PROTOC=/usr/local/bin/protoc npm test + +This will run two separate copies of the tests: one that uses +Closure Compiler style imports and one that uses CommonJS imports. +You can see all the CommonJS files in `commonjs_out/`. +If all of these tests pass, you know you have a working setup. + + +Using Protocol Buffers in your own project +========================================== + +To use Protocol Buffers in your own project, you need to integrate +the Protocol Compiler into your build system. The details are a +little different depending on whether you are using Closure imports +or CommonJS imports: + +Closure Imports +--------------- + +If you want to use Closure imports, your build should run a command +like this: + + $ protoc --js_out=library=myproto_libs,binary:. messages.proto base.proto + +For Closure imports, `protoc` will generate a single output file +(`myproto_libs.js` in this example). The generated file will `goog.provide()` +all of the types defined in your .proto files. For example, for the unit +tests the generated files contain many `goog.provide` statements like: + + goog.provide('proto.google.protobuf.DescriptorProto'); + goog.provide('proto.google.protobuf.DescriptorProto.ExtensionRange'); + goog.provide('proto.google.protobuf.DescriptorProto.ReservedRange'); + goog.provide('proto.google.protobuf.EnumDescriptorProto'); + goog.provide('proto.google.protobuf.EnumOptions'); + +The generated code will also `goog.require()` many types in the core library, +and they will require many types in the Google Closure library. So make sure +that your `goog.provide()` / `goog.require()` setup can find all of your +generated code, the core library `.js` files in this directory, and the +Google Closure library itself. + +Once you've done this, you should be able to import your types with +statements like: + + goog.require('proto.my.package.MyMessage'); + + var message = proto.my.package.MyMessage(); + +CommonJS imports +---------------- + +If you want to use CommonJS imports, your build should run a command +like this: + + $ protoc --js_out=import_style=commonjs,binary:. messages.proto base.proto + +For CommonJS imports, `protoc` will spit out one file per input file +(so `messages_pb.js` and `base_pb.js` in this example). The generated +code will depend on the core runtime, which should be in a file called +`google-protobuf.js`. If you are installing from `npm`, this file should +already be built and available. If you are running from GitHub, you need +to build it first by running: + + $ gulp dist + +Once you've done this, you should be able to import your types with +statements like: + + var messages = require('./messages_pb'); + + var message = new messages.MyMessage(); + +The `--js_out` flag +------------------- + +The syntax of the `--js_out` flag is: + + --js_out=[OPTIONS:]output_dir + +Where `OPTIONS` are separated by commas. Options are either `opt=val` or +just `opt` (for options that don't take a value). The available options +are specified and documented in the `GeneratorOptions` struct in +[src/google/protobuf/compiler/js/js_generator.h](https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/js/js_generator.h#L53). + +Some examples: + +- `--js_out=library=myprotos_lib.js,binary:.`: this contains the options + `library=myprotos.lib.js` and `binary` and outputs to the current directory. + The `import_style` option is left to the default, which is `closure`. +- `--js_out=import_style=commonjs,binary:protos`: this contains the options + `import_style=commonjs` and `binary` and outputs to the directory `protos`. + +API +=== + +The API is not well-documented yet. Here is a quick example to give you an +idea of how the library generally works: + + var message = new MyMessage(); + + message.setName("John Doe"); + message.setAge(25); + message.setPhoneNumbers(["800-555-1212", "800-555-0000"]); + + // Serializes to a UInt8Array. + bytes = message.serializeBinary(); + + var message2 = new MyMessage(); + message2.deserializeBinary(bytes); + +For more examples, see the tests. You can also look at the generated code +to see what methods are defined for your generated messages. diff --git a/js/binary/proto_test.js b/js/binary/proto_test.js index 1cb7ff0e..3b4aa17f 100644 --- a/js/binary/proto_test.js +++ b/js/binary/proto_test.js @@ -31,6 +31,8 @@ // Test suite is written using Jasmine -- see http://jasmine.github.io/ goog.require('goog.testing.asserts'); + +// CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test goog.require('proto.jspb.test.ExtendsWithMessage'); goog.require('proto.jspb.test.ForeignEnum'); goog.require('proto.jspb.test.ForeignMessage'); diff --git a/js/commonjs/export.js b/js/commonjs/export.js new file mode 100644 index 00000000..a3cfbd6f --- /dev/null +++ b/js/commonjs/export.js @@ -0,0 +1,22 @@ +/** + * @fileoverview Export symbols needed by generated code in CommonJS style. + * + * This effectively is our canonical list of what we publicly export from + * the google-protobuf.js file that we build at distribution time. + */ + +goog.require('goog.object'); +goog.require('jspb.BinaryReader'); +goog.require('jspb.BinaryWriter'); +goog.require('jspb.ExtensionFieldInfo'); +goog.require('jspb.Message'); + +exports.Message = jspb.Message; +exports.BinaryReader = jspb.BinaryReader; +exports.BinaryWriter = jspb.BinaryWriter; +exports.ExtensionFieldInfo = jspb.ExtensionFieldInfo; + +// These are used by generated code but should not be used directly by clients. +exports.exportSymbol = goog.exportSymbol; +exports.inherits = goog.inherits; +exports.object = {extend: goog.object.extend}; diff --git a/js/commonjs/export_asserts.js b/js/commonjs/export_asserts.js new file mode 100644 index 00000000..5219d120 --- /dev/null +++ b/js/commonjs/export_asserts.js @@ -0,0 +1,37 @@ +/** + * @fileoverview Exports symbols needed only by tests. + * + * This file exports several Closure Library symbols that are only + * used by tests. It is used to generate a file + * closure_asserts_commonjs.js that is only used at testing time. + */ + +goog.require('goog.testing.asserts'); + +var global = Function('return this')(); + +// All of the closure "assert" functions are exported at the global level. +// +// The Google Closure assert functions start with assert, eg. +// assertThrows +// assertNotThrows +// assertTrue +// ... +// +// The one exception is the "fail" function. +function shouldExport(str) { + return str.lastIndexOf('assert') === 0 || str == 'fail'; +} + +for (var key in global) { + if ((typeof key == "string") && global.hasOwnProperty(key) && + shouldExport(key)) { + exports[key] = global[key]; + } +} + +// The COMPILED variable is set by Closure compiler to "true" when it compiles +// JavaScript, so in practice this is equivalent to "exports.COMPILED = true". +// This will disable some debugging functionality in debug.js. We could +// investigate whether this can/should be enabled in CommonJS builds. +exports.COMPILED = COMPILED diff --git a/js/commonjs/import_test.js b/js/commonjs/import_test.js new file mode 100644 index 00000000..ffa34fea --- /dev/null +++ b/js/commonjs/import_test.js @@ -0,0 +1,52 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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. + +// Test suite is written using Jasmine -- see http://jasmine.github.io/ + + + +var googleProtobuf = require('google-protobuf'); +var asserts = require('closure_asserts_commonjs'); +var global = Function('return this')(); + +// Bring asserts into the global namespace. +googleProtobuf.object.extend(global, asserts); +googleProtobuf.exportSymbol('jspb.Message', googleProtobuf.Message, global); + +var test7_pb = require('./test7/test7_pb'); +googleProtobuf.exportSymbol('proto.jspb.test.framing.FramingMessage', test7_pb.FramingMessage, global); + +describe('Import test suite', function() { + it('testImportedMessage', function() { + var framing1 = new proto.jspb.test.framing.FramingMessage([]); + var framing2 = new proto.jspb.test.framing.FramingMessage([]); + assertObjectEquals(framing1.toObject(), framing2.toObject()); + }); +}); diff --git a/js/commonjs/jasmine.json b/js/commonjs/jasmine.json new file mode 100644 index 00000000..666b8edb --- /dev/null +++ b/js/commonjs/jasmine.json @@ -0,0 +1,9 @@ +{ + "spec_dir": "", + "spec_files": [ + "*_test.js", + "binary/proto_test.js" + ], + "helpers": [ + ] +} diff --git a/js/commonjs/rewrite_tests_for_commonjs.js b/js/commonjs/rewrite_tests_for_commonjs.js new file mode 100644 index 00000000..ffa87722 --- /dev/null +++ b/js/commonjs/rewrite_tests_for_commonjs.js @@ -0,0 +1,93 @@ +/** + * @fileoverview Utility to translate test files to CommonJS imports. + * + * This is a somewhat hacky tool designed to do one very specific thing. + * All of the test files in *_test.js are written with Closure-style + * imports (goog.require()). This works great for running the tests + * against Closure-style generated code, but we also want to run the + * tests against CommonJS-style generated code without having to fork + * the tests. + * + * Closure-style imports import each individual type by name. This is + * very different than CommonJS imports which are by file. So we put + * special comments in these tests like: + * + * // CommonJS-LoadFromFile: test_pb + * goog.require('proto.jspb.test.CloneExtension'); + * goog.require('proto.jspb.test.Complex'); + * goog.require('proto.jspb.test.DefaultValues'); + * + * This script parses that special comment and uses it to generate proper + * CommonJS require() statements so that the tests can run and pass using + * CommonJS imports. The script will change the above statements into: + * + * var test_pb = require('test_pb'); + * googleProtobuf.exportSymbol('proto.jspb.test.CloneExtension', test_pb.CloneExtension, global); + * googleProtobuf.exportSymbol('proto.jspb.test.Complex', test_pb.Complex, global); + * googleProtobuf.exportSymbol('proto.jspb.test.DefaultValues', test_pb.DefaultValues, global); + * + * (The "exportSymbol" function will define the given names in the global + * namespace, taking care not to overwrite any previous value for + * "proto.jspb.test"). + */ + +var lineReader = require('readline').createInterface({ + input: process.stdin, + output: process.stdout +}); + +function tryStripPrefix(str, prefix) { + if (str.lastIndexOf(prefix) !== 0) { + throw "String: " + str + " didn't start with: " + prefix; + } + return str.substr(prefix.length); +} + +function camelCase(str) { + var ret = ''; + var ucaseNext = false; + for (var i = 0; i < str.length; i++) { + if (str[i] == '-') { + ucaseNext = true; + } else if (ucaseNext) { + ret += str[i].toUpperCase(); + ucaseNext = false; + } else { + ret += str[i]; + } + } + return ret; +} + +var module = null; +var pkg = null; +lineReader.on('line', function(line) { + var isRequire = line.match(/goog\.require\('([^']*)'\)/); + var isLoadFromFile = line.match(/CommonJS-LoadFromFile: (\S*) (.*)/); + var isSetTestOnly = line.match(/goog.setTestOnly()/); + if (isRequire) { + if (module) { // Skip goog.require() lines before the first directive. + var fullSym = isRequire[1]; + var sym = tryStripPrefix(fullSym, pkg); + console.log("googleProtobuf.exportSymbol('" + fullSym + "', " + module + sym + ', global);'); + } + } else if (isLoadFromFile) { + if (!module) { + console.log("var googleProtobuf = require('google-protobuf');"); + console.log("var asserts = require('closure_asserts_commonjs');"); + console.log("var global = Function('return this')();"); + console.log(""); + console.log("// Bring asserts into the global namespace."); + console.log("googleProtobuf.object.extend(global, asserts);"); + } + var module_path = isLoadFromFile[1].split('/'); + module = camelCase(module_path[module_path.length - 1]); + pkg = isLoadFromFile[2]; + + if (module != "googleProtobuf") { // We unconditionally require this in the header. + console.log("var " + module + " = require('./" + isLoadFromFile[1] + "');"); + } + } else if (!isSetTestOnly) { // Remove goog.setTestOnly() lines. + console.log(line); + } +}); diff --git a/js/commonjs/test6/test6.proto b/js/commonjs/test6/test6.proto new file mode 100644 index 00000000..a060925f --- /dev/null +++ b/js/commonjs/test6/test6.proto @@ -0,0 +1,40 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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. + +syntax = "proto3"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.test.importing; + +message ImportedMessage { + string string_value = 1; +} diff --git a/js/commonjs/test7/test7.proto b/js/commonjs/test7/test7.proto new file mode 100644 index 00000000..f5574a3d --- /dev/null +++ b/js/commonjs/test7/test7.proto @@ -0,0 +1,42 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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. + +syntax = "proto3"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.test.framing; + +import "test6/test6.proto"; + +message FramingMessage { + jspb.test.importing.ImportedMessage imported_message = 1; +} diff --git a/js/debug_test.js b/js/debug_test.js index 615fc7c6..d7bf3768 100644 --- a/js/debug_test.js +++ b/js/debug_test.js @@ -31,13 +31,16 @@ goog.setTestOnly(); goog.require('goog.testing.asserts'); + +// CommonJS-LoadFromFile: google-protobuf goog.require('jspb.debug'); + +// CommonJS-LoadFromFile: test_pb goog.require('proto.jspb.test.HasExtensions'); goog.require('proto.jspb.test.IsExtension'); goog.require('proto.jspb.test.Simple1'); - describe('debugTest', function() { it('testSimple1', function() { if (COMPILED) { diff --git a/js/gulpfile.js b/js/gulpfile.js index 79095d65..36fd9fda 100644 --- a/js/gulpfile.js +++ b/js/gulpfile.js @@ -1,25 +1,80 @@ var gulp = require('gulp'); var exec = require('child_process').exec; +var glob = require('glob'); -gulp.task('genproto', function (cb) { - exec('../src/protoc --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto', +var protoc = process.env.PROTOC || '../src/protoc'; + +gulp.task('genproto_closure', function (cb) { + exec(protoc + ' --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto', + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('genproto_commonjs', function (cb) { + exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . *.proto commonjs/test*/*.proto ../src/google/protobuf/descriptor.proto', + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('dist', function (cb) { + // TODO(haberman): minify this more aggressively. + // Will require proper externs/exports. + exec('./node_modules/google-closure-library/closure/bin/calcdeps.py -i message.js -i binary/reader.js -i binary/writer.js -i commonjs/export.js -p . -p node_modules/google-closure-library/closure -o compiled --compiler_jar node_modules/google-closure-compiler/compiler.jar > google-protobuf.js', + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('commonjs_asserts', function (cb) { + exec('mkdir -p commonjs_out/test_node_modules && ./node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_asserts.js -p . -p node_modules/google-closure-library/closure -o compiled --compiler_jar node_modules/google-closure-compiler/compiler.jar > commonjs_out/test_node_modules/closure_asserts_commonjs.js', function (err, stdout, stderr) { console.log(stdout); console.log(stderr); cb(err); }); -}) +}); + +gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'commonjs_asserts'], function (cb) { + // TODO(haberman): minify this more aggressively. + // Will require proper externs/exports. + var cmd = "mkdir -p commonjs_out/binary && mkdir -p commonjs_out/test_node_modules && "; + function addTestFile(file) { + cmd += 'node commonjs/rewrite_tests_for_commonjs.js < ' + file + + ' > commonjs_out/' + file + '&& '; + } + + glob.sync('*_test.js').forEach(addTestFile); + glob.sync('binary/*_test.js').forEach(addTestFile); + + exec(cmd + + 'cp commonjs/jasmine.json commonjs_out/jasmine.json && ' + + 'cp google-protobuf.js commonjs_out/test_node_modules && ' + + 'cp commonjs/import_test.js commonjs_out/import_test.js', + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); -gulp.task('deps', ['genproto'], function (cb) { +gulp.task('deps', ['genproto_closure'], function (cb) { exec('./node_modules/google-closure-library/closure/bin/build/depswriter.py *.js binary/*.js > deps.js', function (err, stdout, stderr) { console.log(stdout); console.log(stderr); cb(err); }); -}) +}); -gulp.task('test', ['genproto', 'deps'], function (cb) { +gulp.task('test_closure', ['genproto_closure', 'deps'], function (cb) { exec('JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine', function (err, stdout, stderr) { console.log(stdout); @@ -27,3 +82,16 @@ gulp.task('test', ['genproto', 'deps'], function (cb) { cb(err); }); }); + +gulp.task('test_commonjs', ['make_commonjs_out'], function (cb) { + exec('cd commonjs_out && JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../node_modules/.bin/jasmine', + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('test', ['test_closure', 'test_commonjs'], function(cb) { + cb(); +}); diff --git a/js/message_test.js b/js/message_test.js index 971ea4f4..f572188e 100644 --- a/js/message_test.js +++ b/js/message_test.js @@ -34,35 +34,47 @@ goog.setTestOnly(); goog.require('goog.json'); goog.require('goog.testing.asserts'); + +// CommonJS-LoadFromFile: google-protobuf jspb goog.require('jspb.Message'); + +// CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta goog.require('proto.jspb.exttest.beta.floatingStrField'); + +// CommonJS-LoadFromFile: test3_pb proto.jspb.exttest goog.require('proto.jspb.exttest.floatingMsgField'); + +// CommonJS-LoadFromFile: test4_pb proto.jspb.exttest goog.require('proto.jspb.exttest.floatingMsgFieldTwo'); + +// CommonJS-LoadFromFile: test_pb proto.jspb.test goog.require('proto.jspb.test.CloneExtension'); goog.require('proto.jspb.test.Complex'); goog.require('proto.jspb.test.DefaultValues'); goog.require('proto.jspb.test.Empty'); goog.require('proto.jspb.test.EnumContainer'); -goog.require('proto.jspb.test.ExtensionMessage'); -goog.require('proto.jspb.test.floatingMsgField'); goog.require('proto.jspb.test.floatingStrField'); goog.require('proto.jspb.test.HasExtensions'); goog.require('proto.jspb.test.IndirectExtension'); goog.require('proto.jspb.test.IsExtension'); goog.require('proto.jspb.test.OptionalFields'); goog.require('proto.jspb.test.OuterEnum'); +goog.require('proto.jspb.test.OuterMessage.Complex'); goog.require('proto.jspb.test.simple1'); goog.require('proto.jspb.test.Simple1'); goog.require('proto.jspb.test.Simple2'); goog.require('proto.jspb.test.SpecialCases'); goog.require('proto.jspb.test.TestClone'); -goog.require('proto.jspb.test.TestExtensionsMessage'); goog.require('proto.jspb.test.TestGroup'); goog.require('proto.jspb.test.TestGroup1'); goog.require('proto.jspb.test.TestMessageWithOneof'); goog.require('proto.jspb.test.TestReservedNames'); goog.require('proto.jspb.test.TestReservedNamesExtension'); +// CommonJS-LoadFromFile: test2_pb proto.jspb.test +goog.require('proto.jspb.test.ExtensionMessage'); +goog.require('proto.jspb.test.TestExtensionsMessage'); +goog.require('proto.jspb.test.floatingMsgField'); @@ -86,6 +98,12 @@ describe('Message test suite', function() { assertEquals('some_bytes', data.getBytesField()); }); + it('testNestedMessage', function() { + var msg = new proto.jspb.test.OuterMessage.Complex(); + msg.setInnerComplexField(5); + assertObjectEquals({innerComplexField: 5}, msg.toObject()); + }); + it('testComplexConversion', function() { var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1]; var data2 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1]; diff --git a/js/package.json b/js/package.json index be93286f..6418e507 100644 --- a/js/package.json +++ b/js/package.json @@ -2,13 +2,16 @@ "name": "google-protobuf", "version": "3.0.0-alpha.5", "description": "Protocol Buffers for JavaScript", - "main": "debug.js", + "main": "google-protobuf.js", "dependencies": { "google-closure-library": "~20160125.0.0", "gulp": "~3.9.0", "jasmine": "~2.4.1" }, - "devDependencies": {}, + "devDependencies": { + "google-closure-compiler": "~20151216.2.0", + "glob": "~6.0.4" + }, "scripts": { "test": "./node_modules/gulp/bin/gulp.js test" }, diff --git a/js/proto3_test.js b/js/proto3_test.js index 8102bab6..f8868716 100644 --- a/js/proto3_test.js +++ b/js/proto3_test.js @@ -29,7 +29,11 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. goog.require('goog.testing.asserts'); + +// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test goog.require('proto.jspb.test.ForeignMessage'); + +// CommonJS-LoadFromFile: proto3_test_pb proto.jspb.test goog.require('proto.jspb.test.Proto3Enum'); goog.require('proto.jspb.test.TestProto3'); diff --git a/js/test.proto b/js/test.proto index 5f9078ef..14418ac9 100644 --- a/js/test.proto +++ b/js/test.proto @@ -100,6 +100,13 @@ message Complex { repeated string a_repeated_string = 7; } +message OuterMessage { + // Make sure this doesn't conflict with the other Complex message. + message Complex { + optional int32 inner_complex_field = 1; + } +} + message IsExtension { extend HasExtensions { optional IsExtension ext_field = 100; @@ -209,4 +216,3 @@ message TestMessageWithOneof { int32 btwo = 13 [default = 1234]; } } - diff --git a/objectivec/GPBCodedInputStream.h b/objectivec/GPBCodedInputStream.h index 42a04941..06198883 100644 --- a/objectivec/GPBCodedInputStream.h +++ b/objectivec/GPBCodedInputStream.h @@ -35,52 +35,86 @@ NS_ASSUME_NONNULL_BEGIN -// Reads and decodes protocol message fields. -// Subclassing of GPBCodedInputStream is NOT supported. +/// Reads and decodes protocol message fields. +/// +/// The common uses of protocol buffers shouldn't need to use this class. +/// @c GPBMessage's provide a @c +parseFromData:error: and @c +/// +parseFromData:extensionRegistry:error: method that will decode a +/// message for you. +/// +/// @note Subclassing of GPBCodedInputStream is NOT supported. @interface GPBCodedInputStream : NSObject +/// Creates a new stream wrapping some data. + (instancetype)streamWithData:(NSData *)data; + +/// Initializes a stream wrapping some data. - (instancetype)initWithData:(NSData *)data; -// Attempt to read a field tag, returning zero if we have reached EOF. -// Protocol message parsers use this to read tags, since a protocol message -// may legally end wherever a tag occurs, and zero is not a valid tag number. +/// Attempt to read a field tag, returning zero if we have reached EOF. +/// Protocol message parsers use this to read tags, since a protocol message +/// may legally end wherever a tag occurs, and zero is not a valid tag number. - (int32_t)readTag; +/// Read and return a double. - (double)readDouble; +/// Read and return a float. - (float)readFloat; +/// Read and return a uint64. - (uint64_t)readUInt64; +/// Read and return a uint32. - (uint32_t)readUInt32; +/// Read and return an int64. - (int64_t)readInt64; +/// Read and return an int32. - (int32_t)readInt32; +/// Read and return a fixed64. - (uint64_t)readFixed64; +/// Read and return a fixed32. - (uint32_t)readFixed32; +/// Read and return an enum (int). - (int32_t)readEnum; +/// Read and return a sfixed32. - (int32_t)readSFixed32; +/// Read and return a sfixed64. - (int64_t)readSFixed64; +/// Read and return a sint32. - (int32_t)readSInt32; +/// Read and return a sint64. - (int64_t)readSInt64; +/// Read and return a boolean. - (BOOL)readBool; +/// Read and return a string. - (NSString *)readString; +/// Read and return length delimited data. - (NSData *)readBytes; -// Read an embedded message field value from the stream. +/// Read an embedded message field value from the stream. +/// +/// @param message The message to set fields on as they are read. +/// @param extensionRegistry An optional extension registry to use to lookup +/// extensions for @message. - (void)readMessage:(GPBMessage *)message - extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; + extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; -// Reads and discards a single field, given its tag value. Returns NO if the -// tag is an endgroup tag, in which case nothing is skipped. Otherwise, -// returns YES. +/// Reads and discards a single field, given its tag value. +/// +/// @param tag The tag number of the field to skip. +/// +/// @return NO if the tag is an endgroup tag (in which case nothing is skipped), +/// YES in all other cases. - (BOOL)skipField:(int32_t)tag; -// Reads and discards an entire message. This will read either until EOF -// or until an endgroup tag, whichever comes first. +/// Reads and discards an entire message. This will read either until EOF +/// or until an endgroup tag, whichever comes first. - (void)skipMessage; -// Verifies that the last call to readTag() returned the given tag value. -// This is used to verify that a nested group ended with the correct end tag. -// Throws NSParseErrorException if value does not match the last tag. -- (void)checkLastTagWas:(int32_t)value; +/// Verifies that the last call to @c -readTag returned the given tag value. +/// This is used to verify that a nested group ended with the correct end tag. +/// Throws @c NSParseErrorException if value does not match the last tag. +/// +/// @param expected The tag that was expected. +- (void)checkLastTagWas:(int32_t)expected; @end diff --git a/objectivec/GPBCodedOutputStream.h b/objectivec/GPBCodedOutputStream.h index a5aef170..e67efd2d 100644 --- a/objectivec/GPBCodedOutputStream.h +++ b/objectivec/GPBCodedOutputStream.h @@ -46,36 +46,63 @@ NS_ASSUME_NONNULL_BEGIN +/// Writes out protocol message fields. +/// +/// The common uses of protocol buffers shouldn't need to use this class. +/// @c GPBMessage's provide a @c -data method that will serialize the message +/// for you. +/// +/// @note Subclassing of GPBCodedOutputStream is NOT supported. @interface GPBCodedOutputStream : NSObject -// Creates a new stream to write into data. Data must be sized to fit or it -// will error when it runs out of space. +/// Creates a stream to fill in the given data. Data must be sized to fit or +/// an error will be raised when out of space. + (instancetype)streamWithData:(NSMutableData *)data; + +/// Creates a stream to write into the given @c NSOutputStream. + (instancetype)streamWithOutputStream:(NSOutputStream *)output; -+ (instancetype)streamWithOutputStream:(NSOutputStream *)output - bufferSize:(size_t)bufferSize; +/// Initializes a stream to fill in the given data. Data must be sized to fit +/// or an error will be raised when out of space. - (instancetype)initWithData:(NSMutableData *)data; + +/// Initializes a stream to write into the given @c NSOutputStream. - (instancetype)initWithOutputStream:(NSOutputStream *)output; -- (instancetype)initWithOutputStream:(NSOutputStream *)output - bufferSize:(size_t)bufferSize; +/// Flush any buffered data out. - (void)flush; +/// Write the raw byte out. - (void)writeRawByte:(uint8_t)value; +/// Write the tag for the given field number and wire format. +/// +/// @param fieldNumber The field number. +/// @param format The wire format the data for the field will be in. - (void)writeTag:(uint32_t)fieldNumber format:(GPBWireFormat)format; +/// Write a 32bit value out in little endian format. - (void)writeRawLittleEndian32:(int32_t)value; +/// Write a 64bit value out in little endian format. - (void)writeRawLittleEndian64:(int64_t)value; +/// Write a 32bit value out in varint format. - (void)writeRawVarint32:(int32_t)value; +/// Write a 64bit value out in varint format. - (void)writeRawVarint64:(int64_t)value; -// Note that this will truncate 64 bit values to 32. +/// Write a size_t out as a 32bit varint value. +/// +/// @note This will truncate 64 bit values to 32. - (void)writeRawVarintSizeTAs32:(size_t)value; +/// Writes the contents of an @c NSData out. - (void)writeRawData:(NSData *)data; +/// Writes out the given data. +/// +/// @param data The data blob to write out. +/// @param offset The offset into the blob to start writing out. +/// @param length The number of bytes from the blob to write out. - (void)writeRawPtr:(const void *)data offset:(size_t)offset length:(size_t)length; @@ -83,240 +110,215 @@ NS_ASSUME_NONNULL_BEGIN //%PDDM-EXPAND _WRITE_DECLS() // This block of code is generated, do not edit it directly. +/// Write a double for the given field number. - (void)writeDouble:(int32_t)fieldNumber value:(double)value; +/// Write a packaged array of double for the given field number. - (void)writeDoubleArray:(int32_t)fieldNumber values:(GPBDoubleArray *)values tag:(uint32_t)tag; +/// Write a double without any tag. - (void)writeDoubleNoTag:(double)value; +/// Write a float for the given field number. - (void)writeFloat:(int32_t)fieldNumber value:(float)value; +/// Write a packaged array of float for the given field number. - (void)writeFloatArray:(int32_t)fieldNumber values:(GPBFloatArray *)values tag:(uint32_t)tag; +/// Write a float without any tag. - (void)writeFloatNoTag:(float)value; +/// Write a uint64_t for the given field number. - (void)writeUInt64:(int32_t)fieldNumber value:(uint64_t)value; +/// Write a packaged array of uint64_t for the given field number. - (void)writeUInt64Array:(int32_t)fieldNumber values:(GPBUInt64Array *)values tag:(uint32_t)tag; +/// Write a uint64_t without any tag. - (void)writeUInt64NoTag:(uint64_t)value; +/// Write a int64_t for the given field number. - (void)writeInt64:(int32_t)fieldNumber value:(int64_t)value; +/// Write a packaged array of int64_t for the given field number. - (void)writeInt64Array:(int32_t)fieldNumber values:(GPBInt64Array *)values tag:(uint32_t)tag; +/// Write a int64_t without any tag. - (void)writeInt64NoTag:(int64_t)value; +/// Write a int32_t for the given field number. - (void)writeInt32:(int32_t)fieldNumber value:(int32_t)value; +/// Write a packaged array of int32_t for the given field number. - (void)writeInt32Array:(int32_t)fieldNumber values:(GPBInt32Array *)values tag:(uint32_t)tag; +/// Write a int32_t without any tag. - (void)writeInt32NoTag:(int32_t)value; +/// Write a uint32_t for the given field number. - (void)writeUInt32:(int32_t)fieldNumber value:(uint32_t)value; +/// Write a packaged array of uint32_t for the given field number. - (void)writeUInt32Array:(int32_t)fieldNumber values:(GPBUInt32Array *)values tag:(uint32_t)tag; +/// Write a uint32_t without any tag. - (void)writeUInt32NoTag:(uint32_t)value; +/// Write a uint64_t for the given field number. - (void)writeFixed64:(int32_t)fieldNumber value:(uint64_t)value; +/// Write a packaged array of uint64_t for the given field number. - (void)writeFixed64Array:(int32_t)fieldNumber values:(GPBUInt64Array *)values tag:(uint32_t)tag; +/// Write a uint64_t without any tag. - (void)writeFixed64NoTag:(uint64_t)value; +/// Write a uint32_t for the given field number. - (void)writeFixed32:(int32_t)fieldNumber value:(uint32_t)value; +/// Write a packaged array of uint32_t for the given field number. - (void)writeFixed32Array:(int32_t)fieldNumber values:(GPBUInt32Array *)values tag:(uint32_t)tag; +/// Write a uint32_t without any tag. - (void)writeFixed32NoTag:(uint32_t)value; +/// Write a int32_t for the given field number. - (void)writeSInt32:(int32_t)fieldNumber value:(int32_t)value; +/// Write a packaged array of int32_t for the given field number. - (void)writeSInt32Array:(int32_t)fieldNumber values:(GPBInt32Array *)values tag:(uint32_t)tag; +/// Write a int32_t without any tag. - (void)writeSInt32NoTag:(int32_t)value; +/// Write a int64_t for the given field number. - (void)writeSInt64:(int32_t)fieldNumber value:(int64_t)value; +/// Write a packaged array of int64_t for the given field number. - (void)writeSInt64Array:(int32_t)fieldNumber values:(GPBInt64Array *)values tag:(uint32_t)tag; +/// Write a int64_t without any tag. - (void)writeSInt64NoTag:(int64_t)value; +/// Write a int64_t for the given field number. - (void)writeSFixed64:(int32_t)fieldNumber value:(int64_t)value; +/// Write a packaged array of int64_t for the given field number. - (void)writeSFixed64Array:(int32_t)fieldNumber values:(GPBInt64Array *)values tag:(uint32_t)tag; +/// Write a int64_t without any tag. - (void)writeSFixed64NoTag:(int64_t)value; +/// Write a int32_t for the given field number. - (void)writeSFixed32:(int32_t)fieldNumber value:(int32_t)value; +/// Write a packaged array of int32_t for the given field number. - (void)writeSFixed32Array:(int32_t)fieldNumber values:(GPBInt32Array *)values tag:(uint32_t)tag; +/// Write a int32_t without any tag. - (void)writeSFixed32NoTag:(int32_t)value; +/// Write a BOOL for the given field number. - (void)writeBool:(int32_t)fieldNumber value:(BOOL)value; +/// Write a packaged array of BOOL for the given field number. - (void)writeBoolArray:(int32_t)fieldNumber values:(GPBBoolArray *)values tag:(uint32_t)tag; +/// Write a BOOL without any tag. - (void)writeBoolNoTag:(BOOL)value; +/// Write a int32_t for the given field number. - (void)writeEnum:(int32_t)fieldNumber value:(int32_t)value; +/// Write a packaged array of int32_t for the given field number. - (void)writeEnumArray:(int32_t)fieldNumber values:(GPBEnumArray *)values tag:(uint32_t)tag; +/// Write a int32_t without any tag. - (void)writeEnumNoTag:(int32_t)value; +/// Write a NSString for the given field number. - (void)writeString:(int32_t)fieldNumber value:(NSString *)value; -- (void)writeStringArray:(int32_t)fieldNumber values:(NSArray *)values; +/// Write an array of NSString for the given field number. +- (void)writeStringArray:(int32_t)fieldNumber values:(NSArray<NSString*> *)values; +/// Write a NSString without any tag. - (void)writeStringNoTag:(NSString *)value; +/// Write a GPBMessage for the given field number. - (void)writeMessage:(int32_t)fieldNumber value:(GPBMessage *)value; -- (void)writeMessageArray:(int32_t)fieldNumber values:(NSArray *)values; +/// Write an array of GPBMessage for the given field number. +- (void)writeMessageArray:(int32_t)fieldNumber values:(NSArray<GPBMessage*> *)values; +/// Write a GPBMessage without any tag. - (void)writeMessageNoTag:(GPBMessage *)value; +/// Write a NSData for the given field number. - (void)writeBytes:(int32_t)fieldNumber value:(NSData *)value; -- (void)writeBytesArray:(int32_t)fieldNumber values:(NSArray *)values; +/// Write an array of NSData for the given field number. +- (void)writeBytesArray:(int32_t)fieldNumber values:(NSArray<NSData*> *)values; +/// Write a NSData without any tag. - (void)writeBytesNoTag:(NSData *)value; +/// Write a GPBMessage for the given field number. - (void)writeGroup:(int32_t)fieldNumber value:(GPBMessage *)value; -- (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray *)values; +/// Write an array of GPBMessage for the given field number. +- (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray<GPBMessage*> *)values; +/// Write a GPBMessage without any tag (but does write the endGroup tag). - (void)writeGroupNoTag:(int32_t)fieldNumber value:(GPBMessage *)value; +/// Write a GPBUnknownFieldSet for the given field number. - (void)writeUnknownGroup:(int32_t)fieldNumber value:(GPBUnknownFieldSet *)value; -- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values; +/// Write an array of GPBUnknownFieldSet for the given field number. +- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray<GPBUnknownFieldSet*> *)values; +/// Write a GPBUnknownFieldSet without any tag (but does write the endGroup tag). - (void)writeUnknownGroupNoTag:(int32_t)fieldNumber value:(GPBUnknownFieldSet *)value; //%PDDM-EXPAND-END _WRITE_DECLS() -// Write a MessageSet extension field to the stream. For historical reasons, -// the wire format differs from normal fields. +/// Write a MessageSet extension field to the stream. For historical reasons, +/// the wire format differs from normal fields. - (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value; -// Write an unparsed MessageSet extension field to the stream. For -// historical reasons, the wire format differs from normal fields. +/// Write an unparsed MessageSet extension field to the stream. For +/// historical reasons, the wire format differs from normal fields. - (void)writeRawMessageSetExtension:(int32_t)fieldNumber value:(NSData *)value; @end -CF_EXTERN_C_BEGIN - -size_t GPBComputeDoubleSize(int32_t fieldNumber, double value) - __attribute__((const)); -size_t GPBComputeFloatSize(int32_t fieldNumber, float value) - __attribute__((const)); -size_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value) - __attribute__((const)); -size_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value) - __attribute__((const)); -size_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value) - __attribute__((const)); -size_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value) - __attribute__((const)); -size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) - __attribute__((const)); -size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) - __attribute__((const)); -size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) - __attribute__((const)); -size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) - __attribute__((const)); -size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, - GPBUnknownFieldSet *value) - __attribute__((const)); -size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) - __attribute__((const)); -size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) - __attribute__((const)); -size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) - __attribute__((const)); -size_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value) - __attribute__((const)); -size_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value) - __attribute__((const)); -size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value) - __attribute__((const)); -size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value) - __attribute__((const)); -size_t GPBComputeTagSize(int32_t fieldNumber) __attribute__((const)); -size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType) - __attribute__((const)); - -size_t GPBComputeDoubleSizeNoTag(double value) __attribute__((const)); -size_t GPBComputeFloatSizeNoTag(float value) __attribute__((const)); -size_t GPBComputeUInt64SizeNoTag(uint64_t value) __attribute__((const)); -size_t GPBComputeInt64SizeNoTag(int64_t value) __attribute__((const)); -size_t GPBComputeInt32SizeNoTag(int32_t value) __attribute__((const)); -size_t GPBComputeFixed64SizeNoTag(uint64_t value) __attribute__((const)); -size_t GPBComputeFixed32SizeNoTag(uint32_t value) __attribute__((const)); -size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const)); -size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const)); -size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const)); -size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) - __attribute__((const)); -size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const)); -size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const)); -size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const)); -size_t GPBComputeEnumSizeNoTag(int32_t value) __attribute__((const)); -size_t GPBComputeSFixed32SizeNoTag(int32_t value) __attribute__((const)); -size_t GPBComputeSFixed64SizeNoTag(int64_t value) __attribute__((const)); -size_t GPBComputeSInt32SizeNoTag(int32_t value) __attribute__((const)); -size_t GPBComputeSInt64SizeNoTag(int64_t value) __attribute__((const)); - -// Note that this will calculate the size of 64 bit values truncated to 32. -size_t GPBComputeSizeTSizeAsInt32NoTag(size_t value) __attribute__((const)); - -size_t GPBComputeRawVarint32Size(int32_t value) __attribute__((const)); -size_t GPBComputeRawVarint64Size(int64_t value) __attribute__((const)); - -// Note that this will calculate the size of 64 bit values truncated to 32. -size_t GPBComputeRawVarint32SizeForInteger(NSInteger value) - __attribute__((const)); - -// Compute the number of bytes that would be needed to encode a -// MessageSet extension to the stream. For historical reasons, -// the wire format differs from normal fields. -size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber, GPBMessage *value) - __attribute__((const)); - -// Compute the number of bytes that would be needed to encode an -// unparsed MessageSet extension field to the stream. For -// historical reasons, the wire format differs from normal fields. -size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber, NSData *value) - __attribute__((const)); - -size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value) - __attribute__((const)); - -CF_EXTERN_C_END - NS_ASSUME_NONNULL_END // Write methods for types that can be in packed arrays. //%PDDM-DEFINE _WRITE_PACKABLE_DECLS(NAME, ARRAY_TYPE, TYPE) +//%/// Write a TYPE for the given field number. //%- (void)write##NAME:(int32_t)fieldNumber value:(TYPE)value; +//%/// Write a packaged array of TYPE for the given field number. //%- (void)write##NAME##Array:(int32_t)fieldNumber //% NAME$S values:(GPB##ARRAY_TYPE##Array *)values //% NAME$S tag:(uint32_t)tag; +//%/// Write a TYPE without any tag. //%- (void)write##NAME##NoTag:(TYPE)value; //% // Write methods for types that aren't in packed arrays. //%PDDM-DEFINE _WRITE_UNPACKABLE_DECLS(NAME, TYPE) -//%- (void)write##NAME:(int32_t)fieldNumber value:(TYPE)value; -//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray *)values; -//%- (void)write##NAME##NoTag:(TYPE)value; +//%/// Write a TYPE for the given field number. +//%- (void)write##NAME:(int32_t)fieldNumber value:(TYPE *)value; +//%/// Write an array of TYPE for the given field number. +//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray<##TYPE##*> *)values; +//%/// Write a TYPE without any tag. +//%- (void)write##NAME##NoTag:(TYPE *)value; //% // Special write methods for Groups. //%PDDM-DEFINE _WRITE_GROUP_DECLS(NAME, TYPE) +//%/// Write a TYPE for the given field number. //%- (void)write##NAME:(int32_t)fieldNumber -//% NAME$S value:(TYPE)value; -//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray *)values; +//% NAME$S value:(TYPE *)value; +//%/// Write an array of TYPE for the given field number. +//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray<##TYPE##*> *)values; +//%/// Write a TYPE without any tag (but does write the endGroup tag). //%- (void)write##NAME##NoTag:(int32_t)fieldNumber -//% NAME$S value:(TYPE)value; +//% NAME$S value:(TYPE *)value; //% // One macro to hide it all up above. @@ -335,8 +337,8 @@ NS_ASSUME_NONNULL_END //%_WRITE_PACKABLE_DECLS(SFixed32, Int32, int32_t) //%_WRITE_PACKABLE_DECLS(Bool, Bool, BOOL) //%_WRITE_PACKABLE_DECLS(Enum, Enum, int32_t) -//%_WRITE_UNPACKABLE_DECLS(String, NSString *) -//%_WRITE_UNPACKABLE_DECLS(Message, GPBMessage *) -//%_WRITE_UNPACKABLE_DECLS(Bytes, NSData *) -//%_WRITE_GROUP_DECLS(Group, GPBMessage *) -//%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet *) +//%_WRITE_UNPACKABLE_DECLS(String, NSString) +//%_WRITE_UNPACKABLE_DECLS(Message, GPBMessage) +//%_WRITE_UNPACKABLE_DECLS(Bytes, NSData) +//%_WRITE_GROUP_DECLS(Group, GPBMessage) +//%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet) diff --git a/objectivec/GPBCodedOutputStream.m b/objectivec/GPBCodedOutputStream.m index 70142e6f..fd9ed66c 100644 --- a/objectivec/GPBCodedOutputStream.m +++ b/objectivec/GPBCodedOutputStream.m @@ -28,7 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#import "GPBCodedOutputStream.h" +#import "GPBCodedOutputStream_PackagePrivate.h" #import <mach/vm_param.h> @@ -178,12 +178,6 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, return [self initWithOutputStream:nil data:data]; } -- (instancetype)initWithOutputStream:(NSOutputStream *)output - bufferSize:(size_t)bufferSize { - NSMutableData *data = [NSMutableData dataWithLength:bufferSize]; - return [self initWithOutputStream:output data:data]; -} - // This initializer isn't exposed, but it is the designated initializer. // Setting OutputStream and NSData is to control the buffering behavior/size // of the work, but that is more obvious via the bufferSize: version. @@ -199,15 +193,10 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, return self; } -+ (instancetype)streamWithOutputStream:(NSOutputStream *)output - bufferSize:(size_t)bufferSize { - return [[[self alloc] initWithOutputStream:output - bufferSize:bufferSize] autorelease]; -} - + (instancetype)streamWithOutputStream:(NSOutputStream *)output { + NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE]; return [[[self alloc] initWithOutputStream:output - bufferSize:PAGE_SIZE] autorelease]; + data:data] autorelease]; } + (instancetype)streamWithData:(NSMutableData *)data { diff --git a/objectivec/GPBCodedOutputStream_PackagePrivate.h b/objectivec/GPBCodedOutputStream_PackagePrivate.h new file mode 100644 index 00000000..2e7bb4c4 --- /dev/null +++ b/objectivec/GPBCodedOutputStream_PackagePrivate.h @@ -0,0 +1,126 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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. + +#import "GPBCodedOutputStream.h" + +NS_ASSUME_NONNULL_BEGIN + +CF_EXTERN_C_BEGIN + +size_t GPBComputeDoubleSize(int32_t fieldNumber, double value) + __attribute__((const)); +size_t GPBComputeFloatSize(int32_t fieldNumber, float value) + __attribute__((const)); +size_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value) + __attribute__((const)); +size_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value) + __attribute__((const)); +size_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value) + __attribute__((const)); +size_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value) + __attribute__((const)); +size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) + __attribute__((const)); +size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) + __attribute__((const)); +size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) + __attribute__((const)); +size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) + __attribute__((const)); +size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, + GPBUnknownFieldSet *value) + __attribute__((const)); +size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) + __attribute__((const)); +size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) + __attribute__((const)); +size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) + __attribute__((const)); +size_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value) + __attribute__((const)); +size_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value) + __attribute__((const)); +size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value) + __attribute__((const)); +size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value) + __attribute__((const)); +size_t GPBComputeTagSize(int32_t fieldNumber) __attribute__((const)); +size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType) + __attribute__((const)); + +size_t GPBComputeDoubleSizeNoTag(double value) __attribute__((const)); +size_t GPBComputeFloatSizeNoTag(float value) __attribute__((const)); +size_t GPBComputeUInt64SizeNoTag(uint64_t value) __attribute__((const)); +size_t GPBComputeInt64SizeNoTag(int64_t value) __attribute__((const)); +size_t GPBComputeInt32SizeNoTag(int32_t value) __attribute__((const)); +size_t GPBComputeFixed64SizeNoTag(uint64_t value) __attribute__((const)); +size_t GPBComputeFixed32SizeNoTag(uint32_t value) __attribute__((const)); +size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const)); +size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const)); +size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const)); +size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) + __attribute__((const)); +size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const)); +size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const)); +size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const)); +size_t GPBComputeEnumSizeNoTag(int32_t value) __attribute__((const)); +size_t GPBComputeSFixed32SizeNoTag(int32_t value) __attribute__((const)); +size_t GPBComputeSFixed64SizeNoTag(int64_t value) __attribute__((const)); +size_t GPBComputeSInt32SizeNoTag(int32_t value) __attribute__((const)); +size_t GPBComputeSInt64SizeNoTag(int64_t value) __attribute__((const)); + +// Note that this will calculate the size of 64 bit values truncated to 32. +size_t GPBComputeSizeTSizeAsInt32NoTag(size_t value) __attribute__((const)); + +size_t GPBComputeRawVarint32Size(int32_t value) __attribute__((const)); +size_t GPBComputeRawVarint64Size(int64_t value) __attribute__((const)); + +// Note that this will calculate the size of 64 bit values truncated to 32. +size_t GPBComputeRawVarint32SizeForInteger(NSInteger value) + __attribute__((const)); + +// Compute the number of bytes that would be needed to encode a +// MessageSet extension to the stream. For historical reasons, +// the wire format differs from normal fields. +size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber, GPBMessage *value) + __attribute__((const)); + +// Compute the number of bytes that would be needed to encode an +// unparsed MessageSet extension field to the stream. For +// historical reasons, the wire format differs from normal fields. +size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber, NSData *value) + __attribute__((const)); + +size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value) + __attribute__((const)); + +CF_EXTERN_C_END + +NS_ASSUME_NONNULL_END diff --git a/objectivec/GPBDescriptor.h b/objectivec/GPBDescriptor.h index 360afe96..8d8e9754 100644 --- a/objectivec/GPBDescriptor.h +++ b/objectivec/GPBDescriptor.h @@ -55,9 +55,9 @@ typedef NS_ENUM(NSInteger, GPBFieldType) { @interface GPBDescriptor : NSObject<NSCopying> @property(nonatomic, readonly, copy) NSString *name; -@property(nonatomic, readonly, strong, nullable) NSArray *fields; -@property(nonatomic, readonly, strong, nullable) NSArray *oneofs; -@property(nonatomic, readonly, strong, nullable) NSArray *enums; +@property(nonatomic, readonly, strong, nullable) NSArray<GPBFieldDescriptor*> *fields; +@property(nonatomic, readonly, strong, nullable) NSArray<GPBOneofDescriptor*> *oneofs; +@property(nonatomic, readonly, strong, nullable) NSArray<GPBEnumDescriptor*> *enums; @property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges; @property(nonatomic, readonly) NSUInteger extensionRangesCount; @property(nonatomic, readonly, assign) GPBFileDescriptor *file; @@ -81,7 +81,7 @@ typedef NS_ENUM(NSInteger, GPBFieldType) { @interface GPBOneofDescriptor : NSObject @property(nonatomic, readonly) NSString *name; -@property(nonatomic, readonly) NSArray *fields; +@property(nonatomic, readonly) NSArray<GPBFieldDescriptor*> *fields; - (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber; - (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name; diff --git a/objectivec/GPBDictionary.h b/objectivec/GPBDictionary.h index 6961cfc3..3120814a 100644 --- a/objectivec/GPBDictionary.h +++ b/objectivec/GPBDictionary.h @@ -355,33 +355,33 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - UInt32 -> Object -@interface GPBUInt32ObjectDictionary : NSObject <NSCopying> +@interface GPBUInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying> @property(nonatomic, readonly) NSUInteger count; + (instancetype)dictionary; -+ (instancetype)dictionaryWithObject:(id)object ++ (instancetype)dictionaryWithObject:(ObjectType)object forKey:(uint32_t)key; -+ (instancetype)dictionaryWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects ++ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const uint32_t [])keys count:(NSUInteger)count; + (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary; + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems; -- (instancetype)initWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects +- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const uint32_t [])keys count:(NSUInteger)count NS_DESIGNATED_INITIALIZER; - (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary; - (instancetype)initWithCapacity:(NSUInteger)numItems; -- (id)objectForKey:(uint32_t)key; +- (ObjectType)objectForKey:(uint32_t)key; - (void)enumerateKeysAndObjectsUsingBlock: - (void (^)(uint32_t key, id object, BOOL *stop))block; + (void (^)(uint32_t key, ObjectType object, BOOL *stop))block; - (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary; -- (void)setObject:(id)object forKey:(uint32_t)key; +- (void)setObject:(ObjectType)object forKey:(uint32_t)key; - (void)removeObjectForKey:(uint32_t)aKey; - (void)removeAll; @@ -701,33 +701,33 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Int32 -> Object -@interface GPBInt32ObjectDictionary : NSObject <NSCopying> +@interface GPBInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying> @property(nonatomic, readonly) NSUInteger count; + (instancetype)dictionary; -+ (instancetype)dictionaryWithObject:(id)object ++ (instancetype)dictionaryWithObject:(ObjectType)object forKey:(int32_t)key; -+ (instancetype)dictionaryWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects ++ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const int32_t [])keys count:(NSUInteger)count; + (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary; + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems; -- (instancetype)initWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects +- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const int32_t [])keys count:(NSUInteger)count NS_DESIGNATED_INITIALIZER; - (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary; - (instancetype)initWithCapacity:(NSUInteger)numItems; -- (id)objectForKey:(int32_t)key; +- (ObjectType)objectForKey:(int32_t)key; - (void)enumerateKeysAndObjectsUsingBlock: - (void (^)(int32_t key, id object, BOOL *stop))block; + (void (^)(int32_t key, ObjectType object, BOOL *stop))block; - (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary; -- (void)setObject:(id)object forKey:(int32_t)key; +- (void)setObject:(ObjectType)object forKey:(int32_t)key; - (void)removeObjectForKey:(int32_t)aKey; - (void)removeAll; @@ -1047,33 +1047,33 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - UInt64 -> Object -@interface GPBUInt64ObjectDictionary : NSObject <NSCopying> +@interface GPBUInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying> @property(nonatomic, readonly) NSUInteger count; + (instancetype)dictionary; -+ (instancetype)dictionaryWithObject:(id)object ++ (instancetype)dictionaryWithObject:(ObjectType)object forKey:(uint64_t)key; -+ (instancetype)dictionaryWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects ++ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const uint64_t [])keys count:(NSUInteger)count; + (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary; + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems; -- (instancetype)initWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects +- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const uint64_t [])keys count:(NSUInteger)count NS_DESIGNATED_INITIALIZER; - (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary; - (instancetype)initWithCapacity:(NSUInteger)numItems; -- (id)objectForKey:(uint64_t)key; +- (ObjectType)objectForKey:(uint64_t)key; - (void)enumerateKeysAndObjectsUsingBlock: - (void (^)(uint64_t key, id object, BOOL *stop))block; + (void (^)(uint64_t key, ObjectType object, BOOL *stop))block; - (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary; -- (void)setObject:(id)object forKey:(uint64_t)key; +- (void)setObject:(ObjectType)object forKey:(uint64_t)key; - (void)removeObjectForKey:(uint64_t)aKey; - (void)removeAll; @@ -1393,33 +1393,33 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Int64 -> Object -@interface GPBInt64ObjectDictionary : NSObject <NSCopying> +@interface GPBInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying> @property(nonatomic, readonly) NSUInteger count; + (instancetype)dictionary; -+ (instancetype)dictionaryWithObject:(id)object ++ (instancetype)dictionaryWithObject:(ObjectType)object forKey:(int64_t)key; -+ (instancetype)dictionaryWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects ++ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const int64_t [])keys count:(NSUInteger)count; + (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary; + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems; -- (instancetype)initWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects +- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const int64_t [])keys count:(NSUInteger)count NS_DESIGNATED_INITIALIZER; - (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary; - (instancetype)initWithCapacity:(NSUInteger)numItems; -- (id)objectForKey:(int64_t)key; +- (ObjectType)objectForKey:(int64_t)key; - (void)enumerateKeysAndObjectsUsingBlock: - (void (^)(int64_t key, id object, BOOL *stop))block; + (void (^)(int64_t key, ObjectType object, BOOL *stop))block; - (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary; -- (void)setObject:(id)object forKey:(int64_t)key; +- (void)setObject:(ObjectType)object forKey:(int64_t)key; - (void)removeObjectForKey:(int64_t)aKey; - (void)removeAll; @@ -1739,33 +1739,33 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Bool -> Object -@interface GPBBoolObjectDictionary : NSObject <NSCopying> +@interface GPBBoolObjectDictionary<__covariant ObjectType> : NSObject <NSCopying> @property(nonatomic, readonly) NSUInteger count; + (instancetype)dictionary; -+ (instancetype)dictionaryWithObject:(id)object ++ (instancetype)dictionaryWithObject:(ObjectType)object forKey:(BOOL)key; -+ (instancetype)dictionaryWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects ++ (instancetype)dictionaryWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const BOOL [])keys count:(NSUInteger)count; + (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary; + (instancetype)dictionaryWithCapacity:(NSUInteger)numItems; -- (instancetype)initWithObjects:(const id GPB_UNSAFE_UNRETAINED [])objects +- (instancetype)initWithObjects:(const ObjectType GPB_UNSAFE_UNRETAINED [])objects forKeys:(const BOOL [])keys count:(NSUInteger)count NS_DESIGNATED_INITIALIZER; - (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary; - (instancetype)initWithCapacity:(NSUInteger)numItems; -- (id)objectForKey:(BOOL)key; +- (ObjectType)objectForKey:(BOOL)key; - (void)enumerateKeysAndObjectsUsingBlock: - (void (^)(BOOL key, id object, BOOL *stop))block; + (void (^)(BOOL key, ObjectType object, BOOL *stop))block; - (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary; -- (void)setObject:(id)object forKey:(BOOL)key; +- (void)setObject:(ObjectType)object forKey:(BOOL)key; - (void)removeObjectForKey:(BOOL)aKey; - (void)removeAll; @@ -2096,7 +2096,7 @@ NS_ASSUME_NONNULL_END //%DICTIONARY_POD_INTERFACES_FOR_KEY(String, NSString, *, OBJECT) //%PDDM-DEFINE DICTIONARY_INTERFACES_FOR_POD_KEY(KEY_NAME, KEY_TYPE) //%DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, , POD) -//%DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, Object, id) +//%DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, Object, ObjectType) //%PDDM-DEFINE DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER) //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt32, uint32_t) //%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int32, int32_t) @@ -2122,10 +2122,16 @@ NS_ASSUME_NONNULL_END // Nothing //%PDDM-DEFINE ARRAY_ARG_MODIFIEROBJECT() //%GPB_UNSAFE_UNRETAINED ## +//%PDDM-DEFINE DICTIONARY_CLASS_DECLPOD(KEY_NAME, VALUE_NAME, VALUE_TYPE) +//%GPB##KEY_NAME##VALUE_NAME##Dictionary +//%PDDM-DEFINE DICTIONARY_CLASS_DECLEnum(KEY_NAME, VALUE_NAME, VALUE_TYPE) +//%GPB##KEY_NAME##VALUE_NAME##Dictionary +//%PDDM-DEFINE DICTIONARY_CLASS_DECLOBJECT(KEY_NAME, VALUE_NAME, VALUE_TYPE) +//%GPB##KEY_NAME##VALUE_NAME##Dictionary<__covariant VALUE_TYPE> //%PDDM-DEFINE DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME) //%#pragma mark - KEY_NAME -> VALUE_NAME //% -//%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary : NSObject <NSCopying> +//%@interface DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) : NSObject <NSCopying> //% //%@property(nonatomic, readonly) NSUInteger count; //% diff --git a/objectivec/GPBDictionary.m b/objectivec/GPBDictionary.m index 6baa2a18..3bd146e0 100644 --- a/objectivec/GPBDictionary.m +++ b/objectivec/GPBDictionary.m @@ -31,7 +31,7 @@ #import "GPBDictionary_PackagePrivate.h" #import "GPBCodedInputStream_PackagePrivate.h" -#import "GPBCodedOutputStream.h" +#import "GPBCodedOutputStream_PackagePrivate.h" #import "GPBDescriptor_PackagePrivate.h" #import "GPBMessage_PackagePrivate.h" #import "GPBUtilities_PackagePrivate.h" diff --git a/objectivec/GPBExtensionInternals.m b/objectivec/GPBExtensionInternals.m index 634c3369..7d0dcb2e 100644 --- a/objectivec/GPBExtensionInternals.m +++ b/objectivec/GPBExtensionInternals.m @@ -33,7 +33,7 @@ #import <objc/runtime.h> #import "GPBCodedInputStream_PackagePrivate.h" -#import "GPBCodedOutputStream.h" +#import "GPBCodedOutputStream_PackagePrivate.h" #import "GPBDescriptor_PackagePrivate.h" #import "GPBMessage_PackagePrivate.h" #import "GPBUtilities_PackagePrivate.h" diff --git a/objectivec/GPBExtensionRegistry.h b/objectivec/GPBExtensionRegistry.h index 0363c70a..08a6472a 100644 --- a/objectivec/GPBExtensionRegistry.h +++ b/objectivec/GPBExtensionRegistry.h @@ -35,30 +35,45 @@ NS_ASSUME_NONNULL_BEGIN -// A table of known extensions, searchable by name or field number. When -// parsing a protocol message that might have extensions, you must provide an -// ExtensionRegistry in which you have registered any extensions that you want -// to be able to parse. Otherwise, those extensions will just be treated like -// unknown fields. -// -// The *Root classes provide +extensionRegistry for the extensions defined in a -// given file *and* all files it imports. You can also create a -// GPBExtensionRegistry, and merge those registries to handle parsing extensions -// defined from non overlapping files. -// -// GPBExtensionRegistry *registry = -// [[[MyProtoFileRoot extensionRegistry] copy] autorelease]; -// [registry addExtension:[OtherMessage neededExtension]; // Not in MyProtoFile -// NSError *parseError = nil; -// MyMessage *msg = [MyMessage parseData:data -// extensionRegistry:registry -// error:&parseError]; -// +/// A table of known extensions, searchable by name or field number. When +/// parsing a protocol message that might have extensions, you must provide a +/// @c GPBExtensionRegistry in which you have registered any extensions that you +/// want to be able to parse. Otherwise, those extensions will just be treated +/// like unknown fields. +/// +/// The @c *Root classes provide @c +extensionRegistry for the extensions defined +/// in a given file *and* all files it imports. You can also create a +/// @c GPBExtensionRegistry, and merge those registries to handle parsing +/// extensions defined from non overlapping files. +/// +/// @code +/// GPBExtensionRegistry *registry = +/// [[[MyProtoFileRoot extensionRegistry] copy] autorelease]; +/// [registry addExtension:[OtherMessage neededExtension]; // Not in MyProtoFile +/// NSError *parseError = nil; +/// MyMessage *msg = [MyMessage parseData:data +/// extensionRegistry:registry +/// error:&parseError]; +/// @endcode @interface GPBExtensionRegistry : NSObject<NSCopying> +/// Add the given @c GPBExtensionDescriptor to this registry. +/// +/// @param extension The extension description to add. - (void)addExtension:(GPBExtensionDescriptor *)extension; + +/// Adds all the extensions from another registry to this registry. +/// +/// @param registry The registry to merge into this registry. - (void)addExtensions:(GPBExtensionRegistry *)registry; +/// Looks for the extension registered for the given field number on a given +/// @c GPBDescriptor. +/// +/// @param descriptor The descriptor to look for a registered extension on. +/// @param fieldNumber The field number of an extension to look for. +/// +/// @return The registered @c GPBExtensionDescripto or nil if none was found. - (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor fieldNumber:(NSInteger)fieldNumber; diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h index 332393ed..58c42d02 100644 --- a/objectivec/GPBMessage.h +++ b/objectivec/GPBMessage.h @@ -44,23 +44,27 @@ NS_ASSUME_NONNULL_BEGIN CF_EXTERN_C_BEGIN -// NSError domain used for errors. +/// NSError domain used for errors. extern NSString *const GPBMessageErrorDomain; +/// Error code for NSError with GPBMessageErrorDomain. typedef NS_ENUM(NSInteger, GPBMessageErrorCode) { + /// The data being parsed is bad and a message can not be created from it. GPBMessageErrorCodeMalformedData = -100, + /// A message can't be serialized because it is missing required fields. GPBMessageErrorCodeMissingRequiredField = -101, }; -// In DEBUG ONLY, an NSException is thrown when a parsed message doesn't -// contain required fields. This key allows you to retrieve the parsed message -// from the exception's |userInfo| dictionary. #ifdef DEBUG +/// In DEBUG ONLY, an NSException is thrown when a parsed message doesn't +/// contain required fields. This key allows you to retrieve the parsed message +/// from the exception's @c userInfo dictionary. extern NSString *const GPBExceptionMessageKey; #endif // DEBUG CF_EXTERN_C_END +/// Base class for all of the generated message classes. @interface GPBMessage : NSObject<NSSecureCoding, NSCopying> // NOTE: If you add a instance method/property to this class that may conflict @@ -68,108 +72,235 @@ CF_EXTERN_C_END // The main cases are methods that take no arguments, or setFoo:/hasFoo: type // methods. +/// The unknown fields for this message. +/// +/// Only messages from proto files declared with "proto2" syntax support unknown +/// fields. For "proto3" syntax, any unknown fields found while parsing are +/// dropped. @property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields; -// Are all required fields in the message and all embedded messages set. +/// Are all required fields set in the message and all embedded messages. @property(nonatomic, readonly, getter=isInitialized) BOOL initialized; -// Returns an autoreleased instance. +/// Returns an autoreleased instance. + (instancetype)message; -// Create a message based on a variety of inputs. If there is a data parse -// error, nil is returned and if not NULL, errorPtr is filled in. -// NOTE: In DEBUG ONLY, the message is also checked for all required field, -// if one is missing, the parse will fail (returning nil, filling in errorPtr). +/// Creates a new instance by parsing the data. This method should be sent to +/// the generated message class that the data should be interpreted as. If +/// there is an error the method returns nil and the error is returned in +/// errorPtr (when provided). +/// +/// @note In DEBUG builds, the parsed message is checked to be sure all required +/// fields were provided, and the parse will fail if some are missing. +/// +/// @param data The data to parse. +/// @param errorPtr An optional error pointer to fill in with a failure reason if +/// the data can not be parsed. +/// +/// @return A new instance of the class messaged. + (instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr; + +/// Creates a new instance by parsing the data. This method should be sent to +/// the generated message class that the data should be interpreted as. If +/// there is an error the method returns nil and the error is returned in +/// errorPtr (when provided). +/// +/// @note In DEBUG builds, the parsed message is checked to be sure all required +/// fields were provided, and the parse will fail if some are missing. +/// +/// @param data The data to parse. +/// @param extensionRegistry The extension registry to use to look up extensions. +/// @param errorPtr An optional error pointer to fill in with a failure +/// reason if the data can not be parsed. +/// +/// @return A new instance of the class messaged. + (instancetype)parseFromData:(NSData *)data extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; + +/// Creates a new instance by parsing the data from the given input stream. This +/// method should be sent to the generated message class that the data should +/// be interpreted as. If there is an error the method returns nil and the error +/// is returned in errorPtr (when provided). +/// +/// @note In DEBUG builds, the parsed message is checked to be sure all required +/// fields were provided, and the parse will fail if some are missing. +/// +/// @param input The stream to read data from. +/// @param extensionRegistry The extension registry to use to look up extensions. +/// @param errorPtr An optional error pointer to fill in with a failure +/// reason if the data can not be parsed. +/// +/// @return A new instance of the class messaged. + (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: (nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; -// Create a message based on delimited input. If there is a data parse -// error, nil is returned and if not NULL, errorPtr is filled in. +/// Creates a new instance by parsing the data from the given input stream. This +/// method should be sent to the generated message class that the data should +/// be interpreted as. If there is an error the method returns nil and the error +/// is returned in errorPtr (when provided). +/// +/// @note Unlike the parseFrom... methods, this never checks to see if all of +/// the required fields are set. So this method can be used to reload +/// messages that may not be complete. +/// +/// @param input The stream to read data from. +/// @param extensionRegistry The extension registry to use to look up extensions. +/// @param errorPtr An optional error pointer to fill in with a failure +/// reason if the data can not be parsed. +/// +/// @return A new instance of the class messaged. + (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: (nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; -// If there is a data parse error, nil is returned and if not NULL, errorPtr is -// filled in. -// NOTE: In DEBUG ONLY, the message is also checked for all required field, -// if one is missing, the parse will fail (returning nil, filling in errorPtr). +/// Initializes an instance by parsing the data. This method should be sent to +/// the generated message class that the data should be interpreted as. If +/// there is an error the method returns nil and the error is returned in +/// errorPtr (when provided). +/// +/// @note In DEBUG builds, the parsed message is checked to be sure all required +/// fields were provided, and the parse will fail if some are missing. +/// +/// @param data The data to parse. +/// @param errorPtr An optional error pointer to fill in with a failure reason if +/// the data can not be parsed. - (instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr; + +/// Initializes an instance by parsing the data. This method should be sent to +/// the generated message class that the data should be interpreted as. If +/// there is an error the method returns nil and the error is returned in +/// errorPtr (when provided). +/// +/// @note In DEBUG builds, the parsed message is checked to be sure all required +/// fields were provided, and the parse will fail if some are missing. +/// +/// @param data The data to parse. +/// @param extensionRegistry The extension registry to use to look up extensions. +/// @param errorPtr An optional error pointer to fill in with a failure +/// reason if the data can not be parsed. - (instancetype)initWithData:(NSData *)data extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; + +/// Initializes an instance by parsing the data from the given input stream. This +/// method should be sent to the generated message class that the data should +/// be interpreted as. If there is an error the method returns nil and the error +/// is returned in errorPtr (when provided). +/// +/// @note Unlike the parseFrom... methods, this never checks to see if all of +/// the required fields are set. So this method can be used to reload +/// messages that may not be complete. +/// +/// @param input The stream to read data from. +/// @param extensionRegistry The extension registry to use to look up extensions. +/// @param errorPtr An optional error pointer to fill in with a failure +/// reason if the data can not be parsed. - (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: (nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; -// Serializes the message and writes it to output. +/// Writes out the message to the given output stream. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output; +/// Writes out the message to the given output stream. - (void)writeToOutputStream:(NSOutputStream *)output; -// Serializes the message and writes it to output, but writes the size of the -// message as a variant before writing the message. +/// Writes out a varint for the message size followed by the the message to +/// the given output stream. - (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output; +/// Writes out a varint for the message size followed by the the message to +/// the given output stream. - (void)writeDelimitedToOutputStream:(NSOutputStream *)output; -// Serializes the message to an NSData. Note that this value is not cached, so -// if you are using it repeatedly, cache it yourself. If there is an error -// while generating the data, nil is returned. -// NOTE: In DEBUG ONLY, the message is also checked for all required field, -// if one is missing, nil will be returned. +/// Serializes the message to a @c NSData. +/// +/// If there is an error while generating the data, nil is returned. +/// +/// @note This value is not cached, so if you are using it repeatedly, cache +/// it yourself. +/// +/// @note In DEBUG ONLY, the message is also checked for all required field, +/// if one is missing, nil will be returned. - (nullable NSData *)data; -// Same as -[data], except a delimiter is added to the start of the data -// indicating the size of the message data that follows. +/// Serializes a varint with the message size followed by the message data, +/// returning that as a @c NSData. +/// +/// @note This value is not cached, so if you are using it repeatedly, cache +/// it yourself. - (NSData *)delimitedData; -// Returns the size of the object if it were serialized. -// This is not a cached value. If you are following a pattern like this: -// size_t size = [aMsg serializedSize]; -// NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; -// [foo writeSize:size]; -// [foo appendData:[aMsg data]]; -// you would be better doing: -// NSData *data = [aMsg data]; -// NSUInteger size = [aMsg length]; -// NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; -// [foo writeSize:size]; -// [foo appendData:data]; +/// Calculates the size of the object if it were serialized. +/// +/// This is not a cached value. If you are following a pattern like this: +/// @code +/// size_t size = [aMsg serializedSize]; +/// NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; +/// [foo writeSize:size]; +/// [foo appendData:[aMsg data]]; +/// @endcode +/// you would be better doing: +/// @code +/// NSData *data = [aMsg data]; +/// NSUInteger size = [aMsg length]; +/// NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; +/// [foo writeSize:size]; +/// [foo appendData:data]; +/// @endcode - (size_t)serializedSize; -// Return the descriptor for the message +/// Return the descriptor for the message class. + (GPBDescriptor *)descriptor; +/// Return the descriptor for the message. - (GPBDescriptor *)descriptor; -// Extensions use boxed values (NSNumbers) for PODs, NSMutableArrays for -// repeated. If the extension is a Message one will be auto created for you -// and returned similar to fields. +/// Test to see if the given extension is set on the message. - (BOOL)hasExtension:(GPBExtensionDescriptor *)extension; + +/// Fetches the given extension's value for this message. +/// +/// Extensions use boxed values (NSNumbers) for PODs and NSMutableArrays for +/// repeated fields. If the extension is a Message one will be auto created for you +/// and returned similar to fields. - (nullable id)getExtension:(GPBExtensionDescriptor *)extension; + +/// Sets the given extension's value for this message. This is only for single +/// field extensions (i.e. - not repeated fields). +/// +/// Extensions use boxed values (@c NSNumbers). - (void)setExtension:(GPBExtensionDescriptor *)extension value:(nullable id)value; + +/// Adds the given value to the extension for this message. This is only for +/// repeated field extensions. If the field is a repeated POD type the @c value +/// is a @c NSNumber. - (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value; + +/// Replaces the given value at an index for the extension on this message. This +/// is only for repeated field extensions. If the field is a repeated POD type +/// the @c value is a @c NSNumber. - (void)setExtension:(GPBExtensionDescriptor *)extension index:(NSUInteger)index value:(id)value; + +/// Clears the given extension for this message. - (void)clearExtension:(GPBExtensionDescriptor *)extension; -// Resets all fields to their default values. +/// Resets all of the fields of this message to their default values. - (void)clear; -// Parses a message of this type from the input and merges it with this -// message. -// NOTE: This will throw if there is an error parsing the data. +/// Parses a message of this type from the input and merges it with this +/// message. +/// +/// @note This will throw if there is an error parsing the data. - (void)mergeFromData:(NSData *)data extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; -// Merges the fields from another message (of the same type) into this -// message. +/// Merges the fields from another message (of the same type) into this +/// message. - (void)mergeFrom:(GPBMessage *)other; @end diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index fdb695ec..d5e8d37b 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -35,7 +35,7 @@ #import "GPBArray_PackagePrivate.h" #import "GPBCodedInputStream_PackagePrivate.h" -#import "GPBCodedOutputStream.h" +#import "GPBCodedOutputStream_PackagePrivate.h" #import "GPBDescriptor_PackagePrivate.h" #import "GPBDictionary_PackagePrivate.h" #import "GPBExtensionInternals.h" diff --git a/objectivec/GPBRootObject.h b/objectivec/GPBRootObject.h index e2af5d97..c05b5c62 100644 --- a/objectivec/GPBRootObject.h +++ b/objectivec/GPBRootObject.h @@ -34,11 +34,12 @@ NS_ASSUME_NONNULL_BEGIN -// All Root Objects derive from GPBRootObject. It supplies a registry -// for derived classes to register their extensions to. +/// Every generated proto file defines a local "Root" class that exposes a +/// @c GPBExtensionRegistry for all the extensions defined by that file and +/// the files it depends on. @interface GPBRootObject : NSObject -// Per class registry. +/// An extension registry for the given file and all the files it depends on. + (GPBExtensionRegistry *)extensionRegistry; @end diff --git a/objectivec/GPBUnknownField.h b/objectivec/GPBUnknownField.h index 12d72a9a..0f301e47 100644 --- a/objectivec/GPBUnknownField.h +++ b/objectivec/GPBUnknownField.h @@ -37,22 +37,51 @@ NS_ASSUME_NONNULL_BEGIN +/// Store an unknown field. These are used in conjunction with @c GPBUnknownFieldSet @interface GPBUnknownField : NSObject<NSCopying> +/// The field number the data is stored under. @property(nonatomic, readonly, assign) int32_t number; -// Only one of these will be set. +/// An array of varint values for this field. @property(nonatomic, readonly, strong) GPBUInt64Array *varintList; + +/// An array of fixed32 values for this field. @property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List; + +/// An array of fixed64 values for this field. @property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List; -@property(nonatomic, readonly, strong) NSArray *lengthDelimitedList; // NSData -@property(nonatomic, readonly, strong) NSArray *groupList; // GPBUnknownFieldSet -// Only one of these should be used per Field. +/// An array of data values for this field. +@property(nonatomic, readonly, strong) NSArray<NSData*> *lengthDelimitedList; + +/// An array of groups of values for this field. +@property(nonatomic, readonly, strong) NSArray<GPBUnknownFieldSet*> *groupList; + + +/// Add a value to the varintList. +/// +/// @param value The value to add. - (void)addVarint:(uint64_t)value; + +/// Add a value to the fixed32List. +/// +/// @param value The value to add. - (void)addFixed32:(uint32_t)value; + +/// Add a value to the fixed64List. +/// +/// @param value The value to add. - (void)addFixed64:(uint64_t)value; + +/// Add a value to the lengthDelimitedList. +/// +/// @param value The value to add. - (void)addLengthDelimited:(NSData *)value; + +/// Add a value to the groupList. +/// +/// @param value The value to add. - (void)addGroup:(GPBUnknownFieldSet *)value; @end diff --git a/objectivec/GPBUnknownField.m b/objectivec/GPBUnknownField.m index c49c0dfc..0e29bde5 100644 --- a/objectivec/GPBUnknownField.m +++ b/objectivec/GPBUnknownField.m @@ -31,7 +31,7 @@ #import "GPBUnknownField_PackagePrivate.h" #import "GPBArray.h" -#import "GPBCodedOutputStream.h" +#import "GPBCodedOutputStream_PackagePrivate.h" @implementation GPBUnknownField { @protected @@ -39,8 +39,8 @@ GPBUInt64Array *mutableVarintList_; GPBUInt32Array *mutableFixed32List_; GPBUInt64Array *mutableFixed64List_; - NSMutableArray *mutableLengthDelimitedList_; - NSMutableArray *mutableGroupList_; + NSMutableArray<NSData*> *mutableLengthDelimitedList_; + NSMutableArray<GPBUnknownFieldSet*> *mutableGroupList_; } @synthesize number = number_; diff --git a/objectivec/GPBUnknownFieldSet.h b/objectivec/GPBUnknownFieldSet.h index d785ca16..cf612993 100644 --- a/objectivec/GPBUnknownFieldSet.h +++ b/objectivec/GPBUnknownFieldSet.h @@ -34,16 +34,31 @@ NS_ASSUME_NONNULL_BEGIN +/// A collection of unknown fields. @interface GPBUnknownFieldSet : NSObject<NSCopying> +/// Tests to see if the given field number has a value. +/// +/// @param number The field number to check. +/// +/// @return YES if there is an unknown field for the given field number. - (BOOL)hasField:(int32_t)number; + +/// Fetches the @c GPBUnknownField for the given field number. +/// +/// @param number The field number to look up. +/// +/// @return The @c GPBUnknownField or nil. - (nullable GPBUnknownField *)getField:(int32_t)number; + +/// Returns the number of fields in this set. - (NSUInteger)countOfFields; +/// Adds the given field to the set. - (void)addField:(GPBUnknownField *)field; -// Returns an NSArray of the GPBFields sorted by the field numbers. -- (NSArray *)sortedFields; +/// Returns an NSArray of the @c GPBUnknownFields sorted by the field numbers. +- (NSArray<GPBUnknownField*> *)sortedFields; @end diff --git a/objectivec/GPBUtilities.h b/objectivec/GPBUtilities.h index 5b55104b..b7209324 100644 --- a/objectivec/GPBUtilities.h +++ b/objectivec/GPBUtilities.h @@ -38,24 +38,34 @@ CF_EXTERN_C_BEGIN NS_ASSUME_NONNULL_BEGIN -// Generates a string that should be a valid "Text Format" for the C++ version -// of Protocol Buffers. lineIndent can be nil if no additional line indent is -// needed. The comments provide the names according to the ObjC library, they -// most likely won't exactly match the original .proto file. +/// Generates a string that should be a valid "Text Format" for the C++ version +/// of Protocol Buffers. +/// +/// @param message The message to generate from. +/// @param lineIndent A string to use as the prefix for all lines generated. Can +/// be nil if no extra indent is needed. +/// +/// @return A @c NSString with the Text Format of the message. NSString *GPBTextFormatForMessage(GPBMessage *message, NSString * __nullable lineIndent); + +/// Generates a string that should be a valid "Text Format" for the C++ version +/// of Protocol Buffers. +/// +/// @param unknownSet The unknown field set to generate from. +/// @param lineIndent A string to use as the prefix for all lines generated. Can +/// be nil if no extra indent is needed. +/// +/// @return A @c NSString with the Text Format of the unknown field set. NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet, NSString * __nullable lineIndent); -// -// Test if the given field is set on a message. -// +/// Test if the given field is set on a message. BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber); +/// Test if the given field is set on a message. BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field); -// -// Clear the given field of a message. -// +/// Clear the given field of a message. void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field); //%PDDM-EXPAND GPB_ACCESSORS() @@ -68,60 +78,100 @@ void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field); // Single Fields +/// Gets the value of a bytes field. NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a bytes field. void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value); +/// Gets the value of a string field. NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a string field. void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value); +/// Gets the value of a message field. GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a message field. void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value); +/// Gets the value of a group field. GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a group field. void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value); +/// Gets the value of a bool field. BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a bool field. void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value); +/// Gets the value of an int32 field. int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of an int32 field. void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value); +/// Gets the value of an uint32 field. uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of an uint32 field. void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value); +/// Gets the value of an int64 field. int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of an int64 field. void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value); +/// Gets the value of an uint64 field. uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of an uint64 field. void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value); +/// Gets the value of a float field. float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a float field. void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value); +/// Gets the value of a double field. double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a double field. void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value); -// Get/Set the given enum field of a message. You can only Set values that are -// members of the enum. For proto3, when doing a Get, if the value isn't a -// memeber of the enum, kGPBUnrecognizedEnumeratorValue will be returned. The -// the functions with "Raw" in the will bypass all checks. +/// Get the given enum field of a message. For proto3, if the value isn't a +/// member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned. +/// GPBGetMessageRawEnumField will bypass the check and return whatever value +/// was set. int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field); +/// Set the given enum field of a message. You can only set values that are +/// members of the enum. void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value); +/// Get the given enum field of a message. No check is done to ensure the value +/// was defined in the enum. int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field); +/// Set the given enum field of a message. You can set the value to anything, +/// even a value that is not a member of the enum. void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value); // Repeated Fields -// The object will/should be GPB*Array or NSMutableArray based on the field's -// type. +/// Gets the value of a repeated field. +/// +/// The result will be @c GPB*Array or @c NSMutableArray based on the +/// field's type. id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a repeated field. +/// +/// The value should be @c GPB*Array or @c NSMutableArray based on the +/// field's type. void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array); // Map Fields -// The object will/should be GPB*Dictionary or NSMutableDictionary based on the -// field's type. +/// Gets the value of a map<> field. +/// +/// The result will be @c GPB*Dictionary or @c NSMutableDictionary based on +/// the field's type. id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field); +/// Sets the value of a map<> field. +/// +/// The object should be @c GPB*Dictionary or @c NSMutableDictionary based +/// on the field's type. void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary); //%PDDM-EXPAND-END GPB_ACCESSORS() @@ -144,44 +194,64 @@ CF_EXTERN_C_END //% //%// Single Fields //% -//%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, *) -//%GPB_ACCESSOR_SINGLE_FULL(String, NSString, *) -//%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, *) -//%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, *) -//%GPB_ACCESSOR_SINGLE(Bool, BOOL) -//%GPB_ACCESSOR_SINGLE(Int32, int32_t) -//%GPB_ACCESSOR_SINGLE(UInt32, uint32_t) -//%GPB_ACCESSOR_SINGLE(Int64, int64_t) -//%GPB_ACCESSOR_SINGLE(UInt64, uint64_t) -//%GPB_ACCESSOR_SINGLE(Float, float) -//%GPB_ACCESSOR_SINGLE(Double, double) -//%// Get/Set the given enum field of a message. You can only Set values that are -//%// members of the enum. For proto3, when doing a Get, if the value isn't a -//%// memeber of the enum, kGPBUnrecognizedEnumeratorValue will be returned. The -//%// the functions with "Raw" in the will bypass all checks. +//%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, , *) +//%GPB_ACCESSOR_SINGLE_FULL(String, NSString, , *) +//%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, , *) +//%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, , *) +//%GPB_ACCESSOR_SINGLE(Bool, BOOL, ) +//%GPB_ACCESSOR_SINGLE(Int32, int32_t, n) +//%GPB_ACCESSOR_SINGLE(UInt32, uint32_t, n) +//%GPB_ACCESSOR_SINGLE(Int64, int64_t, n) +//%GPB_ACCESSOR_SINGLE(UInt64, uint64_t, n) +//%GPB_ACCESSOR_SINGLE(Float, float, ) +//%GPB_ACCESSOR_SINGLE(Double, double, ) +//%/// Get the given enum field of a message. For proto3, if the value isn't a +//%/// member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned. +//%/// GPBGetMessageRawEnumField will bypass the check and return whatever value +//%/// was set. //%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field); +//%/// Set the given enum field of a message. You can only set values that are +//%/// members of the enum. //%void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value); +//%/// Get the given enum field of a message. No check is done to ensure the value +//%/// was defined in the enum. //%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field); +//%/// Set the given enum field of a message. You can set the value to anything, +//%/// even a value that is not a member of the enum. //%void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value); //% //%// Repeated Fields //% -//%// The object will/should be GPB*Array or NSMutableArray based on the field's -//%// type. +//%/// Gets the value of a repeated field. +//%/// +//%/// The result will be @c GPB*Array or @c NSMutableArray based on the +//%/// field's type. //%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field); +//%/// Sets the value of a repeated field. +//%/// +//%/// The value should be @c GPB*Array or @c NSMutableArray based on the +//%/// field's type. //%void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array); //% //%// Map Fields //% -//%// The object will/should be GPB*Dictionary or NSMutableDictionary based on the -//%// field's type. +//%/// Gets the value of a map<> field. +//%/// +//%/// The result will be @c GPB*Dictionary or @c NSMutableDictionary based on +//%/// the field's type. //%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field); +//%/// Sets the value of a map<> field. +//%/// +//%/// The object should be @c GPB*Dictionary or @c NSMutableDictionary based +//%/// on the field's type. //%void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary); //% -//%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE) -//%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, ) -//%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, TisP) +//%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE, AN) +//%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, ) +//%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, TisP) +//%/// Gets the value of a##AN NAME$L field. //%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field); +//%/// Sets the value of a##AN NAME$L field. //%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value); //% diff --git a/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj index 6b34b9bf..78c3f9ba 100644 --- a/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj +++ b/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj @@ -188,6 +188,7 @@ F4487C7C1AAE06AC00531423 /* GPBUtilities_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUtilities_PackagePrivate.h; sourceTree = "<group>"; }; F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = "<group>"; }; F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = "<group>"; }; + F44929001C866B1900C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = "<group>"; }; F451D3F51A8AAE8700B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = "<group>"; }; F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = "<group>"; }; F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_map_unittest_data.txt; sourceTree = "<group>"; }; @@ -368,9 +369,10 @@ 7461B4860F94F96B00A0C422 /* IO */ = { isa = PBXGroup; children = ( - 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */, 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */, + 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */, 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */, + F44929001C866B1900C2548A /* GPBCodedOutputStream_PackagePrivate.h */, 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */, 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */, 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */, diff --git a/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj index e9d3fc95..5d96c05f 100644 --- a/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj +++ b/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj @@ -209,6 +209,7 @@ F4487C7D1AAE06C500531423 /* GPBUtilities_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUtilities_PackagePrivate.h; sourceTree = "<group>"; }; F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = "<group>"; }; F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = "<group>"; }; + F44929021C866B3B00C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = "<group>"; }; F451D3F61A8AAEA600B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = "<group>"; }; F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = "<group>"; }; F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_map_unittest_data.txt; sourceTree = "<group>"; }; @@ -405,9 +406,10 @@ 7461B4860F94F96B00A0C422 /* IO */ = { isa = PBXGroup; children = ( - 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */, 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */, + 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */, 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */, + F44929021C866B3B00C2548A /* GPBCodedOutputStream_PackagePrivate.h */, 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */, 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */, 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */, diff --git a/objectivec/Tests/GPBCodedOuputStreamTests.m b/objectivec/Tests/GPBCodedOuputStreamTests.m index 77d88033..0723b645 100644 --- a/objectivec/Tests/GPBCodedOuputStreamTests.m +++ b/objectivec/Tests/GPBCodedOuputStreamTests.m @@ -30,11 +30,30 @@ #import "GPBTestUtilities.h" -#import "GPBCodedOutputStream.h" +#import "GPBCodedOutputStream_PackagePrivate.h" #import "GPBCodedInputStream.h" #import "GPBUtilities_PackagePrivate.h" #import "google/protobuf/Unittest.pbobjc.h" +@interface GPBCodedOutputStream (InternalMethods) +// Declared in the .m file, expose for testing. +- (instancetype)initWithOutputStream:(NSOutputStream *)output + data:(NSMutableData *)data; +@end + +@interface GPBCodedOutputStream (Helper) ++ (instancetype)streamWithOutputStream:(NSOutputStream *)output + bufferSize:(size_t)bufferSize; +@end + +@implementation GPBCodedOutputStream (Helper) ++ (instancetype)streamWithOutputStream:(NSOutputStream *)output + bufferSize:(size_t)bufferSize { + NSMutableData *data = [NSMutableData dataWithLength:bufferSize]; + return [[[self alloc] initWithOutputStream:output data:data] autorelease]; +} +@end + @interface CodedOutputStreamTests : GPBTestCase @end diff --git a/objectivec/Tests/GPBDictionaryTests+Bool.m b/objectivec/Tests/GPBDictionaryTests+Bool.m index 8b1900fe..afa3d11c 100644 --- a/objectivec/Tests/GPBDictionaryTests+Bool.m +++ b/objectivec/Tests/GPBDictionaryTests+Bool.m @@ -2147,7 +2147,7 @@ @end -//%PDDM-EXPAND TESTS_FOR_BOOL_KEY_OBJECT_VALUE(Object, id, @"abc", @"def") +//%PDDM-EXPAND TESTS_FOR_BOOL_KEY_OBJECT_VALUE(Object, NSString*, @"abc", @"def") // This block of code is generated, do not edit it directly. #pragma mark - Bool -> Object @@ -2158,11 +2158,11 @@ @implementation GPBBoolObjectDictionaryTests - (void)testEmpty { - GPBBoolObjectDictionary *dict = [[GPBBoolObjectDictionary alloc] init]; + GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:YES]); - [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; @@ -2170,12 +2170,12 @@ } - (void)testOne { - GPBBoolObjectDictionary *dict = [GPBBoolObjectDictionary dictionaryWithObject:@"abc" forKey:YES]; + GPBBoolObjectDictionary<NSString*> *dict = [GPBBoolObjectDictionary dictionaryWithObject:@"abc" forKey:YES]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); XCTAssertEqualObjects([dict objectForKey:YES], @"abc"); XCTAssertNil([dict objectForKey:NO]); - [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) { XCTAssertEqual(aKey, YES); XCTAssertEqualObjects(aObject, @"abc"); XCTAssertNotEqual(stop, NULL); @@ -2184,8 +2184,8 @@ - (void)testBasics { const BOOL kKeys[] = { YES, NO }; - const id kObjects[] = { @"abc", @"def" }; - GPBBoolObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def" }; + GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -2196,8 +2196,8 @@ __block NSUInteger idx = 0; BOOL *seenKeys = malloc(2 * sizeof(BOOL)); - id *seenObjects = malloc(2 * sizeof(id)); - [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, id aObject, BOOL *stop) { + NSString* *seenObjects = malloc(2 * sizeof(NSString*)); + [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) { XCTAssertLessThan(idx, 2U); seenKeys[idx] = aKey; seenObjects[idx] = aObject; @@ -2219,7 +2219,7 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); @@ -2231,30 +2231,30 @@ - (void)testEquality { const BOOL kKeys1[] = { YES, NO }; const BOOL kKeys2[] = { NO, YES }; - const id kObjects1[] = { @"abc", @"def" }; - const id kObjects2[] = { @"def", @"abc" }; - const id kObjects3[] = { @"def" }; - GPBBoolObjectDictionary *dict1 = + const NSString* kObjects1[] = { @"abc", @"def" }; + const NSString* kObjects2[] = { @"def", @"abc" }; + const NSString* kObjects3[] = { @"def" }; + GPBBoolObjectDictionary<NSString*> *dict1 = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1); - GPBBoolObjectDictionary *dict1prime = + GPBBoolObjectDictionary<NSString*> *dict1prime = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1prime); - GPBBoolObjectDictionary *dict2 = + GPBBoolObjectDictionary<NSString*> *dict2 = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects2)]; XCTAssertNotNil(dict2); - GPBBoolObjectDictionary *dict3 = + GPBBoolObjectDictionary<NSString*> *dict3 = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict3); - GPBBoolObjectDictionary *dict4 = + GPBBoolObjectDictionary<NSString*> *dict4 = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects3 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects3)]; @@ -2284,14 +2284,14 @@ - (void)testCopy { const BOOL kKeys[] = { YES, NO }; - const id kObjects[] = { @"abc", @"def" }; - GPBBoolObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def" }; + GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBBoolObjectDictionary *dict2 = [dict copy]; + GPBBoolObjectDictionary<NSString*> *dict2 = [dict copy]; XCTAssertNotNil(dict2); // Should be new object but equal. @@ -2305,14 +2305,14 @@ - (void)testDictionaryFromDictionary { const BOOL kKeys[] = { YES, NO }; - const id kObjects[] = { @"abc", @"def" }; - GPBBoolObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def" }; + GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBBoolObjectDictionary *dict2 = + GPBBoolObjectDictionary<NSString*> *dict2 = [GPBBoolObjectDictionary dictionaryWithDictionary:dict]; XCTAssertNotNil(dict2); @@ -2323,7 +2323,7 @@ } - (void)testAdds { - GPBBoolObjectDictionary *dict = [GPBBoolObjectDictionary dictionary]; + GPBBoolObjectDictionary<NSString*> *dict = [GPBBoolObjectDictionary dictionary]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -2331,8 +2331,8 @@ XCTAssertEqual(dict.count, 1U); const BOOL kKeys[] = { NO }; - const id kObjects[] = { @"def" }; - GPBBoolObjectDictionary *dict2 = + const NSString* kObjects[] = { @"def" }; + GPBBoolObjectDictionary<NSString*> *dict2 = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -2347,8 +2347,8 @@ - (void)testRemove { const BOOL kKeys[] = { YES, NO}; - const id kObjects[] = { @"abc", @"def" }; - GPBBoolObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def" }; + GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -2375,8 +2375,8 @@ - (void)testInplaceMutation { const BOOL kKeys[] = { YES, NO }; - const id kObjects[] = { @"abc", @"def" }; - GPBBoolObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def" }; + GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -2396,8 +2396,8 @@ XCTAssertEqualObjects([dict objectForKey:NO], @"abc"); const BOOL kKeys2[] = { NO, YES }; - const id kObjects2[] = { @"def", @"abc" }; - GPBBoolObjectDictionary *dict2 = + const NSString* kObjects2[] = { @"def", @"abc" }; + GPBBoolObjectDictionary<NSString*> *dict2 = [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects2)]; diff --git a/objectivec/Tests/GPBDictionaryTests+Int32.m b/objectivec/Tests/GPBDictionaryTests+Int32.m index 21d3f07d..54dd2ed7 100644 --- a/objectivec/Tests/GPBDictionaryTests+Int32.m +++ b/objectivec/Tests/GPBDictionaryTests+Int32.m @@ -3363,11 +3363,11 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @implementation GPBInt32ObjectDictionaryTests - (void)testEmpty { - GPBInt32ObjectDictionary *dict = [[GPBInt32ObjectDictionary alloc] init]; + GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:11]); - [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; @@ -3375,12 +3375,12 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBInt32ObjectDictionary *dict = [GPBInt32ObjectDictionary dictionaryWithObject:@"abc" forKey:11]; + GPBInt32ObjectDictionary<NSString*> *dict = [GPBInt32ObjectDictionary dictionaryWithObject:@"abc" forKey:11]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); XCTAssertEqualObjects([dict objectForKey:11], @"abc"); XCTAssertNil([dict objectForKey:12]); - [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) { XCTAssertEqual(aKey, 11); XCTAssertEqualObjects(aObject, @"abc"); XCTAssertNotEqual(stop, NULL); @@ -3389,8 +3389,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testBasics { const int32_t kKeys[] = { 11, 12, 13 }; - const id kObjects[] = { @"abc", @"def", @"ghi" }; - GPBInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi" }; + GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3403,8 +3403,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { __block NSUInteger idx = 0; int32_t *seenKeys = malloc(3 * sizeof(int32_t)); - id *seenObjects = malloc(3 * sizeof(id)); - [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, id aObject, BOOL *stop) { + NSString* *seenObjects = malloc(3 * sizeof(NSString*)); + [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) { XCTAssertLessThan(idx, 3U); seenKeys[idx] = aKey; seenObjects[idx] = aObject; @@ -3426,7 +3426,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); @@ -3438,30 +3438,30 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testEquality { const int32_t kKeys1[] = { 11, 12, 13, 14 }; const int32_t kKeys2[] = { 12, 11, 14 }; - const id kObjects1[] = { @"abc", @"def", @"ghi" }; - const id kObjects2[] = { @"abc", @"jkl", @"ghi" }; - const id kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt32ObjectDictionary *dict1 = + const NSString* kObjects1[] = { @"abc", @"def", @"ghi" }; + const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" }; + const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt32ObjectDictionary<NSString*> *dict1 = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1); - GPBInt32ObjectDictionary *dict1prime = + GPBInt32ObjectDictionary<NSString*> *dict1prime = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1prime); - GPBInt32ObjectDictionary *dict2 = + GPBInt32ObjectDictionary<NSString*> *dict2 = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects2)]; XCTAssertNotNil(dict2); - GPBInt32ObjectDictionary *dict3 = + GPBInt32ObjectDictionary<NSString*> *dict3 = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict3); - GPBInt32ObjectDictionary *dict4 = + GPBInt32ObjectDictionary<NSString*> *dict4 = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects3 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects3)]; @@ -3491,14 +3491,14 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testCopy { const int32_t kKeys[] = { 11, 12, 13, 14 }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBInt32ObjectDictionary *dict2 = [dict copy]; + GPBInt32ObjectDictionary<NSString*> *dict2 = [dict copy]; XCTAssertNotNil(dict2); // Should be new object but equal. @@ -3512,14 +3512,14 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testDictionaryFromDictionary { const int32_t kKeys[] = { 11, 12, 13, 14 }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBInt32ObjectDictionary *dict2 = + GPBInt32ObjectDictionary<NSString*> *dict2 = [GPBInt32ObjectDictionary dictionaryWithDictionary:dict]; XCTAssertNotNil(dict2); @@ -3530,7 +3530,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testAdds { - GPBInt32ObjectDictionary *dict = [GPBInt32ObjectDictionary dictionary]; + GPBInt32ObjectDictionary<NSString*> *dict = [GPBInt32ObjectDictionary dictionary]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -3538,8 +3538,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(dict.count, 1U); const int32_t kKeys[] = { 12, 13, 14 }; - const id kObjects[] = { @"def", @"ghi", @"jkl" }; - GPBInt32ObjectDictionary *dict2 = + const NSString* kObjects[] = { @"def", @"ghi", @"jkl" }; + GPBInt32ObjectDictionary<NSString*> *dict2 = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3556,8 +3556,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testRemove { const int32_t kKeys[] = { 11, 12, 13, 14 }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3597,8 +3597,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testInplaceMutation { const int32_t kKeys[] = { 11, 12, 13, 14 }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3624,8 +3624,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqualObjects([dict objectForKey:14], @"def"); const int32_t kKeys2[] = { 12, 13 }; - const id kObjects2[] = { @"ghi", @"abc" }; - GPBInt32ObjectDictionary *dict2 = + const NSString* kObjects2[] = { @"ghi", @"abc" }; + GPBInt32ObjectDictionary<NSString*> *dict2 = [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects2)]; diff --git a/objectivec/Tests/GPBDictionaryTests+Int64.m b/objectivec/Tests/GPBDictionaryTests+Int64.m index 27f77f28..66bc6487 100644 --- a/objectivec/Tests/GPBDictionaryTests+Int64.m +++ b/objectivec/Tests/GPBDictionaryTests+Int64.m @@ -3363,11 +3363,11 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @implementation GPBInt64ObjectDictionaryTests - (void)testEmpty { - GPBInt64ObjectDictionary *dict = [[GPBInt64ObjectDictionary alloc] init]; + GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:21LL]); - [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; @@ -3375,12 +3375,12 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBInt64ObjectDictionary *dict = [GPBInt64ObjectDictionary dictionaryWithObject:@"abc" forKey:21LL]; + GPBInt64ObjectDictionary<NSString*> *dict = [GPBInt64ObjectDictionary dictionaryWithObject:@"abc" forKey:21LL]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); XCTAssertEqualObjects([dict objectForKey:21LL], @"abc"); XCTAssertNil([dict objectForKey:22LL]); - [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) { XCTAssertEqual(aKey, 21LL); XCTAssertEqualObjects(aObject, @"abc"); XCTAssertNotEqual(stop, NULL); @@ -3389,8 +3389,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testBasics { const int64_t kKeys[] = { 21LL, 22LL, 23LL }; - const id kObjects[] = { @"abc", @"def", @"ghi" }; - GPBInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi" }; + GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3403,8 +3403,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { __block NSUInteger idx = 0; int64_t *seenKeys = malloc(3 * sizeof(int64_t)); - id *seenObjects = malloc(3 * sizeof(id)); - [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, id aObject, BOOL *stop) { + NSString* *seenObjects = malloc(3 * sizeof(NSString*)); + [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) { XCTAssertLessThan(idx, 3U); seenKeys[idx] = aKey; seenObjects[idx] = aObject; @@ -3426,7 +3426,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); @@ -3438,30 +3438,30 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testEquality { const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL }; const int64_t kKeys2[] = { 22LL, 21LL, 24LL }; - const id kObjects1[] = { @"abc", @"def", @"ghi" }; - const id kObjects2[] = { @"abc", @"jkl", @"ghi" }; - const id kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt64ObjectDictionary *dict1 = + const NSString* kObjects1[] = { @"abc", @"def", @"ghi" }; + const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" }; + const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt64ObjectDictionary<NSString*> *dict1 = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1); - GPBInt64ObjectDictionary *dict1prime = + GPBInt64ObjectDictionary<NSString*> *dict1prime = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1prime); - GPBInt64ObjectDictionary *dict2 = + GPBInt64ObjectDictionary<NSString*> *dict2 = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects2)]; XCTAssertNotNil(dict2); - GPBInt64ObjectDictionary *dict3 = + GPBInt64ObjectDictionary<NSString*> *dict3 = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict3); - GPBInt64ObjectDictionary *dict4 = + GPBInt64ObjectDictionary<NSString*> *dict4 = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects3 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects3)]; @@ -3491,14 +3491,14 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testCopy { const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBInt64ObjectDictionary *dict2 = [dict copy]; + GPBInt64ObjectDictionary<NSString*> *dict2 = [dict copy]; XCTAssertNotNil(dict2); // Should be new object but equal. @@ -3512,14 +3512,14 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testDictionaryFromDictionary { const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBInt64ObjectDictionary *dict2 = + GPBInt64ObjectDictionary<NSString*> *dict2 = [GPBInt64ObjectDictionary dictionaryWithDictionary:dict]; XCTAssertNotNil(dict2); @@ -3530,7 +3530,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testAdds { - GPBInt64ObjectDictionary *dict = [GPBInt64ObjectDictionary dictionary]; + GPBInt64ObjectDictionary<NSString*> *dict = [GPBInt64ObjectDictionary dictionary]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -3538,8 +3538,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(dict.count, 1U); const int64_t kKeys[] = { 22LL, 23LL, 24LL }; - const id kObjects[] = { @"def", @"ghi", @"jkl" }; - GPBInt64ObjectDictionary *dict2 = + const NSString* kObjects[] = { @"def", @"ghi", @"jkl" }; + GPBInt64ObjectDictionary<NSString*> *dict2 = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3556,8 +3556,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testRemove { const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3597,8 +3597,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testInplaceMutation { const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3624,8 +3624,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqualObjects([dict objectForKey:24LL], @"def"); const int64_t kKeys2[] = { 22LL, 23LL }; - const id kObjects2[] = { @"ghi", @"abc" }; - GPBInt64ObjectDictionary *dict2 = + const NSString* kObjects2[] = { @"ghi", @"abc" }; + GPBInt64ObjectDictionary<NSString*> *dict2 = [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects2)]; diff --git a/objectivec/Tests/GPBDictionaryTests+UInt32.m b/objectivec/Tests/GPBDictionaryTests+UInt32.m index c7c57652..499f2adb 100644 --- a/objectivec/Tests/GPBDictionaryTests+UInt32.m +++ b/objectivec/Tests/GPBDictionaryTests+UInt32.m @@ -3363,11 +3363,11 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @implementation GPBUInt32ObjectDictionaryTests - (void)testEmpty { - GPBUInt32ObjectDictionary *dict = [[GPBUInt32ObjectDictionary alloc] init]; + GPBUInt32ObjectDictionary<NSString*> *dict = [[GPBUInt32ObjectDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:1U]); - [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; @@ -3375,12 +3375,12 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBUInt32ObjectDictionary *dict = [GPBUInt32ObjectDictionary dictionaryWithObject:@"abc" forKey:1U]; + GPBUInt32ObjectDictionary<NSString*> *dict = [GPBUInt32ObjectDictionary dictionaryWithObject:@"abc" forKey:1U]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); XCTAssertEqualObjects([dict objectForKey:1U], @"abc"); XCTAssertNil([dict objectForKey:2U]); - [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) { XCTAssertEqual(aKey, 1U); XCTAssertEqualObjects(aObject, @"abc"); XCTAssertNotEqual(stop, NULL); @@ -3389,8 +3389,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testBasics { const uint32_t kKeys[] = { 1U, 2U, 3U }; - const id kObjects[] = { @"abc", @"def", @"ghi" }; - GPBUInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi" }; + GPBUInt32ObjectDictionary<NSString*> *dict = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3403,8 +3403,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { __block NSUInteger idx = 0; uint32_t *seenKeys = malloc(3 * sizeof(uint32_t)); - id *seenObjects = malloc(3 * sizeof(id)); - [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, id aObject, BOOL *stop) { + NSString* *seenObjects = malloc(3 * sizeof(NSString*)); + [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) { XCTAssertLessThan(idx, 3U); seenKeys[idx] = aKey; seenObjects[idx] = aObject; @@ -3426,7 +3426,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); @@ -3438,30 +3438,30 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testEquality { const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U }; const uint32_t kKeys2[] = { 2U, 1U, 4U }; - const id kObjects1[] = { @"abc", @"def", @"ghi" }; - const id kObjects2[] = { @"abc", @"jkl", @"ghi" }; - const id kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt32ObjectDictionary *dict1 = + const NSString* kObjects1[] = { @"abc", @"def", @"ghi" }; + const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" }; + const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt32ObjectDictionary<NSString*> *dict1 = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1); - GPBUInt32ObjectDictionary *dict1prime = + GPBUInt32ObjectDictionary<NSString*> *dict1prime = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1prime); - GPBUInt32ObjectDictionary *dict2 = + GPBUInt32ObjectDictionary<NSString*> *dict2 = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects2)]; XCTAssertNotNil(dict2); - GPBUInt32ObjectDictionary *dict3 = + GPBUInt32ObjectDictionary<NSString*> *dict3 = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict3); - GPBUInt32ObjectDictionary *dict4 = + GPBUInt32ObjectDictionary<NSString*> *dict4 = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects3 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects3)]; @@ -3491,14 +3491,14 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testCopy { const uint32_t kKeys[] = { 1U, 2U, 3U, 4U }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt32ObjectDictionary<NSString*> *dict = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBUInt32ObjectDictionary *dict2 = [dict copy]; + GPBUInt32ObjectDictionary<NSString*> *dict2 = [dict copy]; XCTAssertNotNil(dict2); // Should be new object but equal. @@ -3512,14 +3512,14 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testDictionaryFromDictionary { const uint32_t kKeys[] = { 1U, 2U, 3U, 4U }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt32ObjectDictionary<NSString*> *dict = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBUInt32ObjectDictionary *dict2 = + GPBUInt32ObjectDictionary<NSString*> *dict2 = [GPBUInt32ObjectDictionary dictionaryWithDictionary:dict]; XCTAssertNotNil(dict2); @@ -3530,7 +3530,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testAdds { - GPBUInt32ObjectDictionary *dict = [GPBUInt32ObjectDictionary dictionary]; + GPBUInt32ObjectDictionary<NSString*> *dict = [GPBUInt32ObjectDictionary dictionary]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -3538,8 +3538,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(dict.count, 1U); const uint32_t kKeys[] = { 2U, 3U, 4U }; - const id kObjects[] = { @"def", @"ghi", @"jkl" }; - GPBUInt32ObjectDictionary *dict2 = + const NSString* kObjects[] = { @"def", @"ghi", @"jkl" }; + GPBUInt32ObjectDictionary<NSString*> *dict2 = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3556,8 +3556,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testRemove { const uint32_t kKeys[] = { 1U, 2U, 3U, 4U }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt32ObjectDictionary<NSString*> *dict = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3597,8 +3597,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testInplaceMutation { const uint32_t kKeys[] = { 1U, 2U, 3U, 4U }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt32ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt32ObjectDictionary<NSString*> *dict = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3624,8 +3624,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqualObjects([dict objectForKey:4U], @"def"); const uint32_t kKeys2[] = { 2U, 3U }; - const id kObjects2[] = { @"ghi", @"abc" }; - GPBUInt32ObjectDictionary *dict2 = + const NSString* kObjects2[] = { @"ghi", @"abc" }; + GPBUInt32ObjectDictionary<NSString*> *dict2 = [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects2)]; diff --git a/objectivec/Tests/GPBDictionaryTests+UInt64.m b/objectivec/Tests/GPBDictionaryTests+UInt64.m index b64d3a96..327e1548 100644 --- a/objectivec/Tests/GPBDictionaryTests+UInt64.m +++ b/objectivec/Tests/GPBDictionaryTests+UInt64.m @@ -3363,11 +3363,11 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @implementation GPBUInt64ObjectDictionaryTests - (void)testEmpty { - GPBUInt64ObjectDictionary *dict = [[GPBUInt64ObjectDictionary alloc] init]; + GPBUInt64ObjectDictionary<NSString*> *dict = [[GPBUInt64ObjectDictionary alloc] init]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:31ULL]); - [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; @@ -3375,12 +3375,12 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testOne { - GPBUInt64ObjectDictionary *dict = [GPBUInt64ObjectDictionary dictionaryWithObject:@"abc" forKey:31ULL]; + GPBUInt64ObjectDictionary<NSString*> *dict = [GPBUInt64ObjectDictionary dictionaryWithObject:@"abc" forKey:31ULL]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 1U); XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc"); XCTAssertNil([dict objectForKey:32ULL]); - [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) { XCTAssertEqual(aKey, 31ULL); XCTAssertEqualObjects(aObject, @"abc"); XCTAssertNotEqual(stop, NULL); @@ -3389,8 +3389,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testBasics { const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL }; - const id kObjects[] = { @"abc", @"def", @"ghi" }; - GPBUInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi" }; + GPBUInt64ObjectDictionary<NSString*> *dict = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3403,8 +3403,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { __block NSUInteger idx = 0; uint64_t *seenKeys = malloc(3 * sizeof(uint64_t)); - id *seenObjects = malloc(3 * sizeof(id)); - [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, id aObject, BOOL *stop) { + NSString* *seenObjects = malloc(3 * sizeof(NSString*)); + [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) { XCTAssertLessThan(idx, 3U); seenKeys[idx] = aKey; seenObjects[idx] = aObject; @@ -3426,7 +3426,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, id aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) { #pragma unused(aKey, aObject) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); @@ -3438,30 +3438,30 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testEquality { const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL }; const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL }; - const id kObjects1[] = { @"abc", @"def", @"ghi" }; - const id kObjects2[] = { @"abc", @"jkl", @"ghi" }; - const id kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt64ObjectDictionary *dict1 = + const NSString* kObjects1[] = { @"abc", @"def", @"ghi" }; + const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" }; + const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt64ObjectDictionary<NSString*> *dict1 = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1); - GPBUInt64ObjectDictionary *dict1prime = + GPBUInt64ObjectDictionary<NSString*> *dict1prime = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict1prime); - GPBUInt64ObjectDictionary *dict2 = + GPBUInt64ObjectDictionary<NSString*> *dict2 = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects2)]; XCTAssertNotNil(dict2); - GPBUInt64ObjectDictionary *dict3 = + GPBUInt64ObjectDictionary<NSString*> *dict3 = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects1)]; XCTAssertNotNil(dict3); - GPBUInt64ObjectDictionary *dict4 = + GPBUInt64ObjectDictionary<NSString*> *dict4 = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects3 forKeys:kKeys1 count:GPBARRAYSIZE(kObjects3)]; @@ -3491,14 +3491,14 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testCopy { const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt64ObjectDictionary<NSString*> *dict = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBUInt64ObjectDictionary *dict2 = [dict copy]; + GPBUInt64ObjectDictionary<NSString*> *dict2 = [dict copy]; XCTAssertNotNil(dict2); // Should be new object but equal. @@ -3512,14 +3512,14 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testDictionaryFromDictionary { const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt64ObjectDictionary<NSString*> *dict = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; XCTAssertNotNil(dict); - GPBUInt64ObjectDictionary *dict2 = + GPBUInt64ObjectDictionary<NSString*> *dict2 = [GPBUInt64ObjectDictionary dictionaryWithDictionary:dict]; XCTAssertNotNil(dict2); @@ -3530,7 +3530,7 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { } - (void)testAdds { - GPBUInt64ObjectDictionary *dict = [GPBUInt64ObjectDictionary dictionary]; + GPBUInt64ObjectDictionary<NSString*> *dict = [GPBUInt64ObjectDictionary dictionary]; XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); @@ -3538,8 +3538,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqual(dict.count, 1U); const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL }; - const id kObjects[] = { @"def", @"ghi", @"jkl" }; - GPBUInt64ObjectDictionary *dict2 = + const NSString* kObjects[] = { @"def", @"ghi", @"jkl" }; + GPBUInt64ObjectDictionary<NSString*> *dict2 = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3556,8 +3556,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testRemove { const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt64ObjectDictionary<NSString*> *dict = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3597,8 +3597,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { - (void)testInplaceMutation { const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL }; - const id kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; - GPBUInt64ObjectDictionary *dict = + const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" }; + GPBUInt64ObjectDictionary<NSString*> *dict = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects forKeys:kKeys count:GPBARRAYSIZE(kObjects)]; @@ -3624,8 +3624,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertEqualObjects([dict objectForKey:34ULL], @"def"); const uint64_t kKeys2[] = { 32ULL, 33ULL }; - const id kObjects2[] = { @"ghi", @"abc" }; - GPBUInt64ObjectDictionary *dict2 = + const NSString* kObjects2[] = { @"ghi", @"abc" }; + GPBUInt64ObjectDictionary<NSString*> *dict2 = [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects2 forKeys:kKeys2 count:GPBARRAYSIZE(kObjects2)]; diff --git a/objectivec/Tests/GPBDictionaryTests.pddm b/objectivec/Tests/GPBDictionaryTests.pddm index ada93c64..09512940 100644 --- a/objectivec/Tests/GPBDictionaryTests.pddm +++ b/objectivec/Tests/GPBDictionaryTests.pddm @@ -30,7 +30,7 @@ //%PDDM-DEFINE TEST_FOR_POD_KEY(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4) //%TESTS_FOR_POD_VALUES(KEY_NAME, KEY_TYPE, , , KEY1, KEY2, KEY3, KEY4) -//%TESTS_FOR_POD_KEY_OBJECT_VALUE(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4, Object, id, @"abc", @"def", @"ghi", @"jkl") +//%TESTS_FOR_POD_KEY_OBJECT_VALUE(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4, Object, NSString*, @"abc", @"def", @"ghi", @"jkl") //%PDDM-DEFINE TESTS_FOR_POD_VALUES(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4) //%TEST_HELPERS(KEY_NAME, KEY_TYPE, KisP) @@ -50,6 +50,13 @@ //%PDDM-DEFINE TESTS_FOR_POD_KEY_OBJECT_VALUE(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VAL1, VAL2, VAL3, VAL4) //%TESTS_COMMON(KEY_NAME, KEY_TYPE, , , KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, Objects, object, OBJECT, , VAL1, VAL2, VAL3, VAL4) +//%PDDM-DEFINE DICTIONARY_CLASS_DECLPOD(KEY_NAME, VALUE_NAME, VALUE_TYPE) +//%GPB##KEY_NAME##VALUE_NAME##Dictionary +//%PDDM-DEFINE DICTIONARY_CLASS_DECLEnum(KEY_NAME, VALUE_NAME, VALUE_TYPE) +//%GPB##KEY_NAME##VALUE_NAME##Dictionary +//%PDDM-DEFINE DICTIONARY_CLASS_DECLOBJECT(KEY_NAME, VALUE_NAME, VALUE_TYPE) +//%GPB##KEY_NAME##VALUE_NAME##Dictionary<VALUE_TYPE> + //%PDDM-DEFINE TESTS_COMMON(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VSUFFIX, VNAME, VHELPER, VACCESSOR, VAL1, VAL2, VAL3, VAL4) //%#pragma mark - KEY_NAME -> VALUE_NAME //% @@ -59,7 +66,7 @@ //%@implementation GPB##KEY_NAME##VALUE_NAME##DictionaryTests //% //%- (void)testEmpty { -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; //% XCTAssertNotNil(dict); //% XCTAssertEqual(dict.count, 0U); //%VALUE_NOT_FOUND##VHELPER(dict, KEY1) @@ -71,7 +78,7 @@ //%} //% //%- (void)testOne { -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWith##VNAME$u##:VAL1 forKey:KEY1]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWith##VNAME$u##:VAL1 forKey:KEY1]; //% XCTAssertNotNil(dict); //% XCTAssertEqual(dict.count, 1U); //%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(dict, VNAME, KEY1, VAL1) @@ -86,7 +93,7 @@ //%- (void)testBasics { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; @@ -137,27 +144,27 @@ //% const VALUE_TYPE k##VNAME$u##s1[] = { VAL1, VAL2, VAL3 }; //% const VALUE_TYPE k##VNAME$u##s2[] = { VAL1, VAL4, VAL3 }; //% const VALUE_TYPE k##VNAME$u##s3[] = { VAL1, VAL2, VAL3, VAL4 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict1 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)]; //% XCTAssertNotNil(dict1); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict1prime = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)]; //% XCTAssertNotNil(dict1prime); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s2 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)]; //% XCTAssertNotNil(dict2); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict3 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys2 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)]; //% XCTAssertNotNil(dict3); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict4 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s3 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s3)]; @@ -188,13 +195,13 @@ //%- (void)testCopy { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; //% XCTAssertNotNil(dict); //% -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = [dict copy]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy]; //% XCTAssertNotNil(dict2); //% //% // Should be new object but equal. @@ -209,13 +216,13 @@ //%- (void)testDictionaryFromDictionary { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; //% XCTAssertNotNil(dict); //% -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict]; //% XCTAssertNotNil(dict2); //% @@ -226,7 +233,7 @@ //%} //% //%- (void)testAdds { -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionary]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionary]; //% XCTAssertNotNil(dict); //% //% XCTAssertEqual(dict.count, 0U); @@ -235,7 +242,7 @@ //% //% const KEY_TYPE KisP##kKeys[] = { KEY2, KEY3, KEY4 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL2, VAL3, VAL4 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; @@ -253,7 +260,7 @@ //%- (void)testRemove { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; @@ -294,7 +301,7 @@ //%- (void)testInplaceMutation { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; @@ -321,7 +328,7 @@ //% //% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY3 }; //% const VALUE_TYPE k##VNAME$u##s2[] = { VAL3, VAL1 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s2 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys2 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)]; @@ -353,7 +360,7 @@ //%- (void)testRawBasics { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3 }; //% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys @@ -429,31 +436,31 @@ //% const VALUE_TYPE kValues1[] = { VAL1, VAL2, VAL3 }; // Unknown //% const VALUE_TYPE kValues2[] = { VAL1, VAL4, VAL3 }; // Unknown //% const VALUE_TYPE kValues3[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict1 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues1 //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)]; //% XCTAssertNotNil(dict1); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict1prime = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues1 //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)]; //% XCTAssertNotNil(dict1prime); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues2 //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues2)]; //% XCTAssertNotNil(dict2); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict3 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues1 //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys2 //% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)]; //% XCTAssertNotNil(dict3); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict4 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues3 //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1 @@ -485,14 +492,14 @@ //%- (void)testCopyWithUnknowns { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknown -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)]; //% XCTAssertNotNil(dict); //% -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = [dict copy]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy]; //% XCTAssertNotNil(dict2); //% //% // Should be new pointer, but equal objects. @@ -507,14 +514,14 @@ //%- (void)testDictionaryFromDictionary { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)]; //% XCTAssertNotNil(dict); //% -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict]; //% XCTAssertNotNil(dict2); //% @@ -526,7 +533,7 @@ //%} //% //%- (void)testUnknownAdds { -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue]; //% XCTAssertNotNil(dict); //% @@ -539,7 +546,7 @@ //% //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY3, KEY4 }; //% const VALUE_TYPE kValues[] = { VAL1, VAL3, VAL4 }; // Unknown -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValues:kValues //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)]; @@ -559,7 +566,7 @@ //%- (void)testUnknownRemove { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys @@ -601,7 +608,7 @@ //%- (void)testInplaceMutationUnknowns { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys @@ -637,7 +644,7 @@ //% //% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY3 }; //% const VALUE_TYPE kValues2[] = { VAL3, VAL2 }; // Unknown -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues2 //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys2 @@ -657,14 +664,14 @@ //%- (void)testCopyUnknowns { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 }; //% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue //% KEY_NAME$S VALUE_NAME$S rawValues:kValues //% KEY_NAME$S VALUE_NAME$S forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)]; //% XCTAssertNotNil(dict); //% -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = [dict copy]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy]; //% XCTAssertNotNil(dict2); //% //% // Should be new pointer, but equal objects. @@ -782,7 +789,7 @@ //%@implementation GPB##KEY_NAME##VALUE_NAME##DictionaryTests //% //%- (void)testEmpty { -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; //% XCTAssertNotNil(dict); //% XCTAssertEqual(dict.count, 0U); //%VALUE_NOT_FOUND##VHELPER(dict, KEY1) @@ -794,7 +801,7 @@ //%} //% //%- (void)testOne { -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWith##VNAME$u##:VAL1 forKey:KEY1]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWith##VNAME$u##:VAL1 forKey:KEY1]; //% XCTAssertNotNil(dict); //% XCTAssertEqual(dict.count, 1U); //%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(dict, VNAME, KEY1, VAL1) @@ -809,7 +816,7 @@ //%- (void)testBasics { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; @@ -858,27 +865,27 @@ //% const VALUE_TYPE k##VNAME$u##s1[] = { VAL1, VAL2 }; //% const VALUE_TYPE k##VNAME$u##s2[] = { VAL2, VAL1 }; //% const VALUE_TYPE k##VNAME$u##s3[] = { VAL2 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict1 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)]; //% XCTAssertNotNil(dict1); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict1prime = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)]; //% XCTAssertNotNil(dict1prime); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s2 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)]; //% XCTAssertNotNil(dict2); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict3 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys2 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)]; //% XCTAssertNotNil(dict3); -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict4 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s3 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys1 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s3)]; @@ -909,13 +916,13 @@ //%- (void)testCopy { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; //% XCTAssertNotNil(dict); //% -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = [dict copy]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy]; //% XCTAssertNotNil(dict2); //% //% // Should be new object but equal. @@ -930,13 +937,13 @@ //%- (void)testDictionaryFromDictionary { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; //% XCTAssertNotNil(dict); //% -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict]; //% XCTAssertNotNil(dict2); //% @@ -947,7 +954,7 @@ //%} //% //%- (void)testAdds { -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionary]; +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionary]; //% XCTAssertNotNil(dict); //% //% XCTAssertEqual(dict.count, 0U); @@ -956,7 +963,7 @@ //% //% const KEY_TYPE KisP##kKeys[] = { KEY2 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL2 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; @@ -972,7 +979,7 @@ //%- (void)testRemove { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2}; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; @@ -1000,7 +1007,7 @@ //%- (void)testInplaceMutation { //% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 }; //% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)]; @@ -1021,7 +1028,7 @@ //% //% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1 }; //% const VALUE_TYPE k##VNAME$u##s2[] = { VAL2, VAL1 }; -//% GPB##KEY_NAME##VALUE_NAME##Dictionary *dict2 = +//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VNAME$u##s:k##VNAME$u##s2 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:kKeys2 //% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)]; diff --git a/objectivec/google/protobuf/Any.pbobjc.h b/objectivec/google/protobuf/Any.pbobjc.h index 9866b5b1..a204ae9a 100644 --- a/objectivec/google/protobuf/Any.pbobjc.h +++ b/objectivec/google/protobuf/Any.pbobjc.h @@ -15,13 +15,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - GPBAnyRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBAnyRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBAny @@ -31,61 +33,61 @@ typedef GPB_ENUM(GPBAny_FieldNumber) { GPBAny_FieldNumber_Value = 2, }; -// `Any` contains an arbitrary serialized message along with a URL -// that describes the type of the serialized message. -// -// -// JSON -// ==== -// The JSON representation of an `Any` value uses the regular -// representation of the deserialized, embedded message, with an -// additional field `@type` which contains the type URL. Example: -// -// package google.profile; -// message Person { -// string first_name = 1; -// string last_name = 2; -// } -// -// { -// "@type": "type.googleapis.com/google.profile.Person", -// "firstName": <string>, -// "lastName": <string> -// } -// -// If the embedded message type is well-known and has a custom JSON -// representation, that representation will be embedded adding a field -// `value` which holds the custom JSON in addition to the `@type` -// field. Example (for message [google.protobuf.Duration][]): -// -// { -// "@type": "type.googleapis.com/google.protobuf.Duration", -// "value": "1.212s" -// } +/// `Any` contains an arbitrary serialized message along with a URL +/// that describes the type of the serialized message. +/// +/// +/// JSON +/// ==== +/// The JSON representation of an `Any` value uses the regular +/// representation of the deserialized, embedded message, with an +/// additional field `\@type` which contains the type URL. Example: +/// +/// package google.profile; +/// message Person { +/// string first_name = 1; +/// string last_name = 2; +/// } +/// +/// { +/// "\@type": "type.googleapis.com/google.profile.Person", +/// "firstName": <string>, +/// "lastName": <string> +/// } +/// +/// If the embedded message type is well-known and has a custom JSON +/// representation, that representation will be embedded adding a field +/// `value` which holds the custom JSON in addition to the `\@type` +/// field. Example (for message [google.protobuf.Duration][]): +/// +/// { +/// "\@type": "type.googleapis.com/google.protobuf.Duration", +/// "value": "1.212s" +/// } @interface GPBAny : GPBMessage -// A URL/resource name whose content describes the type of the -// serialized message. -// -// For URLs which use the schema `http`, `https`, or no schema, the -// following restrictions and interpretations apply: -// -// * If no schema is provided, `https` is assumed. -// * The last segment of the URL's path must represent the fully -// qualified name of the type (as in `path/google.protobuf.Duration`). -// * An HTTP GET on the URL must yield a [google.protobuf.Type][] -// value in binary format, or produce an error. -// * Applications are allowed to cache lookup results based on the -// URL, or have them precompiled into a binary to avoid any -// lookup. Therefore, binary compatibility needs to be preserved -// on changes to types. (Use versioned type names to manage -// breaking changes.) -// -// Schemas other than `http`, `https` (or the empty schema) might be -// used with implementation specific semantics. +/// A URL/resource name whose content describes the type of the +/// serialized message. +/// +/// For URLs which use the schema `http`, `https`, or no schema, the +/// following restrictions and interpretations apply: +/// +/// * If no schema is provided, `https` is assumed. +/// * The last segment of the URL's path must represent the fully +/// qualified name of the type (as in `path/google.protobuf.Duration`). +/// * An HTTP GET on the URL must yield a [google.protobuf.Type][] +/// value in binary format, or produce an error. +/// * Applications are allowed to cache lookup results based on the +/// URL, or have them precompiled into a binary to avoid any +/// lookup. Therefore, binary compatibility needs to be preserved +/// on changes to types. (Use versioned type names to manage +/// breaking changes.) +/// +/// Schemas other than `http`, `https` (or the empty schema) might be +/// used with implementation specific semantics. @property(nonatomic, readwrite, copy, null_resettable) NSString *typeURL; -// Must be valid serialized data of the above specified type. +/// Must be valid serialized data of the above specified type. @property(nonatomic, readwrite, copy, null_resettable) NSData *value; @end diff --git a/objectivec/google/protobuf/Api.pbobjc.h b/objectivec/google/protobuf/Api.pbobjc.h index c3cf8e94..271a166f 100644 --- a/objectivec/google/protobuf/Api.pbobjc.h +++ b/objectivec/google/protobuf/Api.pbobjc.h @@ -11,6 +11,9 @@ CF_EXTERN_C_BEGIN +@class GPBMethod; +@class GPBMixin; +@class GPBOption; @class GPBSourceContext; GPB_ENUM_FWD_DECLARE(GPBSyntax); @@ -18,13 +21,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - GPBApiRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBApiRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBApi @@ -39,61 +44,67 @@ typedef GPB_ENUM(GPBApi_FieldNumber) { GPBApi_FieldNumber_Syntax = 7, }; -// Api is a light-weight descriptor for a protocol buffer service. +/// Api is a light-weight descriptor for a protocol buffer service. @interface GPBApi : GPBMessage -// The fully qualified name of this api, including package name -// followed by the api's simple name. +/// The fully qualified name of this api, including package name +/// followed by the api's simple name. @property(nonatomic, readwrite, copy, null_resettable) NSString *name; -// The methods of this api, in unspecified order. -// |methodsArray| contains |GPBMethod| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *methodsArray; +/// The methods of this api, in unspecified order. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBMethod*> *methodsArray; +/// The number of items in @c methodsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger methodsArray_Count; -// Any metadata attached to the API. -// |optionsArray| contains |GPBOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; +/// Any metadata attached to the API. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray; +/// The number of items in @c optionsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger optionsArray_Count; -// A version string for this api. If specified, must have the form -// `major-version.minor-version`, as in `1.10`. If the minor version -// is omitted, it defaults to zero. If the entire version field is -// empty, the major version is derived from the package name, as -// outlined below. If the field is not empty, the version in the -// package name will be verified to be consistent with what is -// provided here. -// -// The versioning schema uses [semantic -// versioning](http://semver.org) where the major version number -// indicates a breaking change and the minor version an additive, -// non-breaking change. Both version numbers are signals to users -// what to expect from different versions, and should be carefully -// chosen based on the product plan. -// -// The major version is also reflected in the package name of the -// API, which must end in `v<major-version>`, as in -// `google.feature.v1`. For major versions 0 and 1, the suffix can -// be omitted. Zero major versions must only be used for -// experimental, none-GA apis. +/// A version string for this api. If specified, must have the form +/// `major-version.minor-version`, as in `1.10`. If the minor version +/// is omitted, it defaults to zero. If the entire version field is +/// empty, the major version is derived from the package name, as +/// outlined below. If the field is not empty, the version in the +/// package name will be verified to be consistent with what is +/// provided here. +/// +/// The versioning schema uses [semantic +/// versioning](http://semver.org) where the major version number +/// indicates a breaking change and the minor version an additive, +/// non-breaking change. Both version numbers are signals to users +/// what to expect from different versions, and should be carefully +/// chosen based on the product plan. +/// +/// The major version is also reflected in the package name of the +/// API, which must end in `v<major-version>`, as in +/// `google.feature.v1`. For major versions 0 and 1, the suffix can +/// be omitted. Zero major versions must only be used for +/// experimental, none-GA apis. @property(nonatomic, readwrite, copy, null_resettable) NSString *version; -// Source context for the protocol buffer service represented by this -// message. -@property(nonatomic, readwrite) BOOL hasSourceContext; +/// Source context for the protocol buffer service represented by this +/// message. @property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext; +/// Test to see if @c sourceContext has been set. +@property(nonatomic, readwrite) BOOL hasSourceContext; -// Included APIs. See [Mixin][]. -// |mixinsArray| contains |GPBMixin| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *mixinsArray; +/// Included APIs. See [Mixin][]. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBMixin*> *mixinsArray; +/// The number of items in @c mixinsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger mixinsArray_Count; -// The source syntax of the service. +/// The source syntax of the service. @property(nonatomic, readwrite) enum GPBSyntax syntax; @end +/// Fetches the raw value of a @c GPBApi's @c syntax property, even +/// if the value was not defined by the enum at the time the code was generated. int32_t GPBApi_Syntax_RawValue(GPBApi *message); +/// Sets the raw value of an @c GPBApi's @c syntax property, allowing +/// it to be set to a value that was not defined by the enum at the time the code +/// was generated. void SetGPBApi_Syntax_RawValue(GPBApi *message, int32_t value); #pragma mark - GPBMethod @@ -108,35 +119,40 @@ typedef GPB_ENUM(GPBMethod_FieldNumber) { GPBMethod_FieldNumber_Syntax = 7, }; -// Method represents a method of an api. +/// Method represents a method of an api. @interface GPBMethod : GPBMessage -// The simple name of this method. +/// The simple name of this method. @property(nonatomic, readwrite, copy, null_resettable) NSString *name; -// A URL of the input message type. +/// A URL of the input message type. @property(nonatomic, readwrite, copy, null_resettable) NSString *requestTypeURL; -// If true, the request is streamed. +/// If true, the request is streamed. @property(nonatomic, readwrite) BOOL requestStreaming; -// The URL of the output message type. +/// The URL of the output message type. @property(nonatomic, readwrite, copy, null_resettable) NSString *responseTypeURL; -// If true, the response is streamed. +/// If true, the response is streamed. @property(nonatomic, readwrite) BOOL responseStreaming; -// Any metadata attached to the method. -// |optionsArray| contains |GPBOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; +/// Any metadata attached to the method. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray; +/// The number of items in @c optionsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger optionsArray_Count; -// The source syntax of this method. +/// The source syntax of this method. @property(nonatomic, readwrite) enum GPBSyntax syntax; @end +/// Fetches the raw value of a @c GPBMethod's @c syntax property, even +/// if the value was not defined by the enum at the time the code was generated. int32_t GPBMethod_Syntax_RawValue(GPBMethod *message); +/// Sets the raw value of an @c GPBMethod's @c syntax property, allowing +/// it to be set to a value that was not defined by the enum at the time the code +/// was generated. void SetGPBMethod_Syntax_RawValue(GPBMethod *message, int32_t value); #pragma mark - GPBMixin @@ -146,90 +162,90 @@ typedef GPB_ENUM(GPBMixin_FieldNumber) { GPBMixin_FieldNumber_Root = 2, }; -// Declares an API to be included in this API. The including API must -// redeclare all the methods from the included API, but documentation -// and options are inherited as follows: -// -// - If after comment and whitespace stripping, the documentation -// string of the redeclared method is empty, it will be inherited -// from the original method. -// -// - Each annotation belonging to the service config (http, -// visibility) which is not set in the redeclared method will be -// inherited. -// -// - If an http annotation is inherited, the path pattern will be -// modified as follows. Any version prefix will be replaced by the -// version of the including API plus the [root][] path if specified. -// -// Example of a simple mixin: -// -// package google.acl.v1; -// service AccessControl { -// // Get the underlying ACL object. -// rpc GetAcl(GetAclRequest) returns (Acl) { -// option (google.api.http).get = "/v1/{resource=**}:getAcl"; -// } -// } -// -// package google.storage.v2; -// service Storage { -// rpc GetAcl(GetAclRequest) returns (Acl); -// -// // Get a data record. -// rpc GetData(GetDataRequest) returns (Data) { -// option (google.api.http).get = "/v2/{resource=**}"; -// } -// } -// -// Example of a mixin configuration: -// -// apis: -// - name: google.storage.v2.Storage -// mixins: -// - name: google.acl.v1.AccessControl -// -// The mixin construct implies that all methods in `AccessControl` are -// also declared with same name and request/response types in -// `Storage`. A documentation generator or annotation processor will -// see the effective `Storage.GetAcl` method after inherting -// documentation and annotations as follows: -// -// service Storage { -// // Get the underlying ACL object. -// rpc GetAcl(GetAclRequest) returns (Acl) { -// option (google.api.http).get = "/v2/{resource=**}:getAcl"; -// } -// ... -// } -// -// Note how the version in the path pattern changed from `v1` to `v2`. -// -// If the `root` field in the mixin is specified, it should be a -// relative path under which inherited HTTP paths are placed. Example: -// -// apis: -// - name: google.storage.v2.Storage -// mixins: -// - name: google.acl.v1.AccessControl -// root: acls -// -// This implies the following inherited HTTP annotation: -// -// service Storage { -// // Get the underlying ACL object. -// rpc GetAcl(GetAclRequest) returns (Acl) { -// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; -// } -// ... -// } +/// Declares an API to be included in this API. The including API must +/// redeclare all the methods from the included API, but documentation +/// and options are inherited as follows: +/// +/// - If after comment and whitespace stripping, the documentation +/// string of the redeclared method is empty, it will be inherited +/// from the original method. +/// +/// - Each annotation belonging to the service config (http, +/// visibility) which is not set in the redeclared method will be +/// inherited. +/// +/// - If an http annotation is inherited, the path pattern will be +/// modified as follows. Any version prefix will be replaced by the +/// version of the including API plus the [root][] path if specified. +/// +/// Example of a simple mixin: +/// +/// package google.acl.v1; +/// service AccessControl { +/// // Get the underlying ACL object. +/// rpc GetAcl(GetAclRequest) returns (Acl) { +/// option (google.api.http).get = "/v1/{resource=**}:getAcl"; +/// } +/// } +/// +/// package google.storage.v2; +/// service Storage { +/// rpc GetAcl(GetAclRequest) returns (Acl); +/// +/// // Get a data record. +/// rpc GetData(GetDataRequest) returns (Data) { +/// option (google.api.http).get = "/v2/{resource=**}"; +/// } +/// } +/// +/// Example of a mixin configuration: +/// +/// apis: +/// - name: google.storage.v2.Storage +/// mixins: +/// - name: google.acl.v1.AccessControl +/// +/// The mixin construct implies that all methods in `AccessControl` are +/// also declared with same name and request/response types in +/// `Storage`. A documentation generator or annotation processor will +/// see the effective `Storage.GetAcl` method after inherting +/// documentation and annotations as follows: +/// +/// service Storage { +/// // Get the underlying ACL object. +/// rpc GetAcl(GetAclRequest) returns (Acl) { +/// option (google.api.http).get = "/v2/{resource=**}:getAcl"; +/// } +/// ... +/// } +/// +/// Note how the version in the path pattern changed from `v1` to `v2`. +/// +/// If the `root` field in the mixin is specified, it should be a +/// relative path under which inherited HTTP paths are placed. Example: +/// +/// apis: +/// - name: google.storage.v2.Storage +/// mixins: +/// - name: google.acl.v1.AccessControl +/// root: acls +/// +/// This implies the following inherited HTTP annotation: +/// +/// service Storage { +/// // Get the underlying ACL object. +/// rpc GetAcl(GetAclRequest) returns (Acl) { +/// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; +/// } +/// ... +/// } @interface GPBMixin : GPBMessage -// The fully qualified name of the API which is included. +/// The fully qualified name of the API which is included. @property(nonatomic, readwrite, copy, null_resettable) NSString *name; -// If non-empty specifies a path under which inherited HTTP paths -// are rooted. +/// If non-empty specifies a path under which inherited HTTP paths +/// are rooted. @property(nonatomic, readwrite, copy, null_resettable) NSString *root; @end diff --git a/objectivec/google/protobuf/Descriptor.pbobjc.h b/objectivec/google/protobuf/Descriptor.pbobjc.h index 9c43cfd2..109711c7 100644 --- a/objectivec/google/protobuf/Descriptor.pbobjc.h +++ b/objectivec/google/protobuf/Descriptor.pbobjc.h @@ -11,99 +11,119 @@ CF_EXTERN_C_BEGIN +@class GPBDescriptorProto; +@class GPBDescriptorProto_ExtensionRange; +@class GPBDescriptorProto_ReservedRange; +@class GPBEnumDescriptorProto; @class GPBEnumOptions; +@class GPBEnumValueDescriptorProto; @class GPBEnumValueOptions; +@class GPBFieldDescriptorProto; @class GPBFieldOptions; +@class GPBFileDescriptorProto; @class GPBFileOptions; +@class GPBGeneratedCodeInfo_Annotation; @class GPBMessageOptions; +@class GPBMethodDescriptorProto; @class GPBMethodOptions; +@class GPBOneofDescriptorProto; +@class GPBServiceDescriptorProto; @class GPBServiceOptions; @class GPBSourceCodeInfo; +@class GPBSourceCodeInfo_Location; +@class GPBUninterpretedOption; +@class GPBUninterpretedOption_NamePart; NS_ASSUME_NONNULL_BEGIN #pragma mark - Enum GPBFieldDescriptorProto_Type typedef GPB_ENUM(GPBFieldDescriptorProto_Type) { - // 0 is reserved for errors. - // Order is weird for historical reasons. + /// 0 is reserved for errors. + /// Order is weird for historical reasons. GPBFieldDescriptorProto_Type_TypeDouble = 1, GPBFieldDescriptorProto_Type_TypeFloat = 2, - // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if - // negative values are likely. + /// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + /// negative values are likely. GPBFieldDescriptorProto_Type_TypeInt64 = 3, GPBFieldDescriptorProto_Type_TypeUint64 = 4, - // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if - // negative values are likely. + /// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + /// negative values are likely. GPBFieldDescriptorProto_Type_TypeInt32 = 5, GPBFieldDescriptorProto_Type_TypeFixed64 = 6, GPBFieldDescriptorProto_Type_TypeFixed32 = 7, GPBFieldDescriptorProto_Type_TypeBool = 8, GPBFieldDescriptorProto_Type_TypeString = 9, - // Tag-delimited aggregate. + /// Tag-delimited aggregate. GPBFieldDescriptorProto_Type_TypeGroup = 10, - // Length-delimited aggregate. + /// Length-delimited aggregate. GPBFieldDescriptorProto_Type_TypeMessage = 11, - // New in version 2. + /// New in version 2. GPBFieldDescriptorProto_Type_TypeBytes = 12, GPBFieldDescriptorProto_Type_TypeUint32 = 13, GPBFieldDescriptorProto_Type_TypeEnum = 14, GPBFieldDescriptorProto_Type_TypeSfixed32 = 15, GPBFieldDescriptorProto_Type_TypeSfixed64 = 16, - // Uses ZigZag encoding. + /// Uses ZigZag encoding. GPBFieldDescriptorProto_Type_TypeSint32 = 17, - // Uses ZigZag encoding. + /// Uses ZigZag encoding. GPBFieldDescriptorProto_Type_TypeSint64 = 18, }; GPBEnumDescriptor *GPBFieldDescriptorProto_Type_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBFieldDescriptorProto_Type_IsValidValue(int32_t value); #pragma mark - Enum GPBFieldDescriptorProto_Label typedef GPB_ENUM(GPBFieldDescriptorProto_Label) { - // 0 is reserved for errors + /// 0 is reserved for errors GPBFieldDescriptorProto_Label_LabelOptional = 1, GPBFieldDescriptorProto_Label_LabelRequired = 2, - // TODO(sanjay): Should we add LABEL_MAP? + /// TODO(sanjay): Should we add LABEL_MAP? GPBFieldDescriptorProto_Label_LabelRepeated = 3, }; GPBEnumDescriptor *GPBFieldDescriptorProto_Label_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBFieldDescriptorProto_Label_IsValidValue(int32_t value); #pragma mark - Enum GPBFileOptions_OptimizeMode -// Generated classes can be optimized for speed or code size. +/// Generated classes can be optimized for speed or code size. typedef GPB_ENUM(GPBFileOptions_OptimizeMode) { - // Generate complete code for parsing, serialization, + /// Generate complete code for parsing, serialization, GPBFileOptions_OptimizeMode_Speed = 1, - // etc. + /// etc. GPBFileOptions_OptimizeMode_CodeSize = 2, - // Generate code using MessageLite and the lite runtime. + /// Generate code using MessageLite and the lite runtime. GPBFileOptions_OptimizeMode_LiteRuntime = 3, }; GPBEnumDescriptor *GPBFileOptions_OptimizeMode_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBFileOptions_OptimizeMode_IsValidValue(int32_t value); #pragma mark - Enum GPBFieldOptions_CType typedef GPB_ENUM(GPBFieldOptions_CType) { - // Default mode. + /// Default mode. GPBFieldOptions_CType_String = 0, GPBFieldOptions_CType_Cord = 1, GPBFieldOptions_CType_StringPiece = 2, @@ -111,34 +131,40 @@ typedef GPB_ENUM(GPBFieldOptions_CType) { GPBEnumDescriptor *GPBFieldOptions_CType_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBFieldOptions_CType_IsValidValue(int32_t value); #pragma mark - Enum GPBFieldOptions_JSType typedef GPB_ENUM(GPBFieldOptions_JSType) { - // Use the default type. + /// Use the default type. GPBFieldOptions_JSType_JsNormal = 0, - // Use JavaScript strings. + /// Use JavaScript strings. GPBFieldOptions_JSType_JsString = 1, - // Use JavaScript numbers. + /// Use JavaScript numbers. GPBFieldOptions_JSType_JsNumber = 2, }; GPBEnumDescriptor *GPBFieldOptions_JSType_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBFieldOptions_JSType_IsValidValue(int32_t value); #pragma mark - GPBDescriptorRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBDescriptorRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBFileDescriptorSet @@ -147,12 +173,12 @@ typedef GPB_ENUM(GPBFileDescriptorSet_FieldNumber) { GPBFileDescriptorSet_FieldNumber_FileArray = 1, }; -// The protocol compiler can output a FileDescriptorSet containing the .proto -// files it parses. +/// The protocol compiler can output a FileDescriptorSet containing the .proto +/// files it parses. @interface GPBFileDescriptorSet : GPBMessage -// |fileArray| contains |GPBFileDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *fileArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBFileDescriptorProto*> *fileArray; +/// The number of items in @c fileArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger fileArray_Count; @end @@ -174,62 +200,69 @@ typedef GPB_ENUM(GPBFileDescriptorProto_FieldNumber) { GPBFileDescriptorProto_FieldNumber_Syntax = 12, }; -// Describes a complete .proto file. +/// Describes a complete .proto file. @interface GPBFileDescriptorProto : GPBMessage -// file name, relative to root of source tree -@property(nonatomic, readwrite) BOOL hasName; +/// file name, relative to root of source tree @property(nonatomic, readwrite, copy, null_resettable) NSString *name; +/// Test to see if @c name has been set. +@property(nonatomic, readwrite) BOOL hasName; -// e.g. "foo", "foo.bar", etc. -@property(nonatomic, readwrite) BOOL hasPackage; +/// e.g. "foo", "foo.bar", etc. @property(nonatomic, readwrite, copy, null_resettable) NSString *package; +/// Test to see if @c package has been set. +@property(nonatomic, readwrite) BOOL hasPackage; -// Names of files imported by this file. -// |dependencyArray| contains |NSString| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *dependencyArray; +/// Names of files imported by this file. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *dependencyArray; +/// The number of items in @c dependencyArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger dependencyArray_Count; -// Indexes of the public imported files in the dependency list above. +/// Indexes of the public imported files in the dependency list above. @property(nonatomic, readwrite, strong, null_resettable) GPBInt32Array *publicDependencyArray; +/// The number of items in @c publicDependencyArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger publicDependencyArray_Count; -// Indexes of the weak imported files in the dependency list. -// For Google-internal migration only. Do not use. +/// Indexes of the weak imported files in the dependency list. +/// For Google-internal migration only. Do not use. @property(nonatomic, readwrite, strong, null_resettable) GPBInt32Array *weakDependencyArray; +/// The number of items in @c weakDependencyArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger weakDependencyArray_Count; -// All top-level definitions in this file. -// |messageTypeArray| contains |GPBDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *messageTypeArray; +/// All top-level definitions in this file. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBDescriptorProto*> *messageTypeArray; +/// The number of items in @c messageTypeArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger messageTypeArray_Count; -// |enumTypeArray| contains |GPBEnumDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *enumTypeArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBEnumDescriptorProto*> *enumTypeArray; +/// The number of items in @c enumTypeArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger enumTypeArray_Count; -// |serviceArray| contains |GPBServiceDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *serviceArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBServiceDescriptorProto*> *serviceArray; +/// The number of items in @c serviceArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger serviceArray_Count; -// |extensionArray| contains |GPBFieldDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *extensionArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBFieldDescriptorProto*> *extensionArray; +/// The number of items in @c extensionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger extensionArray_Count; -@property(nonatomic, readwrite) BOOL hasOptions; @property(nonatomic, readwrite, strong, null_resettable) GPBFileOptions *options; +/// Test to see if @c options has been set. +@property(nonatomic, readwrite) BOOL hasOptions; -// This field contains optional information about the original source code. -// You may safely remove this entire field without harming runtime -// functionality of the descriptors -- the information is needed only by -// development tools. -@property(nonatomic, readwrite) BOOL hasSourceCodeInfo; +/// This field contains optional information about the original source code. +/// You may safely remove this entire field without harming runtime +/// functionality of the descriptors -- the information is needed only by +/// development tools. @property(nonatomic, readwrite, strong, null_resettable) GPBSourceCodeInfo *sourceCodeInfo; +/// Test to see if @c sourceCodeInfo has been set. +@property(nonatomic, readwrite) BOOL hasSourceCodeInfo; -// The syntax of the proto file. -// The supported values are "proto2" and "proto3". -@property(nonatomic, readwrite) BOOL hasSyntax; +/// The syntax of the proto file. +/// The supported values are "proto2" and "proto3". @property(nonatomic, readwrite, copy, null_resettable) NSString *syntax; +/// Test to see if @c syntax has been set. +@property(nonatomic, readwrite) BOOL hasSyntax; @end @@ -248,47 +281,49 @@ typedef GPB_ENUM(GPBDescriptorProto_FieldNumber) { GPBDescriptorProto_FieldNumber_ReservedNameArray = 10, }; -// Describes a message type. +/// Describes a message type. @interface GPBDescriptorProto : GPBMessage -@property(nonatomic, readwrite) BOOL hasName; @property(nonatomic, readwrite, copy, null_resettable) NSString *name; +/// Test to see if @c name has been set. +@property(nonatomic, readwrite) BOOL hasName; -// |fieldArray| contains |GPBFieldDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *fieldArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBFieldDescriptorProto*> *fieldArray; +/// The number of items in @c fieldArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger fieldArray_Count; -// |extensionArray| contains |GPBFieldDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *extensionArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBFieldDescriptorProto*> *extensionArray; +/// The number of items in @c extensionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger extensionArray_Count; -// |nestedTypeArray| contains |GPBDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *nestedTypeArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBDescriptorProto*> *nestedTypeArray; +/// The number of items in @c nestedTypeArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger nestedTypeArray_Count; -// |enumTypeArray| contains |GPBEnumDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *enumTypeArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBEnumDescriptorProto*> *enumTypeArray; +/// The number of items in @c enumTypeArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger enumTypeArray_Count; -// |extensionRangeArray| contains |GPBDescriptorProto_ExtensionRange| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *extensionRangeArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBDescriptorProto_ExtensionRange*> *extensionRangeArray; +/// The number of items in @c extensionRangeArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger extensionRangeArray_Count; -// |oneofDeclArray| contains |GPBOneofDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *oneofDeclArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOneofDescriptorProto*> *oneofDeclArray; +/// The number of items in @c oneofDeclArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger oneofDeclArray_Count; -@property(nonatomic, readwrite) BOOL hasOptions; @property(nonatomic, readwrite, strong, null_resettable) GPBMessageOptions *options; +/// Test to see if @c options has been set. +@property(nonatomic, readwrite) BOOL hasOptions; -// |reservedRangeArray| contains |GPBDescriptorProto_ReservedRange| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *reservedRangeArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBDescriptorProto_ReservedRange*> *reservedRangeArray; +/// The number of items in @c reservedRangeArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger reservedRangeArray_Count; -// Reserved field names, which may not be used by fields in the same message. -// A given name may only be reserved once. -// |reservedNameArray| contains |NSString| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *reservedNameArray; +/// Reserved field names, which may not be used by fields in the same message. +/// A given name may only be reserved once. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *reservedNameArray; +/// The number of items in @c reservedNameArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger reservedNameArray_Count; @end @@ -302,12 +337,12 @@ typedef GPB_ENUM(GPBDescriptorProto_ExtensionRange_FieldNumber) { @interface GPBDescriptorProto_ExtensionRange : GPBMessage -@property(nonatomic, readwrite) BOOL hasStart; @property(nonatomic, readwrite) int32_t start; -@property(nonatomic, readwrite) BOOL hasEnd; +@property(nonatomic, readwrite) BOOL hasStart; @property(nonatomic, readwrite) int32_t end; +@property(nonatomic, readwrite) BOOL hasEnd; @end #pragma mark - GPBDescriptorProto_ReservedRange @@ -317,19 +352,19 @@ typedef GPB_ENUM(GPBDescriptorProto_ReservedRange_FieldNumber) { GPBDescriptorProto_ReservedRange_FieldNumber_End = 2, }; -// Range of reserved tag numbers. Reserved tag numbers may not be used by -// fields or extension ranges in the same message. Reserved ranges may -// not overlap. +/// Range of reserved tag numbers. Reserved tag numbers may not be used by +/// fields or extension ranges in the same message. Reserved ranges may +/// not overlap. @interface GPBDescriptorProto_ReservedRange : GPBMessage -// Inclusive. -@property(nonatomic, readwrite) BOOL hasStart; +/// Inclusive. @property(nonatomic, readwrite) int32_t start; -// Exclusive. -@property(nonatomic, readwrite) BOOL hasEnd; +@property(nonatomic, readwrite) BOOL hasStart; +/// Exclusive. @property(nonatomic, readwrite) int32_t end; +@property(nonatomic, readwrite) BOOL hasEnd; @end #pragma mark - GPBFieldDescriptorProto @@ -347,58 +382,64 @@ typedef GPB_ENUM(GPBFieldDescriptorProto_FieldNumber) { GPBFieldDescriptorProto_FieldNumber_JsonName = 10, }; -// Describes a field within a message. +/// Describes a field within a message. @interface GPBFieldDescriptorProto : GPBMessage -@property(nonatomic, readwrite) BOOL hasName; @property(nonatomic, readwrite, copy, null_resettable) NSString *name; +/// Test to see if @c name has been set. +@property(nonatomic, readwrite) BOOL hasName; -@property(nonatomic, readwrite) BOOL hasNumber; @property(nonatomic, readwrite) int32_t number; -@property(nonatomic, readwrite) BOOL hasLabel; +@property(nonatomic, readwrite) BOOL hasNumber; @property(nonatomic, readwrite) GPBFieldDescriptorProto_Label label; -// 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. -@property(nonatomic, readwrite) BOOL hasType; +@property(nonatomic, readwrite) BOOL hasLabel; +/// 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. @property(nonatomic, readwrite) GPBFieldDescriptorProto_Type type; -// 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 -// rules are used to find the type (i.e. first the nested types within this -// message are searched, then within the parent, on up to the root -// namespace). -@property(nonatomic, readwrite) BOOL hasTypeName; +@property(nonatomic, readwrite) BOOL hasType; +/// 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 +/// rules are used to find the type (i.e. first the nested types within this +/// message are searched, then within the parent, on up to the root +/// namespace). @property(nonatomic, readwrite, copy, null_resettable) NSString *typeName; +/// Test to see if @c typeName has been set. +@property(nonatomic, readwrite) BOOL hasTypeName; -// For extensions, this is the name of the type being extended. It is -// resolved in the same manner as type_name. -@property(nonatomic, readwrite) BOOL hasExtendee; +/// For extensions, this is the name of the type being extended. It is +/// resolved in the same manner as type_name. @property(nonatomic, readwrite, copy, null_resettable) NSString *extendee; +/// Test to see if @c extendee has been set. +@property(nonatomic, readwrite) BOOL hasExtendee; -// For numeric types, contains the original text representation of the value. -// For booleans, "true" or "false". -// For strings, contains the default text contents (not escaped in any way). -// For bytes, contains the C escaped value. All bytes >= 128 are escaped. -// TODO(kenton): Base-64 encode? -@property(nonatomic, readwrite) BOOL hasDefaultValue; +/// For numeric types, contains the original text representation of the value. +/// For booleans, "true" or "false". +/// For strings, contains the default text contents (not escaped in any way). +/// For bytes, contains the C escaped value. All bytes >= 128 are escaped. +/// TODO(kenton): Base-64 encode? @property(nonatomic, readwrite, copy, null_resettable) NSString *defaultValue; +/// Test to see if @c defaultValue has been set. +@property(nonatomic, readwrite) BOOL hasDefaultValue; -// If set, gives the index of a oneof in the containing type's oneof_decl -// list. This field is a member of that oneof. -@property(nonatomic, readwrite) BOOL hasOneofIndex; +/// If set, gives the index of a oneof in the containing type's oneof_decl +/// list. This field is a member of that oneof. @property(nonatomic, readwrite) int32_t oneofIndex; -// 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 -// will be used. Otherwise, it's deduced from the field's name by converting -// it to camelCase. -@property(nonatomic, readwrite) BOOL hasJsonName; +@property(nonatomic, readwrite) BOOL hasOneofIndex; +/// 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 +/// will be used. Otherwise, it's deduced from the field's name by converting +/// it to camelCase. @property(nonatomic, readwrite, copy, null_resettable) NSString *jsonName; +/// Test to see if @c jsonName has been set. +@property(nonatomic, readwrite) BOOL hasJsonName; -@property(nonatomic, readwrite) BOOL hasOptions; @property(nonatomic, readwrite, strong, null_resettable) GPBFieldOptions *options; +/// Test to see if @c options has been set. +@property(nonatomic, readwrite) BOOL hasOptions; @end @@ -408,11 +449,12 @@ typedef GPB_ENUM(GPBOneofDescriptorProto_FieldNumber) { GPBOneofDescriptorProto_FieldNumber_Name = 1, }; -// Describes a oneof. +/// Describes a oneof. @interface GPBOneofDescriptorProto : GPBMessage -@property(nonatomic, readwrite) BOOL hasName; @property(nonatomic, readwrite, copy, null_resettable) NSString *name; +/// Test to see if @c name has been set. +@property(nonatomic, readwrite) BOOL hasName; @end @@ -424,18 +466,20 @@ typedef GPB_ENUM(GPBEnumDescriptorProto_FieldNumber) { GPBEnumDescriptorProto_FieldNumber_Options = 3, }; -// Describes an enum type. +/// Describes an enum type. @interface GPBEnumDescriptorProto : GPBMessage -@property(nonatomic, readwrite) BOOL hasName; @property(nonatomic, readwrite, copy, null_resettable) NSString *name; +/// Test to see if @c name has been set. +@property(nonatomic, readwrite) BOOL hasName; -// |valueArray| contains |GPBEnumValueDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *valueArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBEnumValueDescriptorProto*> *valueArray; +/// The number of items in @c valueArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger valueArray_Count; -@property(nonatomic, readwrite) BOOL hasOptions; @property(nonatomic, readwrite, strong, null_resettable) GPBEnumOptions *options; +/// Test to see if @c options has been set. +@property(nonatomic, readwrite) BOOL hasOptions; @end @@ -447,17 +491,19 @@ typedef GPB_ENUM(GPBEnumValueDescriptorProto_FieldNumber) { GPBEnumValueDescriptorProto_FieldNumber_Options = 3, }; -// Describes a value within an enum. +/// Describes a value within an enum. @interface GPBEnumValueDescriptorProto : GPBMessage -@property(nonatomic, readwrite) BOOL hasName; @property(nonatomic, readwrite, copy, null_resettable) NSString *name; +/// Test to see if @c name has been set. +@property(nonatomic, readwrite) BOOL hasName; -@property(nonatomic, readwrite) BOOL hasNumber; @property(nonatomic, readwrite) int32_t number; -@property(nonatomic, readwrite) BOOL hasOptions; +@property(nonatomic, readwrite) BOOL hasNumber; @property(nonatomic, readwrite, strong, null_resettable) GPBEnumValueOptions *options; +/// Test to see if @c options has been set. +@property(nonatomic, readwrite) BOOL hasOptions; @end @@ -469,18 +515,20 @@ typedef GPB_ENUM(GPBServiceDescriptorProto_FieldNumber) { GPBServiceDescriptorProto_FieldNumber_Options = 3, }; -// Describes a service. +/// Describes a service. @interface GPBServiceDescriptorProto : GPBMessage -@property(nonatomic, readwrite) BOOL hasName; @property(nonatomic, readwrite, copy, null_resettable) NSString *name; +/// Test to see if @c name has been set. +@property(nonatomic, readwrite) BOOL hasName; -// |methodArray| contains |GPBMethodDescriptorProto| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *methodArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBMethodDescriptorProto*> *methodArray; +/// The number of items in @c methodArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger methodArray_Count; -@property(nonatomic, readwrite) BOOL hasOptions; @property(nonatomic, readwrite, strong, null_resettable) GPBServiceOptions *options; +/// Test to see if @c options has been set. +@property(nonatomic, readwrite) BOOL hasOptions; @end @@ -495,31 +543,35 @@ typedef GPB_ENUM(GPBMethodDescriptorProto_FieldNumber) { GPBMethodDescriptorProto_FieldNumber_ServerStreaming = 6, }; -// Describes a method of a service. +/// Describes a method of a service. @interface GPBMethodDescriptorProto : GPBMessage -@property(nonatomic, readwrite) BOOL hasName; @property(nonatomic, readwrite, copy, null_resettable) NSString *name; +/// Test to see if @c name has been set. +@property(nonatomic, readwrite) BOOL hasName; -// Input and output type names. These are resolved in the same way as -// FieldDescriptorProto.type_name, but must refer to a message type. -@property(nonatomic, readwrite) BOOL hasInputType; +/// Input and output type names. These are resolved in the same way as +/// FieldDescriptorProto.type_name, but must refer to a message type. @property(nonatomic, readwrite, copy, null_resettable) NSString *inputType; +/// Test to see if @c inputType has been set. +@property(nonatomic, readwrite) BOOL hasInputType; -@property(nonatomic, readwrite) BOOL hasOutputType; @property(nonatomic, readwrite, copy, null_resettable) NSString *outputType; +/// Test to see if @c outputType has been set. +@property(nonatomic, readwrite) BOOL hasOutputType; -@property(nonatomic, readwrite) BOOL hasOptions; @property(nonatomic, readwrite, strong, null_resettable) GPBMethodOptions *options; +/// Test to see if @c options has been set. +@property(nonatomic, readwrite) BOOL hasOptions; -// Identifies if client streams multiple client messages -@property(nonatomic, readwrite) BOOL hasClientStreaming; +/// Identifies if client streams multiple client messages @property(nonatomic, readwrite) BOOL clientStreaming; -// Identifies if server streams multiple server messages -@property(nonatomic, readwrite) BOOL hasServerStreaming; +@property(nonatomic, readwrite) BOOL hasClientStreaming; +/// Identifies if server streams multiple server messages @property(nonatomic, readwrite) BOOL serverStreaming; +@property(nonatomic, readwrite) BOOL hasServerStreaming; @end #pragma mark - GPBFileOptions @@ -545,113 +597,118 @@ typedef GPB_ENUM(GPBFileOptions_FieldNumber) { @interface GPBFileOptions : GPBMessage -// Sets the Java package where classes generated from this .proto will be -// placed. By default, the proto package is used, but this is often -// inappropriate because proto packages do not normally start with backwards -// domain names. -@property(nonatomic, readwrite) BOOL hasJavaPackage; +/// Sets the Java package where classes generated from this .proto will be +/// placed. By default, the proto package is used, but this is often +/// inappropriate because proto packages do not normally start with backwards +/// domain names. @property(nonatomic, readwrite, copy, null_resettable) NSString *javaPackage; +/// Test to see if @c javaPackage has been set. +@property(nonatomic, readwrite) BOOL hasJavaPackage; -// 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 -// (equivalent to the old "--one_java_file" option) and Proto2 (where -// a .proto always translates to a single class, but you may want to -// explicitly choose the class name). -@property(nonatomic, readwrite) BOOL hasJavaOuterClassname; +/// 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 +/// (equivalent to the old "--one_java_file" option) and Proto2 (where +/// a .proto always translates to a single class, but you may want to +/// explicitly choose the class name). @property(nonatomic, readwrite, copy, null_resettable) NSString *javaOuterClassname; +/// Test to see if @c javaOuterClassname has been set. +@property(nonatomic, readwrite) BOOL hasJavaOuterClassname; -// If set true, then the Java code generator will generate a separate .java -// file for each top-level message, enum, and service defined in the .proto -// file. Thus, these types will *not* be nested inside the outer class -// named by java_outer_classname. However, the outer class will still be -// generated to contain the file's getDescriptor() method as well as any -// top-level extensions defined in the file. -@property(nonatomic, readwrite) BOOL hasJavaMultipleFiles; +/// If set true, then the Java code generator will generate a separate .java +/// file for each top-level message, enum, and service defined in the .proto +/// file. Thus, these types will *not* be nested inside the outer class +/// named by java_outer_classname. However, the outer class will still be +/// generated to contain the file's getDescriptor() method as well as any +/// top-level extensions defined in the file. @property(nonatomic, readwrite) BOOL javaMultipleFiles; -// If set true, then the Java code generator will generate equals() and -// hashCode() methods for all messages defined in the .proto file. -// This increases generated code size, potentially substantially for large -// protos, which may harm a memory-constrained application. -// - In the full runtime this is a speed optimization, as the -// AbstractMessage base class includes reflection-based implementations of -// these methods. -// - In the lite runtime, setting this option changes the semantics of -// equals() and hashCode() to more closely match those of the full runtime; -// the generated methods compute their results based on field values rather -// than object identity. (Implementations should not assume that hashcodes -// will be consistent across runtimes or versions of the protocol compiler.) -@property(nonatomic, readwrite) BOOL hasJavaGenerateEqualsAndHash; +@property(nonatomic, readwrite) BOOL hasJavaMultipleFiles; +/// If set true, then the Java code generator will generate equals() and +/// hashCode() methods for all messages defined in the .proto file. +/// This increases generated code size, potentially substantially for large +/// protos, which may harm a memory-constrained application. +/// - In the full runtime this is a speed optimization, as the +/// AbstractMessage base class includes reflection-based implementations of +/// these methods. +/// - In the lite runtime, setting this option changes the semantics of +/// equals() and hashCode() to more closely match those of the full runtime; +/// the generated methods compute their results based on field values rather +/// than object identity. (Implementations should not assume that hashcodes +/// will be consistent across runtimes or versions of the protocol compiler.) @property(nonatomic, readwrite) BOOL javaGenerateEqualsAndHash; -// If set true, then the Java2 code generator will generate code that -// throws an exception whenever an attempt is made to assign a non-UTF-8 -// byte sequence to a string field. -// Message reflection will do the same. -// However, an extension field still accepts non-UTF-8 byte sequences. -// This option has no effect on when used with the lite runtime. -@property(nonatomic, readwrite) BOOL hasJavaStringCheckUtf8; +@property(nonatomic, readwrite) BOOL hasJavaGenerateEqualsAndHash; +/// If set true, then the Java2 code generator will generate code that +/// throws an exception whenever an attempt is made to assign a non-UTF-8 +/// byte sequence to a string field. +/// Message reflection will do the same. +/// However, an extension field still accepts non-UTF-8 byte sequences. +/// This option has no effect on when used with the lite runtime. @property(nonatomic, readwrite) BOOL javaStringCheckUtf8; -@property(nonatomic, readwrite) BOOL hasOptimizeFor; +@property(nonatomic, readwrite) BOOL hasJavaStringCheckUtf8; @property(nonatomic, readwrite) GPBFileOptions_OptimizeMode optimizeFor; -// Sets the Go package where structs generated from this .proto will be -// placed. If omitted, the Go package will be derived from the following: -// - The basename of the package import path, if provided. -// - Otherwise, the package statement in the .proto file, if present. -// - Otherwise, the basename of the .proto file, without extension. -@property(nonatomic, readwrite) BOOL hasGoPackage; +@property(nonatomic, readwrite) BOOL hasOptimizeFor; +/// Sets the Go package where structs generated from this .proto will be +/// placed. If omitted, the Go package will be derived from the following: +/// - The basename of the package import path, if provided. +/// - Otherwise, the package statement in the .proto file, if present. +/// - Otherwise, the basename of the .proto file, without extension. @property(nonatomic, readwrite, copy, null_resettable) NSString *goPackage; +/// Test to see if @c goPackage has been set. +@property(nonatomic, readwrite) BOOL hasGoPackage; -// Should generic services be generated in each language? "Generic" services -// are not specific to any particular RPC system. They are generated by the -// main code generators in each language (without additional plugins). -// Generic services were the only kind of service generation supported by -// early versions of google.protobuf. -// -// Generic services are now considered deprecated in favor of using plugins -// that generate code specific to your particular RPC system. Therefore, -// these default to false. Old code which depends on generic services should -// explicitly set them to true. -@property(nonatomic, readwrite) BOOL hasCcGenericServices; +/// Should generic services be generated in each language? "Generic" services +/// are not specific to any particular RPC system. They are generated by the +/// main code generators in each language (without additional plugins). +/// Generic services were the only kind of service generation supported by +/// early versions of google.protobuf. +/// +/// Generic services are now considered deprecated in favor of using plugins +/// that generate code specific to your particular RPC system. Therefore, +/// these default to false. Old code which depends on generic services should +/// explicitly set them to true. @property(nonatomic, readwrite) BOOL ccGenericServices; -@property(nonatomic, readwrite) BOOL hasJavaGenericServices; +@property(nonatomic, readwrite) BOOL hasCcGenericServices; @property(nonatomic, readwrite) BOOL javaGenericServices; -@property(nonatomic, readwrite) BOOL hasPyGenericServices; +@property(nonatomic, readwrite) BOOL hasJavaGenericServices; @property(nonatomic, readwrite) BOOL pyGenericServices; -// Is this file deprecated? -// Depending on the target platform, this can emit Deprecated annotations -// for everything in the file, or it will be completely ignored; in the very -// least, this is a formalization for deprecating files. -@property(nonatomic, readwrite) BOOL hasDeprecated; +@property(nonatomic, readwrite) BOOL hasPyGenericServices; +/// Is this file deprecated? +/// Depending on the target platform, this can emit Deprecated annotations +/// for everything in the file, or it will be completely ignored; in the very +/// least, this is a formalization for deprecating files. @property(nonatomic, readwrite) BOOL deprecated; -// Enables the use of arenas for the proto messages in this file. This applies -// only to generated classes for C++. -@property(nonatomic, readwrite) BOOL hasCcEnableArenas; +@property(nonatomic, readwrite) BOOL hasDeprecated; +/// Enables the use of arenas for the proto messages in this file. This applies +/// only to generated classes for C++. @property(nonatomic, readwrite) BOOL ccEnableArenas; -// Sets the objective c class prefix which is prepended to all objective c -// generated classes from this .proto. There is no default. -@property(nonatomic, readwrite) BOOL hasObjcClassPrefix; +@property(nonatomic, readwrite) BOOL hasCcEnableArenas; +/// Sets the objective c class prefix which is prepended to all objective c +/// generated classes from this .proto. There is no default. @property(nonatomic, readwrite, copy, null_resettable) NSString *objcClassPrefix; +/// Test to see if @c objcClassPrefix has been set. +@property(nonatomic, readwrite) BOOL hasObjcClassPrefix; -// Namespace for generated classes; defaults to the package. -@property(nonatomic, readwrite) BOOL hasCsharpNamespace; +/// Namespace for generated classes; defaults to the package. @property(nonatomic, readwrite, copy, null_resettable) NSString *csharpNamespace; +/// Test to see if @c csharpNamespace has been set. +@property(nonatomic, readwrite) BOOL hasCsharpNamespace; -// Whether the nano proto compiler should generate in the deprecated non-nano -// suffixed package. -@property(nonatomic, readwrite) BOOL hasJavananoUseDeprecatedPackage; +/// Whether the nano proto compiler should generate in the deprecated non-nano +/// suffixed package. @property(nonatomic, readwrite) BOOL javananoUseDeprecatedPackage; -// The parser stores options it doesn't recognize here. See above. -// |uninterpretedOptionArray| contains |GPBUninterpretedOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *uninterpretedOptionArray; +@property(nonatomic, readwrite) BOOL hasJavananoUseDeprecatedPackage; +/// The parser stores options it doesn't recognize here. See above. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBUninterpretedOption*> *uninterpretedOptionArray; +/// The number of items in @c uninterpretedOptionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger uninterpretedOptionArray_Count; @end @@ -668,67 +725,67 @@ typedef GPB_ENUM(GPBMessageOptions_FieldNumber) { @interface GPBMessageOptions : GPBMessage -// Set true to use the old proto1 MessageSet wire format for extensions. -// This is provided for backwards-compatibility with the MessageSet wire -// format. You should not use this for any other reason: It's less -// efficient, has fewer features, and is more complicated. -// -// The message must be defined exactly as follows: -// message Foo { -// option message_set_wire_format = true; -// extensions 4 to max; -// } -// Note that the message cannot have any defined fields; MessageSets only -// have extensions. -// -// All extensions of your type must be singular messages; e.g. they cannot -// be int32s, enums, or repeated messages. -// -// Because this is an option, the above two restrictions are not enforced by -// the protocol compiler. -@property(nonatomic, readwrite) BOOL hasMessageSetWireFormat; +/// Set true to use the old proto1 MessageSet wire format for extensions. +/// This is provided for backwards-compatibility with the MessageSet wire +/// format. You should not use this for any other reason: It's less +/// efficient, has fewer features, and is more complicated. +/// +/// The message must be defined exactly as follows: +/// message Foo { +/// option message_set_wire_format = true; +/// extensions 4 to max; +/// } +/// Note that the message cannot have any defined fields; MessageSets only +/// have extensions. +/// +/// All extensions of your type must be singular messages; e.g. they cannot +/// be int32s, enums, or repeated messages. +/// +/// Because this is an option, the above two restrictions are not enforced by +/// the protocol compiler. @property(nonatomic, readwrite) BOOL messageSetWireFormat; -// Disables the generation of the standard "descriptor()" accessor, which can -// conflict with a field of the same name. This is meant to make migration -// from proto1 easier; new code should avoid fields named "descriptor". -@property(nonatomic, readwrite) BOOL hasNoStandardDescriptorAccessor; +@property(nonatomic, readwrite) BOOL hasMessageSetWireFormat; +/// Disables the generation of the standard "descriptor()" accessor, which can +/// conflict with a field of the same name. This is meant to make migration +/// from proto1 easier; new code should avoid fields named "descriptor". @property(nonatomic, readwrite) BOOL noStandardDescriptorAccessor; -// Is this message deprecated? -// Depending on the target platform, this can emit Deprecated annotations -// for the message, or it will be completely ignored; in the very least, -// this is a formalization for deprecating messages. -@property(nonatomic, readwrite) BOOL hasDeprecated; +@property(nonatomic, readwrite) BOOL hasNoStandardDescriptorAccessor; +/// Is this message deprecated? +/// Depending on the target platform, this can emit Deprecated annotations +/// for the message, or it will be completely ignored; in the very least, +/// this is a formalization for deprecating messages. @property(nonatomic, readwrite) BOOL deprecated; -// Whether the message is an automatically generated map entry type for the -// maps field. -// -// For maps fields: -// map<KeyType, ValueType> map_field = 1; -// The parsed descriptor looks like: -// message MapFieldEntry { -// option map_entry = true; -// optional KeyType key = 1; -// optional ValueType value = 2; -// } -// repeated MapFieldEntry map_field = 1; -// -// Implementations may choose not to generate the map_entry=true message, but -// use a native map in the target language to hold the keys and values. -// The reflection APIs in such implementions still need to work as -// if the field is a repeated message field. -// -// NOTE: Do not set the option in .proto files. Always use the maps syntax -// instead. The option should only be implicitly set by the proto compiler -// parser. -@property(nonatomic, readwrite) BOOL hasMapEntry; +@property(nonatomic, readwrite) BOOL hasDeprecated; +/// Whether the message is an automatically generated map entry type for the +/// maps field. +/// +/// For maps fields: +/// map<KeyType, ValueType> map_field = 1; +/// The parsed descriptor looks like: +/// message MapFieldEntry { +/// option map_entry = true; +/// optional KeyType key = 1; +/// optional ValueType value = 2; +/// } +/// repeated MapFieldEntry map_field = 1; +/// +/// Implementations may choose not to generate the map_entry=true message, but +/// use a native map in the target language to hold the keys and values. +/// The reflection APIs in such implementions still need to work as +/// if the field is a repeated message field. +/// +/// NOTE: Do not set the option in .proto files. Always use the maps syntax +/// instead. The option should only be implicitly set by the proto compiler +/// parser. @property(nonatomic, readwrite) BOOL mapEntry; -// The parser stores options it doesn't recognize here. See above. -// |uninterpretedOptionArray| contains |GPBUninterpretedOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *uninterpretedOptionArray; +@property(nonatomic, readwrite) BOOL hasMapEntry; +/// The parser stores options it doesn't recognize here. See above. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBUninterpretedOption*> *uninterpretedOptionArray; +/// The number of items in @c uninterpretedOptionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger uninterpretedOptionArray_Count; @end @@ -747,78 +804,78 @@ typedef GPB_ENUM(GPBFieldOptions_FieldNumber) { @interface GPBFieldOptions : GPBMessage -// The ctype option instructs the C++ code generator to use a different -// representation of the field than it normally would. See the specific -// options below. This option is not yet implemented in the open source -// release -- sorry, we'll try to include it in a future version! -@property(nonatomic, readwrite) BOOL hasCtype; +/// The ctype option instructs the C++ code generator to use a different +/// representation of the field than it normally would. See the specific +/// options below. This option is not yet implemented in the open source +/// release -- sorry, we'll try to include it in a future version! @property(nonatomic, readwrite) GPBFieldOptions_CType ctype; -// The packed option can be enabled for repeated primitive fields to enable -// a more efficient representation on the wire. Rather than repeatedly -// writing the tag and type for each element, the entire array is encoded as -// a single length-delimited blob. In proto3, only explicit setting it to -// false will avoid using packed encoding. -@property(nonatomic, readwrite) BOOL hasPacked; +@property(nonatomic, readwrite) BOOL hasCtype; +/// The packed option can be enabled for repeated primitive fields to enable +/// a more efficient representation on the wire. Rather than repeatedly +/// writing the tag and type for each element, the entire array is encoded as +/// a single length-delimited blob. In proto3, only explicit setting it to +/// false will avoid using packed encoding. @property(nonatomic, readwrite) BOOL packed; -// 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 -// (int64, uint64, sint64, fixed64, sfixed64). By default these types are -// represented as JavaScript strings. This avoids loss of precision that can -// happen when a large value is converted to a floating point JavaScript -// numbers. Specifying JS_NUMBER for the jstype causes the generated -// JavaScript code to use the JavaScript "number" type instead of strings. -// This option is an enum to permit additional types to be added, -// e.g. goog.math.Integer. -@property(nonatomic, readwrite) BOOL hasJstype; +@property(nonatomic, readwrite) BOOL hasPacked; +/// 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 +/// (int64, uint64, sint64, fixed64, sfixed64). By default these types are +/// represented as JavaScript strings. This avoids loss of precision that can +/// happen when a large value is converted to a floating point JavaScript +/// numbers. Specifying JS_NUMBER for the jstype causes the generated +/// JavaScript code to use the JavaScript "number" type instead of strings. +/// This option is an enum to permit additional types to be added, +/// e.g. goog.math.Integer. @property(nonatomic, readwrite) GPBFieldOptions_JSType jstype; -// Should this field be parsed lazily? Lazy applies only to message-type -// fields. It means that when the outer message is initially parsed, the -// inner message's contents will not be parsed but instead stored in encoded -// form. The inner message will actually be parsed when it is first accessed. -// -// This is only a hint. Implementations are free to choose whether to use -// eager or lazy parsing regardless of the value of this option. However, -// setting this option true suggests that the protocol author believes that -// using lazy parsing on this field is worth the additional bookkeeping -// overhead typically needed to implement it. -// -// This option does not affect the public interface of any generated code; -// all method signatures remain the same. Furthermore, thread-safety of the -// interface is not affected by this option; const methods remain safe to -// call from multiple threads concurrently, while non-const methods continue -// to require exclusive access. -// -// -// Note that implementations may choose not to check required fields within -// a lazy sub-message. That is, calling IsInitialized() on the outher message -// may return true even if the inner message has missing required fields. -// This is necessary because otherwise the inner message would have to be -// parsed in order to perform the check, defeating the purpose of lazy -// parsing. An implementation which chooses not to check required fields -// must be consistent about it. That is, for any particular sub-message, the -// implementation must either *always* check its required fields, or *never* -// check its required fields, regardless of whether or not the message has -// been parsed. -@property(nonatomic, readwrite) BOOL hasLazy; +@property(nonatomic, readwrite) BOOL hasJstype; +/// Should this field be parsed lazily? Lazy applies only to message-type +/// fields. It means that when the outer message is initially parsed, the +/// inner message's contents will not be parsed but instead stored in encoded +/// form. The inner message will actually be parsed when it is first accessed. +/// +/// This is only a hint. Implementations are free to choose whether to use +/// eager or lazy parsing regardless of the value of this option. However, +/// setting this option true suggests that the protocol author believes that +/// using lazy parsing on this field is worth the additional bookkeeping +/// overhead typically needed to implement it. +/// +/// This option does not affect the public interface of any generated code; +/// all method signatures remain the same. Furthermore, thread-safety of the +/// interface is not affected by this option; const methods remain safe to +/// call from multiple threads concurrently, while non-const methods continue +/// to require exclusive access. +/// +/// +/// Note that implementations may choose not to check required fields within +/// a lazy sub-message. That is, calling IsInitialized() on the outher message +/// may return true even if the inner message has missing required fields. +/// This is necessary because otherwise the inner message would have to be +/// parsed in order to perform the check, defeating the purpose of lazy +/// parsing. An implementation which chooses not to check required fields +/// must be consistent about it. That is, for any particular sub-message, the +/// implementation must either *always* check its required fields, or *never* +/// check its required fields, regardless of whether or not the message has +/// been parsed. @property(nonatomic, readwrite) BOOL lazy; -// Is this field deprecated? -// Depending on the target platform, this can emit Deprecated annotations -// for accessors, or it will be completely ignored; in the very least, this -// is a formalization for deprecating fields. -@property(nonatomic, readwrite) BOOL hasDeprecated; +@property(nonatomic, readwrite) BOOL hasLazy; +/// Is this field deprecated? +/// Depending on the target platform, this can emit Deprecated annotations +/// for accessors, or it will be completely ignored; in the very least, this +/// is a formalization for deprecating fields. @property(nonatomic, readwrite) BOOL deprecated; -// For Google-internal migration only. Do not use. -@property(nonatomic, readwrite) BOOL hasWeak; +@property(nonatomic, readwrite) BOOL hasDeprecated; +/// For Google-internal migration only. Do not use. @property(nonatomic, readwrite) BOOL weak; -// The parser stores options it doesn't recognize here. See above. -// |uninterpretedOptionArray| contains |GPBUninterpretedOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *uninterpretedOptionArray; +@property(nonatomic, readwrite) BOOL hasWeak; +/// The parser stores options it doesn't recognize here. See above. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBUninterpretedOption*> *uninterpretedOptionArray; +/// The number of items in @c uninterpretedOptionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger uninterpretedOptionArray_Count; @end @@ -833,21 +890,21 @@ typedef GPB_ENUM(GPBEnumOptions_FieldNumber) { @interface GPBEnumOptions : GPBMessage -// Set this option to true to allow mapping different tag names to the same -// value. -@property(nonatomic, readwrite) BOOL hasAllowAlias; +/// Set this option to true to allow mapping different tag names to the same +/// value. @property(nonatomic, readwrite) BOOL allowAlias; -// Is this enum deprecated? -// Depending on the target platform, this can emit Deprecated annotations -// for the enum, or it will be completely ignored; in the very least, this -// is a formalization for deprecating enums. -@property(nonatomic, readwrite) BOOL hasDeprecated; +@property(nonatomic, readwrite) BOOL hasAllowAlias; +/// Is this enum deprecated? +/// Depending on the target platform, this can emit Deprecated annotations +/// for the enum, or it will be completely ignored; in the very least, this +/// is a formalization for deprecating enums. @property(nonatomic, readwrite) BOOL deprecated; -// The parser stores options it doesn't recognize here. See above. -// |uninterpretedOptionArray| contains |GPBUninterpretedOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *uninterpretedOptionArray; +@property(nonatomic, readwrite) BOOL hasDeprecated; +/// The parser stores options it doesn't recognize here. See above. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBUninterpretedOption*> *uninterpretedOptionArray; +/// The number of items in @c uninterpretedOptionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger uninterpretedOptionArray_Count; @end @@ -861,16 +918,16 @@ typedef GPB_ENUM(GPBEnumValueOptions_FieldNumber) { @interface GPBEnumValueOptions : GPBMessage -// Is this enum value deprecated? -// Depending on the target platform, this can emit Deprecated annotations -// for the enum value, or it will be completely ignored; in the very least, -// this is a formalization for deprecating enum values. -@property(nonatomic, readwrite) BOOL hasDeprecated; +/// Is this enum value deprecated? +/// Depending on the target platform, this can emit Deprecated annotations +/// for the enum value, or it will be completely ignored; in the very least, +/// this is a formalization for deprecating enum values. @property(nonatomic, readwrite) BOOL deprecated; -// The parser stores options it doesn't recognize here. See above. -// |uninterpretedOptionArray| contains |GPBUninterpretedOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *uninterpretedOptionArray; +@property(nonatomic, readwrite) BOOL hasDeprecated; +/// The parser stores options it doesn't recognize here. See above. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBUninterpretedOption*> *uninterpretedOptionArray; +/// The number of items in @c uninterpretedOptionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger uninterpretedOptionArray_Count; @end @@ -884,16 +941,16 @@ typedef GPB_ENUM(GPBServiceOptions_FieldNumber) { @interface GPBServiceOptions : GPBMessage -// Is this service deprecated? -// Depending on the target platform, this can emit Deprecated annotations -// for the service, or it will be completely ignored; in the very least, -// this is a formalization for deprecating services. -@property(nonatomic, readwrite) BOOL hasDeprecated; +/// Is this service deprecated? +/// Depending on the target platform, this can emit Deprecated annotations +/// for the service, or it will be completely ignored; in the very least, +/// this is a formalization for deprecating services. @property(nonatomic, readwrite) BOOL deprecated; -// The parser stores options it doesn't recognize here. See above. -// |uninterpretedOptionArray| contains |GPBUninterpretedOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *uninterpretedOptionArray; +@property(nonatomic, readwrite) BOOL hasDeprecated; +/// The parser stores options it doesn't recognize here. See above. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBUninterpretedOption*> *uninterpretedOptionArray; +/// The number of items in @c uninterpretedOptionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger uninterpretedOptionArray_Count; @end @@ -907,16 +964,16 @@ typedef GPB_ENUM(GPBMethodOptions_FieldNumber) { @interface GPBMethodOptions : GPBMessage -// Is this method deprecated? -// Depending on the target platform, this can emit Deprecated annotations -// for the method, or it will be completely ignored; in the very least, -// this is a formalization for deprecating methods. -@property(nonatomic, readwrite) BOOL hasDeprecated; +/// Is this method deprecated? +/// Depending on the target platform, this can emit Deprecated annotations +/// for the method, or it will be completely ignored; in the very least, +/// this is a formalization for deprecating methods. @property(nonatomic, readwrite) BOOL deprecated; -// The parser stores options it doesn't recognize here. See above. -// |uninterpretedOptionArray| contains |GPBUninterpretedOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *uninterpretedOptionArray; +@property(nonatomic, readwrite) BOOL hasDeprecated; +/// The parser stores options it doesn't recognize here. See above. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBUninterpretedOption*> *uninterpretedOptionArray; +/// The number of items in @c uninterpretedOptionArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger uninterpretedOptionArray_Count; @end @@ -933,37 +990,40 @@ typedef GPB_ENUM(GPBUninterpretedOption_FieldNumber) { GPBUninterpretedOption_FieldNumber_AggregateValue = 8, }; -// A message representing a option the parser does not recognize. This only -// appears in options protos created by the compiler::Parser class. -// DescriptorPool resolves these when building Descriptor objects. Therefore, -// options protos in descriptor objects (e.g. returned by Descriptor::options(), -// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions -// in them. +/// A message representing a option the parser does not recognize. This only +/// appears in options protos created by the compiler::Parser class. +/// DescriptorPool resolves these when building Descriptor objects. Therefore, +/// options protos in descriptor objects (e.g. returned by Descriptor::options(), +/// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions +/// in them. @interface GPBUninterpretedOption : GPBMessage -// |nameArray| contains |GPBUninterpretedOption_NamePart| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *nameArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBUninterpretedOption_NamePart*> *nameArray; +/// The number of items in @c nameArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger nameArray_Count; -// The value of the uninterpreted option, in whatever type the tokenizer -// identified it as during parsing. Exactly one of these should be set. -@property(nonatomic, readwrite) BOOL hasIdentifierValue; +/// The value of the uninterpreted option, in whatever type the tokenizer +/// identified it as during parsing. Exactly one of these should be set. @property(nonatomic, readwrite, copy, null_resettable) NSString *identifierValue; +/// Test to see if @c identifierValue has been set. +@property(nonatomic, readwrite) BOOL hasIdentifierValue; -@property(nonatomic, readwrite) BOOL hasPositiveIntValue; @property(nonatomic, readwrite) uint64_t positiveIntValue; -@property(nonatomic, readwrite) BOOL hasNegativeIntValue; +@property(nonatomic, readwrite) BOOL hasPositiveIntValue; @property(nonatomic, readwrite) int64_t negativeIntValue; -@property(nonatomic, readwrite) BOOL hasDoubleValue; +@property(nonatomic, readwrite) BOOL hasNegativeIntValue; @property(nonatomic, readwrite) double doubleValue; -@property(nonatomic, readwrite) BOOL hasStringValue; +@property(nonatomic, readwrite) BOOL hasDoubleValue; @property(nonatomic, readwrite, copy, null_resettable) NSData *stringValue; +/// Test to see if @c stringValue has been set. +@property(nonatomic, readwrite) BOOL hasStringValue; -@property(nonatomic, readwrite) BOOL hasAggregateValue; @property(nonatomic, readwrite, copy, null_resettable) NSString *aggregateValue; +/// Test to see if @c aggregateValue has been set. +@property(nonatomic, readwrite) BOOL hasAggregateValue; @end @@ -974,19 +1034,20 @@ typedef GPB_ENUM(GPBUninterpretedOption_NamePart_FieldNumber) { GPBUninterpretedOption_NamePart_FieldNumber_IsExtension = 2, }; -// The name of the uninterpreted option. Each string represents a segment in -// a dot-separated name. is_extension is true iff a segment represents an -// extension (denoted with parentheses in options specs in .proto files). -// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents -// "foo.(bar.baz).qux". +/// The name of the uninterpreted option. Each string represents a segment in +/// a dot-separated name. is_extension is true iff a segment represents an +/// extension (denoted with parentheses in options specs in .proto files). +/// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents +/// "foo.(bar.baz).qux". @interface GPBUninterpretedOption_NamePart : GPBMessage -@property(nonatomic, readwrite) BOOL hasNamePart; @property(nonatomic, readwrite, copy, null_resettable) NSString *namePart; +/// Test to see if @c namePart has been set. +@property(nonatomic, readwrite) BOOL hasNamePart; -@property(nonatomic, readwrite) BOOL hasIsExtension; @property(nonatomic, readwrite) BOOL isExtension; +@property(nonatomic, readwrite) BOOL hasIsExtension; @end #pragma mark - GPBSourceCodeInfo @@ -995,55 +1056,55 @@ typedef GPB_ENUM(GPBSourceCodeInfo_FieldNumber) { GPBSourceCodeInfo_FieldNumber_LocationArray = 1, }; -// Encapsulates information about the original source file from which a -// FileDescriptorProto was generated. +/// Encapsulates information about the original source file from which a +/// FileDescriptorProto was generated. @interface GPBSourceCodeInfo : GPBMessage -// A Location identifies a piece of source code in a .proto file which -// corresponds to a particular definition. This information is intended -// to be useful to IDEs, code indexers, documentation generators, and similar -// tools. -// -// For example, say we have a file like: -// message Foo { -// optional string foo = 1; -// } -// Let's look at just the field definition: -// optional string foo = 1; -// ^ ^^ ^^ ^ ^^^ -// a bc de f ghi -// We have the following locations: -// span path represents -// [a,i) [ 4, 0, 2, 0 ] The whole field definition. -// [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). -// [c,d) [ 4, 0, 2, 0, 5 ] The type (string). -// [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). -// [g,h) [ 4, 0, 2, 0, 3 ] The number (1). -// -// Notes: -// - A location may refer to a repeated field itself (i.e. not to any -// particular index within it). This is used whenever a set of elements are -// logically enclosed in a single code segment. For example, an entire -// extend block (possibly containing multiple extension definitions) will -// have an outer location whose path refers to the "extensions" repeated -// field without an index. -// - Multiple locations may have the same path. This happens when a single -// logical declaration is spread out across multiple places. The most -// obvious example is the "extend" block again -- there may be multiple -// extend blocks in the same scope, each of which will have the same path. -// - A location's span is not always a subset of its parent's span. For -// example, the "extendee" of an extension declaration appears at the -// beginning of the "extend" block and is shared by all extensions within -// the block. -// - Just because a location's span is a subset of some other location's span -// does not mean that it is a descendent. For example, a "group" defines -// both a type and a field in a single declaration. Thus, the locations -// corresponding to the type and field and their components will overlap. -// - Code which tries to interpret locations should probably be designed to -// ignore those that it doesn't understand, as more types of locations could -// be recorded in the future. -// |locationArray| contains |GPBSourceCodeInfo_Location| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *locationArray; +/// A Location identifies a piece of source code in a .proto file which +/// corresponds to a particular definition. This information is intended +/// to be useful to IDEs, code indexers, documentation generators, and similar +/// tools. +/// +/// For example, say we have a file like: +/// message Foo { +/// optional string foo = 1; +/// } +/// Let's look at just the field definition: +/// optional string foo = 1; +/// ^ ^^ ^^ ^ ^^^ +/// a bc de f ghi +/// We have the following locations: +/// span path represents +/// [a,i) [ 4, 0, 2, 0 ] The whole field definition. +/// [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). +/// [c,d) [ 4, 0, 2, 0, 5 ] The type (string). +/// [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). +/// [g,h) [ 4, 0, 2, 0, 3 ] The number (1). +/// +/// Notes: +/// - A location may refer to a repeated field itself (i.e. not to any +/// particular index within it). This is used whenever a set of elements are +/// logically enclosed in a single code segment. For example, an entire +/// extend block (possibly containing multiple extension definitions) will +/// have an outer location whose path refers to the "extensions" repeated +/// field without an index. +/// - Multiple locations may have the same path. This happens when a single +/// logical declaration is spread out across multiple places. The most +/// obvious example is the "extend" block again -- there may be multiple +/// extend blocks in the same scope, each of which will have the same path. +/// - A location's span is not always a subset of its parent's span. For +/// example, the "extendee" of an extension declaration appears at the +/// beginning of the "extend" block and is shared by all extensions within +/// the block. +/// - Just because a location's span is a subset of some other location's span +/// does not mean that it is a descendent. For example, a "group" defines +/// both a type and a field in a single declaration. Thus, the locations +/// corresponding to the type and field and their components will overlap. +/// - Code which tries to interpret locations should probably be designed to +/// ignore those that it doesn't understand, as more types of locations could +/// be recorded in the future. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBSourceCodeInfo_Location*> *locationArray; +/// The number of items in @c locationArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger locationArray_Count; @end @@ -1060,95 +1121,99 @@ typedef GPB_ENUM(GPBSourceCodeInfo_Location_FieldNumber) { @interface GPBSourceCodeInfo_Location : GPBMessage -// Identifies which part of the FileDescriptorProto was defined at this -// location. -// -// Each element is a field number or an index. They form a path from -// the root FileDescriptorProto to the place where the definition. For -// example, this path: -// [ 4, 3, 2, 7, 1 ] -// refers to: -// file.message_type(3) // 4, 3 -// .field(7) // 2, 7 -// .name() // 1 -// This is because FileDescriptorProto.message_type has field number 4: -// repeated DescriptorProto message_type = 4; -// and DescriptorProto.field has field number 2: -// repeated FieldDescriptorProto field = 2; -// and FieldDescriptorProto.name has field number 1: -// optional string name = 1; -// -// Thus, the above path gives the location of a field name. If we removed -// the last element: -// [ 4, 3, 2, 7 ] -// this path refers to the whole field declaration (from the beginning -// of the label to the terminating semicolon). +/// Identifies which part of the FileDescriptorProto was defined at this +/// location. +/// +/// Each element is a field number or an index. They form a path from +/// the root FileDescriptorProto to the place where the definition. For +/// example, this path: +/// [ 4, 3, 2, 7, 1 ] +/// refers to: +/// file.message_type(3) // 4, 3 +/// .field(7) // 2, 7 +/// .name() // 1 +/// This is because FileDescriptorProto.message_type has field number 4: +/// repeated DescriptorProto message_type = 4; +/// and DescriptorProto.field has field number 2: +/// repeated FieldDescriptorProto field = 2; +/// and FieldDescriptorProto.name has field number 1: +/// optional string name = 1; +/// +/// Thus, the above path gives the location of a field name. If we removed +/// the last element: +/// [ 4, 3, 2, 7 ] +/// this path refers to the whole field declaration (from the beginning +/// of the label to the terminating semicolon). @property(nonatomic, readwrite, strong, null_resettable) GPBInt32Array *pathArray; +/// The number of items in @c pathArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger pathArray_Count; -// Always has exactly three or four elements: start line, start column, -// end line (optional, otherwise assumed same as start line), end column. -// These are packed into a single field for efficiency. Note that line -// and column numbers are zero-based -- typically you will want to add -// 1 to each before displaying to a user. +/// Always has exactly three or four elements: start line, start column, +/// end line (optional, otherwise assumed same as start line), end column. +/// These are packed into a single field for efficiency. Note that line +/// and column numbers are zero-based -- typically you will want to add +/// 1 to each before displaying to a user. @property(nonatomic, readwrite, strong, null_resettable) GPBInt32Array *spanArray; +/// The number of items in @c spanArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger spanArray_Count; -// If this SourceCodeInfo represents a complete declaration, these are any -// comments appearing before and after the declaration which appear to be -// attached to the declaration. -// -// A series of line comments appearing on consecutive lines, with no other -// tokens appearing on those lines, will be treated as a single comment. -// -// leading_detached_comments will keep paragraphs of comments that appear -// before (but not connected to) the current element. Each paragraph, -// separated by empty lines, will be one comment element in the repeated -// field. -// -// Only the comment content is provided; comment markers (e.g. //) are -// stripped out. For block comments, leading whitespace and an asterisk -// will be stripped from the beginning of each line other than the first. -// Newlines are included in the output. -// -// Examples: -// -// optional int32 foo = 1; // Comment attached to foo. -// // Comment attached to bar. -// optional int32 bar = 2; -// -// optional string baz = 3; -// // Comment attached to baz. -// // Another line attached to baz. -// -// // Comment attached to qux. -// // -// // Another line attached to qux. -// optional double qux = 4; -// -// // Detached comment for corge. This is not leading or trailing comments -// // to qux or corge because there are blank lines separating it from -// // both. -// -// // Detached comment for corge paragraph 2. -// -// optional string corge = 5; -// /* Block comment attached -// * to corge. Leading asterisks -// * will be removed. */ -// /* Block comment attached to -// * grault. */ -// optional int32 grault = 6; -// -// // ignored detached comments. -@property(nonatomic, readwrite) BOOL hasLeadingComments; +/// If this SourceCodeInfo represents a complete declaration, these are any +/// comments appearing before and after the declaration which appear to be +/// attached to the declaration. +/// +/// A series of line comments appearing on consecutive lines, with no other +/// tokens appearing on those lines, will be treated as a single comment. +/// +/// leading_detached_comments will keep paragraphs of comments that appear +/// before (but not connected to) the current element. Each paragraph, +/// separated by empty lines, will be one comment element in the repeated +/// field. +/// +/// Only the comment content is provided; comment markers (e.g. //) are +/// stripped out. For block comments, leading whitespace and an asterisk +/// will be stripped from the beginning of each line other than the first. +/// Newlines are included in the output. +/// +/// Examples: +/// +/// optional int32 foo = 1; // Comment attached to foo. +/// // Comment attached to bar. +/// optional int32 bar = 2; +/// +/// optional string baz = 3; +/// // Comment attached to baz. +/// // Another line attached to baz. +/// +/// // Comment attached to qux. +/// // +/// // Another line attached to qux. +/// optional double qux = 4; +/// +/// // Detached comment for corge. This is not leading or trailing comments +/// // to qux or corge because there are blank lines separating it from +/// // both. +/// +/// // Detached comment for corge paragraph 2. +/// +/// optional string corge = 5; +/// /* Block comment attached +/// * to corge. Leading asterisks +/// * will be removed. */ +/// /* Block comment attached to +/// * grault. */ +/// optional int32 grault = 6; +/// +/// // ignored detached comments. @property(nonatomic, readwrite, copy, null_resettable) NSString *leadingComments; +/// Test to see if @c leadingComments has been set. +@property(nonatomic, readwrite) BOOL hasLeadingComments; -@property(nonatomic, readwrite) BOOL hasTrailingComments; @property(nonatomic, readwrite, copy, null_resettable) NSString *trailingComments; +/// Test to see if @c trailingComments has been set. +@property(nonatomic, readwrite) BOOL hasTrailingComments; -// |leadingDetachedCommentsArray| contains |NSString| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *leadingDetachedCommentsArray; +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *leadingDetachedCommentsArray; +/// The number of items in @c leadingDetachedCommentsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger leadingDetachedCommentsArray_Count; @end @@ -1159,15 +1224,15 @@ typedef GPB_ENUM(GPBGeneratedCodeInfo_FieldNumber) { GPBGeneratedCodeInfo_FieldNumber_AnnotationArray = 1, }; -// Describes the relationship between generated code and its original source -// file. A GeneratedCodeInfo message is associated with only one generated -// source file, but may contain references to different source .proto files. +/// Describes the relationship between generated code and its original source +/// file. A GeneratedCodeInfo message is associated with only one generated +/// source file, but may contain references to different source .proto files. @interface GPBGeneratedCodeInfo : GPBMessage -// An Annotation connects some span of text in generated code to an element -// of its generating .proto file. -// |annotationArray| contains |GPBGeneratedCodeInfo_Annotation| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *annotationArray; +/// An Annotation connects some span of text in generated code to an element +/// of its generating .proto file. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBGeneratedCodeInfo_Annotation*> *annotationArray; +/// The number of items in @c annotationArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger annotationArray_Count; @end @@ -1183,26 +1248,28 @@ typedef GPB_ENUM(GPBGeneratedCodeInfo_Annotation_FieldNumber) { @interface GPBGeneratedCodeInfo_Annotation : GPBMessage -// Identifies the element in the original source .proto file. This field -// is formatted the same as SourceCodeInfo.Location.path. +/// Identifies the element in the original source .proto file. This field +/// is formatted the same as SourceCodeInfo.Location.path. @property(nonatomic, readwrite, strong, null_resettable) GPBInt32Array *pathArray; +/// The number of items in @c pathArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger pathArray_Count; -// Identifies the filesystem path to the original source .proto. -@property(nonatomic, readwrite) BOOL hasSourceFile; +/// Identifies the filesystem path to the original source .proto. @property(nonatomic, readwrite, copy, null_resettable) NSString *sourceFile; +/// Test to see if @c sourceFile has been set. +@property(nonatomic, readwrite) BOOL hasSourceFile; -// Identifies the starting offset in bytes in the generated code -// that relates to the identified object. -@property(nonatomic, readwrite) BOOL hasBegin; +/// Identifies the starting offset in bytes in the generated code +/// that relates to the identified object. @property(nonatomic, readwrite) int32_t begin; -// Identifies the ending offset in bytes in the generated code that -// relates to the identified offset. The end offset should be one past -// the last relevant byte (so the length of the text = end - begin). -@property(nonatomic, readwrite) BOOL hasEnd; +@property(nonatomic, readwrite) BOOL hasBegin; +/// Identifies the ending offset in bytes in the generated code that +/// relates to the identified offset. The end offset should be one past +/// the last relevant byte (so the length of the text = end - begin). @property(nonatomic, readwrite) int32_t end; +@property(nonatomic, readwrite) BOOL hasEnd; @end NS_ASSUME_NONNULL_END diff --git a/objectivec/google/protobuf/Duration.pbobjc.h b/objectivec/google/protobuf/Duration.pbobjc.h index b592640b..ebf9119e 100644 --- a/objectivec/google/protobuf/Duration.pbobjc.h +++ b/objectivec/google/protobuf/Duration.pbobjc.h @@ -15,13 +15,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - GPBDurationRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBDurationRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBDuration @@ -31,58 +33,58 @@ typedef GPB_ENUM(GPBDuration_FieldNumber) { GPBDuration_FieldNumber_Nanos = 2, }; -// A Duration represents a signed, fixed-length span of time represented -// as a count of seconds and fractions of seconds at nanosecond -// resolution. It is independent of any calendar and concepts like "day" -// or "month". It is related to Timestamp in that the difference between -// two Timestamp values is a Duration and it can be added or subtracted -// from a Timestamp. Range is approximately +-10,000 years. -// -// Example 1: Compute Duration from two Timestamps in pseudo code. -// -// Timestamp start = ...; -// Timestamp end = ...; -// Duration duration = ...; -// -// duration.seconds = end.seconds - start.seconds; -// duration.nanos = end.nanos - start.nanos; -// -// if (duration.seconds < 0 && duration.nanos > 0) { -// duration.seconds += 1; -// duration.nanos -= 1000000000; -// } else if (durations.seconds > 0 && duration.nanos < 0) { -// duration.seconds -= 1; -// duration.nanos += 1000000000; -// } -// -// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. -// -// Timestamp start = ...; -// Duration duration = ...; -// Timestamp end = ...; -// -// end.seconds = start.seconds + duration.seconds; -// end.nanos = start.nanos + duration.nanos; -// -// if (end.nanos < 0) { -// end.seconds -= 1; -// end.nanos += 1000000000; -// } else if (end.nanos >= 1000000000) { -// end.seconds += 1; -// end.nanos -= 1000000000; -// } +/// A Duration represents a signed, fixed-length span of time represented +/// as a count of seconds and fractions of seconds at nanosecond +/// resolution. It is independent of any calendar and concepts like "day" +/// or "month". It is related to Timestamp in that the difference between +/// two Timestamp values is a Duration and it can be added or subtracted +/// from a Timestamp. Range is approximately +-10,000 years. +/// +/// Example 1: Compute Duration from two Timestamps in pseudo code. +/// +/// Timestamp start = ...; +/// Timestamp end = ...; +/// Duration duration = ...; +/// +/// duration.seconds = end.seconds - start.seconds; +/// duration.nanos = end.nanos - start.nanos; +/// +/// if (duration.seconds < 0 && duration.nanos > 0) { +/// duration.seconds += 1; +/// duration.nanos -= 1000000000; +/// } else if (durations.seconds > 0 && duration.nanos < 0) { +/// duration.seconds -= 1; +/// duration.nanos += 1000000000; +/// } +/// +/// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. +/// +/// Timestamp start = ...; +/// Duration duration = ...; +/// Timestamp end = ...; +/// +/// end.seconds = start.seconds + duration.seconds; +/// end.nanos = start.nanos + duration.nanos; +/// +/// if (end.nanos < 0) { +/// end.seconds -= 1; +/// end.nanos += 1000000000; +/// } else if (end.nanos >= 1000000000) { +/// end.seconds += 1; +/// end.nanos -= 1000000000; +/// } @interface GPBDuration : GPBMessage -// Signed seconds of the span of time. Must be from -315,576,000,000 -// to +315,576,000,000 inclusive. +/// Signed seconds of the span of time. Must be from -315,576,000,000 +/// to +315,576,000,000 inclusive. @property(nonatomic, readwrite) int64_t seconds; -// Signed fractions of a second at nanosecond resolution of the span -// of time. Durations less than one second are represented with a 0 -// `seconds` field and a positive or negative `nanos` field. For durations -// of one second or more, a non-zero value for the `nanos` field must be -// of the same sign as the `seconds` field. Must be from -999,999,999 -// to +999,999,999 inclusive. +/// Signed fractions of a second at nanosecond resolution of the span +/// of time. Durations less than one second are represented with a 0 +/// `seconds` field and a positive or negative `nanos` field. For durations +/// of one second or more, a non-zero value for the `nanos` field must be +/// of the same sign as the `seconds` field. Must be from -999,999,999 +/// to +999,999,999 inclusive. @property(nonatomic, readwrite) int32_t nanos; @end diff --git a/objectivec/google/protobuf/Empty.pbobjc.h b/objectivec/google/protobuf/Empty.pbobjc.h index bace614d..ca09f71d 100644 --- a/objectivec/google/protobuf/Empty.pbobjc.h +++ b/objectivec/google/protobuf/Empty.pbobjc.h @@ -15,26 +15,28 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - GPBEmptyRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBEmptyRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBEmpty -// A generic empty message that you can re-use to avoid defining duplicated -// empty messages in your APIs. A typical example is to use it as the request -// or the response type of an API method. For instance: -// -// service Foo { -// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); -// } -// -// The JSON representation for `Empty` is empty JSON object `{}`. +/// A generic empty message that you can re-use to avoid defining duplicated +/// empty messages in your APIs. A typical example is to use it as the request +/// or the response type of an API method. For instance: +/// +/// service Foo { +/// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); +/// } +/// +/// The JSON representation for `Empty` is empty JSON object `{}`. @interface GPBEmpty : GPBMessage @end diff --git a/objectivec/google/protobuf/FieldMask.pbobjc.h b/objectivec/google/protobuf/FieldMask.pbobjc.h index 4e4ec387..f861a986 100644 --- a/objectivec/google/protobuf/FieldMask.pbobjc.h +++ b/objectivec/google/protobuf/FieldMask.pbobjc.h @@ -15,13 +15,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - GPBFieldMaskRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBFieldMaskRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBFieldMask @@ -30,133 +32,133 @@ typedef GPB_ENUM(GPBFieldMask_FieldNumber) { GPBFieldMask_FieldNumber_PathsArray = 1, }; -// `FieldMask` represents a set of symbolic field paths, for example: -// -// paths: "f.a" -// paths: "f.b.d" -// -// Here `f` represents a field in some root message, `a` and `b` -// fields in the message found in `f`, and `d` a field found in the -// message in `f.b`. -// -// Field masks are used to specify a subset of fields that should be -// returned by a get operation or modified by an update operation. -// Field masks also have a custom JSON encoding (see below). -// -// # Field Masks in Projections -// -// When used in the context of a projection, a response message or -// sub-message is filtered by the API to only contain those fields as -// specified in the mask. For example, if the mask in the previous -// example is applied to a response message as follows: -// -// f { -// a : 22 -// b { -// d : 1 -// x : 2 -// } -// y : 13 -// } -// z: 8 -// -// The result will not contain specific values for fields x,y and z -// (their value will be set to the default, and omitted in proto text -// output): -// -// -// f { -// a : 22 -// b { -// d : 1 -// } -// } -// -// A repeated field is not allowed except at the last position of a -// field mask. -// -// If a FieldMask object is not present in a get operation, the -// operation applies to all fields (as if a FieldMask of all fields -// had been specified). -// -// Note that a field mask does not necessarily applies to the -// top-level response message. In case of a REST get operation, the -// field mask applies directly to the response, but in case of a REST -// list operation, the mask instead applies to each individual message -// in the returned resource list. In case of a REST custom method, -// other definitions may be used. Where the mask applies will be -// clearly documented together with its declaration in the API. In -// any case, the effect on the returned resource/resources is required -// behavior for APIs. -// -// # Field Masks in Update Operations -// -// A field mask in update operations specifies which fields of the -// targeted resource are going to be updated. The API is required -// to only change the values of the fields as specified in the mask -// and leave the others untouched. If a resource is passed in to -// describe the updated values, the API ignores the values of all -// fields not covered by the mask. -// -// In order to reset a field's value to the default, the field must -// be in the mask and set to the default value in the provided resource. -// Hence, in order to reset all fields of a resource, provide a default -// instance of the resource and set all fields in the mask, or do -// not provide a mask as described below. -// -// If a field mask is not present on update, the operation applies to -// all fields (as if a field mask of all fields has been specified). -// Note that in the presence of schema evolution, this may mean that -// fields the client does not know and has therefore not filled into -// the request will be reset to their default. If this is unwanted -// behavior, a specific service may require a client to always specify -// a field mask, producing an error if not. -// -// As with get operations, the location of the resource which -// describes the updated values in the request message depends on the -// operation kind. In any case, the effect of the field mask is -// required to be honored by the API. -// -// ## Considerations for HTTP REST -// -// The HTTP kind of an update operation which uses a field mask must -// be set to PATCH instead of PUT in order to satisfy HTTP semantics -// (PUT must only be used for full updates). -// -// # JSON Encoding of Field Masks -// -// In JSON, a field mask is encoded as a single string where paths are -// separated by a comma. Fields name in each path are converted -// to/from lower-camel naming conventions. -// -// As an example, consider the following message declarations: -// -// message Profile { -// User user = 1; -// Photo photo = 2; -// } -// message User { -// string display_name = 1; -// string address = 2; -// } -// -// In proto a field mask for `Profile` may look as such: -// -// mask { -// paths: "user.display_name" -// paths: "photo" -// } -// -// In JSON, the same mask is represented as below: -// -// { -// mask: "user.displayName,photo" -// } +/// `FieldMask` represents a set of symbolic field paths, for example: +/// +/// paths: "f.a" +/// paths: "f.b.d" +/// +/// Here `f` represents a field in some root message, `a` and `b` +/// fields in the message found in `f`, and `d` a field found in the +/// message in `f.b`. +/// +/// Field masks are used to specify a subset of fields that should be +/// returned by a get operation or modified by an update operation. +/// Field masks also have a custom JSON encoding (see below). +/// +/// # Field Masks in Projections +/// +/// When used in the context of a projection, a response message or +/// sub-message is filtered by the API to only contain those fields as +/// specified in the mask. For example, if the mask in the previous +/// example is applied to a response message as follows: +/// +/// f { +/// a : 22 +/// b { +/// d : 1 +/// x : 2 +/// } +/// y : 13 +/// } +/// z: 8 +/// +/// The result will not contain specific values for fields x,y and z +/// (their value will be set to the default, and omitted in proto text +/// output): +/// +/// +/// f { +/// a : 22 +/// b { +/// d : 1 +/// } +/// } +/// +/// A repeated field is not allowed except at the last position of a +/// field mask. +/// +/// If a FieldMask object is not present in a get operation, the +/// operation applies to all fields (as if a FieldMask of all fields +/// had been specified). +/// +/// Note that a field mask does not necessarily applies to the +/// top-level response message. In case of a REST get operation, the +/// field mask applies directly to the response, but in case of a REST +/// list operation, the mask instead applies to each individual message +/// in the returned resource list. In case of a REST custom method, +/// other definitions may be used. Where the mask applies will be +/// clearly documented together with its declaration in the API. In +/// any case, the effect on the returned resource/resources is required +/// behavior for APIs. +/// +/// # Field Masks in Update Operations +/// +/// A field mask in update operations specifies which fields of the +/// targeted resource are going to be updated. The API is required +/// to only change the values of the fields as specified in the mask +/// and leave the others untouched. If a resource is passed in to +/// describe the updated values, the API ignores the values of all +/// fields not covered by the mask. +/// +/// In order to reset a field's value to the default, the field must +/// be in the mask and set to the default value in the provided resource. +/// Hence, in order to reset all fields of a resource, provide a default +/// instance of the resource and set all fields in the mask, or do +/// not provide a mask as described below. +/// +/// If a field mask is not present on update, the operation applies to +/// all fields (as if a field mask of all fields has been specified). +/// Note that in the presence of schema evolution, this may mean that +/// fields the client does not know and has therefore not filled into +/// the request will be reset to their default. If this is unwanted +/// behavior, a specific service may require a client to always specify +/// a field mask, producing an error if not. +/// +/// As with get operations, the location of the resource which +/// describes the updated values in the request message depends on the +/// operation kind. In any case, the effect of the field mask is +/// required to be honored by the API. +/// +/// ## Considerations for HTTP REST +/// +/// The HTTP kind of an update operation which uses a field mask must +/// be set to PATCH instead of PUT in order to satisfy HTTP semantics +/// (PUT must only be used for full updates). +/// +/// # JSON Encoding of Field Masks +/// +/// In JSON, a field mask is encoded as a single string where paths are +/// separated by a comma. Fields name in each path are converted +/// to/from lower-camel naming conventions. +/// +/// As an example, consider the following message declarations: +/// +/// message Profile { +/// User user = 1; +/// Photo photo = 2; +/// } +/// message User { +/// string display_name = 1; +/// string address = 2; +/// } +/// +/// In proto a field mask for `Profile` may look as such: +/// +/// mask { +/// paths: "user.display_name" +/// paths: "photo" +/// } +/// +/// In JSON, the same mask is represented as below: +/// +/// { +/// mask: "user.displayName,photo" +/// } @interface GPBFieldMask : GPBMessage -// The set of field mask paths. -// |pathsArray| contains |NSString| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *pathsArray; +/// The set of field mask paths. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *pathsArray; +/// The number of items in @c pathsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger pathsArray_Count; @end diff --git a/objectivec/google/protobuf/SourceContext.pbobjc.h b/objectivec/google/protobuf/SourceContext.pbobjc.h index 8480db1d..546db674 100644 --- a/objectivec/google/protobuf/SourceContext.pbobjc.h +++ b/objectivec/google/protobuf/SourceContext.pbobjc.h @@ -15,13 +15,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - GPBSourceContextRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBSourceContextRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBSourceContext @@ -30,12 +32,12 @@ typedef GPB_ENUM(GPBSourceContext_FieldNumber) { GPBSourceContext_FieldNumber_FileName = 1, }; -// `SourceContext` represents information about the source of a -// protobuf element, like the file in which it is defined. +/// `SourceContext` represents information about the source of a +/// protobuf element, like the file in which it is defined. @interface GPBSourceContext : GPBMessage -// The path-qualified name of the .proto file that contained the associated -// protobuf element. For example: `"google/protobuf/source.proto"`. +/// The path-qualified name of the .proto file that contained the associated +/// protobuf element. For example: `"google/protobuf/source.proto"`. @property(nonatomic, readwrite, copy, null_resettable) NSString *fileName; @end diff --git a/objectivec/google/protobuf/Struct.pbobjc.h b/objectivec/google/protobuf/Struct.pbobjc.h index f40414fa..7b9c45a0 100644 --- a/objectivec/google/protobuf/Struct.pbobjc.h +++ b/objectivec/google/protobuf/Struct.pbobjc.h @@ -13,34 +13,42 @@ CF_EXTERN_C_BEGIN @class GPBListValue; @class GPBStruct; +@class GPBValue; NS_ASSUME_NONNULL_BEGIN #pragma mark - Enum GPBNullValue -// `NullValue` is a singleton enumeration to represent the null value for the -// `Value` type union. -// -// The JSON representation for `NullValue` is JSON `null`. +/// `NullValue` is a singleton enumeration to represent the null value for the +/// `Value` type union. +/// +/// The JSON representation for `NullValue` is JSON `null`. typedef GPB_ENUM(GPBNullValue) { + /// Value used if any message's field encounters a value that is not defined + /// by this enum. The message will also have C functions to get/set the rawValue + /// of the field. GPBNullValue_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue, - // Null value. + /// Null value. GPBNullValue_NullValue = 0, }; GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBNullValue_IsValidValue(int32_t value); #pragma mark - GPBStructRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBStructRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBStruct @@ -49,19 +57,19 @@ typedef GPB_ENUM(GPBStruct_FieldNumber) { GPBStruct_FieldNumber_Fields = 1, }; -// `Struct` represents a structured data value, consisting of fields -// which map to dynamically typed values. In some languages, `Struct` -// might be supported by a native representation. For example, in -// scripting languages like JS a struct is represented as an -// object. The details of that representation are described together -// with the proto support for the language. -// -// The JSON representation for `Struct` is JSON object. +/// `Struct` represents a structured data value, consisting of fields +/// which map to dynamically typed values. In some languages, `Struct` +/// might be supported by a native representation. For example, in +/// scripting languages like JS a struct is represented as an +/// object. The details of that representation are described together +/// with the proto support for the language. +/// +/// The JSON representation for `Struct` is JSON object. @interface GPBStruct : GPBMessage -// Map of dynamically typed values. -// |fields| values are |GPBValue| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *fields; +/// Map of dynamically typed values. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary<NSString*, GPBValue*> *fields; +/// The number of items in @c fields without causing the array to be created. @property(nonatomic, readonly) NSUInteger fields_Count; @end @@ -87,40 +95,46 @@ typedef GPB_ENUM(GPBValue_Kind_OneOfCase) { GPBValue_Kind_OneOfCase_ListValue = 6, }; -// `Value` represents a dynamically typed value which can be either -// null, a number, a string, a boolean, a recursive struct value, or a -// list of values. A producer of value is expected to set one of that -// variants, absence of any variant indicates an error. -// -// The JSON representation for `Value` is JSON value. +/// `Value` represents a dynamically typed value which can be either +/// null, a number, a string, a boolean, a recursive struct value, or a +/// list of values. A producer of value is expected to set one of that +/// variants, absence of any variant indicates an error. +/// +/// The JSON representation for `Value` is JSON value. @interface GPBValue : GPBMessage -// The kind of value. +/// The kind of value. @property(nonatomic, readonly) GPBValue_Kind_OneOfCase kindOneOfCase; -// Represents a null value. +/// Represents a null value. @property(nonatomic, readwrite) GPBNullValue nullValue; -// Represents a double value. +/// Represents a double value. @property(nonatomic, readwrite) double numberValue; -// Represents a string value. +/// Represents a string value. @property(nonatomic, readwrite, copy, null_resettable) NSString *stringValue; -// Represents a boolean value. +/// Represents a boolean value. @property(nonatomic, readwrite) BOOL boolValue; -// Represents a structured value. +/// Represents a structured value. @property(nonatomic, readwrite, strong, null_resettable) GPBStruct *structValue; -// Represents a repeated `Value`. +/// Represents a repeated `Value`. @property(nonatomic, readwrite, strong, null_resettable) GPBListValue *listValue; @end +/// Fetches the raw value of a @c GPBValue's @c nullValue property, even +/// if the value was not defined by the enum at the time the code was generated. int32_t GPBValue_NullValue_RawValue(GPBValue *message); +/// Sets the raw value of an @c GPBValue's @c nullValue property, allowing +/// it to be set to a value that was not defined by the enum at the time the code +/// was generated. void SetGPBValue_NullValue_RawValue(GPBValue *message, int32_t value); +/// Clears whatever value was set for the oneof 'kind'. void GPBValue_ClearKindOneOfCase(GPBValue *message); #pragma mark - GPBListValue @@ -129,14 +143,14 @@ typedef GPB_ENUM(GPBListValue_FieldNumber) { GPBListValue_FieldNumber_ValuesArray = 1, }; -// `ListValue` is a wrapper around a repeated field of values. -// -// The JSON representation for `ListValue` is JSON array. +/// `ListValue` is a wrapper around a repeated field of values. +/// +/// The JSON representation for `ListValue` is JSON array. @interface GPBListValue : GPBMessage -// Repeated field of dynamically typed values. -// |valuesArray| contains |GPBValue| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *valuesArray; +/// Repeated field of dynamically typed values. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBValue*> *valuesArray; +/// The number of items in @c valuesArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger valuesArray_Count; @end diff --git a/objectivec/google/protobuf/Timestamp.pbobjc.h b/objectivec/google/protobuf/Timestamp.pbobjc.h index 79b24ec6..d17c2860 100644 --- a/objectivec/google/protobuf/Timestamp.pbobjc.h +++ b/objectivec/google/protobuf/Timestamp.pbobjc.h @@ -15,13 +15,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - GPBTimestampRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBTimestampRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBTimestamp @@ -31,70 +33,70 @@ typedef GPB_ENUM(GPBTimestamp_FieldNumber) { GPBTimestamp_FieldNumber_Nanos = 2, }; -// A Timestamp represents a point in time independent of any time zone -// or calendar, represented as seconds and fractions of seconds at -// nanosecond resolution in UTC Epoch time. It is encoded using the -// Proleptic Gregorian Calendar which extends the Gregorian calendar -// backwards to year one. It is encoded assuming all minutes are 60 -// seconds long, i.e. leap seconds are "smeared" so that no leap second -// table is needed for interpretation. Range is from -// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. -// By restricting to that range, we ensure that we can convert to -// and from RFC 3339 date strings. -// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). -// -// Example 1: Compute Timestamp from POSIX `time()`. -// -// Timestamp timestamp; -// timestamp.set_seconds(time(NULL)); -// timestamp.set_nanos(0); -// -// Example 2: Compute Timestamp from POSIX `gettimeofday()`. -// -// struct timeval tv; -// gettimeofday(&tv, NULL); -// -// Timestamp timestamp; -// timestamp.set_seconds(tv.tv_sec); -// timestamp.set_nanos(tv.tv_usec * 1000); -// -// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. -// -// FILETIME ft; -// GetSystemTimeAsFileTime(&ft); -// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; -// -// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z -// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. -// Timestamp timestamp; -// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); -// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); -// -// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. -// -// long millis = System.currentTimeMillis(); -// -// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) -// .setNanos((int) ((millis % 1000) * 1000000)).build(); -// -// -// Example 5: Compute Timestamp from current time in Python. -// -// now = time.time() -// seconds = int(now) -// nanos = int((now - seconds) * 10**9) -// timestamp = Timestamp(seconds=seconds, nanos=nanos) +/// A Timestamp represents a point in time independent of any time zone +/// or calendar, represented as seconds and fractions of seconds at +/// nanosecond resolution in UTC Epoch time. It is encoded using the +/// Proleptic Gregorian Calendar which extends the Gregorian calendar +/// backwards to year one. It is encoded assuming all minutes are 60 +/// seconds long, i.e. leap seconds are "smeared" so that no leap second +/// table is needed for interpretation. Range is from +/// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. +/// By restricting to that range, we ensure that we can convert to +/// and from RFC 3339 date strings. +/// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). +/// +/// Example 1: Compute Timestamp from POSIX `time()`. +/// +/// Timestamp timestamp; +/// timestamp.set_seconds(time(NULL)); +/// timestamp.set_nanos(0); +/// +/// Example 2: Compute Timestamp from POSIX `gettimeofday()`. +/// +/// struct timeval tv; +/// gettimeofday(&tv, NULL); +/// +/// Timestamp timestamp; +/// timestamp.set_seconds(tv.tv_sec); +/// timestamp.set_nanos(tv.tv_usec * 1000); +/// +/// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. +/// +/// FILETIME ft; +/// GetSystemTimeAsFileTime(&ft); +/// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; +/// +/// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z +/// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. +/// Timestamp timestamp; +/// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); +/// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); +/// +/// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. +/// +/// long millis = System.currentTimeMillis(); +/// +/// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) +/// .setNanos((int) ((millis % 1000) * 1000000)).build(); +/// +/// +/// Example 5: Compute Timestamp from current time in Python. +/// +/// now = time.time() +/// seconds = int(now) +/// nanos = int((now - seconds) * 10**9) +/// timestamp = Timestamp(seconds=seconds, nanos=nanos) @interface GPBTimestamp : GPBMessage -// Represents seconds of UTC time since Unix epoch -// 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to -// 9999-12-31T23:59:59Z inclusive. +/// Represents seconds of UTC time since Unix epoch +/// 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to +/// 9999-12-31T23:59:59Z inclusive. @property(nonatomic, readwrite) int64_t seconds; -// Non-negative fractions of a second at nanosecond resolution. Negative -// second values with fractions must still have non-negative nanos values -// that count forward in time. Must be from 0 to 999,999,999 -// inclusive. +/// Non-negative fractions of a second at nanosecond resolution. Negative +/// second values with fractions must still have non-negative nanos values +/// that count forward in time. Must be from 0 to 999,999,999 +/// inclusive. @property(nonatomic, readwrite) int32_t nanos; @end diff --git a/objectivec/google/protobuf/Type.pbobjc.h b/objectivec/google/protobuf/Type.pbobjc.h index e4c7a251..9301e4f4 100644 --- a/objectivec/google/protobuf/Type.pbobjc.h +++ b/objectivec/google/protobuf/Type.pbobjc.h @@ -12,124 +12,144 @@ CF_EXTERN_C_BEGIN @class GPBAny; +@class GPBEnumValue; +@class GPBField; +@class GPBOption; @class GPBSourceContext; NS_ASSUME_NONNULL_BEGIN #pragma mark - Enum GPBSyntax -// The syntax in which a protocol buffer element is defined. +/// The syntax in which a protocol buffer element is defined. typedef GPB_ENUM(GPBSyntax) { + /// Value used if any message's field encounters a value that is not defined + /// by this enum. The message will also have C functions to get/set the rawValue + /// of the field. GPBSyntax_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue, - // Syntax `proto2`. + /// Syntax `proto2`. GPBSyntax_SyntaxProto2 = 0, - // Syntax `proto3`. + /// Syntax `proto3`. GPBSyntax_SyntaxProto3 = 1, }; GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBSyntax_IsValidValue(int32_t value); #pragma mark - Enum GPBField_Kind -// Basic field types. +/// Basic field types. typedef GPB_ENUM(GPBField_Kind) { + /// Value used if any message's field encounters a value that is not defined + /// by this enum. The message will also have C functions to get/set the rawValue + /// of the field. GPBField_Kind_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue, - // Field type unknown. + /// Field type unknown. GPBField_Kind_TypeUnknown = 0, - // Field type double. + /// Field type double. GPBField_Kind_TypeDouble = 1, - // Field type float. + /// Field type float. GPBField_Kind_TypeFloat = 2, - // Field type int64. + /// Field type int64. GPBField_Kind_TypeInt64 = 3, - // Field type uint64. + /// Field type uint64. GPBField_Kind_TypeUint64 = 4, - // Field type int32. + /// Field type int32. GPBField_Kind_TypeInt32 = 5, - // Field type fixed64. + /// Field type fixed64. GPBField_Kind_TypeFixed64 = 6, - // Field type fixed32. + /// Field type fixed32. GPBField_Kind_TypeFixed32 = 7, - // Field type bool. + /// Field type bool. GPBField_Kind_TypeBool = 8, - // Field type string. + /// Field type string. GPBField_Kind_TypeString = 9, - // Field type group. Proto2 syntax only, and deprecated. + /// Field type group. Proto2 syntax only, and deprecated. GPBField_Kind_TypeGroup = 10, - // Field type message. + /// Field type message. GPBField_Kind_TypeMessage = 11, - // Field type bytes. + /// Field type bytes. GPBField_Kind_TypeBytes = 12, - // Field type uint32. + /// Field type uint32. GPBField_Kind_TypeUint32 = 13, - // Field type enum. + /// Field type enum. GPBField_Kind_TypeEnum = 14, - // Field type sfixed32. + /// Field type sfixed32. GPBField_Kind_TypeSfixed32 = 15, - // Field type sfixed64. + /// Field type sfixed64. GPBField_Kind_TypeSfixed64 = 16, - // Field type sint32. + /// Field type sint32. GPBField_Kind_TypeSint32 = 17, - // Field type sint64. + /// Field type sint64. GPBField_Kind_TypeSint64 = 18, }; GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBField_Kind_IsValidValue(int32_t value); #pragma mark - Enum GPBField_Cardinality -// Whether a field is optional, required, or repeated. +/// Whether a field is optional, required, or repeated. typedef GPB_ENUM(GPBField_Cardinality) { + /// Value used if any message's field encounters a value that is not defined + /// by this enum. The message will also have C functions to get/set the rawValue + /// of the field. GPBField_Cardinality_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue, - // For fields with unknown cardinality. + /// For fields with unknown cardinality. GPBField_Cardinality_CardinalityUnknown = 0, - // For optional fields. + /// For optional fields. GPBField_Cardinality_CardinalityOptional = 1, - // For required fields. Proto2 syntax only. + /// For required fields. Proto2 syntax only. GPBField_Cardinality_CardinalityRequired = 2, - // For repeated fields. + /// For repeated fields. GPBField_Cardinality_CardinalityRepeated = 3, }; GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void); +/// Checks to see if the given value is defined by the enum or was not known at +/// the time this source was generated. BOOL GPBField_Cardinality_IsValidValue(int32_t value); #pragma mark - GPBTypeRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBTypeRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBType @@ -143,37 +163,43 @@ typedef GPB_ENUM(GPBType_FieldNumber) { GPBType_FieldNumber_Syntax = 6, }; -// A protocol buffer message type. +/// A protocol buffer message type. @interface GPBType : GPBMessage -// The fully qualified message name. +/// The fully qualified message name. @property(nonatomic, readwrite, copy, null_resettable) NSString *name; -// The list of fields. -// |fieldsArray| contains |GPBField| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *fieldsArray; +/// The list of fields. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBField*> *fieldsArray; +/// The number of items in @c fieldsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger fieldsArray_Count; -// The list of types appearing in `oneof` definitions in this type. -// |oneofsArray| contains |NSString| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *oneofsArray; +/// The list of types appearing in `oneof` definitions in this type. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *oneofsArray; +/// The number of items in @c oneofsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger oneofsArray_Count; -// The protocol buffer options. -// |optionsArray| contains |GPBOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; +/// The protocol buffer options. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray; +/// The number of items in @c optionsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger optionsArray_Count; -// The source context. -@property(nonatomic, readwrite) BOOL hasSourceContext; +/// The source context. @property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext; +/// Test to see if @c sourceContext has been set. +@property(nonatomic, readwrite) BOOL hasSourceContext; -// The source syntax. +/// The source syntax. @property(nonatomic, readwrite) GPBSyntax syntax; @end +/// Fetches the raw value of a @c GPBType's @c syntax property, even +/// if the value was not defined by the enum at the time the code was generated. int32_t GPBType_Syntax_RawValue(GPBType *message); +/// Sets the raw value of an @c GPBType's @c syntax property, allowing +/// it to be set to a value that was not defined by the enum at the time the code +/// was generated. void SetGPBType_Syntax_RawValue(GPBType *message, int32_t value); #pragma mark - GPBField @@ -191,49 +217,59 @@ typedef GPB_ENUM(GPBField_FieldNumber) { GPBField_FieldNumber_DefaultValue = 11, }; -// A single field of a message type. +/// A single field of a message type. @interface GPBField : GPBMessage -// The field type. +/// The field type. @property(nonatomic, readwrite) GPBField_Kind kind; -// The field cardinality. +/// The field cardinality. @property(nonatomic, readwrite) GPBField_Cardinality cardinality; -// The field number. +/// The field number. @property(nonatomic, readwrite) int32_t number; -// The field name. +/// The field name. @property(nonatomic, readwrite, copy, null_resettable) NSString *name; -// The field type URL, without the scheme, for message or enumeration -// types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. +/// The field type URL, without the scheme, for message or enumeration +/// types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. @property(nonatomic, readwrite, copy, null_resettable) NSString *typeURL; -// The index of the field type in `Type.oneofs`, for message or enumeration -// types. The first type has index 1; zero means the type is not in the list. +/// The index of the field type in `Type.oneofs`, for message or enumeration +/// types. The first type has index 1; zero means the type is not in the list. @property(nonatomic, readwrite) int32_t oneofIndex; -// Whether to use alternative packed wire representation. +/// Whether to use alternative packed wire representation. @property(nonatomic, readwrite) BOOL packed; -// The protocol buffer options. -// |optionsArray| contains |GPBOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; +/// The protocol buffer options. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray; +/// The number of items in @c optionsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger optionsArray_Count; -// The field JSON name. +/// The field JSON name. @property(nonatomic, readwrite, copy, null_resettable) NSString *jsonName; -// The string value of the default value of this field. Proto2 syntax only. +/// The string value of the default value of this field. Proto2 syntax only. @property(nonatomic, readwrite, copy, null_resettable) NSString *defaultValue; @end +/// Fetches the raw value of a @c GPBField's @c kind property, even +/// if the value was not defined by the enum at the time the code was generated. int32_t GPBField_Kind_RawValue(GPBField *message); +/// Sets the raw value of an @c GPBField's @c kind property, allowing +/// it to be set to a value that was not defined by the enum at the time the code +/// was generated. void SetGPBField_Kind_RawValue(GPBField *message, int32_t value); +/// Fetches the raw value of a @c GPBField's @c cardinality property, even +/// if the value was not defined by the enum at the time the code was generated. int32_t GPBField_Cardinality_RawValue(GPBField *message); +/// Sets the raw value of an @c GPBField's @c cardinality property, allowing +/// it to be set to a value that was not defined by the enum at the time the code +/// was generated. void SetGPBField_Cardinality_RawValue(GPBField *message, int32_t value); #pragma mark - GPBEnum @@ -246,32 +282,38 @@ typedef GPB_ENUM(GPBEnum_FieldNumber) { GPBEnum_FieldNumber_Syntax = 5, }; -// Enum type definition. +/// Enum type definition. @interface GPBEnum : GPBMessage -// Enum type name. +/// Enum type name. @property(nonatomic, readwrite, copy, null_resettable) NSString *name; -// Enum value definitions. -// |enumvalueArray| contains |GPBEnumValue| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *enumvalueArray; +/// Enum value definitions. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBEnumValue*> *enumvalueArray; +/// The number of items in @c enumvalueArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger enumvalueArray_Count; -// Protocol buffer options. -// |optionsArray| contains |GPBOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; +/// Protocol buffer options. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray; +/// The number of items in @c optionsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger optionsArray_Count; -// The source context. -@property(nonatomic, readwrite) BOOL hasSourceContext; +/// The source context. @property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext; +/// Test to see if @c sourceContext has been set. +@property(nonatomic, readwrite) BOOL hasSourceContext; -// The source syntax. +/// The source syntax. @property(nonatomic, readwrite) GPBSyntax syntax; @end +/// Fetches the raw value of a @c GPBEnum's @c syntax property, even +/// if the value was not defined by the enum at the time the code was generated. int32_t GPBEnum_Syntax_RawValue(GPBEnum *message); +/// Sets the raw value of an @c GPBEnum's @c syntax property, allowing +/// it to be set to a value that was not defined by the enum at the time the code +/// was generated. void SetGPBEnum_Syntax_RawValue(GPBEnum *message, int32_t value); #pragma mark - GPBEnumValue @@ -282,18 +324,18 @@ typedef GPB_ENUM(GPBEnumValue_FieldNumber) { GPBEnumValue_FieldNumber_OptionsArray = 3, }; -// Enum value definition. +/// Enum value definition. @interface GPBEnumValue : GPBMessage -// Enum value name. +/// Enum value name. @property(nonatomic, readwrite, copy, null_resettable) NSString *name; -// Enum value number. +/// Enum value number. @property(nonatomic, readwrite) int32_t number; -// Protocol buffer options. -// |optionsArray| contains |GPBOption| -@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; +/// Protocol buffer options. +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray; +/// The number of items in @c optionsArray without causing the array to be created. @property(nonatomic, readonly) NSUInteger optionsArray_Count; @end @@ -305,16 +347,17 @@ typedef GPB_ENUM(GPBOption_FieldNumber) { GPBOption_FieldNumber_Value = 2, }; -// A protocol buffer option, which can be attached to a message, field, -// enumeration, etc. +/// A protocol buffer option, which can be attached to a message, field, +/// enumeration, etc. @interface GPBOption : GPBMessage -// The option's name. For example, `"java_package"`. +/// The option's name. For example, `"java_package"`. @property(nonatomic, readwrite, copy, null_resettable) NSString *name; -// The option's value. For example, `"com.google.protobuf"`. -@property(nonatomic, readwrite) BOOL hasValue; +/// The option's value. For example, `"com.google.protobuf"`. @property(nonatomic, readwrite, strong, null_resettable) GPBAny *value; +/// Test to see if @c value has been set. +@property(nonatomic, readwrite) BOOL hasValue; @end diff --git a/objectivec/google/protobuf/Wrappers.pbobjc.h b/objectivec/google/protobuf/Wrappers.pbobjc.h index 580945c4..38b99622 100644 --- a/objectivec/google/protobuf/Wrappers.pbobjc.h +++ b/objectivec/google/protobuf/Wrappers.pbobjc.h @@ -15,13 +15,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - GPBWrappersRoot +/// Exposes the extension registry for this file. +/// +/// The base class provides: +/// @code +/// + (GPBExtensionRegistry *)extensionRegistry; +/// @endcode +/// which is a @c GPBExtensionRegistry that includes all the extensions defined by +/// this file and all files that it depends on. @interface GPBWrappersRoot : GPBRootObject - -// The base class provides: -// + (GPBExtensionRegistry *)extensionRegistry; -// which is an GPBExtensionRegistry that includes all the extensions defined by -// this file and all files that it depends on. - @end #pragma mark - GPBDoubleValue @@ -30,12 +32,12 @@ typedef GPB_ENUM(GPBDoubleValue_FieldNumber) { GPBDoubleValue_FieldNumber_Value = 1, }; -// Wrapper message for `double`. -// -// The JSON representation for `DoubleValue` is JSON number. +/// Wrapper message for `double`. +/// +/// The JSON representation for `DoubleValue` is JSON number. @interface GPBDoubleValue : GPBMessage -// The double value. +/// The double value. @property(nonatomic, readwrite) double value; @end @@ -46,12 +48,12 @@ typedef GPB_ENUM(GPBFloatValue_FieldNumber) { GPBFloatValue_FieldNumber_Value = 1, }; -// Wrapper message for `float`. -// -// The JSON representation for `FloatValue` is JSON number. +/// Wrapper message for `float`. +/// +/// The JSON representation for `FloatValue` is JSON number. @interface GPBFloatValue : GPBMessage -// The float value. +/// The float value. @property(nonatomic, readwrite) float value; @end @@ -62,12 +64,12 @@ typedef GPB_ENUM(GPBInt64Value_FieldNumber) { GPBInt64Value_FieldNumber_Value = 1, }; -// Wrapper message for `int64`. -// -// The JSON representation for `Int64Value` is JSON string. +/// Wrapper message for `int64`. +/// +/// The JSON representation for `Int64Value` is JSON string. @interface GPBInt64Value : GPBMessage -// The int64 value. +/// The int64 value. @property(nonatomic, readwrite) int64_t value; @end @@ -78,12 +80,12 @@ typedef GPB_ENUM(GPBUInt64Value_FieldNumber) { GPBUInt64Value_FieldNumber_Value = 1, }; -// Wrapper message for `uint64`. -// -// The JSON representation for `UInt64Value` is JSON string. +/// Wrapper message for `uint64`. +/// +/// The JSON representation for `UInt64Value` is JSON string. @interface GPBUInt64Value : GPBMessage -// The uint64 value. +/// The uint64 value. @property(nonatomic, readwrite) uint64_t value; @end @@ -94,12 +96,12 @@ typedef GPB_ENUM(GPBInt32Value_FieldNumber) { GPBInt32Value_FieldNumber_Value = 1, }; -// Wrapper message for `int32`. -// -// The JSON representation for `Int32Value` is JSON number. +/// Wrapper message for `int32`. +/// +/// The JSON representation for `Int32Value` is JSON number. @interface GPBInt32Value : GPBMessage -// The int32 value. +/// The int32 value. @property(nonatomic, readwrite) int32_t value; @end @@ -110,12 +112,12 @@ typedef GPB_ENUM(GPBUInt32Value_FieldNumber) { GPBUInt32Value_FieldNumber_Value = 1, }; -// Wrapper message for `uint32`. -// -// The JSON representation for `UInt32Value` is JSON number. +/// Wrapper message for `uint32`. +/// +/// The JSON representation for `UInt32Value` is JSON number. @interface GPBUInt32Value : GPBMessage -// The uint32 value. +/// The uint32 value. @property(nonatomic, readwrite) uint32_t value; @end @@ -126,12 +128,12 @@ typedef GPB_ENUM(GPBBoolValue_FieldNumber) { GPBBoolValue_FieldNumber_Value = 1, }; -// Wrapper message for `bool`. -// -// The JSON representation for `BoolValue` is JSON `true` and `false`. +/// Wrapper message for `bool`. +/// +/// The JSON representation for `BoolValue` is JSON `true` and `false`. @interface GPBBoolValue : GPBMessage -// The bool value. +/// The bool value. @property(nonatomic, readwrite) BOOL value; @end @@ -142,12 +144,12 @@ typedef GPB_ENUM(GPBStringValue_FieldNumber) { GPBStringValue_FieldNumber_Value = 1, }; -// Wrapper message for `string`. -// -// The JSON representation for `StringValue` is JSON string. +/// Wrapper message for `string`. +/// +/// The JSON representation for `StringValue` is JSON string. @interface GPBStringValue : GPBMessage -// The string value. +/// The string value. @property(nonatomic, readwrite, copy, null_resettable) NSString *value; @end @@ -158,12 +160,12 @@ typedef GPB_ENUM(GPBBytesValue_FieldNumber) { GPBBytesValue_FieldNumber_Value = 1, }; -// Wrapper message for `bytes`. -// -// The JSON representation for `BytesValue` is JSON string. +/// Wrapper message for `bytes`. +/// +/// The JSON representation for `BytesValue` is JSON string. @interface GPBBytesValue : GPBMessage -// The bytes value. +/// The bytes value. @property(nonatomic, readwrite, copy, null_resettable) NSData *value; @end diff --git a/protobuf.bzl b/protobuf.bzl index f674a6c6..71eaba22 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -15,9 +15,13 @@ def _GenDir(ctx): return _GetPath(ctx, ctx.attr.includes[0]) return _GetPath(ctx, ctx.label.package + '/' + ctx.attr.includes[0]) -def _CcOuts(srcs): - return [s[:-len(".proto")] + ".pb.h" for s in srcs] + \ - [s[:-len(".proto")] + ".pb.cc" for s in srcs] +def _CcOuts(srcs, use_grpc_plugin=False): + ret = [s[:-len(".proto")] + ".pb.h" for s in srcs] + \ + [s[:-len(".proto")] + ".pb.cc" for s in srcs] + if use_grpc_plugin: + ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs] + \ + [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs] + return ret def _PyOuts(srcs): return [s[:-len(".proto")] + "_pb2.py" for s in srcs] @@ -63,6 +67,10 @@ def _proto_gen_impl(ctx): if ctx.attr.gen_py: args += ["--python_out=" + ctx.var["GENDIR"] + "/" + gen_dir] + if ctx.executable.grpc_cpp_plugin: + args += ["--plugin=protoc-gen-grpc=" + ctx.executable.grpc_cpp_plugin.path] + args += ["--grpc_out=" + ctx.var["GENDIR"] + "/" + gen_dir] + if args: ctx.action( inputs=srcs + deps, @@ -90,6 +98,11 @@ _proto_gen = rule( single_file = True, mandatory = True, ), + "grpc_cpp_plugin": attr.label( + cfg = HOST_CFG, + executable = True, + single_file = True, + ), "gen_cc": attr.bool(), "gen_py": attr.bool(), "outs": attr.output_list(), @@ -104,9 +117,10 @@ def cc_proto_library( deps=[], cc_libs=[], include=None, - protoc="//google/protobuf:protoc", + protoc="//:protoc", internal_bootstrap_hack=False, - default_runtime="//google/protobuf:protobuf", + use_grpc_plugin=False, + default_runtime="//:protobuf", **kargs): """Bazel rule to create a C++ protobuf library from proto source files @@ -126,6 +140,8 @@ def cc_proto_library( for bootstraping. When it is set to True, no files will be generated. The rule will simply be a provider for .proto files, so that other cc_proto_library can depend on it. + use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin + when processing the proto files. default_runtime: the implicitly default runtime which will be depended on by the generated cc_library target. **kargs: other keyword arguments that are passed to cc_library. @@ -153,13 +169,19 @@ def cc_proto_library( **kargs) return - outs = _CcOuts(srcs) + grpc_cpp_plugin = None + if use_grpc_plugin: + grpc_cpp_plugin = "//external:grpc_cpp_plugin" + + outs = _CcOuts(srcs, use_grpc_plugin) + _proto_gen( name=name + "_genproto", srcs=srcs, deps=[s + "_genproto" for s in deps], includes=includes, protoc=protoc, + grpc_cpp_plugin=grpc_cpp_plugin, gen_cc=1, outs=outs, visibility=["//visibility:public"], @@ -167,6 +189,8 @@ def cc_proto_library( if default_runtime and not default_runtime in cc_libs: cc_libs += [default_runtime] + if use_grpc_plugin: + cc_libs += ["//external:grpc_lib"] native.cc_library( name=name, @@ -175,37 +199,6 @@ def cc_proto_library( includes=includes, **kargs) - -def internal_copied_filegroup( - name, - srcs, - include, - **kargs): - """Bazel rule to fix sources file to workaround with python path issues. - - Args: - name: the name of the internal_copied_filegroup rule, which will be the - name of the generated filegroup. - srcs: the source files to be copied. - include: the expected import root of the source. - **kargs: extra arguments that will be passed into the filegroup. - """ - outs = [_RelativeOutputPath(s, include) for s in srcs] - - native.genrule( - name=name+"_genrule", - srcs=srcs, - outs=outs, - cmd=" && ".join(["cp $(location %s) $(location %s)" % - (s, _RelativeOutputPath(s, include)) - for s in srcs])) - - native.filegroup( - name=name, - srcs=outs, - **kargs) - - def py_proto_library( name, srcs=[], @@ -213,8 +206,8 @@ def py_proto_library( py_libs=[], py_extra_srcs=[], include=None, - default_runtime="//google/protobuf:protobuf_python", - protoc="//google/protobuf:protoc", + default_runtime="//:protobuf_python", + protoc="//:protoc", **kargs): """Bazel rule to create a Python protobuf library from proto source files @@ -254,15 +247,6 @@ def py_proto_library( visibility=["//visibility:public"], ) - if include != None: - # Copy the output files to the desired location to make the import work. - internal_copied_filegroup_name=name + "_internal_copied_filegroup" - internal_copied_filegroup( - name=internal_copied_filegroup_name, - srcs=outs, - include=include) - outs=[internal_copied_filegroup_name] - if default_runtime and not default_runtime in py_libs + deps: py_libs += [default_runtime] @@ -270,6 +254,7 @@ def py_proto_library( name=name, srcs=outs+py_extra_srcs, deps=py_libs+deps, + imports=includes, **kargs) def internal_protobuf_py_tests( @@ -286,8 +271,7 @@ def internal_protobuf_py_tests( """ for m in modules: - s = _RelativeOutputPath( - "python/google/protobuf/internal/%s.py" % m, "python") + s = "python/google/protobuf/internal/%s.py" % m native.py_test( name="py_%s" % m, srcs=[s], diff --git a/python/setup.py b/python/setup.py index 24ac53db..6ea3bad7 100755 --- a/python/setup.py +++ b/python/setup.py @@ -210,6 +210,7 @@ if __name__ == '__main__': "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", ], + namespace_packages=['google'], packages=find_packages( exclude=[ 'import_test_package', diff --git a/ruby/Rakefile b/ruby/Rakefile index 81c3119e..8eb7a2df 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -34,6 +34,49 @@ else end end +well_known_protos = %w[ + google/protobuf/any.proto + google/protobuf/api.proto + google/protobuf/duration.proto + google/protobuf/empty.proto + google/protobuf/field_mask.proto + google/protobuf/source_context.proto + google/protobuf/struct.proto + google/protobuf/timestamp.proto + google/protobuf/type.proto + google/protobuf/wrappers.proto +] + +# These are omitted for now because we don't support proto2. +proto2_protos = %w[ + google/protobuf/descriptor.proto + google/protobuf/compiler/plugin.proto +] + +genproto_output = [] + +well_known_protos.each do |proto_file| + input_file = "../src/" + proto_file + output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb") + genproto_output << output_file + file output_file => input_file do |file_task| + sh "../src/protoc -I../src --ruby_out=lib #{input_file}" + end +end + + +# Proto for tests. +genproto_output << "tests/generated_code.rb" +file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task| + sh "../src/protoc --ruby_out=. tests/generated_code.proto" +end + +task :genproto => genproto_output + +task :clean do + sh "rm -f #{genproto_output.join(' ')}" +end + Gem::PackageTask.new(spec) do |pkg| end @@ -41,7 +84,7 @@ Rake::TestTask.new(:test => :build) do |t| t.test_files = FileList["tests/*.rb"] end -task :build => [:clean, :compile] +task :build => [:clean, :compile, :genproto] task :default => [:build] # vim:sw=2:et diff --git a/ruby/ext/google/protobuf_c/defs.c b/ruby/ext/google/protobuf_c/defs.c index 7e0cd14c..96ef4953 100644 --- a/ruby/ext/google/protobuf_c/defs.c +++ b/ruby/ext/google/protobuf_c/defs.c @@ -243,6 +243,10 @@ void Descriptor_free(void* _self) { if (self->fill_method) { upb_pbdecodermethod_unref(self->fill_method, &self->fill_method); } + if (self->json_fill_method) { + upb_json_parsermethod_unref(self->json_fill_method, + &self->json_fill_method); + } if (self->pb_serialize_handlers) { upb_handlers_unref(self->pb_serialize_handlers, &self->pb_serialize_handlers); @@ -271,6 +275,7 @@ VALUE Descriptor_alloc(VALUE klass) { self->layout = NULL; self->fill_handlers = NULL; self->fill_method = NULL; + self->json_fill_method = NULL; self->pb_serialize_handlers = NULL; self->json_serialize_handlers = NULL; self->typeclass_references = rb_ary_new(); diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index 1c48281f..c2c369eb 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -640,6 +640,14 @@ static const upb_pbdecodermethod *msgdef_decodermethod(Descriptor* desc) { return desc->fill_method; } +static const upb_json_parsermethod *msgdef_jsonparsermethod(Descriptor* desc) { + if (desc->json_fill_method == NULL) { + desc->json_fill_method = + upb_json_parsermethod_new(desc->msgdef, &desc->json_fill_method); + } + return desc->json_fill_method; +} + // Stack-allocated context during an encode/decode operation. Contains the upb // environment and its stack-based allocator, an initial buffer for allocations @@ -752,13 +760,14 @@ VALUE Message_decode_json(VALUE klass, VALUE data) { TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); { + const upb_json_parsermethod* method = msgdef_jsonparsermethod(desc); stackenv se; upb_sink sink; upb_json_parser* parser; stackenv_init(&se, "Error occurred during parsing: %s"); upb_sink_reset(&sink, get_fill_handlers(desc), msg); - parser = upb_json_parser_create(&se.env, &sink); + parser = upb_json_parser_create(&se.env, method, &sink); upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data), upb_json_parser_input(parser)); @@ -1041,6 +1050,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc, !upb_msg_field_done(&i); upb_msg_field_next(&i)) { upb_fielddef *f = upb_msg_iter_field(&i); + bool is_matching_oneof = false; uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset + sizeof(MessageHeader); @@ -1057,6 +1067,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc, } // Otherwise, fall through to the appropriate singular-field handler // below. + is_matching_oneof = true; } if (is_map_field(f)) { @@ -1071,7 +1082,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc, } } else if (upb_fielddef_isstring(f)) { VALUE str = DEREF(msg, offset, VALUE); - if (RSTRING_LEN(str) > 0) { + if (is_matching_oneof || RSTRING_LEN(str) > 0) { putstr(str, f, sink); } } else if (upb_fielddef_issubmsg(f)) { @@ -1082,7 +1093,7 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc, #define T(upbtypeconst, upbtype, ctype, default_value) \ case upbtypeconst: { \ ctype value = DEREF(msg, offset, ctype); \ - if (value != default_value) { \ + if (is_matching_oneof || value != default_value) { \ upb_sink_put##upbtype(sink, sel, value); \ } \ } \ @@ -1189,7 +1200,7 @@ VALUE Message_encode_json(VALUE klass, VALUE msg_rb) { putmsg(msg_rb, desc, upb_json_printer_input(printer), 0); - ret = rb_str_new(sink.ptr, sink.len); + ret = rb_enc_str_new(sink.ptr, sink.len, rb_utf8_encoding()); stackenv_uninit(&se); stringsink_uninit(&sink); diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 8750c93d..21ce7bb3 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -112,6 +112,7 @@ struct Descriptor { VALUE klass; // begins as nil const upb_handlers* fill_handlers; const upb_pbdecodermethod* fill_method; + const upb_json_parsermethod* json_fill_method; const upb_handlers* pb_serialize_handlers; const upb_handlers* json_serialize_handlers; // Handlers hold type class references for sub-message fields directly in some diff --git a/ruby/ext/google/protobuf_c/upb.c b/ruby/ext/google/protobuf_c/upb.c index 9e6aa674..b2a69b66 100644 --- a/ruby/ext/google/protobuf_c/upb.c +++ b/ruby/ext/google/protobuf_c/upb.c @@ -2,6 +2,7 @@ #include "upb.h" +#include <ctype.h> #include <stdlib.h> #include <string.h> @@ -525,6 +526,10 @@ static void upb_fielddef_uninit_default(upb_fielddef *f) { freestr(f->defaultval.bytes); } +const char *upb_fielddef_fullname(const upb_fielddef *e) { + return upb_def_fullname(upb_fielddef_upcast(e)); +} + static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit, void *closure) { const upb_fielddef *f = (const upb_fielddef*)r; @@ -716,6 +721,45 @@ const char *upb_fielddef_name(const upb_fielddef *f) { return upb_def_fullname(upb_fielddef_upcast(f)); } +size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len) { + const char *name = upb_fielddef_name(f); + size_t src, dst = 0; + bool ucase_next = false; + +#define WRITE(byte) \ + ++dst; \ + if (dst < len) buf[dst - 1] = byte; \ + else if (dst == len) buf[dst - 1] = '\0' + + if (!name) { + WRITE('\0'); + return 0; + } + + /* Implement the transformation as described in the spec: + * 1. upper case all letters after an underscore. + * 2. remove all underscores. + */ + for (src = 0; name[src]; src++) { + if (name[src] == '_') { + ucase_next = true; + continue; + } + + if (ucase_next) { + WRITE(toupper(name[src])); + ucase_next = false; + } else { + WRITE(name[src]); + } + } + + WRITE('\0'); + return dst; + +#undef WRITE +} + const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) { return f->msg_is_symbolic ? NULL : f->msg.def; } @@ -1212,6 +1256,16 @@ bool upb_fielddef_ismap(const upb_fielddef *f) { upb_msgdef_mapentry(upb_fielddef_msgsubdef(f)); } +bool upb_fielddef_haspresence(const upb_fielddef *f) { + if (upb_fielddef_isseq(f)) return false; + if (upb_fielddef_issubmsg(f)) return true; + + /* Primitive field: return true unless there is a message that specifies + * presence should not exist. */ + if (f->msg_is_symbolic || !f->msg.def) return true; + return f->msg.def->primitives_have_presence; +} + bool upb_fielddef_hassubdef(const upb_fielddef *f) { return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM; } @@ -1268,6 +1322,7 @@ upb_msgdef *upb_msgdef_new(const void *owner) { if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err2; if (!upb_strtable_init(&m->ntoo, UPB_CTYPE_PTR)) goto err1; m->map_entry = false; + m->primitives_have_presence = true; return m; err1: @@ -1290,6 +1345,7 @@ upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner) { upb_def_fullname(upb_msgdef_upcast(m)), NULL); newm->map_entry = m->map_entry; + newm->primitives_have_presence = m->primitives_have_presence; UPB_ASSERT_VAR(ok, ok); for(upb_msg_field_begin(&i, m); !upb_msg_field_done(&i); @@ -1434,6 +1490,11 @@ bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, return true; } +void upb_msgdef_setprimitiveshavepresence(upb_msgdef *m, bool have_presence) { + assert(!upb_msgdef_isfrozen(m)); + m->primitives_have_presence = have_presence; +} + const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) { upb_value val; return upb_inttable_lookup32(&m->itof, i, &val) ? @@ -4095,7 +4156,11 @@ static upb_tabent *mutable_entries(upb_table *t) { } static bool isfull(upb_table *t) { - return (double)(t->count + 1) / upb_table_size(t) > MAX_LOAD; + if (upb_table_size(t) == 0) { + return true; + } else { + return ((double)(t->count + 1) / upb_table_size(t)) > MAX_LOAD; + } } static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2) { @@ -4589,54 +4654,49 @@ bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) { } void upb_inttable_compact(upb_inttable *t) { - /* Create a power-of-two histogram of the table keys. */ - int counts[UPB_MAXARRSIZE + 1] = {0}; - uintptr_t max_key = 0; + /* A power-of-two histogram of the table keys. */ + size_t counts[UPB_MAXARRSIZE + 1] = {0}; + + /* The max key in each bucket. */ + uintptr_t max[UPB_MAXARRSIZE + 1] = {0}; + upb_inttable_iter i; - size_t arr_size; - int arr_count; + size_t arr_count; + int size_lg2; upb_inttable new_t; upb_inttable_begin(&i, t); for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { uintptr_t key = upb_inttable_iter_key(&i); - if (key > max_key) { - max_key = key; - } - counts[log2ceil(key)]++; + int bucket = log2ceil(key); + max[bucket] = UPB_MAX(max[bucket], key); + counts[bucket]++; } - arr_size = 1; + /* Find the largest power of two that satisfies the MIN_DENSITY + * definition (while actually having some keys). */ arr_count = upb_inttable_count(t); - if (upb_inttable_count(t) >= max_key * MIN_DENSITY) { - /* We can put 100% of the entries in the array part. */ - arr_size = max_key + 1; - } else { - /* Find the largest power of two that satisfies the MIN_DENSITY - * definition. */ - int size_lg2; - for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 1; size_lg2--) { - arr_size = 1 << size_lg2; - arr_count -= counts[size_lg2]; - if (arr_count >= arr_size * MIN_DENSITY) { - break; - } + for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) { + if (counts[size_lg2] == 0) { + /* We can halve again without losing any entries. */ + continue; + } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) { + break; } + + arr_count -= counts[size_lg2]; } - /* Array part must always be at least 1 entry large to catch lookups of key - * 0. Key 0 must always be in the array part because "0" in the hash part - * denotes an empty entry. */ - arr_size = UPB_MAX(arr_size, 1); + assert(arr_count <= upb_inttable_count(t)); { /* Insert all elements into new, perfectly-sized table. */ - int hash_count = upb_inttable_count(t) - arr_count; - int hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; - int hashsize_lg2 = log2ceil(hash_size); + size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ + size_t hash_count = upb_inttable_count(t) - arr_count; + size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; + size_t hashsize_lg2 = log2ceil(hash_size); - assert(hash_count >= 0); upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2); upb_inttable_begin(&i, t); for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { @@ -4978,293 +5038,348 @@ void upb_status_copy(upb_status *to, const upb_status *from) { * regenerated. */ -static const upb_msgdef msgs[20]; -static const upb_fielddef fields[81]; -static const upb_enumdef enums[4]; -static const upb_tabent strentries[236]; -static const upb_tabent intentries[14]; -static const upb_tabval arrays[232]; +static const upb_msgdef msgs[22]; +static const upb_fielddef fields[105]; +static const upb_enumdef enums[5]; +static const upb_tabent strentries[268]; +static const upb_tabent intentries[18]; +static const upb_tabval arrays[184]; #ifdef UPB_DEBUG_REFS -static upb_inttable reftables[212]; +static upb_inttable reftables[266]; #endif -static const upb_msgdef msgs[20] = { - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 27, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 8, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[0]),&reftables[0], &reftables[1]), - UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 4, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[8], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]),&reftables[2], &reftables[3]), - UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[20]),&reftables[4], &reftables[5]), - UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 7, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[15], 8, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[24]),&reftables[6], &reftables[7]), - UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 8, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[23], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]),&reftables[8], &reftables[9]), - UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 6, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[27], 4, 0), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[32]),&reftables[10], &reftables[11]), - UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 9, 8), UPB_STRTABLE_INIT(8, 15, UPB_CTYPE_PTR, 4, &strentries[36]),&reftables[12], &reftables[13]), - UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 14, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[40], 32, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[52]),&reftables[14], &reftables[15]), - UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 39, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[72], 12, 11), UPB_STRTABLE_INIT(11, 15, UPB_CTYPE_PTR, 4, &strentries[68]),&reftables[16], &reftables[17]), - UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[84], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[84]),&reftables[18], &reftables[19]), - UPB_MSGDEF_INIT("google.protobuf.FileOptions", 21, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[86], 64, 9), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[88]),&reftables[20], &reftables[21]), - UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[150], 16, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[104]),&reftables[22], &reftables[23]), - UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 13, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[166], 5, 4), UPB_STRTABLE_INIT(4, 7, UPB_CTYPE_PTR, 3, &strentries[108]),&reftables[24], &reftables[25]), - UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 6, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[10], &arrays[171], 4, 0), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[116]),&reftables[26], &reftables[27]), - UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[175], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[120]),&reftables[28], &reftables[29]), - UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 6, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[12], &arrays[179], 4, 0), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[124]),&reftables[30], &reftables[31]), - UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[183], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[128]),&reftables[32], &reftables[33]), - UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 14, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[185], 5, 4), UPB_STRTABLE_INIT(4, 7, UPB_CTYPE_PTR, 3, &strentries[132]),&reftables[34], &reftables[35]), - UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 18, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[190], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[140]),&reftables[36], &reftables[37]), - UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[199], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[156]),&reftables[38], &reftables[39]), +static const upb_msgdef msgs[22] = { + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 40, 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]),&reftables[0], &reftables[1]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 4, 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]),&reftables[2], &reftables[3]), + UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 4, 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]),&reftables[4], &reftables[5]), + UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 11, 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]),&reftables[6], &reftables[7]), + UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 8, 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]),&reftables[8], &reftables[9]), + UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 8, 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]),&reftables[10], &reftables[11]), + UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 7, 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]),&reftables[12], &reftables[13]), + UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 23, 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]),&reftables[14], &reftables[15]), + UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 12, 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]),&reftables[16], &reftables[17]), + UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 42, 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]),&reftables[18], &reftables[19]), + UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 6, 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]),&reftables[20], &reftables[21]), + UPB_MSGDEF_INIT("google.protobuf.FileOptions", 31, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 39, 15), UPB_STRTABLE_INIT(16, 31, UPB_CTYPE_PTR, 5, &strentries[92]),&reftables[22], &reftables[23]), + UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 10, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[107], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]),&reftables[24], &reftables[25]), + UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 15, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[115], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]),&reftables[26], &reftables[27]), + UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[122], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]),&reftables[28], &reftables[29]), + UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[123], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]),&reftables[30], &reftables[31]), + UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[125], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]),&reftables[32], &reftables[33]), + UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[129], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]),&reftables[34], &reftables[35]), + UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[130], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]),&reftables[36], &reftables[37]), + UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 19, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[132], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]),&reftables[38], &reftables[39]), + UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 18, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[139], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]),&reftables[40], &reftables[41]), + UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[148], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]),&reftables[42], &reftables[43]), }; -static const upb_fielddef fields[81] = { - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "aggregate_value", 8, &msgs[18], NULL, 15, 6, {0},&reftables[40], &reftables[41]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "allow_alias", 2, &msgs[3], NULL, 6, 1, {0},&reftables[42], &reftables[43]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_generic_services", 16, &msgs[10], NULL, 17, 6, {0},&reftables[44], &reftables[45]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "ctype", 1, &msgs[7], (const upb_def*)(&enums[2]), 6, 1, {0},&reftables[46], &reftables[47]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "default_value", 7, &msgs[6], NULL, 16, 7, {0},&reftables[48], &reftables[49]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "dependency", 3, &msgs[8], NULL, 30, 8, {0},&reftables[50], &reftables[51]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[7], NULL, 8, 3, {0},&reftables[52], &reftables[53]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_DOUBLE, 0, false, false, false, false, "double_value", 6, &msgs[18], NULL, 11, 4, {0},&reftables[54], &reftables[55]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[1], NULL, 3, 1, {0},&reftables[56], &reftables[57]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 4, &msgs[0], (const upb_def*)(&msgs[2]), 16, 2, {0},&reftables[58], &reftables[59]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 5, &msgs[8], (const upb_def*)(&msgs[2]), 13, 1, {0},&reftables[60], &reftables[61]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "experimental_map_key", 9, &msgs[7], NULL, 10, 5, {0},&reftables[62], &reftables[63]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "extendee", 2, &msgs[6], NULL, 7, 2, {0},&reftables[64], &reftables[65]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 7, &msgs[8], (const upb_def*)(&msgs[6]), 19, 3, {0},&reftables[66], &reftables[67]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 6, &msgs[0], (const upb_def*)(&msgs[6]), 22, 4, {0},&reftables[68], &reftables[69]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension_range", 5, &msgs[0], (const upb_def*)(&msgs[1]), 19, 3, {0},&reftables[70], &reftables[71]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "field", 2, &msgs[0], (const upb_def*)(&msgs[6]), 10, 0, {0},&reftables[72], &reftables[73]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "file", 1, &msgs[9], (const upb_def*)(&msgs[8]), 5, 0, {0},&reftables[74], &reftables[75]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "go_package", 11, &msgs[10], NULL, 14, 5, {0},&reftables[76], &reftables[77]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "identifier_value", 3, &msgs[18], NULL, 6, 1, {0},&reftables[78], &reftables[79]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "input_type", 2, &msgs[12], NULL, 7, 2, {0},&reftables[80], &reftables[81]), - UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_BOOL, 0, false, false, false, false, "is_extension", 2, &msgs[19], NULL, 5, 1, {0},&reftables[82], &reftables[83]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generate_equals_and_hash", 20, &msgs[10], NULL, 20, 9, {0},&reftables[84], &reftables[85]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generic_services", 17, &msgs[10], NULL, 18, 7, {0},&reftables[86], &reftables[87]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_multiple_files", 10, &msgs[10], NULL, 13, 4, {0},&reftables[88], &reftables[89]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_outer_classname", 8, &msgs[10], NULL, 9, 2, {0},&reftables[90], &reftables[91]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_package", 1, &msgs[10], NULL, 6, 1, {0},&reftables[92], &reftables[93]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "label", 4, &msgs[6], (const upb_def*)(&enums[0]), 11, 4, {0},&reftables[94], &reftables[95]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "lazy", 5, &msgs[7], NULL, 9, 4, {0},&reftables[96], &reftables[97]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "leading_comments", 3, &msgs[17], NULL, 8, 2, {0},&reftables[98], &reftables[99]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "location", 1, &msgs[16], (const upb_def*)(&msgs[17]), 5, 0, {0},&reftables[100], &reftables[101]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "message_set_wire_format", 1, &msgs[11], NULL, 6, 1, {0},&reftables[102], &reftables[103]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "message_type", 4, &msgs[8], (const upb_def*)(&msgs[0]), 10, 0, {0},&reftables[104], &reftables[105]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "method", 2, &msgs[14], (const upb_def*)(&msgs[12]), 6, 0, {0},&reftables[106], &reftables[107]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[8], NULL, 22, 6, {0},&reftables[108], &reftables[109]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[14], NULL, 8, 2, {0},&reftables[110], &reftables[111]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "name", 2, &msgs[18], (const upb_def*)(&msgs[19]), 5, 0, {0},&reftables[112], &reftables[113]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[4], NULL, 4, 1, {0},&reftables[114], &reftables[115]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[0], NULL, 24, 6, {0},&reftables[116], &reftables[117]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[12], NULL, 4, 1, {0},&reftables[118], &reftables[119]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[2], NULL, 8, 2, {0},&reftables[120], &reftables[121]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[6], NULL, 4, 1, {0},&reftables[122], &reftables[123]), - UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_STRING, 0, false, false, false, false, "name_part", 1, &msgs[19], NULL, 2, 0, {0},&reftables[124], &reftables[125]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "negative_int_value", 5, &msgs[18], NULL, 10, 3, {0},&reftables[126], &reftables[127]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "nested_type", 3, &msgs[0], (const upb_def*)(&msgs[0]), 13, 1, {0},&reftables[128], &reftables[129]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "no_standard_descriptor_accessor", 2, &msgs[11], NULL, 7, 2, {0},&reftables[130], &reftables[131]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 3, &msgs[6], NULL, 10, 3, {0},&reftables[132], &reftables[133]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 2, &msgs[4], NULL, 7, 2, {0},&reftables[134], &reftables[135]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "optimize_for", 9, &msgs[10], (const upb_def*)(&enums[3]), 12, 3, {0},&reftables[136], &reftables[137]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 7, &msgs[0], (const upb_def*)(&msgs[11]), 23, 5, {0},&reftables[138], &reftables[139]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[2], (const upb_def*)(&msgs[3]), 7, 1, {0},&reftables[140], &reftables[141]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[6], (const upb_def*)(&msgs[7]), 3, 0, {0},&reftables[142], &reftables[143]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[4], (const upb_def*)(&msgs[5]), 3, 0, {0},&reftables[144], &reftables[145]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[8], (const upb_def*)(&msgs[10]), 20, 4, {0},&reftables[146], &reftables[147]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[14], (const upb_def*)(&msgs[15]), 7, 1, {0},&reftables[148], &reftables[149]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 4, &msgs[12], (const upb_def*)(&msgs[13]), 3, 0, {0},&reftables[150], &reftables[151]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "output_type", 3, &msgs[12], NULL, 10, 3, {0},&reftables[152], &reftables[153]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "package", 2, &msgs[8], NULL, 25, 7, {0},&reftables[154], &reftables[155]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "packed", 2, &msgs[7], NULL, 7, 2, {0},&reftables[156], &reftables[157]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "path", 1, &msgs[17], NULL, 4, 0, {0},&reftables[158], &reftables[159]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, false, false, false, false, "positive_int_value", 4, &msgs[18], NULL, 9, 2, {0},&reftables[160], &reftables[161]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "public_dependency", 10, &msgs[8], NULL, 35, 9, {0},&reftables[162], &reftables[163]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "py_generic_services", 18, &msgs[10], NULL, 19, 8, {0},&reftables[164], &reftables[165]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "service", 6, &msgs[8], (const upb_def*)(&msgs[14]), 16, 2, {0},&reftables[166], &reftables[167]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "source_code_info", 9, &msgs[8], (const upb_def*)(&msgs[16]), 21, 5, {0},&reftables[168], &reftables[169]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "span", 2, &msgs[17], NULL, 7, 1, {0},&reftables[170], &reftables[171]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[1], NULL, 2, 0, {0},&reftables[172], &reftables[173]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "string_value", 7, &msgs[18], NULL, 12, 5, {0},&reftables[174], &reftables[175]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "trailing_comments", 4, &msgs[17], NULL, 11, 3, {0},&reftables[176], &reftables[177]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "type", 5, &msgs[6], (const upb_def*)(&enums[1]), 12, 5, {0},&reftables[178], &reftables[179]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "type_name", 6, &msgs[6], NULL, 13, 6, {0},&reftables[180], &reftables[181]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[5], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[182], &reftables[183]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[15], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[184], &reftables[185]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[3], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[186], &reftables[187]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[13], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[188], &reftables[189]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[10], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[190], &reftables[191]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[11], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[192], &reftables[193]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[7], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[194], &reftables[195]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "value", 2, &msgs[2], (const upb_def*)(&msgs[4]), 6, 0, {0},&reftables[196], &reftables[197]), - UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "weak", 10, &msgs[7], NULL, 13, 6, {0},&reftables[198], &reftables[199]), - UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "weak_dependency", 11, &msgs[8], NULL, 38, 10, {0},&reftables[200], &reftables[201]), +static const upb_fielddef fields[105] = { + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "aggregate_value", 8, &msgs[20], NULL, 15, 6, {0},&reftables[44], &reftables[45]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "allow_alias", 2, &msgs[4], NULL, 6, 1, {0},&reftables[46], &reftables[47]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_enable_arenas", 31, &msgs[11], NULL, 23, 12, {0},&reftables[48], &reftables[49]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_generic_services", 16, &msgs[11], NULL, 17, 6, {0},&reftables[50], &reftables[51]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "client_streaming", 5, &msgs[13], NULL, 13, 4, {0},&reftables[52], &reftables[53]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "csharp_namespace", 37, &msgs[11], NULL, 27, 14, {0},&reftables[54], &reftables[55]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "ctype", 1, &msgs[8], (const upb_def*)(&enums[2]), 6, 1, {0},&reftables[56], &reftables[57]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "default_value", 7, &msgs[7], NULL, 16, 7, {0},&reftables[58], &reftables[59]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "dependency", 3, &msgs[9], NULL, 30, 8, {0},&reftables[60], &reftables[61]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 1, &msgs[6], NULL, 6, 1, {0},&reftables[62], &reftables[63]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[4], NULL, 7, 2, {0},&reftables[64], &reftables[65]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[17], NULL, 6, 1, {0},&reftables[66], &reftables[67]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[8], NULL, 8, 3, {0},&reftables[68], &reftables[69]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[14], NULL, 6, 1, {0},&reftables[70], &reftables[71]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[12], NULL, 8, 3, {0},&reftables[72], &reftables[73]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 23, &msgs[11], NULL, 21, 10, {0},&reftables[74], &reftables[75]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_DOUBLE, 0, false, false, false, false, "double_value", 6, &msgs[20], NULL, 11, 4, {0},&reftables[76], &reftables[77]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[2], NULL, 3, 1, {0},&reftables[78], &reftables[79]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[1], NULL, 3, 1, {0},&reftables[80], &reftables[81]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 5, &msgs[9], (const upb_def*)(&msgs[3]), 13, 1, {0},&reftables[82], &reftables[83]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 4, &msgs[0], (const upb_def*)(&msgs[3]), 18, 2, {0},&reftables[84], &reftables[85]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "extendee", 2, &msgs[7], NULL, 7, 2, {0},&reftables[86], &reftables[87]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 6, &msgs[0], (const upb_def*)(&msgs[7]), 24, 4, {0},&reftables[88], &reftables[89]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 7, &msgs[9], (const upb_def*)(&msgs[7]), 19, 3, {0},&reftables[90], &reftables[91]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension_range", 5, &msgs[0], (const upb_def*)(&msgs[1]), 21, 3, {0},&reftables[92], &reftables[93]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "field", 2, &msgs[0], (const upb_def*)(&msgs[7]), 12, 0, {0},&reftables[94], &reftables[95]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "file", 1, &msgs[10], (const upb_def*)(&msgs[9]), 5, 0, {0},&reftables[96], &reftables[97]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "go_package", 11, &msgs[11], NULL, 14, 5, {0},&reftables[98], &reftables[99]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "identifier_value", 3, &msgs[20], NULL, 6, 1, {0},&reftables[100], &reftables[101]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "input_type", 2, &msgs[13], NULL, 7, 2, {0},&reftables[102], &reftables[103]), + UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_BOOL, 0, false, false, false, false, "is_extension", 2, &msgs[21], NULL, 5, 1, {0},&reftables[104], &reftables[105]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generate_equals_and_hash", 20, &msgs[11], NULL, 20, 9, {0},&reftables[106], &reftables[107]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generic_services", 17, &msgs[11], NULL, 18, 7, {0},&reftables[108], &reftables[109]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_multiple_files", 10, &msgs[11], NULL, 13, 4, {0},&reftables[110], &reftables[111]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_outer_classname", 8, &msgs[11], NULL, 9, 2, {0},&reftables[112], &reftables[113]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_package", 1, &msgs[11], NULL, 6, 1, {0},&reftables[114], &reftables[115]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_string_check_utf8", 27, &msgs[11], NULL, 22, 11, {0},&reftables[116], &reftables[117]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "javanano_use_deprecated_package", 38, &msgs[11], NULL, 30, 15, {0},&reftables[118], &reftables[119]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "json_name", 10, &msgs[7], NULL, 20, 9, {0},&reftables[120], &reftables[121]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "jstype", 6, &msgs[8], (const upb_def*)(&enums[3]), 10, 5, {0},&reftables[122], &reftables[123]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "label", 4, &msgs[7], (const upb_def*)(&enums[0]), 11, 4, {0},&reftables[124], &reftables[125]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "lazy", 5, &msgs[8], NULL, 9, 4, {0},&reftables[126], &reftables[127]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "leading_comments", 3, &msgs[19], NULL, 8, 2, {0},&reftables[128], &reftables[129]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "leading_detached_comments", 6, &msgs[19], NULL, 16, 4, {0},&reftables[130], &reftables[131]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "location", 1, &msgs[18], (const upb_def*)(&msgs[19]), 5, 0, {0},&reftables[132], &reftables[133]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "map_entry", 7, &msgs[12], NULL, 9, 4, {0},&reftables[134], &reftables[135]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "message_set_wire_format", 1, &msgs[12], NULL, 6, 1, {0},&reftables[136], &reftables[137]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "message_type", 4, &msgs[9], (const upb_def*)(&msgs[0]), 10, 0, {0},&reftables[138], &reftables[139]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "method", 2, &msgs[16], (const upb_def*)(&msgs[13]), 6, 0, {0},&reftables[140], &reftables[141]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[9], NULL, 22, 6, {0},&reftables[142], &reftables[143]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[5], NULL, 4, 1, {0},&reftables[144], &reftables[145]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[13], NULL, 4, 1, {0},&reftables[146], &reftables[147]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[0], NULL, 32, 8, {0},&reftables[148], &reftables[149]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[3], NULL, 8, 2, {0},&reftables[150], &reftables[151]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[15], NULL, 2, 0, {0},&reftables[152], &reftables[153]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[16], NULL, 8, 2, {0},&reftables[154], &reftables[155]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[7], NULL, 4, 1, {0},&reftables[156], &reftables[157]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "name", 2, &msgs[20], (const upb_def*)(&msgs[21]), 5, 0, {0},&reftables[158], &reftables[159]), + UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_STRING, 0, false, false, false, false, "name_part", 1, &msgs[21], NULL, 2, 0, {0},&reftables[160], &reftables[161]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "negative_int_value", 5, &msgs[20], NULL, 10, 3, {0},&reftables[162], &reftables[163]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "nested_type", 3, &msgs[0], (const upb_def*)(&msgs[0]), 15, 1, {0},&reftables[164], &reftables[165]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "no_standard_descriptor_accessor", 2, &msgs[12], NULL, 7, 2, {0},&reftables[166], &reftables[167]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 3, &msgs[7], NULL, 10, 3, {0},&reftables[168], &reftables[169]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 2, &msgs[5], NULL, 7, 2, {0},&reftables[170], &reftables[171]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "objc_class_prefix", 36, &msgs[11], NULL, 24, 13, {0},&reftables[172], &reftables[173]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "oneof_decl", 8, &msgs[0], (const upb_def*)(&msgs[15]), 28, 6, {0},&reftables[174], &reftables[175]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "oneof_index", 9, &msgs[7], NULL, 19, 8, {0},&reftables[176], &reftables[177]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "optimize_for", 9, &msgs[11], (const upb_def*)(&enums[4]), 12, 3, {0},&reftables[178], &reftables[179]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 4, &msgs[13], (const upb_def*)(&msgs[14]), 3, 0, {0},&reftables[180], &reftables[181]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[3], (const upb_def*)(&msgs[4]), 7, 1, {0},&reftables[182], &reftables[183]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 7, &msgs[0], (const upb_def*)(&msgs[12]), 25, 5, {0},&reftables[184], &reftables[185]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[5], (const upb_def*)(&msgs[6]), 3, 0, {0},&reftables[186], &reftables[187]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[9], (const upb_def*)(&msgs[11]), 20, 4, {0},&reftables[188], &reftables[189]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[16], (const upb_def*)(&msgs[17]), 7, 1, {0},&reftables[190], &reftables[191]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[7], (const upb_def*)(&msgs[8]), 3, 0, {0},&reftables[192], &reftables[193]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "output_type", 3, &msgs[13], NULL, 10, 3, {0},&reftables[194], &reftables[195]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "package", 2, &msgs[9], NULL, 25, 7, {0},&reftables[196], &reftables[197]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "packed", 2, &msgs[8], NULL, 7, 2, {0},&reftables[198], &reftables[199]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "path", 1, &msgs[19], NULL, 4, 0, {0},&reftables[200], &reftables[201]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, false, false, false, false, "positive_int_value", 4, &msgs[20], NULL, 9, 2, {0},&reftables[202], &reftables[203]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "public_dependency", 10, &msgs[9], NULL, 35, 9, {0},&reftables[204], &reftables[205]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "py_generic_services", 18, &msgs[11], NULL, 19, 8, {0},&reftables[206], &reftables[207]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "reserved_name", 10, &msgs[0], NULL, 37, 9, {0},&reftables[208], &reftables[209]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "reserved_range", 9, &msgs[0], (const upb_def*)(&msgs[2]), 31, 7, {0},&reftables[210], &reftables[211]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "server_streaming", 6, &msgs[13], NULL, 14, 5, {0},&reftables[212], &reftables[213]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "service", 6, &msgs[9], (const upb_def*)(&msgs[16]), 16, 2, {0},&reftables[214], &reftables[215]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "source_code_info", 9, &msgs[9], (const upb_def*)(&msgs[18]), 21, 5, {0},&reftables[216], &reftables[217]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "span", 2, &msgs[19], NULL, 7, 1, {0},&reftables[218], &reftables[219]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[1], NULL, 2, 0, {0},&reftables[220], &reftables[221]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[2], NULL, 2, 0, {0},&reftables[222], &reftables[223]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "string_value", 7, &msgs[20], NULL, 12, 5, {0},&reftables[224], &reftables[225]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "syntax", 12, &msgs[9], NULL, 39, 11, {0},&reftables[226], &reftables[227]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "trailing_comments", 4, &msgs[19], NULL, 11, 3, {0},&reftables[228], &reftables[229]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "type", 5, &msgs[7], (const upb_def*)(&enums[1]), 12, 5, {0},&reftables[230], &reftables[231]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "type_name", 6, &msgs[7], NULL, 13, 6, {0},&reftables[232], &reftables[233]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[17], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[234], &reftables[235]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[12], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[236], &reftables[237]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[8], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[238], &reftables[239]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[14], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[240], &reftables[241]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[11], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[242], &reftables[243]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[4], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[244], &reftables[245]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[6], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[246], &reftables[247]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "value", 2, &msgs[3], (const upb_def*)(&msgs[5]), 6, 0, {0},&reftables[248], &reftables[249]), + UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "weak", 10, &msgs[8], NULL, 11, 6, {0},&reftables[250], &reftables[251]), + UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "weak_dependency", 11, &msgs[9], NULL, 38, 10, {0},&reftables[252], &reftables[253]), }; -static const upb_enumdef enums[4] = { - UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Label", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[160]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[202], 4, 3), 0, &reftables[202], &reftables[203]), - UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Type", UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_INT32, 5, &strentries[164]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[206], 19, 18), 0, &reftables[204], &reftables[205]), - UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.CType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[196]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[225], 3, 3), 0, &reftables[206], &reftables[207]), - UPB_ENUMDEF_INIT("google.protobuf.FileOptions.OptimizeMode", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[200]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[228], 4, 3), 0, &reftables[208], &reftables[209]), +static const upb_enumdef enums[5] = { + UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Label", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[188]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[151], 4, 3), 0, &reftables[254], &reftables[255]), + UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Type", UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_INT32, 5, &strentries[192]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[155], 19, 18), 0, &reftables[256], &reftables[257]), + UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.CType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[224]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[174], 3, 3), 0, &reftables[258], &reftables[259]), + UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.JSType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[228]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[177], 3, 3), 0, &reftables[260], &reftables[261]), + UPB_ENUMDEF_INIT("google.protobuf.FileOptions.OptimizeMode", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[232]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[180], 4, 3), 0, &reftables[262], &reftables[263]), }; -static const upb_tabent strentries[236] = { - {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR_INIT(&fields[14]), NULL}, +static const upb_tabent strentries[268] = { + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR_INIT(&fields[22]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "reserved_name"), UPB_TABVALUE_PTR_INIT(&fields[82]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[52]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[38]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "field"), UPB_TABVALUE_PTR_INIT(&fields[25]), &strentries[12]}, + {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "extension_range"), UPB_TABVALUE_PTR_INIT(&fields[24]), &strentries[14]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "field"), UPB_TABVALUE_PTR_INIT(&fields[16]), NULL}, - {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "extension_range"), UPB_TABVALUE_PTR_INIT(&fields[15]), NULL}, + {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "nested_type"), UPB_TABVALUE_PTR_INIT(&fields[60]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "nested_type"), UPB_TABVALUE_PTR_INIT(&fields[44]), NULL}, + {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "reserved_range"), UPB_TABVALUE_PTR_INIT(&fields[83]), NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[70]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "oneof_decl"), UPB_TABVALUE_PTR_INIT(&fields[65]), NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR_INIT(&fields[20]), &strentries[13]}, + {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INIT(&fields[88]), NULL}, + {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(&fields[18]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INIT(&fields[89]), NULL}, + {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(&fields[17]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[49]), NULL}, - {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR_INIT(&fields[9]), &strentries[14]}, - {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INIT(&fields[66]), NULL}, - {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(&fields[8]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[102]), NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[69]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[53]), &strentries[26]}, + {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[10]), NULL}, + {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "allow_alias"), UPB_TABVALUE_PTR_INIT(&fields[1]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[78]), NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[50]), NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[40]), &strentries[22]}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[73]), NULL}, + {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_INIT(&fields[63]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "allow_alias"), UPB_TABVALUE_PTR_INIT(&fields[1]), NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[71]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[50]), &strentries[34]}, + {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[101]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[9]), NULL}, + {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "oneof_index"), UPB_TABVALUE_PTR_INIT(&fields[66]), NULL}, + {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "label"), UPB_TABVALUE_PTR_INIT(&fields[40]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_INIT(&fields[47]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[56]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[52]), NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[37]), &strentries[30]}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[71]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_INIT(&fields[62]), &strentries[53]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "label"), UPB_TABVALUE_PTR_INIT(&fields[27]), NULL}, + {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "extendee"), UPB_TABVALUE_PTR_INIT(&fields[21]), NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "type_name"), UPB_TABVALUE_PTR_INIT(&fields[94]), NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "json_name"), UPB_TABVALUE_PTR_INIT(&fields[38]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "type"), UPB_TABVALUE_PTR_INIT(&fields[93]), &strentries[50]}, + {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "default_value"), UPB_TABVALUE_PTR_INIT(&fields[7]), NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[74]), NULL}, + {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[41]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT(&fields[103]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_INIT(&fields[46]), &strentries[49]}, + {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "packed"), UPB_TABVALUE_PTR_INIT(&fields[77]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT(&fields[41]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "ctype"), UPB_TABVALUE_PTR_INIT(&fields[6]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "type_name"), UPB_TABVALUE_PTR_INIT(&fields[70]), NULL}, - {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "extendee"), UPB_TABVALUE_PTR_INIT(&fields[12]), NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "type"), UPB_TABVALUE_PTR_INIT(&fields[69]), &strentries[48]}, - {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "default_value"), UPB_TABVALUE_PTR_INIT(&fields[4]), NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[51]), NULL}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "experimental_map_key"), UPB_TABVALUE_PTR_INIT(&fields[11]), &strentries[67]}, + {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "jstype"), UPB_TABVALUE_PTR_INIT(&fields[39]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[12]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT(&fields[79]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR_INIT(&fields[23]), NULL}, + {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "weak_dependency"), UPB_TABVALUE_PTR_INIT(&fields[104]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[49]), NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "service"), UPB_TABVALUE_PTR_INIT(&fields[85]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "source_code_info"), UPB_TABVALUE_PTR_INIT(&fields[86]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "packed"), UPB_TABVALUE_PTR_INIT(&fields[58]), NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT(&fields[28]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "ctype"), UPB_TABVALUE_PTR_INIT(&fields[3]), NULL}, + {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "syntax"), UPB_TABVALUE_PTR_INIT(&fields[91]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "dependency"), UPB_TABVALUE_PTR_INIT(&fields[8]), NULL}, + {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "message_type"), UPB_TABVALUE_PTR_INIT(&fields[47]), NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "package"), UPB_TABVALUE_PTR_INIT(&fields[76]), NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[72]), &strentries[86]}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR_INIT(&fields[19]), NULL}, + {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "public_dependency"), UPB_TABVALUE_PTR_INIT(&fields[80]), &strentries[85]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT(&fields[26]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[6]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[77]), NULL}, - {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR_INIT(&fields[13]), NULL}, - {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "weak_dependency"), UPB_TABVALUE_PTR_INIT(&fields[80]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[34]), NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "service"), UPB_TABVALUE_PTR_INIT(&fields[63]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "source_code_info"), UPB_TABVALUE_PTR_INIT(&fields[64]), NULL}, + {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "cc_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[3]), NULL}, + {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "csharp_namespace"), UPB_TABVALUE_PTR_INIT(&fields[5]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "dependency"), UPB_TABVALUE_PTR_INIT(&fields[5]), NULL}, - {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "message_type"), UPB_TABVALUE_PTR_INIT(&fields[32]), NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "package"), UPB_TABVALUE_PTR_INIT(&fields[57]), NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[53]), &strentries[82]}, - {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR_INIT(&fields[10]), NULL}, - {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "public_dependency"), UPB_TABVALUE_PTR_INIT(&fields[61]), &strentries[81]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT(&fields[17]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[75]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "cc_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[2]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "go_package"), UPB_TABVALUE_PTR_INIT(&fields[27]), NULL}, + {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "java_package"), UPB_TABVALUE_PTR_INIT(&fields[35]), &strentries[120]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "java_multiple_files"), UPB_TABVALUE_PTR_INIT(&fields[24]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\025", "\000", "\000", "\000", "java_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[23]), &strentries[102]}, - {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "java_generate_equals_and_hash"), UPB_TABVALUE_PTR_INIT(&fields[22]), NULL}, + {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "java_outer_classname"), UPB_TABVALUE_PTR_INIT(&fields[34]), NULL}, + {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "go_package"), UPB_TABVALUE_PTR_INIT(&fields[18]), NULL}, - {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "java_package"), UPB_TABVALUE_PTR_INIT(&fields[26]), NULL}, - {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optimize_for"), UPB_TABVALUE_PTR_INIT(&fields[48]), NULL}, - {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "py_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[62]), NULL}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "java_outer_classname"), UPB_TABVALUE_PTR_INIT(&fields[25]), NULL}, - {UPB_TABKEY_STR("\027", "\000", "\000", "\000", "message_set_wire_format"), UPB_TABVALUE_PTR_INIT(&fields[31]), &strentries[106]}, + {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "java_multiple_files"), UPB_TABVALUE_PTR_INIT(&fields[33]), &strentries[117]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[76]), NULL}, - {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "no_standard_descriptor_accessor"), UPB_TABVALUE_PTR_INIT(&fields[45]), NULL}, + {UPB_TABKEY_STR("\025", "\000", "\000", "\000", "java_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[32]), &strentries[118]}, + {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "java_generate_equals_and_hash"), UPB_TABVALUE_PTR_INIT(&fields[31]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "javanano_use_deprecated_package"), UPB_TABVALUE_PTR_INIT(&fields[37]), &strentries[123]}, + {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "py_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[81]), NULL}, + {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optimize_for"), UPB_TABVALUE_PTR_INIT(&fields[67]), NULL}, + {UPB_TABKEY_STR("\026", "\000", "\000", "\000", "java_string_check_utf8"), UPB_TABVALUE_PTR_INIT(&fields[36]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[15]), &strentries[119]}, + {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "objc_class_prefix"), UPB_TABVALUE_PTR_INIT(&fields[64]), NULL}, + {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "cc_enable_arenas"), UPB_TABVALUE_PTR_INIT(&fields[2]), NULL}, + {UPB_TABKEY_STR("\027", "\000", "\000", "\000", "message_set_wire_format"), UPB_TABVALUE_PTR_INIT(&fields[46]), &strentries[128]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[39]), NULL}, - {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "input_type"), UPB_TABVALUE_PTR_INIT(&fields[20]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "output_type"), UPB_TABVALUE_PTR_INIT(&fields[56]), NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[55]), NULL}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[74]), NULL}, + {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[14]), NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "map_entry"), UPB_TABVALUE_PTR_INIT(&fields[45]), NULL}, + {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "no_standard_descriptor_accessor"), UPB_TABVALUE_PTR_INIT(&fields[61]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "client_streaming"), UPB_TABVALUE_PTR_INIT(&fields[4]), NULL}, + {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "server_streaming"), UPB_TABVALUE_PTR_INIT(&fields[84]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[51]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "input_type"), UPB_TABVALUE_PTR_INIT(&fields[29]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "output_type"), UPB_TABVALUE_PTR_INIT(&fields[75]), NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[68]), NULL}, + {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[13]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[54]), &strentries[122]}, - {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "method"), UPB_TABVALUE_PTR_INIT(&fields[33]), NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[35]), &strentries[121]}, - {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[72]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[54]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[73]), &strentries[150]}, + {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "method"), UPB_TABVALUE_PTR_INIT(&fields[48]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[55]), &strentries[149]}, + {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[95]), NULL}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "location"), UPB_TABVALUE_PTR_INIT(&fields[30]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "location"), UPB_TABVALUE_PTR_INIT(&fields[44]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "span"), UPB_TABVALUE_PTR_INIT(&fields[65]), &strentries[139]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "trailing_comments"), UPB_TABVALUE_PTR_INIT(&fields[68]), NULL}, - {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "leading_comments"), UPB_TABVALUE_PTR_INIT(&fields[29]), &strentries[137]}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT(&fields[59]), NULL}, - {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "double_value"), UPB_TABVALUE_PTR_INIT(&fields[7]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[36]), NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "span"), UPB_TABVALUE_PTR_INIT(&fields[87]), &strentries[167]}, + {UPB_TABKEY_STR("\031", "\000", "\000", "\000", "leading_detached_comments"), UPB_TABVALUE_PTR_INIT(&fields[43]), &strentries[165]}, + {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "trailing_comments"), UPB_TABVALUE_PTR_INIT(&fields[92]), NULL}, + {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "leading_comments"), UPB_TABVALUE_PTR_INIT(&fields[42]), &strentries[164]}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT(&fields[78]), NULL}, + {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "double_value"), UPB_TABVALUE_PTR_INIT(&fields[16]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[57]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "negative_int_value"), UPB_TABVALUE_PTR_INIT(&fields[43]), NULL}, + {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "negative_int_value"), UPB_TABVALUE_PTR_INIT(&fields[59]), NULL}, {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "aggregate_value"), UPB_TABVALUE_PTR_INIT(&fields[0]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "positive_int_value"), UPB_TABVALUE_PTR_INIT(&fields[60]), NULL}, - {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "identifier_value"), UPB_TABVALUE_PTR_INIT(&fields[19]), NULL}, - {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "string_value"), UPB_TABVALUE_PTR_INIT(&fields[67]), &strentries[154]}, + {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "positive_int_value"), UPB_TABVALUE_PTR_INIT(&fields[79]), NULL}, + {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "identifier_value"), UPB_TABVALUE_PTR_INIT(&fields[28]), NULL}, + {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "string_value"), UPB_TABVALUE_PTR_INIT(&fields[90]), &strentries[182]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "is_extension"), UPB_TABVALUE_PTR_INIT(&fields[21]), NULL}, - {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "name_part"), UPB_TABVALUE_PTR_INIT(&fields[42]), NULL}, - {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REQUIRED"), UPB_TABVALUE_INT_INIT(2), &strentries[162]}, + {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "is_extension"), UPB_TABVALUE_PTR_INIT(&fields[30]), NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "name_part"), UPB_TABVALUE_PTR_INIT(&fields[58]), NULL}, + {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REQUIRED"), UPB_TABVALUE_INT_INIT(2), &strentries[190]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REPEATED"), UPB_TABVALUE_INT_INIT(3), NULL}, {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_OPTIONAL"), UPB_TABVALUE_INT_INIT(1), NULL}, @@ -5274,17 +5389,17 @@ static const upb_tabent strentries[236] = { {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_STRING"), UPB_TABVALUE_INT_INIT(9), NULL}, - {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_FLOAT"), UPB_TABVALUE_INT_INIT(2), &strentries[193]}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_FLOAT"), UPB_TABVALUE_INT_INIT(2), &strentries[221]}, {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_DOUBLE"), UPB_TABVALUE_INT_INIT(1), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT32"), UPB_TABVALUE_INT_INIT(5), NULL}, {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED32"), UPB_TABVALUE_INT_INIT(15), NULL}, {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED32"), UPB_TABVALUE_INT_INIT(7), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_MESSAGE"), UPB_TABVALUE_INT_INIT(11), &strentries[194]}, + {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_MESSAGE"), UPB_TABVALUE_INT_INIT(11), &strentries[222]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT64"), UPB_TABVALUE_INT_INIT(3), &strentries[191]}, + {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT64"), UPB_TABVALUE_INT_INIT(3), &strentries[219]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, @@ -5292,7 +5407,7 @@ static const upb_tabent strentries[236] = { {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_ENUM"), UPB_TABVALUE_INT_INIT(14), NULL}, {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT32"), UPB_TABVALUE_INT_INIT(13), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT64"), UPB_TABVALUE_INT_INIT(4), &strentries[190]}, + {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT64"), UPB_TABVALUE_INT_INIT(4), &strentries[218]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED64"), UPB_TABVALUE_INT_INIT(16), NULL}, {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_BYTES"), UPB_TABVALUE_INT_INIT(12), NULL}, @@ -5302,266 +5417,223 @@ static const upb_tabent strentries[236] = { {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT32"), UPB_TABVALUE_INT_INIT(17), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "CORD"), UPB_TABVALUE_INT_INIT(1), NULL}, - {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "STRING"), UPB_TABVALUE_INT_INIT(0), &strentries[197]}, + {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "STRING"), UPB_TABVALUE_INT_INIT(0), &strentries[225]}, {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "STRING_PIECE"), UPB_TABVALUE_INT_INIT(2), NULL}, + {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NORMAL"), UPB_TABVALUE_INT_INIT(0), NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NUMBER"), UPB_TABVALUE_INT_INIT(2), NULL}, + {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_STRING"), UPB_TABVALUE_INT_INIT(1), NULL}, {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "CODE_SIZE"), UPB_TABVALUE_INT_INIT(2), NULL}, - {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "SPEED"), UPB_TABVALUE_INT_INIT(1), &strentries[203]}, + {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "SPEED"), UPB_TABVALUE_INT_INIT(1), &strentries[235]}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "LITE_RUNTIME"), UPB_TABVALUE_INT_INIT(3), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\047", "\000", "\000", "\000", "google.protobuf.SourceCodeInfo.Location"), UPB_TABVALUE_PTR_INIT(&msgs[17]), NULL}, - {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.UninterpretedOption"), UPB_TABVALUE_PTR_INIT(&msgs[18]), NULL}, - {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.FileDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[8]), NULL}, - {UPB_TABKEY_STR("\045", "\000", "\000", "\000", "google.protobuf.MethodDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[12]), NULL}, + {UPB_TABKEY_STR("\047", "\000", "\000", "\000", "google.protobuf.SourceCodeInfo.Location"), UPB_TABVALUE_PTR_INIT(&msgs[19]), NULL}, + {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.UninterpretedOption"), UPB_TABVALUE_PTR_INIT(&msgs[20]), NULL}, + {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.FileDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[9]), NULL}, + {UPB_TABKEY_STR("\045", "\000", "\000", "\000", "google.protobuf.MethodDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[13]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\040", "\000", "\000", "\000", "google.protobuf.EnumValueOptions"), UPB_TABVALUE_PTR_INIT(&msgs[5]), NULL}, + {UPB_TABKEY_STR("\040", "\000", "\000", "\000", "google.protobuf.EnumValueOptions"), UPB_TABVALUE_PTR_INIT(&msgs[6]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "google.protobuf.DescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[0]), &strentries[228]}, - {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.SourceCodeInfo"), UPB_TABVALUE_PTR_INIT(&msgs[16]), NULL}, + {UPB_TABKEY_STR("\055", "\000", "\000", "\000", "google.protobuf.DescriptorProto.ReservedRange"), UPB_TABVALUE_PTR_INIT(&msgs[2]), NULL}, + {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "google.protobuf.DescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[0]), &strentries[248]}, + {UPB_TABKEY_STR("\041", "\000", "\000", "\000", "google.protobuf.FileDescriptorSet"), UPB_TABVALUE_PTR_INIT(&msgs[10]), &strentries[267]}, + {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.SourceCodeInfo"), UPB_TABVALUE_PTR_INIT(&msgs[18]), NULL}, {UPB_TABKEY_STR("\051", "\000", "\000", "\000", "google.protobuf.FieldDescriptorProto.Type"), UPB_TABVALUE_PTR_INIT(&enums[1]), NULL}, {UPB_TABKEY_STR("\056", "\000", "\000", "\000", "google.protobuf.DescriptorProto.ExtensionRange"), UPB_TABVALUE_PTR_INIT(&msgs[1]), NULL}, - {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_STR("\050", "\000", "\000", "\000", "google.protobuf.EnumValueDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[4]), NULL}, - {UPB_TABKEY_STR("\034", "\000", "\000", "\000", "google.protobuf.FieldOptions"), UPB_TABVALUE_PTR_INIT(&msgs[7]), NULL}, - {UPB_TABKEY_STR("\033", "\000", "\000", "\000", "google.protobuf.FileOptions"), UPB_TABVALUE_PTR_INIT(&msgs[10]), NULL}, - {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.EnumDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[2]), &strentries[233]}, + {UPB_TABKEY_STR("\044", "\000", "\000", "\000", "google.protobuf.OneofDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[15]), NULL}, + {UPB_TABKEY_STR("\046", "\000", "\000", "\000", "google.protobuf.ServiceDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[16]), NULL}, + {UPB_TABKEY_STR("\034", "\000", "\000", "\000", "google.protobuf.FieldOptions"), UPB_TABVALUE_PTR_INIT(&msgs[8]), NULL}, + {UPB_TABKEY_STR("\033", "\000", "\000", "\000", "google.protobuf.FileOptions"), UPB_TABVALUE_PTR_INIT(&msgs[11]), NULL}, + {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.EnumDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[3]), &strentries[265]}, {UPB_TABKEY_STR("\052", "\000", "\000", "\000", "google.protobuf.FieldDescriptorProto.Label"), UPB_TABVALUE_PTR_INIT(&enums[0]), NULL}, - {UPB_TABKEY_STR("\046", "\000", "\000", "\000", "google.protobuf.ServiceDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[14]), NULL}, - {UPB_TABKEY_STR("\042", "\000", "\000", "\000", "google.protobuf.FieldOptions.CType"), UPB_TABVALUE_PTR_INIT(&enums[2]), &strentries[229]}, - {UPB_TABKEY_STR("\041", "\000", "\000", "\000", "google.protobuf.FileDescriptorSet"), UPB_TABVALUE_PTR_INIT(&msgs[9]), &strentries[235]}, - {UPB_TABKEY_STR("\033", "\000", "\000", "\000", "google.protobuf.EnumOptions"), UPB_TABVALUE_PTR_INIT(&msgs[3]), NULL}, - {UPB_TABKEY_STR("\044", "\000", "\000", "\000", "google.protobuf.FieldDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[6]), NULL}, - {UPB_TABKEY_STR("\050", "\000", "\000", "\000", "google.protobuf.FileOptions.OptimizeMode"), UPB_TABVALUE_PTR_INIT(&enums[3]), &strentries[221]}, - {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.ServiceOptions"), UPB_TABVALUE_PTR_INIT(&msgs[15]), NULL}, - {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.MessageOptions"), UPB_TABVALUE_PTR_INIT(&msgs[11]), NULL}, - {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "google.protobuf.MethodOptions"), UPB_TABVALUE_PTR_INIT(&msgs[13]), &strentries[226]}, - {UPB_TABKEY_STR("\054", "\000", "\000", "\000", "google.protobuf.UninterpretedOption.NamePart"), UPB_TABVALUE_PTR_INIT(&msgs[19]), NULL}, + {UPB_TABKEY_STR("\050", "\000", "\000", "\000", "google.protobuf.FileOptions.OptimizeMode"), UPB_TABVALUE_PTR_INIT(&enums[4]), NULL}, + {UPB_TABKEY_STR("\042", "\000", "\000", "\000", "google.protobuf.FieldOptions.CType"), UPB_TABVALUE_PTR_INIT(&enums[2]), &strentries[261]}, + {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.FieldOptions.JSType"), UPB_TABVALUE_PTR_INIT(&enums[3]), NULL}, + {UPB_TABKEY_STR("\033", "\000", "\000", "\000", "google.protobuf.EnumOptions"), UPB_TABVALUE_PTR_INIT(&msgs[4]), NULL}, + {UPB_TABKEY_STR("\044", "\000", "\000", "\000", "google.protobuf.FieldDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[7]), NULL}, + {UPB_TABKEY_STR("\050", "\000", "\000", "\000", "google.protobuf.EnumValueDescriptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[5]), &strentries[258]}, + {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.ServiceOptions"), UPB_TABVALUE_PTR_INIT(&msgs[17]), NULL}, + {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.MessageOptions"), UPB_TABVALUE_PTR_INIT(&msgs[12]), NULL}, + {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "google.protobuf.MethodOptions"), UPB_TABVALUE_PTR_INIT(&msgs[14]), &strentries[253]}, + {UPB_TABKEY_STR("\054", "\000", "\000", "\000", "google.protobuf.UninterpretedOption.NamePart"), UPB_TABVALUE_PTR_INIT(&msgs[21]), NULL}, }; -static const upb_tabent intentries[14] = { +static const upb_tabent intentries[18] = { + {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[73]), NULL}, + {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[101]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[71]), NULL}, + {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[77]), NULL}, + {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[75]), NULL}, + {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[76]), NULL}, + {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[13]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[74]), NULL}, + {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL}, {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, - {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[72]), NULL}, + {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL}, + {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, + {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[95]), NULL}, }; -static const upb_tabval arrays[232] = { - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[38]), - UPB_TABVALUE_PTR_INIT(&fields[16]), - UPB_TABVALUE_PTR_INIT(&fields[44]), - UPB_TABVALUE_PTR_INIT(&fields[9]), - UPB_TABVALUE_PTR_INIT(&fields[15]), - UPB_TABVALUE_PTR_INIT(&fields[14]), - UPB_TABVALUE_PTR_INIT(&fields[49]), +static const upb_tabval arrays[184] = { UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[66]), - UPB_TABVALUE_PTR_INIT(&fields[8]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[40]), - UPB_TABVALUE_PTR_INIT(&fields[78]), - UPB_TABVALUE_PTR_INIT(&fields[50]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[1]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[37]), - UPB_TABVALUE_PTR_INIT(&fields[47]), UPB_TABVALUE_PTR_INIT(&fields[52]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[41]), - UPB_TABVALUE_PTR_INIT(&fields[12]), - UPB_TABVALUE_PTR_INIT(&fields[46]), - UPB_TABVALUE_PTR_INIT(&fields[27]), - UPB_TABVALUE_PTR_INIT(&fields[69]), - UPB_TABVALUE_PTR_INIT(&fields[70]), - UPB_TABVALUE_PTR_INIT(&fields[4]), - UPB_TABVALUE_PTR_INIT(&fields[51]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[3]), - UPB_TABVALUE_PTR_INIT(&fields[58]), - UPB_TABVALUE_PTR_INIT(&fields[6]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[28]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[11]), - UPB_TABVALUE_PTR_INIT(&fields[79]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[34]), - UPB_TABVALUE_PTR_INIT(&fields[57]), - UPB_TABVALUE_PTR_INIT(&fields[5]), - UPB_TABVALUE_PTR_INIT(&fields[32]), - UPB_TABVALUE_PTR_INIT(&fields[10]), - UPB_TABVALUE_PTR_INIT(&fields[63]), - UPB_TABVALUE_PTR_INIT(&fields[13]), - UPB_TABVALUE_PTR_INIT(&fields[53]), - UPB_TABVALUE_PTR_INIT(&fields[64]), - UPB_TABVALUE_PTR_INIT(&fields[61]), - UPB_TABVALUE_PTR_INIT(&fields[80]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[17]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[26]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_PTR_INIT(&fields[25]), - UPB_TABVALUE_PTR_INIT(&fields[48]), + UPB_TABVALUE_PTR_INIT(&fields[60]), + UPB_TABVALUE_PTR_INIT(&fields[20]), UPB_TABVALUE_PTR_INIT(&fields[24]), - UPB_TABVALUE_PTR_INIT(&fields[18]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[2]), - UPB_TABVALUE_PTR_INIT(&fields[23]), - UPB_TABVALUE_PTR_INIT(&fields[62]), - UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_PTR_INIT(&fields[22]), + UPB_TABVALUE_PTR_INIT(&fields[70]), + UPB_TABVALUE_PTR_INIT(&fields[65]), + UPB_TABVALUE_PTR_INIT(&fields[83]), + UPB_TABVALUE_PTR_INIT(&fields[82]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[88]), + UPB_TABVALUE_PTR_INIT(&fields[18]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[89]), + UPB_TABVALUE_PTR_INIT(&fields[17]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[53]), + UPB_TABVALUE_PTR_INIT(&fields[102]), + UPB_TABVALUE_PTR_INIT(&fields[69]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[1]), + UPB_TABVALUE_PTR_INIT(&fields[10]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[50]), + UPB_TABVALUE_PTR_INIT(&fields[63]), + UPB_TABVALUE_PTR_INIT(&fields[71]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[9]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[56]), + UPB_TABVALUE_PTR_INIT(&fields[21]), + UPB_TABVALUE_PTR_INIT(&fields[62]), + UPB_TABVALUE_PTR_INIT(&fields[40]), + UPB_TABVALUE_PTR_INIT(&fields[93]), + UPB_TABVALUE_PTR_INIT(&fields[94]), + UPB_TABVALUE_PTR_INIT(&fields[7]), + UPB_TABVALUE_PTR_INIT(&fields[74]), + UPB_TABVALUE_PTR_INIT(&fields[66]), + UPB_TABVALUE_PTR_INIT(&fields[38]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[6]), + UPB_TABVALUE_PTR_INIT(&fields[77]), + UPB_TABVALUE_PTR_INIT(&fields[12]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[41]), + UPB_TABVALUE_PTR_INIT(&fields[39]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[103]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[49]), + UPB_TABVALUE_PTR_INIT(&fields[76]), + UPB_TABVALUE_PTR_INIT(&fields[8]), + UPB_TABVALUE_PTR_INIT(&fields[47]), + UPB_TABVALUE_PTR_INIT(&fields[19]), + UPB_TABVALUE_PTR_INIT(&fields[85]), + UPB_TABVALUE_PTR_INIT(&fields[23]), + UPB_TABVALUE_PTR_INIT(&fields[72]), + UPB_TABVALUE_PTR_INIT(&fields[86]), + UPB_TABVALUE_PTR_INIT(&fields[80]), + UPB_TABVALUE_PTR_INIT(&fields[104]), + UPB_TABVALUE_PTR_INIT(&fields[91]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[26]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[35]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[34]), + UPB_TABVALUE_PTR_INIT(&fields[67]), + UPB_TABVALUE_PTR_INIT(&fields[33]), + UPB_TABVALUE_PTR_INIT(&fields[27]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[3]), + UPB_TABVALUE_PTR_INIT(&fields[32]), + UPB_TABVALUE_PTR_INIT(&fields[81]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[31]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[15]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[36]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[2]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[64]), + UPB_TABVALUE_PTR_INIT(&fields[5]), + UPB_TABVALUE_PTR_INIT(&fields[37]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[46]), + UPB_TABVALUE_PTR_INIT(&fields[61]), + UPB_TABVALUE_PTR_INIT(&fields[14]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[31]), UPB_TABVALUE_PTR_INIT(&fields[45]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[51]), + UPB_TABVALUE_PTR_INIT(&fields[29]), + UPB_TABVALUE_PTR_INIT(&fields[75]), + UPB_TABVALUE_PTR_INIT(&fields[68]), + UPB_TABVALUE_PTR_INIT(&fields[4]), + UPB_TABVALUE_PTR_INIT(&fields[84]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[54]), UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[39]), - UPB_TABVALUE_PTR_INIT(&fields[20]), - UPB_TABVALUE_PTR_INIT(&fields[56]), UPB_TABVALUE_PTR_INIT(&fields[55]), + UPB_TABVALUE_PTR_INIT(&fields[48]), + UPB_TABVALUE_PTR_INIT(&fields[73]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[44]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[78]), + UPB_TABVALUE_PTR_INIT(&fields[87]), + UPB_TABVALUE_PTR_INIT(&fields[42]), + UPB_TABVALUE_PTR_INIT(&fields[92]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[43]), UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[35]), - UPB_TABVALUE_PTR_INIT(&fields[33]), - UPB_TABVALUE_PTR_INIT(&fields[54]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[30]), UPB_TABVALUE_EMPTY_INIT, + UPB_TABVALUE_PTR_INIT(&fields[57]), + UPB_TABVALUE_PTR_INIT(&fields[28]), + UPB_TABVALUE_PTR_INIT(&fields[79]), UPB_TABVALUE_PTR_INIT(&fields[59]), - UPB_TABVALUE_PTR_INIT(&fields[65]), - UPB_TABVALUE_PTR_INIT(&fields[29]), - UPB_TABVALUE_PTR_INIT(&fields[68]), - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[36]), - UPB_TABVALUE_PTR_INIT(&fields[19]), - UPB_TABVALUE_PTR_INIT(&fields[60]), - UPB_TABVALUE_PTR_INIT(&fields[43]), - UPB_TABVALUE_PTR_INIT(&fields[7]), - UPB_TABVALUE_PTR_INIT(&fields[67]), + UPB_TABVALUE_PTR_INIT(&fields[16]), + UPB_TABVALUE_PTR_INIT(&fields[90]), UPB_TABVALUE_PTR_INIT(&fields[0]), UPB_TABVALUE_EMPTY_INIT, - UPB_TABVALUE_PTR_INIT(&fields[42]), - UPB_TABVALUE_PTR_INIT(&fields[21]), + UPB_TABVALUE_PTR_INIT(&fields[58]), + UPB_TABVALUE_PTR_INIT(&fields[30]), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"), UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"), @@ -5588,13 +5660,16 @@ static const upb_tabval arrays[232] = { UPB_TABVALUE_PTR_INIT("STRING"), UPB_TABVALUE_PTR_INIT("CORD"), UPB_TABVALUE_PTR_INIT("STRING_PIECE"), + UPB_TABVALUE_PTR_INIT("JS_NORMAL"), + UPB_TABVALUE_PTR_INIT("JS_STRING"), + UPB_TABVALUE_PTR_INIT("JS_NUMBER"), UPB_TABVALUE_EMPTY_INIT, UPB_TABVALUE_PTR_INIT("SPEED"), UPB_TABVALUE_PTR_INIT("CODE_SIZE"), UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"), }; -static const upb_symtab symtab = UPB_SYMTAB_INIT(UPB_STRTABLE_INIT(24, 31, UPB_CTYPE_PTR, 5, &strentries[204]), &reftables[210], &reftables[211]); +static const upb_symtab symtab = UPB_SYMTAB_INIT(UPB_STRTABLE_INIT(27, 31, UPB_CTYPE_PTR, 5, &strentries[236]), &reftables[264], &reftables[265]); const upb_symtab *upbdefs_google_protobuf_descriptor(const void *owner) { upb_symtab_ref(&symtab, owner); @@ -5602,7 +5677,61 @@ const upb_symtab *upbdefs_google_protobuf_descriptor(const void *owner) { } #ifdef UPB_DEBUG_REFS -static upb_inttable reftables[212] = { +static upb_inttable reftables[266] = { + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), + UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), @@ -5831,6 +5960,11 @@ static upb_inttable reftables[212] = { #include <stdlib.h> #include <string.h> +/* Compares a NULL-terminated string with a non-NULL-terminated string. */ +static bool upb_streq(const char *str, const char *buf, size_t n) { + return strlen(str) == n && memcmp(str, buf, n) == 0; +} + /* upb_deflist is an internal-only dynamic array for storing a growing list of * upb_defs. */ typedef struct { @@ -5869,6 +6003,9 @@ struct upb_descreader { upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; int stack_len; + bool primitives_have_presence; + int file_start; + uint32_t number; char *name; bool saw_number; @@ -5995,9 +6132,12 @@ void upb_descreader_setscopename(upb_descreader *r, char *str) { } /* Handlers for google.protobuf.FileDescriptorProto. */ -static bool file_startmsg(void *r, const void *hd) { +static bool file_startmsg(void *closure, const void *hd) { + upb_descreader *r = closure; UPB_UNUSED(hd); upb_descreader_startcontainer(r); + r->primitives_have_presence = true; + r->file_start = r->defs.len; return true; } @@ -6019,6 +6159,35 @@ static size_t file_onpackage(void *closure, const void *hd, const char *buf, return n; } +static size_t file_onsyntax(void *closure, const void *hd, const char *buf, + size_t n, const upb_bufhandle *handle) { + upb_descreader *r = closure; + UPB_UNUSED(hd); + UPB_UNUSED(handle); + /* XXX: see comment at the top of the file. */ + if (upb_streq("proto2", buf, n)) { + /* Technically we could verify that proto3 hadn't previously been seen. */ + } else if (upb_streq("proto3", buf, n)) { + uint32_t i; + /* Update messages created before the syntax was read. */ + for (i = r->file_start; i < r->defs.len; i++) { + upb_msgdef *m = upb_dyncast_msgdef_mutable(r->defs.defs[i]); + if (m) { + upb_msgdef_setprimitiveshavepresence(m, false); + } + } + + /* Set a flag for any future messages that will be created. */ + r->primitives_have_presence = false; + } else { + /* Error: neither proto3 nor proto3. + * TODO(haberman): there should be a status object we can report this to. */ + return 0; + } + + return n; +} + /* Handlers for google.protobuf.EnumValueDescriptorProto. */ static bool enumval_startmsg(void *closure, const void *hd) { upb_descreader *r = closure; @@ -6313,10 +6482,12 @@ static size_t field_ondefaultval(void *closure, const void *hd, const char *buf, /* Handlers for google.protobuf.DescriptorProto (representing a message). */ static bool msg_startmsg(void *closure, const void *hd) { upb_descreader *r = closure; + upb_msgdef *m; UPB_UNUSED(hd); - upb_deflist_push(&r->defs, - upb_msgdef_upcast_mutable(upb_msgdef_new(&r->defs))); + m = upb_msgdef_new(&r->defs); + upb_msgdef_setprimitiveshavepresence(m, r->primitives_have_presence); + upb_deflist_push(&r->defs, upb_msgdef_upcast_mutable(m)); upb_descreader_startcontainer(r); return true; } @@ -6388,6 +6559,8 @@ static void reghandlers(const void *closure, upb_handlers *h) { upb_handlers_setendmsg(h, &file_endmsg, NULL); upb_handlers_setstring(h, D(FileDescriptorProto_package), &file_onpackage, NULL); + upb_handlers_setstring(h, D(FileDescriptorProto_syntax), &file_onsyntax, + NULL); upb_handlers_setendsubmsg(h, D(FileDescriptorProto_extension), &pushextension, NULL); } else if (m == D(EnumValueDescriptorProto)) { @@ -7067,7 +7240,12 @@ static void generate_msgfield(compiler *c, const upb_fielddef *f, if (!sub_m) { /* Don't emit any code for this field at all; it will be parsed as an - * unknown field. */ + * unknown field. + * + * TODO(haberman): we should change this to parse it as a string field + * instead. It will probably be faster, but more importantly, once we + * start vending unknown fields, a field shouldn't be treated as unknown + * just because it doesn't have subhandlers registered. */ return; } @@ -7384,11 +7562,16 @@ const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy, #ifdef UPB_DUMP_BYTECODE { - FILE *f = fopen("/tmp/upb-bytecode", "wb"); + FILE *f = fopen("/tmp/upb-bytecode", "w"); assert(f); dumpbc(g->bytecode, g->bytecode_end, stderr); dumpbc(g->bytecode, g->bytecode_end, f); fclose(f); + + f = fopen("/tmp/upb-bytecode.bin", "wb"); + assert(f); + fwrite(g->bytecode, 1, g->bytecode_end - g->bytecode, f); + fclose(f); } #endif @@ -7488,6 +7671,11 @@ static const char *kUnterminatedVarint = "Unterminated varint."; static opcode halt = OP_HALT; +/* A dummy character we can point to when the user passes us a NULL buffer. + * We need this because in C (NULL + 0) and (NULL - NULL) are undefined + * behavior, which would invalidate functions like curbufleft(). */ +static const char dummy_char; + /* Whether an op consumes any of the input buffer. */ static bool consumes_input(opcode op) { switch (op) { @@ -7643,7 +7831,7 @@ static int32_t skip(upb_pbdecoder *d, size_t bytes) { if (bytes > delim_remaining(d)) { seterr(d, "Skipped value extended beyond enclosing submessage."); return upb_pbdecoder_suspend(d); - } else if (bufleft(d) > bytes) { + } else if (bufleft(d) >= bytes) { /* Skipped data is all in current buffer, and more is still available. */ advance(d, bytes); d->skip = 0; @@ -7665,10 +7853,39 @@ int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, size_t size, const upb_bufhandle *handle) { UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */ - d->buf_param = buf; + /* d->skip and d->residual_end could probably elegantly be represented + * as a single variable, to more easily represent this invariant. */ + assert(!(d->skip && d->residual_end > d->residual)); + + /* We need to remember the original size_param, so that the value we return + * is relative to it, even if we do some skipping first. */ d->size_param = size; d->handle = handle; + /* Have to handle this case specially (ie. not with skip()) because the user + * is allowed to pass a NULL buffer here, which won't allow us to safely + * calculate a d->end or use our normal functions like curbufleft(). */ + if (d->skip && d->skip >= size) { + d->skip -= size; + d->bufstart_ofs += size; + buf = &dummy_char; + size = 0; + + /* We can't just return now, because we might need to execute some ops + * like CHECKDELIM, which could call some callbacks and pop the stack. */ + } + + /* We need to pretend that this was the actual buffer param, since some of the + * calculations assume that d->ptr/d->buf is relative to this. */ + d->buf_param = buf; + + if (!buf) { + /* NULL buf is ok if its entire span is covered by the "skip" above, but + * by this point we know that "skip" doesn't cover the buffer. */ + seterr(d, "Passed NULL buffer over non-skippable region."); + return upb_pbdecoder_suspend(d); + } + if (d->residual_end > d->residual) { /* We have residual bytes from the last buffer. */ assert(d->ptr == d->residual); @@ -7678,23 +7895,18 @@ int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, d->checkpoint = d->ptr; + /* Handle skips that don't cover the whole buffer (as above). */ if (d->skip) { size_t skip_bytes = d->skip; d->skip = 0; CHECK_RETURN(skip(d, skip_bytes)); - d->checkpoint = d->ptr; - } - - if (!buf) { - /* NULL buf is ok if its entire span is covered by the "skip" above, but - * by this point we know that "skip" doesn't cover the buffer. */ - seterr(d, "Passed NULL buffer over non-skippable region."); - return upb_pbdecoder_suspend(d); + checkpoint(d); } + /* If we're inside an unknown group, continue to parse unknown values. */ if (d->top->groupnum < 0) { CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0)); - d->checkpoint = d->ptr; + checkpoint(d); } return DECODE_OK; @@ -7709,15 +7921,14 @@ size_t upb_pbdecoder_suspend(upb_pbdecoder *d) { d->ptr = d->residual; return 0; } else { - size_t consumed; + size_t ret = d->size_param - (d->end - d->checkpoint); assert(!in_residual_buf(d, d->checkpoint)); - assert(d->buf == d->buf_param); + assert(d->buf == d->buf_param || d->buf == &dummy_char); - consumed = d->checkpoint - d->buf; - d->bufstart_ofs += consumed; + d->bufstart_ofs += (d->checkpoint - d->buf); d->residual_end = d->residual; switchtobuf(d, d->residual, d->residual_end); - return consumed; + return ret; } } @@ -7835,8 +8046,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, int bitpos; *u64 = 0; for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) { - int32_t ret = getbytes(d, &byte, 1); - if (ret >= 0) return ret; + CHECK_RETURN(getbytes(d, &byte, 1)); *u64 |= (uint64_t)(byte & 0x7F) << bitpos; } if(bitpos == 70 && (byte & 0x80)) { @@ -8436,6 +8646,7 @@ upb_pbdecoder *upb_pbdecoder_create(upb_env *e, const upb_pbdecodermethod *m, d->env = e; d->limit = d->stack + default_max_nesting - 1; d->stack_size = default_max_nesting; + d->status = NULL; upb_pbdecoder_reset(d); upb_bytessink_reset(&d->input_, &m->input_handler_, d); @@ -8537,7 +8748,7 @@ bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) { ** to perfectly match the output of reference encoders that always use the ** optimal amount of space for each length. ** -** (2) requires guessing the size upfront, and if multiple lengths are +** (2) requires guessing the the size upfront, and if multiple lengths are ** guessed wrong the minimum required number of memmove() operations may ** be complicated to compute correctly. Implemented properly, it may have ** a useful amortized or average cost, but more investigation is required @@ -9654,6 +9865,9 @@ typedef struct { const upb_msgdef *m; const upb_fielddef *f; + /* The table mapping json name to fielddef for this message. */ + upb_strtable *name_table; + /* We are in a repeated-field context, ready to emit mapentries as * submessages. This flag alters the start-of-object (open-brace) behavior to * begin a sequence of mapentry messages rather than a single submessage. */ @@ -9674,7 +9888,7 @@ typedef struct { struct upb_json_parser { upb_env *env; - upb_byteshandler input_handler_; + const upb_json_parsermethod *method; upb_bytessink input_; /* Stack to track the JSON scopes we are in. */ @@ -9709,6 +9923,19 @@ struct upb_json_parser { uint32_t digit; }; +struct upb_json_parsermethod { + upb_refcounted base; + + upb_byteshandler input_handler_; + + /* Mainly for the purposes of refcounting, so all the fielddefs we point + * to stay alive. */ + const upb_msgdef *msg; + + /* Keys are upb_msgdef*, values are upb_strtable (json_name -> fielddef) */ + upb_inttable name_tables; +}; + #define PARSER_CHECK_RETURN(x) if (!(x)) return false /* Used to signal that a capture has been suspended. */ @@ -9737,6 +9964,13 @@ static bool check_stack(upb_json_parser *p) { return true; } +static void set_name_table(upb_json_parser *p, upb_jsonparser_frame *frame) { + upb_value v; + bool ok = upb_inttable_lookupptr(&p->method->name_tables, frame->m, &v); + UPB_ASSERT_VAR(ok, ok); + frame->name_table = upb_value_getptr(v); +} + /* There are GCC/Clang built-ins for overflow checking which we could start * using if there was any performance benefit to it. */ @@ -10333,6 +10567,7 @@ static bool start_stringval(upb_json_parser *p) { upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); inner->m = p->top->m; inner->f = p->top->f; + inner->name_table = NULL; inner->is_map = false; inner->is_mapentry = false; p->top = inner; @@ -10519,6 +10754,7 @@ static bool handle_mapentry(upb_json_parser *p) { sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); inner->m = mapentrymsg; + inner->name_table = NULL; inner->mapfield = mapfield; inner->is_map = false; @@ -10555,20 +10791,20 @@ static bool end_membername(upb_json_parser *p) { } else { size_t len; const char *buf = accumulate_getptr(p, &len); - const upb_fielddef *f = upb_msgdef_ntof(p->top->m, buf, len); + upb_value v; - if (!f) { + if (upb_strtable_lookup2(p->top->name_table, buf, len, &v)) { + p->top->f = upb_value_getconstptr(v); + multipart_end(p); + + return true; + } else { /* TODO(haberman): Ignore unknown fields if requested/configured to do * so. */ upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf); upb_env_reporterror(p->env, &p->status); return false; } - - p->top->f = f; - multipart_end(p); - - return true; } } @@ -10610,6 +10846,7 @@ static bool start_subobject(upb_json_parser *p) { sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); upb_sink_startseq(&p->top->sink, sel, &inner->sink); inner->m = upb_fielddef_msgsubdef(p->top->f); + inner->name_table = NULL; inner->mapfield = p->top->f; inner->f = NULL; inner->is_map = true; @@ -10630,6 +10867,7 @@ static bool start_subobject(upb_json_parser *p) { sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); inner->m = upb_fielddef_msgsubdef(p->top->f); + set_name_table(p, inner); inner->f = NULL; inner->is_map = false; inner->is_mapentry = false; @@ -10679,6 +10917,7 @@ static bool start_array(upb_json_parser *p) { sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); upb_sink_startseq(&p->top->sink, sel, &inner->sink); inner->m = p->top->m; + inner->name_table = NULL; inner->f = p->top->f; inner->is_map = false; inner->is_mapentry = false; @@ -10736,11 +10975,11 @@ static void end_object(upb_json_parser *p) { * final state once, when the closing '"' is seen. */ -#line 1218 "upb/json/parser.rl" +#line 1246 "upb/json/parser.rl" -#line 1130 "upb/json/parser.c" +#line 1158 "upb/json/parser.c" static const char _json_actions[] = { 0, 1, 0, 1, 2, 1, 3, 1, 5, 1, 6, 1, 7, 1, 8, 1, @@ -10889,7 +11128,7 @@ static const int json_en_value_machine = 27; static const int json_en_main = 1; -#line 1221 "upb/json/parser.rl" +#line 1249 "upb/json/parser.rl" size_t parse(void *closure, const void *hd, const char *buf, size_t size, const upb_bufhandle *handle) { @@ -10911,7 +11150,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size, capture_resume(parser, buf); -#line 1301 "upb/json/parser.c" +#line 1329 "upb/json/parser.c" { int _klen; unsigned int _trans; @@ -10986,118 +11225,118 @@ _match: switch ( *_acts++ ) { case 0: -#line 1133 "upb/json/parser.rl" +#line 1161 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 1: -#line 1134 "upb/json/parser.rl" +#line 1162 "upb/json/parser.rl" { p--; {stack[top++] = cs; cs = 10; goto _again;} } break; case 2: -#line 1138 "upb/json/parser.rl" +#line 1166 "upb/json/parser.rl" { start_text(parser, p); } break; case 3: -#line 1139 "upb/json/parser.rl" +#line 1167 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_text(parser, p)); } break; case 4: -#line 1145 "upb/json/parser.rl" +#line 1173 "upb/json/parser.rl" { start_hex(parser); } break; case 5: -#line 1146 "upb/json/parser.rl" +#line 1174 "upb/json/parser.rl" { hexdigit(parser, p); } break; case 6: -#line 1147 "upb/json/parser.rl" +#line 1175 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_hex(parser)); } break; case 7: -#line 1153 "upb/json/parser.rl" +#line 1181 "upb/json/parser.rl" { CHECK_RETURN_TOP(escape(parser, p)); } break; case 8: -#line 1159 "upb/json/parser.rl" +#line 1187 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; case 9: -#line 1162 "upb/json/parser.rl" +#line 1190 "upb/json/parser.rl" { {stack[top++] = cs; cs = 19; goto _again;} } break; case 10: -#line 1164 "upb/json/parser.rl" +#line 1192 "upb/json/parser.rl" { p--; {stack[top++] = cs; cs = 27; goto _again;} } break; case 11: -#line 1169 "upb/json/parser.rl" +#line 1197 "upb/json/parser.rl" { start_member(parser); } break; case 12: -#line 1170 "upb/json/parser.rl" +#line 1198 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_membername(parser)); } break; case 13: -#line 1173 "upb/json/parser.rl" +#line 1201 "upb/json/parser.rl" { end_member(parser); } break; case 14: -#line 1179 "upb/json/parser.rl" +#line 1207 "upb/json/parser.rl" { start_object(parser); } break; case 15: -#line 1182 "upb/json/parser.rl" +#line 1210 "upb/json/parser.rl" { end_object(parser); } break; case 16: -#line 1188 "upb/json/parser.rl" +#line 1216 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_array(parser)); } break; case 17: -#line 1192 "upb/json/parser.rl" +#line 1220 "upb/json/parser.rl" { end_array(parser); } break; case 18: -#line 1197 "upb/json/parser.rl" +#line 1225 "upb/json/parser.rl" { start_number(parser, p); } break; case 19: -#line 1198 "upb/json/parser.rl" +#line 1226 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_number(parser, p)); } break; case 20: -#line 1200 "upb/json/parser.rl" +#line 1228 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_stringval(parser)); } break; case 21: -#line 1201 "upb/json/parser.rl" +#line 1229 "upb/json/parser.rl" { CHECK_RETURN_TOP(end_stringval(parser)); } break; case 22: -#line 1203 "upb/json/parser.rl" +#line 1231 "upb/json/parser.rl" { CHECK_RETURN_TOP(parser_putbool(parser, true)); } break; case 23: -#line 1205 "upb/json/parser.rl" +#line 1233 "upb/json/parser.rl" { CHECK_RETURN_TOP(parser_putbool(parser, false)); } break; case 24: -#line 1207 "upb/json/parser.rl" +#line 1235 "upb/json/parser.rl" { /* null value */ } break; case 25: -#line 1209 "upb/json/parser.rl" +#line 1237 "upb/json/parser.rl" { CHECK_RETURN_TOP(start_subobject(parser)); } break; case 26: -#line 1210 "upb/json/parser.rl" +#line 1238 "upb/json/parser.rl" { end_subobject(parser); } break; case 27: -#line 1215 "upb/json/parser.rl" +#line 1243 "upb/json/parser.rl" { p--; {cs = stack[--top]; goto _again;} } break; -#line 1487 "upb/json/parser.c" +#line 1515 "upb/json/parser.c" } } @@ -11110,7 +11349,7 @@ _again: _out: {} } -#line 1242 "upb/json/parser.rl" +#line 1270 "upb/json/parser.rl" if (p != pe) { upb_status_seterrf(&parser->status, "Parse error at %s\n", p); @@ -11151,13 +11390,13 @@ static void json_parser_reset(upb_json_parser *p) { /* Emit Ragel initialization of the parser. */ -#line 1541 "upb/json/parser.c" +#line 1569 "upb/json/parser.c" { cs = json_start; top = 0; } -#line 1282 "upb/json/parser.rl" +#line 1310 "upb/json/parser.rl" p->current_state = cs; p->parser_top = top; accumulate_clear(p); @@ -11167,10 +11406,73 @@ static void json_parser_reset(upb_json_parser *p) { upb_status_clear(&p->status); } +static void visit_json_parsermethod(const upb_refcounted *r, + upb_refcounted_visit *visit, + void *closure) { + const upb_json_parsermethod *method = (upb_json_parsermethod*)r; + visit(r, upb_msgdef_upcast2(method->msg), closure); +} + +static void free_json_parsermethod(upb_refcounted *r) { + upb_json_parsermethod *method = (upb_json_parsermethod*)r; + + upb_inttable_iter i; + upb_inttable_begin(&i, &method->name_tables); + for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { + upb_value val = upb_inttable_iter_value(&i); + upb_strtable *t = upb_value_getptr(val); + upb_strtable_uninit(t); + free(t); + } + + upb_inttable_uninit(&method->name_tables); + + free(r); +} + +static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { + upb_msg_field_iter i; + upb_strtable *t; + + /* It would be nice to stack-allocate this, but protobufs do not limit the + * length of fields to any reasonable limit. */ + char *buf = NULL; + size_t len = 0; + + if (upb_inttable_lookupptr(&m->name_tables, md, NULL)) { + return; + } + + /* TODO(haberman): handle malloc failure. */ + t = malloc(sizeof(*t)); + upb_strtable_init(t, UPB_CTYPE_CONSTPTR); + upb_inttable_insertptr(&m->name_tables, md, upb_value_ptr(t)); + + 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 field_len = upb_fielddef_getjsonname(f, buf, len); + if (field_len > len) { + buf = realloc(buf, field_len); + len = field_len; + upb_fielddef_getjsonname(f, buf, len); + } + upb_strtable_insert(t, buf, upb_value_constptr(f)); + + if (upb_fielddef_issubmsg(f)) { + add_jsonname_table(m, upb_fielddef_msgsubdef(f)); + } + } + + free(buf); +} /* Public API *****************************************************************/ -upb_json_parser *upb_json_parser_create(upb_env *env, upb_sink *output) { +upb_json_parser *upb_json_parser_create(upb_env *env, + const upb_json_parsermethod *method, + upb_sink *output) { #ifndef NDEBUG const size_t size_before = upb_env_bytesallocated(env); #endif @@ -11178,17 +11480,16 @@ upb_json_parser *upb_json_parser_create(upb_env *env, upb_sink *output) { if (!p) return false; p->env = env; + p->method = method; p->limit = p->stack + UPB_JSON_MAX_DEPTH; p->accumulate_buf = NULL; p->accumulate_buf_size = 0; - upb_byteshandler_init(&p->input_handler_); - upb_byteshandler_setstring(&p->input_handler_, parse, NULL); - upb_byteshandler_setendstr(&p->input_handler_, end, NULL); - upb_bytessink_reset(&p->input_, &p->input_handler_, p); + upb_bytessink_reset(&p->input_, &method->input_handler_, p); json_parser_reset(p); upb_sink_reset(&p->top->sink, output->handlers, output->closure); p->top->m = upb_handlers_msgdef(output->handlers); + set_name_table(p, p->top); /* If this fails, uncomment and increase the value in parser.h. */ /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */ @@ -11199,6 +11500,32 @@ upb_json_parser *upb_json_parser_create(upb_env *env, upb_sink *output) { upb_bytessink *upb_json_parser_input(upb_json_parser *p) { return &p->input_; } + +upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md, + const void* owner) { + static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod, + free_json_parsermethod}; + upb_json_parsermethod *ret = malloc(sizeof(*ret)); + upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner); + + ret->msg = md; + upb_ref2(md, ret); + + upb_byteshandler_init(&ret->input_handler_); + upb_byteshandler_setstring(&ret->input_handler_, parse, ret); + upb_byteshandler_setendstr(&ret->input_handler_, end, ret); + + upb_inttable_init(&ret->name_tables, UPB_CTYPE_PTR); + + add_jsonname_table(ret, md); + + return ret; +} + +const upb_byteshandler *upb_json_parsermethod_inputhandler( + const upb_json_parsermethod *m) { + return &m->input_handler_; +} /* ** This currently uses snprintf() to format primitives, and could be optimized ** further. @@ -11233,15 +11560,28 @@ struct upb_json_printer { /* StringPiece; a pointer plus a length. */ typedef struct { - const char *ptr; + char *ptr; size_t len; } strpc; +void freestrpc(void *ptr) { + strpc *pc = ptr; + free(pc->ptr); + free(pc); +} + +/* Convert fielddef name to JSON name and return as a string piece. */ strpc *newstrpc(upb_handlers *h, const upb_fielddef *f) { + /* TODO(haberman): handle malloc failure. */ strpc *ret = malloc(sizeof(*ret)); - ret->ptr = upb_fielddef_name(f); - ret->len = strlen(ret->ptr); - upb_handlers_addcleanup(h, ret, free); + size_t len; + ret->len = upb_fielddef_getjsonname(f, NULL, 0); + ret->ptr = malloc(ret->len); + len = upb_fielddef_getjsonname(f, ret->ptr, ret->len); + UPB_ASSERT_VAR(len, len == ret->len); + ret->len--; /* NULL */ + + upb_handlers_addcleanup(h, ret, freestrpc); return ret; } @@ -11272,7 +11612,7 @@ UPB_INLINE bool is_json_escaped(char c) { return uc < kControlCharLimit || uc == '"' || uc == '\\'; } -UPB_INLINE char* json_nice_escape(char c) { +UPB_INLINE const char* json_nice_escape(char c) { switch (c) { case '"': return "\\\""; case '\\': return "\\\\"; diff --git a/ruby/ext/google/protobuf_c/upb.h b/ruby/ext/google/protobuf_c/upb.h index 078e2a28..0be5b296 100644 --- a/ruby/ext/google/protobuf_c/upb.h +++ b/ruby/ext/google/protobuf_c/upb.h @@ -193,13 +193,15 @@ template <> \ class Pointer<cppname> : public PointerBase<cppname, cppbase> { \ public: \ - explicit Pointer(cppname* ptr) : PointerBase(ptr) {} \ + explicit Pointer(cppname* ptr) \ + : PointerBase<cppname, cppbase>(ptr) {} \ }; \ template <> \ class Pointer<const cppname> \ : public PointerBase<const cppname, const cppbase> { \ public: \ - explicit Pointer(const cppname* ptr) : PointerBase(ptr) {} \ + explicit Pointer(const cppname* ptr) \ + : PointerBase<const cppname, const cppbase>(ptr) {} \ }; \ } @@ -211,13 +213,15 @@ template <> \ class Pointer<cppname> : public PointerBase2<cppname, cppbase, cppbase2> { \ public: \ - explicit Pointer(cppname* ptr) : PointerBase2(ptr) {} \ + explicit Pointer(cppname* ptr) \ + : PointerBase2<cppname, cppbase, cppbase2>(ptr) {} \ }; \ template <> \ class Pointer<const cppname> \ : public PointerBase2<const cppname, const cppbase, const cppbase2> { \ public: \ - explicit Pointer(const cppname* ptr) : PointerBase2(ptr) {} \ + explicit Pointer(const cppname* ptr) \ + : PointerBase2<const cppname, const cppbase, const cppbase2>(ptr) {} \ }; \ } @@ -1537,6 +1541,27 @@ class upb::FieldDef { uint32_t number() const; /* Returns 0 if uninitialized. */ bool is_extension() const; + /* Copies the JSON name for this field into the given buffer. Returns the + * actual size of the JSON name, including the NULL terminator. If the + * return value is 0, the JSON name is unset. If the return value is + * greater than len, the JSON name was truncated. The buffer is always + * NULL-terminated if len > 0. + * + * The JSON name always defaults to a camelCased version of the regular + * name. However if the regular name is unset, the JSON name will be unset + * also. + */ + size_t GetJsonName(char* buf, size_t len) const; + + /* Convenience version of the above function which copies the JSON name + * into the given string, returning false if the name is not set. */ + template <class T> + bool GetJsonName(T* str) { + str->resize(GetJsonName(NULL, 0)); + GetJsonName(&(*str)[0], str->size()); + return str->size() > 0; + } + /* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false, * indicates whether this field should have lazy parsing handlers that yield * the unparsed string for the submessage. @@ -1589,6 +1614,18 @@ class upb::FieldDef { bool IsPrimitive() const; bool IsMap() const; + /* Whether this field must be able to explicitly represent presence: + * + * * This is always false for repeated fields (an empty repeated field is + * equivalent to a repeated field with zero entries). + * + * * This is always true for submessages. + * + * * For other fields, it depends on the message (see + * MessageDef::SetPrimitivesHavePresence()) + */ + bool HasPresence() const; + /* How integers are encoded. Only meaningful for integer types. * Defaults to UPB_INTFMT_VARIABLE, and is reset when "type" changes. */ IntegerFormat integer_format() const; @@ -1690,6 +1727,16 @@ class upb::FieldDef { bool set_name(const char* name, upb::Status* s); bool set_name(const std::string& name, upb::Status* s); + /* Sets the JSON name to the given string. */ + /* TODO(haberman): implement. Right now only default json_name (camelCase) + * is supported. */ + bool set_json_name(const char* json_name, upb::Status* s); + bool set_json_name(const std::string& name, upb::Status* s); + + /* Clears the JSON name. This will make it revert to its default, which is + * a camelCased version of the regular field name. */ + void clear_json_name(); + void set_integer_format(IntegerFormat format); bool set_tag_delimited(bool tag_delimited, upb::Status* s); @@ -1754,6 +1801,7 @@ const char *upb_fielddef_name(const upb_fielddef *f); bool upb_fielddef_isextension(const upb_fielddef *f); bool upb_fielddef_lazy(const upb_fielddef *f); bool upb_fielddef_packed(const upb_fielddef *f); +size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len); const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f); const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f); upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f); @@ -1766,6 +1814,7 @@ bool upb_fielddef_isstring(const upb_fielddef *f); bool upb_fielddef_isseq(const upb_fielddef *f); bool upb_fielddef_isprimitive(const upb_fielddef *f); bool upb_fielddef_ismap(const upb_fielddef *f); +bool upb_fielddef_haspresence(const upb_fielddef *f); int64_t upb_fielddef_defaultint64(const upb_fielddef *f); int32_t upb_fielddef_defaultint32(const upb_fielddef *f); uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f); @@ -1787,6 +1836,8 @@ void upb_fielddef_setdescriptortype(upb_fielddef *f, int type); void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label); bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s); bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s); +bool upb_fielddef_setjsonname(upb_fielddef *f, const char *name, upb_status *s); +bool upb_fielddef_clearjsonname(upb_fielddef *f); bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name, upb_status *s); void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension); @@ -1884,6 +1935,11 @@ class upb::MessageDef { bool AddOneof(OneofDef* o, Status* s); bool AddOneof(const reffed_ptr<OneofDef>& o, Status* s); + /* Set this to false to indicate that primitive fields should not have + * explicit presence information associated with them. This will affect all + * fields added to this message. Defaults to true. */ + void SetPrimitivesHavePresence(bool have_presence); + /* These return NULL if the field is not found. */ FieldDef* FindFieldByNumber(uint32_t number); FieldDef* FindFieldByName(const char *name, size_t len); @@ -2077,6 +2133,7 @@ bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor, upb_status *s); bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, upb_status *s); +void upb_msgdef_setprimitiveshavepresence(upb_msgdef *m, bool have_presence); /* Field lookup in a couple of different variations: * - itof = int to field @@ -2527,6 +2584,9 @@ inline const char* FieldDef::name() const { return upb_fielddef_name(this); } inline bool FieldDef::is_extension() const { return upb_fielddef_isextension(this); } +inline size_t FieldDef::GetJsonName(char* buf, size_t len) const { + return upb_fielddef_getjsonname(this, buf, len); +} inline bool FieldDef::lazy() const { return upb_fielddef_lazy(this); } @@ -2557,6 +2617,15 @@ inline bool FieldDef::set_name(const char *name, Status* s) { inline bool FieldDef::set_name(const std::string& name, Status* s) { return upb_fielddef_setname(this, upb_safecstr(name), s); } +inline bool FieldDef::set_json_name(const char *name, Status* s) { + return upb_fielddef_setjsonname(this, name, s); +} +inline bool FieldDef::set_json_name(const std::string& name, Status* s) { + return upb_fielddef_setjsonname(this, upb_safecstr(name), s); +} +inline void FieldDef::clear_json_name() { + upb_fielddef_clearjsonname(this); +} inline bool FieldDef::set_containing_type_name(const char *name, Status* s) { return upb_fielddef_setcontainingtypename(this, name, s); } @@ -3107,6 +3176,11 @@ struct upb_msgdef { * descriptor.upb.c. */ bool map_entry; + /* Do primitive values in this message have explicit presence or not? + * TODO: set this flag properly for static descriptors; regenerate + * descriptor.upb.c. */ + bool primitives_have_presence; + /* TODO(haberman): proper extension ranges (there can be multiple). */ }; @@ -3117,7 +3191,7 @@ struct upb_msgdef { { \ UPB_DEF_INIT(name, UPB_DEF_MSG, refs, ref2s), selector_count, \ submsg_field_count, itof, ntof, \ - UPB_EMPTY_STRTABLE_INIT(UPB_CTYPE_PTR), false \ + UPB_EMPTY_STRTABLE_INIT(UPB_CTYPE_PTR), false, true \ } @@ -6279,6 +6353,12 @@ typedef enum { } google_protobuf_FieldOptions_CType; typedef enum { + GOOGLE_PROTOBUF_FIELDOPTIONS_JS_NORMAL = 0, + GOOGLE_PROTOBUF_FIELDOPTIONS_JS_STRING = 1, + GOOGLE_PROTOBUF_FIELDOPTIONS_JS_NUMBER = 2 +} google_protobuf_FieldOptions_JSType; + +typedef enum { GOOGLE_PROTOBUF_FILEOPTIONS_SPEED = 1, GOOGLE_PROTOBUF_FILEOPTIONS_CODE_SIZE = 2, GOOGLE_PROTOBUF_FILEOPTIONS_LITE_RUNTIME = 3 @@ -6293,30 +6373,47 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_STARTSUBMSG 5 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_STARTSUBMSG 6 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_OPTIONS_STARTSUBMSG 7 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_STARTSEQ 8 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_ENDSEQ 9 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_ENDSUBMSG 10 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_STARTSEQ 11 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_ENDSEQ 12 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_ENDSUBMSG 13 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_STARTSEQ 14 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_ENDSEQ 15 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_ENDSUBMSG 16 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_STARTSEQ 17 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_ENDSEQ 18 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_ENDSUBMSG 19 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_STARTSEQ 20 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_ENDSEQ 21 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_ENDSUBMSG 22 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_OPTIONS_ENDSUBMSG 23 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_STRING 24 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_STARTSTR 25 -#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_ENDSTR 26 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ONEOF_DECL_STARTSUBMSG 8 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_RANGE_STARTSUBMSG 9 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_STARTSEQ 10 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_ENDSEQ 11 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_ENDSUBMSG 12 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_STARTSEQ 13 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_ENDSEQ 14 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_ENDSUBMSG 15 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_STARTSEQ 16 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_ENDSEQ 17 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_ENDSUBMSG 18 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_STARTSEQ 19 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_ENDSEQ 20 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_ENDSUBMSG 21 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_STARTSEQ 22 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_ENDSEQ 23 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_ENDSUBMSG 24 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_OPTIONS_ENDSUBMSG 25 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ONEOF_DECL_STARTSEQ 26 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ONEOF_DECL_ENDSEQ 27 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ONEOF_DECL_ENDSUBMSG 28 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_RANGE_STARTSEQ 29 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_RANGE_ENDSEQ 30 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_RANGE_ENDSUBMSG 31 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_STRING 32 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_STARTSTR 33 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_ENDSTR 34 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_NAME_STARTSEQ 35 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_NAME_ENDSEQ 36 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_NAME_STRING 37 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_NAME_STARTSTR 38 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVED_NAME_ENDSTR 39 /* google.protobuf.DescriptorProto.ExtensionRange */ #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSIONRANGE_START_INT32 2 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSIONRANGE_END_INT32 3 +/* google.protobuf.DescriptorProto.ReservedRange */ +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVEDRANGE_START_INT32 2 +#define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_RESERVEDRANGE_END_INT32 3 + /* google.protobuf.EnumDescriptorProto */ #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_STARTSUBMSG 2 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 3 @@ -6334,6 +6431,7 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 #define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 #define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_ALLOW_ALIAS_BOOL 6 +#define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_DEPRECATED_BOOL 7 /* google.protobuf.EnumValueDescriptorProto */ #define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 @@ -6348,6 +6446,7 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_DEPRECATED_BOOL 6 /* google.protobuf.FieldDescriptorProto */ #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 @@ -6367,6 +6466,10 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_STRING 16 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_STARTSTR 17 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_ENDSTR 18 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_ONEOF_INDEX_INT32 19 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_JSON_NAME_STRING 20 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_JSON_NAME_STARTSTR 21 +#define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_JSON_NAME_ENDSTR 22 /* google.protobuf.FieldOptions */ #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 @@ -6377,10 +6480,8 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_PACKED_BOOL 7 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_DEPRECATED_BOOL 8 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_LAZY_BOOL 9 -#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_STRING 10 -#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_STARTSTR 11 -#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_ENDSTR 12 -#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_WEAK_BOOL 13 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_JSTYPE_INT32 10 +#define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_WEAK_BOOL 11 /* google.protobuf.FileDescriptorProto */ #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_STARTSUBMSG 2 @@ -6420,6 +6521,9 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_STARTSEQ 36 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_ENDSEQ 37 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_INT32 38 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SYNTAX_STRING 39 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SYNTAX_STARTSTR 40 +#define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SYNTAX_ENDSTR 41 /* google.protobuf.FileDescriptorSet */ #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_STARTSUBMSG 2 @@ -6447,6 +6551,16 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_GENERIC_SERVICES_BOOL 18 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_PY_GENERIC_SERVICES_BOOL 19 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_GENERATE_EQUALS_AND_HASH_BOOL 20 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_DEPRECATED_BOOL 21 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_STRING_CHECK_UTF8_BOOL 22 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_CC_ENABLE_ARENAS_BOOL 23 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_OBJC_CLASS_PREFIX_STRING 24 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_OBJC_CLASS_PREFIX_STARTSTR 25 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_OBJC_CLASS_PREFIX_ENDSTR 26 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_CSHARP_NAMESPACE_STRING 27 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_CSHARP_NAMESPACE_STARTSTR 28 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_CSHARP_NAMESPACE_ENDSTR 29 +#define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVANANO_USE_DEPRECATED_PACKAGE_BOOL 30 /* google.protobuf.MessageOptions */ #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 @@ -6455,6 +6569,8 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_MESSAGE_SET_WIRE_FORMAT_BOOL 6 #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_NO_STANDARD_DESCRIPTOR_ACCESSOR_BOOL 7 +#define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_DEPRECATED_BOOL 8 +#define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_MAP_ENTRY_BOOL 9 /* google.protobuf.MethodDescriptorProto */ #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 @@ -6468,12 +6584,20 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_STRING 10 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_STARTSTR 11 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_ENDSTR 12 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_CLIENT_STREAMING_BOOL 13 +#define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_SERVER_STREAMING_BOOL 14 /* google.protobuf.MethodOptions */ #define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 #define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 #define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 #define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_DEPRECATED_BOOL 6 + +/* google.protobuf.OneofDescriptorProto */ +#define SEL_GOOGLE_PROTOBUF_ONEOFDESCRIPTORPROTO_NAME_STRING 2 +#define SEL_GOOGLE_PROTOBUF_ONEOFDESCRIPTORPROTO_NAME_STARTSTR 3 +#define SEL_GOOGLE_PROTOBUF_ONEOFDESCRIPTORPROTO_NAME_ENDSTR 4 /* google.protobuf.ServiceDescriptorProto */ #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_STARTSUBMSG 2 @@ -6491,6 +6615,7 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 #define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 #define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 +#define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_DEPRECATED_BOOL 6 /* google.protobuf.SourceCodeInfo */ #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_STARTSUBMSG 2 @@ -6511,6 +6636,11 @@ typedef enum { #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_STRING 11 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_STARTSTR 12 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_ENDSTR 13 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_DETACHED_COMMENTS_STARTSEQ 14 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_DETACHED_COMMENTS_ENDSEQ 15 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_DETACHED_COMMENTS_STRING 16 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_DETACHED_COMMENTS_STARTSTR 17 +#define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_DETACHED_COMMENTS_ENDSTR 18 /* google.protobuf.UninterpretedOption */ #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_STARTSUBMSG 2 @@ -6549,6 +6679,11 @@ UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRa assert(m); return m; } +UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange(const upb_symtab *s) { + const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.DescriptorProto.ReservedRange"); + assert(m); + return m; +} UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto(const upb_symtab *s) { const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.EnumDescriptorProto"); assert(m); @@ -6609,6 +6744,11 @@ UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_MethodOptions(const upb_sym assert(m); return m; } +UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto(const upb_symtab *s) { + const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.OneofDescriptorProto"); + assert(m); + return m; +} UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto(const upb_symtab *s) { const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.ServiceDescriptorProto"); assert(m); @@ -6657,6 +6797,11 @@ UPB_INLINE const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType(const u assert(e); return e; } +UPB_INLINE const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType(const upb_symtab *s) { + const upb_enumdef *e = upb_symtab_lookupenum(s, "google.protobuf.FieldOptions.JSType"); + assert(e); + return e; +} UPB_INLINE const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode(const upb_symtab *s) { const upb_enumdef *e = upb_symtab_lookupenum(s, "google.protobuf.FileOptions.OptimizeMode"); assert(e); @@ -6665,33 +6810,42 @@ UPB_INLINE const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode(c UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_end(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto_ExtensionRange(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_start(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto_ExtensionRange(s), 1); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_end(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto_ReservedRange(s), 2); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_start(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto_ReservedRange(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_enum_type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 4); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_extension(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 6); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_extension_range(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 5); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_field(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_nested_type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 3); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_oneof_decl(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 8); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_options(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 7); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_reserved_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 10); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_reserved_range(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProto(s), 9); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumDescriptorProto(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_options(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumDescriptorProto(s), 3); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumDescriptorProto(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_allow_alias(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumOptions(s), 2); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_deprecated(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumOptions(s), 3); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_uninterpreted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumOptions(s), 999); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumValueDescriptorProto(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_number(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumValueDescriptorProto(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_options(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumValueDescriptorProto(s), 3); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_deprecated(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumValueOptions(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_uninterpreted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumValueOptions(s), 999); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_default_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 7); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_extendee(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 2); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_json_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 10); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_label(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 4); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_number(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 3); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_oneof_index(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 9); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_options(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 8); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 5); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_type_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDescriptorProto(s), 6); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_ctype(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_deprecated(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 3); } -UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_experimental_map_key(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 9); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_jstype(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 6); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_lazy(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 5); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_packed(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_uninterpreted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 999); } @@ -6706,31 +6860,46 @@ UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_packa UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_public_dependency(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDescriptorProto(s), 10); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_service(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDescriptorProto(s), 6); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_source_code_info(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDescriptorProto(s), 9); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_syntax(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDescriptorProto(s), 12); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_weak_dependency(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDescriptorProto(s), 11); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorSet_file(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDescriptorSet(s), 1); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_cc_enable_arenas(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 31); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_cc_generic_services(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 16); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_csharp_namespace(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 37); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_deprecated(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 23); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_go_package(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 11); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_generate_equals_and_hash(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 20); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_generic_services(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 17); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_multiple_files(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 10); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_outer_classname(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 8); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_package(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 1); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_string_check_utf8(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 27); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_javanano_use_deprecated_package(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 38); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_objc_class_prefix(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 36); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_optimize_for(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 9); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_py_generic_services(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 18); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_uninterpreted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions(s), 999); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_deprecated(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MessageOptions(s), 3); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_map_entry(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MessageOptions(s), 7); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_message_set_wire_format(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MessageOptions(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_no_standard_descriptor_accessor(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MessageOptions(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_uninterpreted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MessageOptions(s), 999); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_client_streaming(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodDescriptorProto(s), 5); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_input_type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodDescriptorProto(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodDescriptorProto(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_options(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodDescriptorProto(s), 4); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_output_type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodDescriptorProto(s), 3); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_server_streaming(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodDescriptorProto(s), 6); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_deprecated(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodOptions(s), 33); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_uninterpreted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodOptions(s), 999); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_OneofDescriptorProto_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_OneofDescriptorProto(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_method(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_ServiceDescriptorProto(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_ServiceDescriptorProto(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_options(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_ServiceDescriptorProto(s), 3); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_deprecated(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_ServiceOptions(s), 33); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_uninterpreted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_ServiceOptions(s), 999); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_leading_comments(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_SourceCodeInfo_Location(s), 3); } +UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_SourceCodeInfo_Location(s), 6); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_path(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_SourceCodeInfo_Location(s), 1); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_span(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_SourceCodeInfo_Location(s), 2); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_trailing_comments(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_SourceCodeInfo_Location(s), 4); } @@ -6775,7 +6944,10 @@ inline upb::reffed_ptr<const upb::FieldDef> extension_range() { RETURN_REFFED(up inline upb::reffed_ptr<const upb::FieldDef> field() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_field) } inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_name) } inline upb::reffed_ptr<const upb::FieldDef> nested_type() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_nested_type) } +inline upb::reffed_ptr<const upb::FieldDef> oneof_decl() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_oneof_decl) } inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_options) } +inline upb::reffed_ptr<const upb::FieldDef> reserved_name() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_reserved_name) } +inline upb::reffed_ptr<const upb::FieldDef> reserved_range() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_reserved_range) } } /* namespace DescriptorProto */ } /* namespace protobuf */ } /* namespace google */ @@ -6794,6 +6966,18 @@ inline upb::reffed_ptr<const upb::FieldDef> start() { RETURN_REFFED(upb::FieldDe namespace google { namespace protobuf { +namespace DescriptorProto { +namespace ReservedRange { +inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_DescriptorProto_ReservedRange) } +inline upb::reffed_ptr<const upb::FieldDef> end() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_ReservedRange_end) } +inline upb::reffed_ptr<const upb::FieldDef> start() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_ReservedRange_start) } +} /* namespace ReservedRange */ +} /* namespace DescriptorProto */ +} /* namespace protobuf */ +} /* namespace google */ + +namespace google { +namespace protobuf { namespace EnumDescriptorProto { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_EnumDescriptorProto) } inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_EnumDescriptorProto_name) } @@ -6808,6 +6992,7 @@ namespace protobuf { namespace EnumOptions { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_EnumOptions) } inline upb::reffed_ptr<const upb::FieldDef> allow_alias() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_EnumOptions_allow_alias) } +inline upb::reffed_ptr<const upb::FieldDef> deprecated() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_EnumOptions_deprecated) } inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_EnumOptions_uninterpreted_option) } } /* namespace EnumOptions */ } /* namespace protobuf */ @@ -6828,6 +7013,7 @@ namespace google { namespace protobuf { namespace EnumValueOptions { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_EnumValueOptions) } +inline upb::reffed_ptr<const upb::FieldDef> deprecated() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_EnumValueOptions_deprecated) } inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_EnumValueOptions_uninterpreted_option) } } /* namespace EnumValueOptions */ } /* namespace protobuf */ @@ -6839,9 +7025,11 @@ namespace FieldDescriptorProto { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_FieldDescriptorProto) } inline upb::reffed_ptr<const upb::FieldDef> default_value() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_default_value) } inline upb::reffed_ptr<const upb::FieldDef> extendee() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_extendee) } +inline upb::reffed_ptr<const upb::FieldDef> json_name() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_json_name) } inline upb::reffed_ptr<const upb::FieldDef> label() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_label) } inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_name) } inline upb::reffed_ptr<const upb::FieldDef> number() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_number) } +inline upb::reffed_ptr<const upb::FieldDef> oneof_index() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_oneof_index) } inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_options) } inline upb::reffed_ptr<const upb::FieldDef> type() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_type) } inline upb::reffed_ptr<const upb::FieldDef> type_name() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_type_name) } @@ -6857,12 +7045,13 @@ namespace FieldOptions { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_FieldOptions) } inline upb::reffed_ptr<const upb::FieldDef> ctype() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_ctype) } inline upb::reffed_ptr<const upb::FieldDef> deprecated() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_deprecated) } -inline upb::reffed_ptr<const upb::FieldDef> experimental_map_key() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_experimental_map_key) } +inline upb::reffed_ptr<const upb::FieldDef> jstype() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_jstype) } inline upb::reffed_ptr<const upb::FieldDef> lazy() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_lazy) } inline upb::reffed_ptr<const upb::FieldDef> packed() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_packed) } inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_uninterpreted_option) } inline upb::reffed_ptr<const upb::FieldDef> weak() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_weak) } inline upb::reffed_ptr<const upb::EnumDef> CType() { RETURN_REFFED(upb::EnumDef, upbdefs_google_protobuf_FieldOptions_CType) } +inline upb::reffed_ptr<const upb::EnumDef> JSType() { RETURN_REFFED(upb::EnumDef, upbdefs_google_protobuf_FieldOptions_JSType) } } /* namespace FieldOptions */ } /* namespace protobuf */ } /* namespace google */ @@ -6881,6 +7070,7 @@ inline upb::reffed_ptr<const upb::FieldDef> package() { RETURN_REFFED(upb::Field inline upb::reffed_ptr<const upb::FieldDef> public_dependency() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileDescriptorProto_public_dependency) } inline upb::reffed_ptr<const upb::FieldDef> service() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileDescriptorProto_service) } inline upb::reffed_ptr<const upb::FieldDef> source_code_info() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileDescriptorProto_source_code_info) } +inline upb::reffed_ptr<const upb::FieldDef> syntax() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileDescriptorProto_syntax) } inline upb::reffed_ptr<const upb::FieldDef> weak_dependency() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileDescriptorProto_weak_dependency) } } /* namespace FileDescriptorProto */ } /* namespace protobuf */ @@ -6899,13 +7089,19 @@ namespace google { namespace protobuf { namespace FileOptions { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_FileOptions) } +inline upb::reffed_ptr<const upb::FieldDef> cc_enable_arenas() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_cc_enable_arenas) } inline upb::reffed_ptr<const upb::FieldDef> cc_generic_services() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_cc_generic_services) } +inline upb::reffed_ptr<const upb::FieldDef> csharp_namespace() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_csharp_namespace) } +inline upb::reffed_ptr<const upb::FieldDef> deprecated() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_deprecated) } inline upb::reffed_ptr<const upb::FieldDef> go_package() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_go_package) } inline upb::reffed_ptr<const upb::FieldDef> java_generate_equals_and_hash() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_generate_equals_and_hash) } inline upb::reffed_ptr<const upb::FieldDef> java_generic_services() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_generic_services) } inline upb::reffed_ptr<const upb::FieldDef> java_multiple_files() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_multiple_files) } inline upb::reffed_ptr<const upb::FieldDef> java_outer_classname() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_outer_classname) } inline upb::reffed_ptr<const upb::FieldDef> java_package() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_package) } +inline upb::reffed_ptr<const upb::FieldDef> java_string_check_utf8() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_string_check_utf8) } +inline upb::reffed_ptr<const upb::FieldDef> javanano_use_deprecated_package() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_javanano_use_deprecated_package) } +inline upb::reffed_ptr<const upb::FieldDef> objc_class_prefix() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_objc_class_prefix) } inline upb::reffed_ptr<const upb::FieldDef> optimize_for() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_optimize_for) } inline upb::reffed_ptr<const upb::FieldDef> py_generic_services() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_py_generic_services) } inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_uninterpreted_option) } @@ -6918,6 +7114,8 @@ namespace google { namespace protobuf { namespace MessageOptions { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_MessageOptions) } +inline upb::reffed_ptr<const upb::FieldDef> deprecated() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MessageOptions_deprecated) } +inline upb::reffed_ptr<const upb::FieldDef> map_entry() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MessageOptions_map_entry) } inline upb::reffed_ptr<const upb::FieldDef> message_set_wire_format() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MessageOptions_message_set_wire_format) } inline upb::reffed_ptr<const upb::FieldDef> no_standard_descriptor_accessor() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MessageOptions_no_standard_descriptor_accessor) } inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MessageOptions_uninterpreted_option) } @@ -6929,10 +7127,12 @@ namespace google { namespace protobuf { namespace MethodDescriptorProto { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_MethodDescriptorProto) } +inline upb::reffed_ptr<const upb::FieldDef> client_streaming() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MethodDescriptorProto_client_streaming) } inline upb::reffed_ptr<const upb::FieldDef> input_type() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MethodDescriptorProto_input_type) } inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MethodDescriptorProto_name) } inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MethodDescriptorProto_options) } inline upb::reffed_ptr<const upb::FieldDef> output_type() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MethodDescriptorProto_output_type) } +inline upb::reffed_ptr<const upb::FieldDef> server_streaming() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MethodDescriptorProto_server_streaming) } } /* namespace MethodDescriptorProto */ } /* namespace protobuf */ } /* namespace google */ @@ -6941,6 +7141,7 @@ namespace google { namespace protobuf { namespace MethodOptions { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_MethodOptions) } +inline upb::reffed_ptr<const upb::FieldDef> deprecated() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MethodOptions_deprecated) } inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MethodOptions_uninterpreted_option) } } /* namespace MethodOptions */ } /* namespace protobuf */ @@ -6948,6 +7149,15 @@ inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFF namespace google { namespace protobuf { +namespace OneofDescriptorProto { +inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_OneofDescriptorProto) } +inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_OneofDescriptorProto_name) } +} /* namespace OneofDescriptorProto */ +} /* namespace protobuf */ +} /* namespace google */ + +namespace google { +namespace protobuf { namespace ServiceDescriptorProto { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_ServiceDescriptorProto) } inline upb::reffed_ptr<const upb::FieldDef> method() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_ServiceDescriptorProto_method) } @@ -6961,6 +7171,7 @@ namespace google { namespace protobuf { namespace ServiceOptions { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_ServiceOptions) } +inline upb::reffed_ptr<const upb::FieldDef> deprecated() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_ServiceOptions_deprecated) } inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_ServiceOptions_uninterpreted_option) } } /* namespace ServiceOptions */ } /* namespace protobuf */ @@ -6981,6 +7192,7 @@ namespace SourceCodeInfo { namespace Location { inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb::MessageDef, upbdefs_google_protobuf_SourceCodeInfo_Location) } inline upb::reffed_ptr<const upb::FieldDef> leading_comments() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_SourceCodeInfo_Location_leading_comments) } +inline upb::reffed_ptr<const upb::FieldDef> leading_detached_comments() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_SourceCodeInfo_Location_leading_detached_comments) } inline upb::reffed_ptr<const upb::FieldDef> path() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_SourceCodeInfo_Location_path) } inline upb::reffed_ptr<const upb::FieldDef> span() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_SourceCodeInfo_Location_span) } inline upb::reffed_ptr<const upb::FieldDef> trailing_comments() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_SourceCodeInfo_Location_trailing_comments) } @@ -7067,6 +7279,13 @@ UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts) UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted, upb_pbdecodermethod, upb_refcounted) +/* The maximum number of bytes we are required to buffer internally between + * calls to the decoder. The value is 14: a 5 byte unknown tag plus ten-byte + * varint, less one because we are buffering an incomplete value. + * + * Should only be used by unit tests. */ +#define UPB_DECODER_MAX_RESIDUAL_BYTES 14 + #ifdef __cplusplus /* The parameters one uses to construct a DecoderMethod. @@ -7541,11 +7760,8 @@ struct upb_pbdecoder { /* Overall stream offset of "buf." */ uint64_t bufstart_ofs; - /* Buffer for residual bytes not parsed from the previous buffer. - * The maximum number of residual bytes we require is 12; a five-byte - * unknown tag plus an eight-byte value, less one because the value - * is only a partial value. */ - char residual[12]; + /* Buffer for residual bytes not parsed from the previous buffer. */ + char residual[UPB_DECODER_MAX_RESIDUAL_BYTES]; char *residual_end; /* Bytes of data that should be discarded from the input beore we start @@ -8083,11 +8299,14 @@ inline reffed_ptr<const Handlers> TextPrinter::NewHandlers( namespace upb { namespace json { class Parser; +class ParserMethod; } /* namespace json */ } /* namespace upb */ #endif UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser) +UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, + upb_json_parsermethod, upb_refcounted) /* upb::json::Parser **********************************************************/ @@ -8095,7 +8314,7 @@ UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser) * 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 3704 +#define UPB_JSON_PARSER_SIZE 4104 #ifdef __cplusplus @@ -8103,7 +8322,8 @@ UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser) * sink. */ class upb::json::Parser { public: - static Parser* Create(Environment* env, Sink* output); + static Parser* Create(Environment* env, const ParserMethod* method, + Sink* output); BytesSink* input(); @@ -8111,25 +8331,72 @@ class upb::json::Parser { UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser) }; +class upb::json::ParserMethod { + public: + /* Include base methods from upb::ReferenceCounted. */ + UPB_REFCOUNTED_CPPMETHODS + + /* Returns handlers for parsing according to the specified schema. */ + static reffed_ptr<const ParserMethod> New(const upb::MessageDef* md); + + /* The destination handlers that are statically bound to this method. + * This method is only capable of outputting to a sink that uses these + * handlers. */ + const Handlers* dest_handlers() const; + + /* The input handlers for this decoder method. */ + const BytesHandler* input_handler() const; + + private: + UPB_DISALLOW_POD_OPS(ParserMethod, upb::json::ParserMethod) +}; + #endif UPB_BEGIN_EXTERN_C -upb_json_parser *upb_json_parser_create(upb_env *e, upb_sink *output); +upb_json_parser* upb_json_parser_create(upb_env* e, + const upb_json_parsermethod* m, + upb_sink* output); upb_bytessink *upb_json_parser_input(upb_json_parser *p); +upb_json_parsermethod* upb_json_parsermethod_new(const upb_msgdef* md, + const void* owner); +const upb_handlers *upb_json_parsermethod_desthandlers( + const upb_json_parsermethod *m); +const upb_byteshandler *upb_json_parsermethod_inputhandler( + const upb_json_parsermethod *m); + +/* Include refcounted methods like upb_json_parsermethod_ref(). */ +UPB_REFCOUNTED_CMETHODS(upb_json_parsermethod, upb_json_parsermethod_upcast) + UPB_END_EXTERN_C #ifdef __cplusplus namespace upb { namespace json { -inline Parser* Parser::Create(Environment* env, Sink* output) { - return upb_json_parser_create(env, output); +inline Parser* Parser::Create(Environment* env, const ParserMethod* method, + Sink* output) { + return upb_json_parser_create(env, method, output); } inline BytesSink* Parser::input() { return upb_json_parser_input(this); } + +inline const Handlers* ParserMethod::dest_handlers() const { + return upb_json_parsermethod_desthandlers(this); +} +inline const BytesHandler* ParserMethod::input_handler() const { + return upb_json_parsermethod_inputhandler(this); +} +/* static */ +inline reffed_ptr<const ParserMethod> ParserMethod::New( + const MessageDef* md) { + const upb_json_parsermethod *m = upb_json_parsermethod_new(md, &m); + return reffed_ptr<const ParserMethod>(m, &m); +} + } /* namespace json */ } /* namespace upb */ diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index da85520f..86c74c2a 100644 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -1160,7 +1160,7 @@ module BasicTest # TODO: Fix JSON in JRuby version. return if RUBY_PLATFORM == "java" m = MapMessage.new(:map_string_int32 => {"a" => 1}) - expected = '{"map_string_int32":{"a":1},"map_string_msg":{}}' + expected = '{"mapStringInt32":{"a":1},"mapStringMsg":{}}' assert MapMessage.encode_json(m) == expected m2 = MapMessage.decode_json(MapMessage.encode_json(m)) assert m == m2 diff --git a/ruby/tests/generated_code.rb b/ruby/tests/generated_code.rb deleted file mode 100644 index 5a685433..00000000 --- a/ruby/tests/generated_code.rb +++ /dev/null @@ -1,74 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: generated_code.proto - -require 'google/protobuf' - -Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "A.B.C.TestMessage" do - optional :optional_int32, :int32, 1 - optional :optional_int64, :int64, 2 - optional :optional_uint32, :uint32, 3 - optional :optional_uint64, :uint64, 4 - optional :optional_bool, :bool, 5 - optional :optional_double, :double, 6 - optional :optional_float, :float, 7 - optional :optional_string, :string, 8 - optional :optional_bytes, :string, 9 - optional :optional_enum, :enum, 10, "A.B.C.TestEnum" - optional :optional_msg, :message, 11, "A.B.C.TestMessage" - repeated :repeated_int32, :int32, 21 - repeated :repeated_int64, :int64, 22 - repeated :repeated_uint32, :uint32, 23 - repeated :repeated_uint64, :uint64, 24 - repeated :repeated_bool, :bool, 25 - repeated :repeated_double, :double, 26 - repeated :repeated_float, :float, 27 - repeated :repeated_string, :string, 28 - repeated :repeated_bytes, :string, 29 - repeated :repeated_enum, :enum, 30, "A.B.C.TestEnum" - repeated :repeated_msg, :message, 31, "A.B.C.TestMessage" - map :map_int32_string, :int32, :string, 61 - map :map_int64_string, :int64, :string, 62 - map :map_uint32_string, :uint32, :string, 63 - map :map_uint64_string, :uint64, :string, 64 - map :map_bool_string, :bool, :string, 65 - map :map_string_string, :string, :string, 66 - map :map_string_msg, :string, :message, 67, "A.B.C.TestMessage" - map :map_string_enum, :string, :enum, 68, "A.B.C.TestEnum" - map :map_string_int32, :string, :int32, 69 - map :map_string_bool, :string, :bool, 70 - optional :nested_message, :message, 80, "A.B.C.TestMessage.NestedMessage" - oneof :my_oneof do - optional :oneof_int32, :int32, 41 - optional :oneof_int64, :int64, 42 - optional :oneof_uint32, :uint32, 43 - optional :oneof_uint64, :uint64, 44 - optional :oneof_bool, :bool, 45 - optional :oneof_double, :double, 46 - optional :oneof_float, :float, 47 - optional :oneof_string, :string, 48 - optional :oneof_bytes, :string, 49 - optional :oneof_enum, :enum, 50, "A.B.C.TestEnum" - optional :oneof_msg, :message, 51, "A.B.C.TestMessage" - end - end - add_message "A.B.C.TestMessage.NestedMessage" do - optional :foo, :int32, 1 - end - add_enum "A.B.C.TestEnum" do - value :Default, 0 - value :A, 1 - value :B, 2 - value :C, 3 - end -end - -module A - module B - module C - TestMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("A.B.C.TestMessage").msgclass - TestMessage::NestedMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("A.B.C.TestMessage.NestedMessage").msgclass - TestEnum = Google::Protobuf::DescriptorPool.generated_pool.lookup("A.B.C.TestEnum").enummodule - end - end -end diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 1a11bce8..5ee6f000 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc @@ -178,12 +178,13 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) { map<string, string> vars; vars["nested_name"] = descriptor_->name(); vars["classname"] = classname_; + vars["constexpr"] = options_.proto_h ? "constexpr " : ""; printer->Print(vars, "typedef $classname$ $nested_name$;\n"); for (int j = 0; j < descriptor_->value_count(); j++) { vars["tag"] = EnumValueName(descriptor_->value(j)); printer->Print(vars, - "static const $nested_name$ $tag$ = $classname$_$tag$;\n"); + "static $constexpr$const $nested_name$ $tag$ = $classname$_$tag$;\n"); } printer->Print(vars, @@ -237,6 +238,7 @@ void EnumGenerator::GenerateDescriptorInitializer( void EnumGenerator::GenerateMethods(io::Printer* printer) { map<string, string> vars; vars["classname"] = classname_; + vars["constexpr"] = options_.proto_h ? "constexpr " : ""; if (HasDescriptorMethods(descriptor_->file())) { printer->Print(vars, @@ -287,7 +289,7 @@ void EnumGenerator::GenerateMethods(io::Printer* printer) { for (int i = 0; i < descriptor_->value_count(); i++) { vars["value"] = EnumValueName(descriptor_->value(i)); printer->Print(vars, - "const $classname$ $parent$::$value$;\n"); + "$constexpr$const $classname$ $parent$::$value$;\n"); } printer->Print(vars, "const $classname$ $parent$::$nested_name$_MIN;\n" diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index e6c3b36a..0de7e2c6 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -134,12 +134,51 @@ bool IsReserved(const string& ident) { // Returns a copy of |filename| with any trailing ".protodevel" or ".proto // suffix stripped. +// TODO(robinson): Unify with copy in compiler/cpp/internal/helpers.cc. string StripProto(const string& filename) { const char* suffix = HasSuffixString(filename, ".protodevel") ? ".protodevel" : ".proto"; return StripSuffixString(filename, suffix); } +// Given a filename like foo/bar/baz.proto, returns the correspoding JavaScript +// file foo/bar/baz.js. +string GetJSFilename(const string& filename) { + const char* suffix = HasSuffixString(filename, ".protodevel") + ? ".protodevel" : ".proto"; + return StripSuffixString(filename, suffix) + "_pb.js"; +} + +// Given a filename like foo/bar/baz.proto, returns the root directory +// path ../../ +string GetRootPath(const string& filename) { + size_t slashes = std::count(filename.begin(), filename.end(), '/'); + if (slashes == 0) { + return "./"; + } + string result = ""; + for (size_t i = 0; i < slashes; i++) { + result += "../"; + } + return result; +} + +// Returns the alias we assign to the module of the given .proto filename +// when importing. +string ModuleAlias(const string& filename) { + // This scheme could technically cause problems if a file includes any 2 of: + // foo/bar_baz.proto + // foo_bar_baz.proto + // foo_bar/baz.proto + // + // We'll worry about this problem if/when we actually see it. This name isn't + // exposed to users so we can change it later if we need to. + string basename = StripProto(filename); + StripString(&basename, "-", '$'); + StripString(&basename, "/", '_'); + return basename + "_pb"; +} + // Returns the fully normalized JavaScript path for the given // file descriptor's package. string GetPath(const GeneratorOptions& options, @@ -215,6 +254,26 @@ string GetPath(const GeneratorOptions& options, value_descriptor->type()) + "." + value_descriptor->name(); } +string MaybeCrossFileRef(const GeneratorOptions& options, + const FileDescriptor* from_file, + const Descriptor* to_message) { + if (options.import_style == GeneratorOptions::IMPORT_COMMONJS && + from_file != to_message->file()) { + // Cross-file ref in CommonJS needs to use the module alias instead of + // the global name. + return ModuleAlias(to_message->file()->name()) + "." + to_message->name(); + } else { + // Within a single file we use a full name. + return GetPath(options, to_message); + } +} + +string SubmessageTypeRef(const GeneratorOptions& options, + const FieldDescriptor* field) { + GOOGLE_CHECK(field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE); + return MaybeCrossFileRef(options, field->file(), field->message_type()); +} + // - Object field name: LOWER_UNDERSCORE -> LOWER_CAMEL, except for group fields // (UPPER_CAMEL -> LOWER_CAMEL), with "List" (or "Map") appended if appropriate, // and with reserved words triggering a "pb_" prefix. @@ -952,11 +1011,13 @@ string RelativeTypeName(const FieldDescriptor* field) { } string JSExtensionsObjectName(const GeneratorOptions& options, + const FileDescriptor* from_file, const Descriptor* desc) { if (desc->full_name() == "google.protobuf.bridge.MessageSet") { + // TODO(haberman): fix this for the IMPORT_COMMONJS case. return "jspb.Message.messageSetExtensions"; } else { - return GetPath(options, desc) + ".extensions"; + return MaybeCrossFileRef(options, from_file, desc) + ".extensions"; } } @@ -1113,19 +1174,24 @@ void Generator::GenerateHeader(const GeneratorOptions& options, "\n"); } +void Generator::FindProvidesForFile(const GeneratorOptions& options, + io::Printer* printer, + const FileDescriptor* file, + std::set<string>* provided) const { + for (int i = 0; i < file->message_type_count(); i++) { + FindProvidesForMessage(options, printer, file->message_type(i), provided); + } + for (int i = 0; i < file->enum_type_count(); i++) { + FindProvidesForEnum(options, printer, file->enum_type(i), provided); + } +} + void Generator::FindProvides(const GeneratorOptions& options, io::Printer* printer, const vector<const FileDescriptor*>& files, std::set<string>* provided) const { for (int i = 0; i < files.size(); i++) { - for (int j = 0; j < files[i]->message_type_count(); j++) { - FindProvidesForMessage(options, printer, files[i]->message_type(j), - provided); - } - for (int j = 0; j < files[i]->enum_type_count(); j++) { - FindProvidesForEnum(options, printer, files[i]->enum_type(j), - provided); - } + FindProvidesForFile(options, printer, files[i], provided); } printer->Print("\n"); @@ -1204,38 +1270,45 @@ void Generator::GenerateRequires(const GeneratorOptions& options, io::Printer* printer, const vector<const FileDescriptor*>& files, std::set<string>* provided) const { - std::set<string> required; - std::set<string> forwards; - bool have_extensions = false; - bool have_message = false; - - for (int i = 0; i < files.size(); i++) { - for (int j = 0; j < files[i]->message_type_count(); j++) { - FindRequiresForMessage(options, - files[i]->message_type(j), - &required, &forwards, &have_message); - } - if (!have_extensions && HasExtensions(files[i])) { - have_extensions = true; - } + if (options.import_style == GeneratorOptions::IMPORT_BROWSER) { + return; + } else if (options.import_style == GeneratorOptions::IMPORT_CLOSURE) { + // For Closure imports we need to import every message type individually. + std::set<string> required; + std::set<string> forwards; + bool have_extensions = false; + bool have_message = false; - for (int j = 0; j < files[i]->extension_count(); j++) { - const FieldDescriptor* extension = files[i]->extension(j); - if (IgnoreField(extension)) { - continue; + for (int i = 0; i < files.size(); i++) { + for (int j = 0; j < files[i]->message_type_count(); j++) { + FindRequiresForMessage(options, + files[i]->message_type(j), + &required, &forwards, &have_message); } - if (extension->containing_type()->full_name() != - "google.protobuf.bridge.MessageSet") { - required.insert(GetPath(options, extension->containing_type())); + if (!have_extensions && HasExtensions(files[i])) { + have_extensions = true; + } + + for (int j = 0; j < files[i]->extension_count(); j++) { + const FieldDescriptor* extension = files[i]->extension(j); + if (IgnoreField(extension)) { + continue; + } + if (extension->containing_type()->full_name() != + "google.protobuf.bridge.MessageSet") { + required.insert(GetPath(options, extension->containing_type())); + } + FindRequiresForField(options, extension, &required, &forwards); + have_extensions = true; } - FindRequiresForField(options, extension, &required, &forwards); - have_extensions = true; } - } - GenerateRequiresImpl(options, printer, &required, &forwards, provided, - /* require_jspb = */ have_message, - /* require_extension = */ have_extensions); + GenerateRequiresImpl(options, printer, &required, &forwards, provided, + /* require_jspb = */ have_message, + /* require_extension = */ have_extensions); + } else if (options.import_style == GeneratorOptions::IMPORT_COMMONJS) { + // CommonJS imports are based on files + } } void Generator::GenerateRequires(const GeneratorOptions& options, @@ -1406,6 +1479,12 @@ void Generator::GenerateClass(const GeneratorOptions& options, if (IsExtendable(desc) && desc->full_name() != "google.protobuf.bridge.MessageSet") { GenerateClassExtensionFieldInfo(options, printer, desc); } + + if (options.import_style != GeneratorOptions:: IMPORT_CLOSURE) { + for (int i = 0; i < desc->extension_count(); i++) { + GenerateExtension(options, printer, desc->extension(i)); + } + } } // Recurse on nested types. @@ -1623,7 +1702,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options, "obj,\n" " $extObject$, $class$.prototype.getExtension,\n" " includeInstance);\n", - "extObject", JSExtensionsObjectName(options, desc), + "extObject", JSExtensionsObjectName(options, desc->file(), desc), "class", GetPath(options, desc)); } @@ -1652,13 +1731,13 @@ void Generator::GenerateClassFieldToObject(const GeneratorOptions& options, printer->Print("jspb.Message.toObjectList(msg.get$getter$(),\n" " $type$.toObject, includeInstance)", "getter", JSGetterName(field), - "type", GetPath(options, field->message_type())); + "type", SubmessageTypeRef(options, field)); } } else { printer->Print("(f = msg.get$getter$()) && " "$type$.toObject(includeInstance, f)", "getter", JSGetterName(field), - "type", GetPath(options, field->message_type())); + "type", SubmessageTypeRef(options, field)); } } else { // Simple field (singular or repeated). @@ -1723,7 +1802,7 @@ void Generator::GenerateClassFieldFromObject( " }));\n", "name", JSObjectFieldName(field), "index", JSFieldIndex(field), - "fieldclass", GetPath(options, field->message_type())); + "fieldclass", SubmessageTypeRef(options, field)); } } else { printer->Print( @@ -1731,7 +1810,7 @@ void Generator::GenerateClassFieldFromObject( " msg, $index$, $fieldclass$.fromObject(obj.$name$));\n", "name", JSObjectFieldName(field), "index", JSFieldIndex(field), - "fieldclass", GetPath(options, field->message_type())); + "fieldclass", SubmessageTypeRef(options, field)); } } else { // Simple (primitive) field. @@ -1815,7 +1894,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, /* always_singular = */ false), "rpt", (field->is_repeated() ? "Repeated" : ""), "index", JSFieldIndex(field), - "wrapperclass", GetPath(options, field->message_type()), + "wrapperclass", SubmessageTypeRef(options, field), "required", (field->label() == FieldDescriptor::LABEL_REQUIRED ? ", 1" : "")); printer->Print( @@ -2043,7 +2122,7 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options, " $class$.prototype.getExtension,\n" " $class$.prototype.setExtension);\n" " break;\n", - "extobj", JSExtensionsObjectName(options, desc), + "extobj", JSExtensionsObjectName(options, desc->file(), desc), "class", GetPath(options, desc)); } else { printer->Print( @@ -2073,7 +2152,7 @@ void Generator::GenerateClassDeserializeBinaryField( " var value = new $fieldclass$;\n" " reader.read$msgOrGroup$($grpfield$value," "$fieldclass$.deserializeBinaryFromReader);\n", - "fieldclass", GetPath(options, field->message_type()), + "fieldclass", SubmessageTypeRef(options, field), "msgOrGroup", (field->type() == FieldDescriptor::TYPE_GROUP) ? "Group" : "Message", "grpfield", (field->type() == FieldDescriptor::TYPE_GROUP) ? @@ -2149,7 +2228,7 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options, printer->Print( " jspb.Message.serializeBinaryExtensions(this, writer, $extobj$,\n" " $class$.prototype.getExtension);\n", - "extobj", JSExtensionsObjectName(options, desc), + "extobj", JSExtensionsObjectName(options, desc->file(), desc), "class", GetPath(options, desc)); } @@ -2222,7 +2301,7 @@ void Generator::GenerateClassSerializeBinaryField( printer->Print( ",\n" " $submsg$.serializeBinaryToWriter\n", - "submsg", GetPath(options, field->message_type())); + "submsg", SubmessageTypeRef(options, field)); } else { printer->Print("\n"); } @@ -2290,9 +2369,9 @@ void Generator::GenerateExtension(const GeneratorOptions& options, "index", SimpleItoa(field->number()), "name", JSObjectFieldName(field), "ctor", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ? - GetPath(options, field->message_type()) : string("null")), + SubmessageTypeRef(options, field) : string("null")), "toObject", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ? - (GetPath(options, field->message_type()) + ".toObject") : + (SubmessageTypeRef(options, field) + ".toObject") : string("null")), "repeated", (field->is_repeated() ? "1" : "0")); @@ -2308,11 +2387,11 @@ void Generator::GenerateExtension(const GeneratorOptions& options, "binaryWriterFn", JSBinaryWriterMethodName(field), "binaryMessageSerializeFn", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ? - (GetPath(options, field->message_type()) + + (SubmessageTypeRef(options, field) + ".serializeBinaryToWriter") : "null", "binaryMessageDeserializeFn", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ? - (GetPath(options, field->message_type()) + + (SubmessageTypeRef(options, field) + ".deserializeBinaryFromReader") : "null", "isPacked", (field->is_packed() ? "true" : "false")); } else { @@ -2324,7 +2403,8 @@ void Generator::GenerateExtension(const GeneratorOptions& options, "// toObject() will function correctly.\n" "$extendName$[$index$] = $class$.$name$;\n" "\n", - "extendName", JSExtensionsObjectName(options, field->containing_type()), + "extendName", JSExtensionsObjectName(options, field->file(), + field->containing_type()), "index", SimpleItoa(field->number()), "class", extension_scope, "name", JSObjectFieldName(field)); @@ -2364,6 +2444,19 @@ bool GeneratorOptions::ParseFromOptions( namespace_prefix = options[i].second; } else if (options[i].first == "library") { library = options[i].second; + } else if (options[i].first == "import_style") { + if (options[i].second == "closure") { + import_style = IMPORT_CLOSURE; + } else if (options[i].second == "commonjs") { + import_style = IMPORT_COMMONJS; + } else if (options[i].second == "browser") { + import_style = IMPORT_BROWSER; + } else if (options[i].second == "es6") { + import_style = IMPORT_ES6; + } else { + *error = "Unknown import style " + options[i].second + ", expected " + + "one of: closure, commonjs, browser, es6."; + } } else { // Assume any other option is an output directory, as long as it is a bare // `key` rather than a `key=value` option. @@ -2375,6 +2468,11 @@ bool GeneratorOptions::ParseFromOptions( } } + if (!library.empty() && import_style != IMPORT_CLOSURE) { + *error = "The library option should only be used for " + "import_style=closure"; + } + return true; } @@ -2418,6 +2516,63 @@ void Generator::GenerateFileAndDeps( } } +void Generator::GenerateFile(const GeneratorOptions& options, + io::Printer* printer, + const FileDescriptor* file) const { + GenerateHeader(options, printer); + + // Generate "require" statements. + if (options.import_style == GeneratorOptions::IMPORT_COMMONJS) { + printer->Print("var jspb = require('google-protobuf');\n"); + printer->Print("var goog = jspb;\n"); + printer->Print("var global = Function('return this')();\n\n"); + + for (int i = 0; i < file->dependency_count(); i++) { + const std::string& name = file->dependency(i)->name(); + printer->Print( + "var $alias$ = require('$file$');\n", + "alias", ModuleAlias(name), + "file", GetRootPath(file->name()) + GetJSFilename(name)); + } + } + + // We aren't using Closure's import system, but we use goog.exportSymbol() + // to construct the expected tree of objects, eg. + // + // goog.exportSymbol('foo.bar.Baz', null, this); + // + // // Later generated code expects foo.bar = {} to exist: + // foo.bar.Baz = function() { /* ... */ } + std::set<std::string> provided; + + // Cover the case where this file declares extensions but no messages. + // This will ensure that the file-level object will be declared to hold + // the extensions. + for (int i = 0; i < file->extension_count(); i++) { + provided.insert(file->extension(i)->full_name()); + } + + FindProvidesForFile(options, printer, file, &provided); + for (std::set<string>::iterator it = provided.begin(); + it != provided.end(); ++it) { + printer->Print("goog.exportSymbol('$name$', null, global);\n", + "name", *it); + } + + GenerateClassesAndEnums(options, printer, file); + + // Extensions nested inside messages are emitted inside + // GenerateClassesAndEnums(). + for (int i = 0; i < file->extension_count(); i++) { + GenerateExtension(options, printer, file->extension(i)); + } + + if (options.import_style == GeneratorOptions::IMPORT_COMMONJS) { + printer->Print("goog.object.extend(exports, $package$);\n", + "package", GetPath(options, file)); + } +} + bool Generator::GenerateAll(const vector<const FileDescriptor*>& files, const string& parameter, GeneratorContext* context, @@ -2430,10 +2585,14 @@ bool Generator::GenerateAll(const vector<const FileDescriptor*>& files, } - // We're either generating a single library file with definitions for message - // and enum types in *all* FileDescriptor inputs, or we're generating a single - // file for each type. - if (options.library != "") { + // There are three schemes for where output files go: + // + // - import_style = IMPORT_CLOSURE, library non-empty: all output in one file + // - import_style = IMPORT_CLOSURE, library empty: one output file per type + // - import_style != IMPORT_CLOSURE: one output file per .proto file + if (options.import_style == GeneratorOptions::IMPORT_CLOSURE && + options.library != "") { + // All output should go in a single file. string filename = options.output_dir + "/" + options.library + ".js"; google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output(context->Open(filename)); GOOGLE_CHECK(output.get()); @@ -2469,7 +2628,7 @@ bool Generator::GenerateAll(const vector<const FileDescriptor*>& files, if (printer.failed()) { return false; } - } else { + } else if (options.import_style == GeneratorOptions::IMPORT_CLOSURE) { // Collect all types, and print each type to a separate file. Pull out // free-floating extensions while we make this pass. map< string, vector<const FieldDescriptor*> > extensions_by_namespace; @@ -2611,6 +2770,24 @@ bool Generator::GenerateAll(const vector<const FileDescriptor*>& files, } } } + } else { + // Generate one output file per input (.proto) file. + + for (int i = 0; i < files.size(); i++) { + const google::protobuf::FileDescriptor* file = files[i]; + + string filename = options.output_dir + "/" + GetJSFilename(file->name()); + google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( + context->Open(filename)); + GOOGLE_CHECK(output.get()); + io::Printer printer(output.get(), '$'); + + GenerateFile(options, &printer, file); + + if (printer.failed()) { + return false; + } + } } return true; diff --git a/src/google/protobuf/compiler/js/js_generator.h b/src/google/protobuf/compiler/js/js_generator.h index db2dceb3..db9178d3 100755 --- a/src/google/protobuf/compiler/js/js_generator.h +++ b/src/google/protobuf/compiler/js/js_generator.h @@ -67,6 +67,13 @@ struct GeneratorOptions { bool error_on_name_conflict; // Enable binary-format support? bool binary; + // What style of imports should be used. + enum ImportStyle { + IMPORT_CLOSURE, // goog.require() + IMPORT_COMMONJS, // require() + IMPORT_BROWSER, // no import statements + IMPORT_ES6, // import { member } from '' + } import_style; GeneratorOptions() : add_require_for_enums(false), @@ -75,7 +82,8 @@ struct GeneratorOptions { namespace_prefix(""), library(""), error_on_name_conflict(false), - binary(false) {} + binary(false), + import_style(IMPORT_CLOSURE) {} bool ParseFromOptions( const vector< pair< string, string > >& options, @@ -111,6 +119,10 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { io::Printer* printer, const vector<const FileDescriptor*>& file, std::set<string>* provided) const; + void FindProvidesForFile(const GeneratorOptions& options, + io::Printer* printer, + const FileDescriptor* file, + std::set<string>* provided) const; void FindProvidesForMessage(const GeneratorOptions& options, io::Printer* printer, const Descriptor* desc, @@ -168,6 +180,10 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { std::set<string>* required, std::set<string>* forwards) const; + void GenerateFile(const GeneratorOptions& options, + io::Printer* printer, + const FileDescriptor* file) const; + // Generate definitions for all message classes and enums in all files, // processing the files in dependence order. void GenerateFilesInDepOrder(const GeneratorOptions& options, diff --git a/src/google/protobuf/compiler/main.cc b/src/google/protobuf/compiler/main.cc index 97df536e..66ad13b7 100644 --- a/src/google/protobuf/compiler/main.cc +++ b/src/google/protobuf/compiler/main.cc @@ -78,7 +78,7 @@ int main(int argc, char* argv[]) { // Objective C google::protobuf::compiler::objectivec::ObjectiveCGenerator objc_generator; - cli.RegisterGenerator("--objc_out", &objc_generator, + cli.RegisterGenerator("--objc_out", "--objc_opt", &objc_generator, "Generate Objective C header and source."); // JavaScript diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc index d6f01c60..857d24a4 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc @@ -80,10 +80,12 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { // Include the unknown value. printer->Print( + "/// Value used if any message's field encounters a value that is not defined\n" + "/// by this enum. The message will also have C functions to get/set the rawValue\n" + "/// of the field.\n" "$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\n", "name", name_); } - for (int i = 0; i < all_values_.size(); i++) { SourceLocation location; if (all_values_[i]->GetSourceLocation(&location)) { @@ -107,6 +109,8 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { "\n" "GPBEnumDescriptor *$name$_EnumDescriptor(void);\n" "\n" + "/// Checks to see if the given value is defined by the enum or was not known at\n" + "/// the time this source was generated.\n" "BOOL $name$_IsValidValue(int32_t value);\n" "\n", "name", name_); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc index 30a13ddb..cfbb8c52 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc @@ -44,6 +44,7 @@ namespace compiler { namespace objectivec { namespace { + void SetEnumVariables(const FieldDescriptor* descriptor, map<string, string>* variables) { string type = EnumName(descriptor->enum_type()); @@ -63,8 +64,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor, } } // namespace -EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor) - : SingleFieldGenerator(descriptor) { +EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor, + const Options& options) + : SingleFieldGenerator(descriptor, options) { SetEnumVariables(descriptor, &variables_); } @@ -85,7 +87,12 @@ void EnumFieldGenerator::GenerateCFunctionDeclarations( printer->Print( variables_, + "/// Fetches the raw value of a @c $owning_message_class$'s @c $name$ property, even\n" + "/// if the value was not defined by the enum at the time the code was generated.\n" "int32_t $owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message);\n" + "/// Sets the raw value of an @c $owning_message_class$'s @c $name$ property, allowing\n" + "/// it to be set to a value that was not defined by the enum at the time the code\n" + "/// was generated.\n" "void Set$owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message, int32_t value);\n" "\n"); } @@ -112,6 +119,7 @@ void EnumFieldGenerator::GenerateCFunctionImplementations( void EnumFieldGenerator::DetermineForwardDeclarations( set<string>* fwd_decls) const { + SingleFieldGenerator::DetermineForwardDeclarations(fwd_decls); // If it is an enum defined in a different file, then we'll need a forward // declaration for it. When it is in our file, all the enums are output // before the message, so it will be declared before it is needed. @@ -123,14 +131,20 @@ void EnumFieldGenerator::DetermineForwardDeclarations( } RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator( - const FieldDescriptor* descriptor) - : RepeatedFieldGenerator(descriptor) { + const FieldDescriptor* descriptor, const Options& options) + : RepeatedFieldGenerator(descriptor, options) { SetEnumVariables(descriptor, &variables_); variables_["array_storage_type"] = "GPBEnumArray"; } RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {} +void RepeatedEnumFieldGenerator::FinishInitialization(void) { + RepeatedFieldGenerator::FinishInitialization(); + variables_["array_comment"] = + "// |" + variables_["name"] + "| contains |" + variables_["storage_type"] + "|\n"; +} + void RepeatedEnumFieldGenerator::GenerateFieldDescriptionTypeSpecific( io::Printer* printer) const { printer->Print( diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h index b629eae8..ae2f57e3 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h @@ -41,7 +41,8 @@ namespace compiler { namespace objectivec { class EnumFieldGenerator : public SingleFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options); public: virtual void GenerateFieldDescriptionTypeSpecific(io::Printer* printer) const; @@ -50,7 +51,7 @@ class EnumFieldGenerator : public SingleFieldGenerator { virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; protected: - explicit EnumFieldGenerator(const FieldDescriptor* descriptor); + EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options); virtual ~EnumFieldGenerator(); private: @@ -58,13 +59,16 @@ class EnumFieldGenerator : public SingleFieldGenerator { }; class RepeatedEnumFieldGenerator : public RepeatedFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options); public: + virtual void FinishInitialization(); virtual void GenerateFieldDescriptionTypeSpecific(io::Printer* printer) const; protected: - RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor); + RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); virtual ~RepeatedEnumFieldGenerator(); private: diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index cf5d8cfb..8697e225 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -45,6 +45,7 @@ namespace compiler { namespace objectivec { namespace { + void SetCommonFieldVariables(const FieldDescriptor* descriptor, map<string, string>* variables) { string camel_case_name = FieldName(descriptor); @@ -117,39 +118,40 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, } // namespace -FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field) { +FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options) { FieldGenerator* result = NULL; if (field->is_repeated()) { switch (GetObjectiveCType(field)) { case OBJECTIVECTYPE_MESSAGE: { if (field->is_map()) { - result = new MapFieldGenerator(field); + result = new MapFieldGenerator(field, options); } else { - result = new RepeatedMessageFieldGenerator(field); + result = new RepeatedMessageFieldGenerator(field, options); } break; } case OBJECTIVECTYPE_ENUM: - result = new RepeatedEnumFieldGenerator(field); + result = new RepeatedEnumFieldGenerator(field, options); break; default: - result = new RepeatedPrimitiveFieldGenerator(field); + result = new RepeatedPrimitiveFieldGenerator(field, options); break; } } else { switch (GetObjectiveCType(field)) { case OBJECTIVECTYPE_MESSAGE: { - result = new MessageFieldGenerator(field); + result = new MessageFieldGenerator(field, options); break; } case OBJECTIVECTYPE_ENUM: - result = new EnumFieldGenerator(field); + result = new EnumFieldGenerator(field, options); break; default: if (IsReferenceType(field)) { - result = new PrimitiveObjFieldGenerator(field); + result = new PrimitiveObjFieldGenerator(field, options); } else { - result = new PrimitiveFieldGenerator(field); + result = new PrimitiveFieldGenerator(field, options); } break; } @@ -158,8 +160,8 @@ FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field) { return result; } - -FieldGenerator::FieldGenerator(const FieldDescriptor* descriptor) +FieldGenerator::FieldGenerator(const FieldDescriptor* descriptor, + const Options& options) : descriptor_(descriptor) { SetCommonFieldVariables(descriptor, &variables_); } @@ -252,9 +254,9 @@ void FieldGenerator::FinishInitialization(void) { } } -SingleFieldGenerator::SingleFieldGenerator( - const FieldDescriptor* descriptor) - : FieldGenerator(descriptor) { +SingleFieldGenerator::SingleFieldGenerator(const FieldDescriptor* descriptor, + const Options& options) + : FieldGenerator(descriptor, options) { // Nothing } @@ -268,15 +270,15 @@ void SingleFieldGenerator::GenerateFieldStorageDeclaration( void SingleFieldGenerator::GeneratePropertyDeclaration( io::Printer* printer) const { printer->Print(variables_, "$comments$"); + printer->Print( + variables_, + "@property(nonatomic, readwrite) $property_type$ $name$;\n" + "\n"); if (WantsHasProperty()) { printer->Print( variables_, "@property(nonatomic, readwrite) BOOL has$capitalized_name$;\n"); } - printer->Print( - variables_, - "@property(nonatomic, readwrite) $property_type$ $name$;\n" - "\n"); } void SingleFieldGenerator::GeneratePropertyImplementation( @@ -300,9 +302,9 @@ bool SingleFieldGenerator::WantsHasProperty(void) const { return false; } -ObjCObjFieldGenerator::ObjCObjFieldGenerator( - const FieldDescriptor* descriptor) - : SingleFieldGenerator(descriptor) { +ObjCObjFieldGenerator::ObjCObjFieldGenerator(const FieldDescriptor* descriptor, + const Options& options) + : SingleFieldGenerator(descriptor, options) { variables_["property_storage_attribute"] = "strong"; if (IsRetainedName(variables_["name"])) { variables_["storage_attribute"] = " NS_RETURNS_NOT_RETAINED"; @@ -324,14 +326,15 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration( // conventions (init*, new*, etc.) printer->Print(variables_, "$comments$"); + printer->Print( + variables_, + "@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$;\n"); if (WantsHasProperty()) { printer->Print( variables_, + "/// Test to see if @c $name$ has been set.\n" "@property(nonatomic, readwrite) BOOL has$capitalized_name$;\n"); } - printer->Print( - variables_, - "@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$;\n"); if (IsInitName(variables_.find("name")->second)) { // If property name starts with init we need to annotate it to get past ARC. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 @@ -342,18 +345,21 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration( } RepeatedFieldGenerator::RepeatedFieldGenerator( - const FieldDescriptor* descriptor) - : ObjCObjFieldGenerator(descriptor) { + const FieldDescriptor* descriptor, const Options& options) + : ObjCObjFieldGenerator(descriptor, options) { // Repeated fields don't use the has index. variables_["has_index"] = "GPBNoHasBit"; + // Default to no comment and let the cases needing it fill it in. + variables_["array_comment"] = ""; } RepeatedFieldGenerator::~RepeatedFieldGenerator() {} void RepeatedFieldGenerator::FinishInitialization(void) { FieldGenerator::FinishInitialization(); - variables_["array_comment"] = - "// |" + variables_["name"] + "| contains |" + variables_["storage_type"] + "|\n"; + if (variables_.find("array_property_type") == variables_.end()) { + variables_["array_property_type"] = variable("array_storage_type"); + } } void RepeatedFieldGenerator::GenerateFieldStorageDeclaration( @@ -379,13 +385,14 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration( variables_, "$comments$" "$array_comment$" - "@property(nonatomic, readwrite, strong, null_resettable) $array_storage_type$ *$name$$storage_attribute$;\n" + "@property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$;\n" + "/// The number of items in @c $name$ without causing the array to be created.\n" "@property(nonatomic, readonly) NSUInteger $name$_Count;\n"); if (IsInitName(variables_.find("name")->second)) { // If property name starts with init we need to annotate it to get past ARC. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 printer->Print(variables_, - "- ($array_storage_type$ *)$name$ GPB_METHOD_FAMILY_NONE;\n"); + "- ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE;\n"); } printer->Print("\n"); } @@ -395,7 +402,8 @@ bool RepeatedFieldGenerator::WantsHasProperty(void) const { return false; } -FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor) +FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor, + const Options& options) : descriptor_(descriptor), field_generators_( new scoped_ptr<FieldGenerator>[descriptor->field_count()]), @@ -403,10 +411,12 @@ FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor) new scoped_ptr<FieldGenerator>[descriptor->extension_count()]) { // Construct all the FieldGenerators. for (int i = 0; i < descriptor->field_count(); i++) { - field_generators_[i].reset(FieldGenerator::Make(descriptor->field(i))); + field_generators_[i].reset( + FieldGenerator::Make(descriptor->field(i), options)); } for (int i = 0; i < descriptor->extension_count(); i++) { - extension_generators_[i].reset(FieldGenerator::Make(descriptor->extension(i))); + extension_generators_[i].reset( + FieldGenerator::Make(descriptor->extension(i), options)); } } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.h b/src/google/protobuf/compiler/objectivec/objectivec_field.h index 130a52dd..e8a20a72 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.h @@ -49,24 +49,31 @@ namespace objectivec { class FieldGenerator { public: - static FieldGenerator* Make(const FieldDescriptor* field); + static FieldGenerator* Make(const FieldDescriptor* field, + const Options& options); virtual ~FieldGenerator(); + // Exposed for subclasses to fill in. virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const = 0; virtual void GeneratePropertyDeclaration(io::Printer* printer) const = 0; - virtual void GeneratePropertyImplementation(io::Printer* printer) const = 0; - virtual void GenerateFieldDescription(io::Printer* printer) const; + // Called by GenerateFieldDescription, exposed for classes that need custom + // generation. virtual void GenerateFieldDescriptionTypeSpecific(io::Printer* printer) const; - virtual void GenerateFieldNumberConstant(io::Printer* printer) const; + // Exposed for subclasses to extend, base does nothing. virtual void GenerateCFunctionDeclarations(io::Printer* printer) const; virtual void GenerateCFunctionImplementations(io::Printer* printer) const; + // Exposed for subclasses, should always call it on the parent class also. virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + // Used during generation, not intended to be extended by subclasses. + void GenerateFieldDescription(io::Printer* printer) const; + void GenerateFieldNumberConstant(io::Printer* printer) const; + void SetOneofIndexBase(int index_base); string variable(const char* key) const { @@ -81,7 +88,7 @@ class FieldGenerator { string raw_field_name() const { return variable("raw_field_name"); } protected: - explicit FieldGenerator(const FieldDescriptor* descriptor); + FieldGenerator(const FieldDescriptor* descriptor, const Options& options); virtual void FinishInitialization(void); virtual bool WantsHasProperty(void) const = 0; @@ -103,7 +110,8 @@ class SingleFieldGenerator : public FieldGenerator { virtual void GeneratePropertyImplementation(io::Printer* printer) const; protected: - explicit SingleFieldGenerator(const FieldDescriptor* descriptor); + SingleFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); virtual bool WantsHasProperty(void) const; private: @@ -119,7 +127,8 @@ class ObjCObjFieldGenerator : public SingleFieldGenerator { virtual void GeneratePropertyDeclaration(io::Printer* printer) const; protected: - explicit ObjCObjFieldGenerator(const FieldDescriptor* descriptor); + ObjCObjFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ObjCObjFieldGenerator); @@ -135,7 +144,8 @@ class RepeatedFieldGenerator : public ObjCObjFieldGenerator { virtual void GeneratePropertyImplementation(io::Printer* printer) const; protected: - explicit RepeatedFieldGenerator(const FieldDescriptor* descriptor); + RepeatedFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); virtual void FinishInitialization(void); virtual bool WantsHasProperty(void) const; @@ -146,7 +156,7 @@ class RepeatedFieldGenerator : public ObjCObjFieldGenerator { // Convenience class which constructs FieldGenerators for a Descriptor. class FieldGeneratorMap { public: - explicit FieldGeneratorMap(const Descriptor* descriptor); + FieldGeneratorMap(const Descriptor* descriptor, const Options& options); ~FieldGeneratorMap(); const FieldGenerator& get(const FieldDescriptor* field) const; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 228c66f0..16199884 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -50,17 +50,18 @@ const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30000; namespace compiler { namespace objectivec { -FileGenerator::FileGenerator(const FileDescriptor *file) +FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options) : file_(file), root_class_name_(FileClassName(file)), - is_public_dep_(false) { + is_public_dep_(false), + options_(options) { for (int i = 0; i < file_->enum_type_count(); i++) { EnumGenerator *generator = new EnumGenerator(file_->enum_type(i)); enum_generators_.push_back(generator); } for (int i = 0; i < file_->message_type_count(); i++) { MessageGenerator *generator = - new MessageGenerator(root_class_name_, file_->message_type(i)); + new MessageGenerator(root_class_name_, file_->message_type(i), options_); message_generators_.push_back(generator); } for (int i = 0; i < file_->extension_count(); i++) { @@ -150,13 +151,15 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { printer->Print( "#pragma mark - $root_class_name$\n" "\n" + "/// Exposes the extension registry for this file.\n" + "///\n" + "/// The base class provides:\n" + "/// @code\n" + "/// + (GPBExtensionRegistry *)extensionRegistry;\n" + "/// @endcode\n" + "/// which is a @c GPBExtensionRegistry that includes all the extensions defined by\n" + "/// this file and all files that it depends on.\n" "@interface $root_class_name$ : GPBRootObject\n" - "\n" - "// The base class provides:\n" - "// + (GPBExtensionRegistry *)extensionRegistry;\n" - "// which is an GPBExtensionRegistry that includes all the extensions defined by\n" - "// this file and all files that it depends on.\n" - "\n" "@end\n" "\n", "root_class_name", root_class_name_); @@ -352,7 +355,8 @@ const vector<FileGenerator *> &FileGenerator::DependencyGenerators() { public_import_names.insert(file_->public_dependency(i)->name()); } for (int i = 0; i < file_->dependency_count(); i++) { - FileGenerator *generator = new FileGenerator(file_->dependency(i)); + FileGenerator *generator = + new FileGenerator(file_->dependency(i), options_); const string& name = file_->dependency(i)->name(); bool public_import = (public_import_names.count(name) != 0); generator->SetIsPublicDependency(public_import); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.h b/src/google/protobuf/compiler/objectivec/objectivec_file.h index 1bb4f0ea..4c0fcd3f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.h @@ -55,7 +55,7 @@ class MessageGenerator; class FileGenerator { public: - explicit FileGenerator(const FileDescriptor* file); + FileGenerator(const FileDescriptor* file, const Options& options); ~FileGenerator(); void GenerateSource(io::Printer* printer); @@ -84,6 +84,8 @@ class FileGenerator { vector<ExtensionGenerator*> extension_generators_; bool is_public_dep_; + const Options options_; + const vector<FileGenerator*>& DependencyGenerators(); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index 375b4e0f..72e295de 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -49,21 +49,31 @@ bool ObjectiveCGenerator::Generate(const FileDescriptor* file, const string& parameter, OutputDirectory* output_directory, string* error) const { - // ObjC doesn't have any options at the moment, error if passed one. + // ----------------------------------------------------------------- + // Parse generator options. + + Options generation_options; + vector<pair<string, string> > options; ParseGeneratorParameter(parameter, &options); for (int i = 0; i < options.size(); i++) { - *error = "error:: Unknown generator option: " + options[i].first; - return false; + if (options[i].first == "expected_prefixes_path") { + generation_options.expected_prefixes_path = options[i].second; + } else { + *error = "error: Unknown generator option: " + options[i].first; + return false; + } } + // ----------------------------------------------------------------- + // Validate the objc prefix/package pairing. - if (!ValidateObjCClassPrefix(file, error)) { + if (!ValidateObjCClassPrefix(file, generation_options, error)) { // *error will have been filled in. return false; } - FileGenerator file_generator(file); + FileGenerator file_generator(file, generation_options); string filepath = FilePath(file); // Generate header. diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 8527b74b..24ff2b56 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -58,6 +58,14 @@ namespace protobuf { namespace compiler { namespace objectivec { +Options::Options() { + // Default is the value of the env for the package prefixes. + const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES"); + if (file_path) { + expected_prefixes_path = file_path; + } +} + namespace { hash_set<string> MakeWordsMap(const char* const words[], size_t num_words) { @@ -763,16 +771,14 @@ string BuildCommentsString(const SourceLocation& location) { while (!lines.empty() && lines.back().empty()) { lines.pop_back(); } - string prefix("//"); + string prefix("///"); string suffix("\n"); string final_comments; for (int i = 0; i < lines.size(); i++) { - // We use $ for delimiters, so replace comments with dollars with - // html escaped version. - // None of the other compilers handle this (as of this writing) but we - // ran into it once, so just to be safe. + // HeaderDoc uses '\' and '@' for markers; escape them. + const string line = StringReplace(lines[i], "\\", "\\\\", true); final_comments += - prefix + StringReplace(lines[i], "$", "$", true) + suffix; + prefix + StringReplace(line, "@", "\\@", true) + suffix; } return final_comments; } @@ -890,26 +896,26 @@ bool Parser::ParseLoop() { return true; } -bool LoadExpectedPackagePrefixes(map<string, string>* prefix_map, - string* out_expect_file_path, +bool LoadExpectedPackagePrefixes(const Options &generation_options, + map<string, string>* prefix_map, string* out_error) { - const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES"); - if (file_path == NULL) { + if (generation_options.expected_prefixes_path.empty()) { return true; } int fd; do { - fd = open(file_path, O_RDONLY); + fd = open(generation_options.expected_prefixes_path.c_str(), O_RDONLY); } while (fd < 0 && errno == EINTR); if (fd < 0) { *out_error = - string(file_path) + ":0:0: error: Unable to open." + strerror(errno); + string("error: Unable to open \"") + + generation_options.expected_prefixes_path + + "\", " + strerror(errno); return false; } io::FileInputStream file_stream(fd); file_stream.SetCloseOnDelete(true); - *out_expect_file_path = file_path; Parser parser(prefix_map); const void* buf; @@ -920,8 +926,9 @@ bool LoadExpectedPackagePrefixes(map<string, string>* prefix_map, } if (!parser.ParseChunk(StringPiece(static_cast<const char*>(buf), buf_len))) { - *out_error = string(file_path) + ":" + SimpleItoa(parser.last_line()) + - ":0: error: " + parser.error_str(); + *out_error = + string("error: ") + generation_options.expected_prefixes_path + + " Line " + SimpleItoa(parser.last_line()) + ", " + parser.error_str(); return false; } } @@ -930,7 +937,9 @@ bool LoadExpectedPackagePrefixes(map<string, string>* prefix_map, } // namespace -bool ValidateObjCClassPrefix(const FileDescriptor* file, string* out_error) { +bool ValidateObjCClassPrefix(const FileDescriptor* file, + const Options& generation_options, + string* out_error) { const string prefix = file->options().objc_class_prefix(); const string package = file->package(); @@ -939,11 +948,10 @@ bool ValidateObjCClassPrefix(const FileDescriptor* file, string* out_error) { // Load any expected package prefixes to validate against those. map<string, string> expected_package_prefixes; - string expect_file_path; - if (!LoadExpectedPackagePrefixes(&expected_package_prefixes, - &expect_file_path, out_error)) { - // Any error, clear the entries that were read. - expected_package_prefixes.clear(); + if (!LoadExpectedPackagePrefixes(generation_options, + &expected_package_prefixes, + out_error)) { + return false; } // Check: Error - See if there was an expected prefix for the package and @@ -957,7 +965,7 @@ bool ValidateObjCClassPrefix(const FileDescriptor* file, string* out_error) { return true; } else { // ...it didn't match! - *out_error = "protoc:0: error: Expected 'option objc_class_prefix = \"" + + *out_error = "error: Expected 'option objc_class_prefix = \"" + package_match->second + "\";' in '" + file->name() + "'"; if (prefix.length()) { *out_error += "; but found '" + prefix + "' instead"; @@ -980,11 +988,11 @@ bool ValidateObjCClassPrefix(const FileDescriptor* file, string* out_error) { i != expected_package_prefixes.end(); ++i) { if (i->second == prefix) { *out_error = - "protoc:0: error: Found 'option objc_class_prefix = \"" + prefix + + "error: Found 'option objc_class_prefix = \"" + prefix + "\";' in '" + file->name() + "'; that prefix is already used for 'package " + i->first + ";'. It can only be reused by listing it in the expected file (" + - expect_file_path + ")."; + generation_options.expected_prefixes_path + ")."; return false; // Only report first usage of the prefix. } } @@ -1017,7 +1025,7 @@ bool ValidateObjCClassPrefix(const FileDescriptor* file, string* out_error) { << "protoc:0: warning: Found unexpected 'option objc_class_prefix = \"" << prefix << "\";' in '" << file->name() << "';" << " consider adding it to the expected prefixes file (" - << expect_file_path << ")." << endl; + << generation_options.expected_prefixes_path << ")." << endl; cerr.flush(); } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 85744862..a301493e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -42,6 +42,12 @@ namespace protobuf { namespace compiler { namespace objectivec { +// Generator options (see objectivec_generator.cc for a description of each): +struct Options { + Options(); + string expected_prefixes_path; +}; + // Strips ".proto" or ".protodevel" from the end of a filename. string StripProto(const string& filename); @@ -140,12 +146,15 @@ string DefaultValue(const FieldDescriptor* field); string BuildFlagsString(const vector<string>& strings); +// Builds a HeaderDoc style comment out of the comments in the .proto file. string BuildCommentsString(const SourceLocation& location); // Checks the prefix for a given file and outputs any warnings needed, if // there are flat out errors, then out_error is filled in and the result is // false. -bool ValidateObjCClassPrefix(const FileDescriptor* file, string *out_error); +bool ValidateObjCClassPrefix(const FileDescriptor* file, + const Options& generation_options, + string* out_error); // Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform // the input into the expected output. diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc index 2987f3db..2751e936 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc @@ -84,13 +84,14 @@ const char* MapEntryTypeName(const FieldDescriptor* descriptor, bool isKey) { } // namespace -MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor) - : RepeatedFieldGenerator(descriptor) { +MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor, + const Options& options) + : RepeatedFieldGenerator(descriptor, options) { const FieldDescriptor* key_descriptor = descriptor->message_type()->FindFieldByName("key"); const FieldDescriptor* value_descriptor = descriptor->message_type()->FindFieldByName("value"); - value_field_generator_.reset(FieldGenerator::Make(value_descriptor)); + value_field_generator_.reset(FieldGenerator::Make(value_descriptor, options)); // Pull over some variables_ from the value. variables_["field_type"] = value_field_generator_->variable("field_type"); @@ -117,16 +118,27 @@ MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor) variables_["fieldflags"] = BuildFlagsString(field_flags); ObjectiveCType value_objc_type = GetObjectiveCType(value_descriptor); - if ((GetObjectiveCType(key_descriptor) == OBJECTIVECTYPE_STRING) && + const bool value_is_object_type = ((value_objc_type == OBJECTIVECTYPE_STRING) || (value_objc_type == OBJECTIVECTYPE_DATA) || - (value_objc_type == OBJECTIVECTYPE_MESSAGE))) { + (value_objc_type == OBJECTIVECTYPE_MESSAGE)); + if ((GetObjectiveCType(key_descriptor) == OBJECTIVECTYPE_STRING) && + value_is_object_type) { variables_["array_storage_type"] = "NSMutableDictionary"; + variables_["array_property_type"] = + "NSMutableDictionary<NSString*, " + + value_field_generator_->variable("storage_type") + "*>"; } else { - string base_name = MapEntryTypeName(key_descriptor, true); - base_name += MapEntryTypeName(value_descriptor, false); - base_name += "Dictionary"; - variables_["array_storage_type"] = "GPB" + base_name; + string class_name("GPB"); + class_name += MapEntryTypeName(key_descriptor, true); + class_name += MapEntryTypeName(value_descriptor, false); + class_name += "Dictionary"; + variables_["array_storage_type"] = class_name; + if (value_is_object_type) { + variables_["array_property_type"] = + class_name + "<" + + value_field_generator_->variable("storage_type") + "*>"; + } } } @@ -138,15 +150,9 @@ void MapFieldGenerator::FinishInitialization(void) { // values in the map are. const FieldDescriptor* value_descriptor = descriptor_->message_type()->FindFieldByName("value"); - ObjectiveCType value_objc_type = GetObjectiveCType(value_descriptor); - if ((value_objc_type == OBJECTIVECTYPE_MESSAGE) || - (value_objc_type == OBJECTIVECTYPE_DATA) || - (value_objc_type == OBJECTIVECTYPE_STRING) || - (value_objc_type == OBJECTIVECTYPE_ENUM)) { + if (GetObjectiveCType(value_descriptor) == OBJECTIVECTYPE_ENUM) { variables_["array_comment"] = "// |" + variables_["name"] + "| values are |" + value_field_generator_->variable("storage_type") + "|\n"; - } else { - variables_["array_comment"] = ""; } } @@ -157,6 +163,19 @@ void MapFieldGenerator::GenerateFieldDescriptionTypeSpecific( value_field_generator_->GenerateFieldDescriptionTypeSpecific(printer); } +void MapFieldGenerator::DetermineForwardDeclarations( + set<string>* fwd_decls) const { + RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls); + const FieldDescriptor* value_descriptor = + descriptor_->message_type()->FindFieldByName("value"); + if (GetObjectiveCType(value_descriptor) == OBJECTIVECTYPE_MESSAGE) { + const string& value_storage_type = + value_field_generator_->variable("storage_type"); + fwd_decls->insert("@class " + value_storage_type); + } +} + + } // namespace objectivec } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h index 173541f2..7351ea05 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_map_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_map_field.h @@ -41,18 +41,22 @@ namespace compiler { namespace objectivec { class MapFieldGenerator : public RepeatedFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options); public: virtual void FinishInitialization(void); virtual void GenerateFieldDescriptionTypeSpecific(io::Printer* printer) const; protected: - explicit MapFieldGenerator(const FieldDescriptor* descriptor); + MapFieldGenerator(const FieldDescriptor* descriptor, const Options& options); virtual ~MapFieldGenerator(); + virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + private: scoped_ptr<FieldGenerator> value_field_generator_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator); }; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 32671d42..e0ea8bd2 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -174,10 +174,11 @@ const FieldDescriptor** SortFieldsByStorageSize(const Descriptor* descriptor) { } // namespace MessageGenerator::MessageGenerator(const string& root_classname, - const Descriptor* descriptor) + const Descriptor* descriptor, + const Options& options) : root_classname_(root_classname), descriptor_(descriptor), - field_generators_(descriptor), + field_generators_(descriptor, options), class_name_(ClassName(descriptor_)) { for (int i = 0; i < descriptor_->extension_count(); i++) { extension_generators_.push_back( @@ -196,7 +197,9 @@ MessageGenerator::MessageGenerator(const string& root_classname, for (int i = 0; i < descriptor_->nested_type_count(); i++) { MessageGenerator* generator = - new MessageGenerator(root_classname_, descriptor_->nested_type(i)); + new MessageGenerator(root_classname_, + descriptor_->nested_type(i), + options); nested_message_generators_.push_back(generator); } } @@ -230,11 +233,6 @@ void MessageGenerator::DetermineForwardDeclarations(set<string>* fwd_decls) { if (!IsMapEntryMessage(descriptor_)) { for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* fieldDescriptor = descriptor_->field(i); - // If it is a the field is repeated, the type will be and *Array, and we - // don't need any forward decl. - if (fieldDescriptor->is_repeated()) { - continue; - } field_generators_.get(fieldDescriptor) .DetermineForwardDeclarations(fwd_decls); } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h index 06b536ff..8565e76f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -54,7 +54,9 @@ class EnumGenerator; class MessageGenerator { public: - MessageGenerator(const string& root_classname, const Descriptor* descriptor); + MessageGenerator(const string& root_classname, + const Descriptor* descriptor, + const Options& options); ~MessageGenerator(); void GenerateStaticVariablesInitialization(io::Printer* printer); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc index f2ce4e5b..d6ccd6d1 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc @@ -58,8 +58,9 @@ void SetMessageVariables(const FieldDescriptor* descriptor, } // namespace -MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor) - : ObjCObjFieldGenerator(descriptor) { +MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor, + const Options& options) + : ObjCObjFieldGenerator(descriptor, options) { SetMessageVariables(descriptor, &variables_); } @@ -67,6 +68,7 @@ MessageFieldGenerator::~MessageFieldGenerator() {} void MessageFieldGenerator::DetermineForwardDeclarations( set<string>* fwd_decls) const { + ObjCObjFieldGenerator::DetermineForwardDeclarations(fwd_decls); // Class name is already in "storage_type". fwd_decls->insert("@class " + variable("storage_type")); } @@ -82,14 +84,24 @@ bool MessageFieldGenerator::WantsHasProperty(void) const { } RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator( - const FieldDescriptor* descriptor) - : RepeatedFieldGenerator(descriptor) { + const FieldDescriptor* descriptor, const Options& options) + : RepeatedFieldGenerator(descriptor, options) { SetMessageVariables(descriptor, &variables_); variables_["array_storage_type"] = "NSMutableArray"; + variables_["array_property_type"] = + "NSMutableArray<" + variables_["storage_type"] + "*>"; } RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {} +void RepeatedMessageFieldGenerator::DetermineForwardDeclarations( + set<string>* fwd_decls) const { + RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls); + // Class name is already in "storage_type". + fwd_decls->insert("@class " + variable("storage_type")); +} + + } // namespace objectivec } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h index 708ea566..d2dba153 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.h @@ -41,10 +41,12 @@ namespace compiler { namespace objectivec { class MessageFieldGenerator : public ObjCObjFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options); protected: - explicit MessageFieldGenerator(const FieldDescriptor* descriptor); + MessageFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); virtual ~MessageFieldGenerator(); virtual bool WantsHasProperty(void) const; @@ -56,12 +58,17 @@ class MessageFieldGenerator : public ObjCObjFieldGenerator { }; class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options); protected: - explicit RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor); + RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); virtual ~RepeatedMessageFieldGenerator(); + public: + virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); }; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc b/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc index 3cb87482..24e6df07 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc @@ -104,6 +104,7 @@ void OneofGenerator::GeneratePublicCasePropertyDeclaration( void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) { printer->Print( variables_, + "/// Clears whatever value was set for the oneof '$name$'.\n" "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_message_class$ *message);\n"); } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc index c185b66d..ea7f1b91 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc @@ -74,7 +74,7 @@ const char* PrimitiveTypeName(const FieldDescriptor* descriptor) { case OBJECTIVECTYPE_ENUM: return "int32_t"; case OBJECTIVECTYPE_MESSAGE: - return NULL; + return NULL; // Messages go through objectivec_message_field.cc|h. } // Some compilers report reaching end of function even though all cases of @@ -107,7 +107,8 @@ const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) { case OBJECTIVECTYPE_ENUM: return "Enum"; case OBJECTIVECTYPE_MESSAGE: - return ""; // Want NSArray + // Want NSArray (but goes through objectivec_message_field.cc|h). + return ""; } // Some compilers report reaching end of function even though all cases of @@ -126,16 +127,16 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, } // namespace PrimitiveFieldGenerator::PrimitiveFieldGenerator( - const FieldDescriptor* descriptor) - : SingleFieldGenerator(descriptor) { + const FieldDescriptor* descriptor, const Options& options) + : SingleFieldGenerator(descriptor, options) { SetPrimitiveVariables(descriptor, &variables_); } PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {} PrimitiveObjFieldGenerator::PrimitiveObjFieldGenerator( - const FieldDescriptor* descriptor) - : ObjCObjFieldGenerator(descriptor) { + const FieldDescriptor* descriptor, const Options& options) + : ObjCObjFieldGenerator(descriptor, options) { SetPrimitiveVariables(descriptor, &variables_); variables_["property_storage_attribute"] = "copy"; } @@ -143,8 +144,8 @@ PrimitiveObjFieldGenerator::PrimitiveObjFieldGenerator( PrimitiveObjFieldGenerator::~PrimitiveObjFieldGenerator() {} RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator( - const FieldDescriptor* descriptor) - : RepeatedFieldGenerator(descriptor) { + const FieldDescriptor* descriptor, const Options& options) + : RepeatedFieldGenerator(descriptor, options) { SetPrimitiveVariables(descriptor, &variables_); string base_name = PrimitiveArrayTypeName(descriptor); @@ -152,19 +153,13 @@ RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator( variables_["array_storage_type"] = "GPB" + base_name + "Array"; } else { variables_["array_storage_type"] = "NSMutableArray"; + variables_["array_property_type"] = + "NSMutableArray<" + variables_["storage_type"] + "*>"; } } RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {} -void RepeatedPrimitiveFieldGenerator::FinishInitialization(void) { - RepeatedFieldGenerator::FinishInitialization(); - if (IsPrimitiveType(descriptor_)) { - // No comment needed for primitive types. - variables_["array_comment"] = ""; - } -} - } // namespace objectivec } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h index 9bb79343..87139afb 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h @@ -41,10 +41,12 @@ namespace compiler { namespace objectivec { class PrimitiveFieldGenerator : public SingleFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options); protected: - explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor); + PrimitiveFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); virtual ~PrimitiveFieldGenerator(); private: @@ -52,10 +54,12 @@ class PrimitiveFieldGenerator : public SingleFieldGenerator { }; class PrimitiveObjFieldGenerator : public ObjCObjFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options); protected: - explicit PrimitiveObjFieldGenerator(const FieldDescriptor* descriptor); + PrimitiveObjFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); virtual ~PrimitiveObjFieldGenerator(); private: @@ -63,12 +67,13 @@ class PrimitiveObjFieldGenerator : public ObjCObjFieldGenerator { }; class RepeatedPrimitiveFieldGenerator : public RepeatedFieldGenerator { - friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field); + friend FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field, + const Options& options); protected: - explicit RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor); + RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, + const Options& options); virtual ~RepeatedPrimitiveFieldGenerator(); - virtual void FinishInitialization(void); private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index 9692f1bf..92c76fb0 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -75,6 +75,10 @@ std::string StripDotProto(const std::string& proto_file) { return proto_file.substr(0, lastindex); } +std::string GetOutputFilename(const std::string& proto_file) { + return StripDotProto(proto_file) + ".rb"; +} + std::string LabelForField(const google::protobuf::FieldDescriptor* field) { switch (field->label()) { case FieldDescriptor::LABEL_OPTIONAL: return "optional"; @@ -331,8 +335,69 @@ void EndPackageModules( } } -void GenerateFile(const google::protobuf::FileDescriptor* file, - google::protobuf::io::Printer* printer) { +bool UsesTypeFromFile(const Descriptor* message, const FileDescriptor* file, + string* error) { + for (int i = 0; i < message->field_count(); i++) { + const FieldDescriptor* field = message->field(i); + if ((field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && + field->message_type()->file() == file) || + (field->type() == FieldDescriptor::TYPE_ENUM && + field->enum_type()->file() == file)) { + *error = "proto3 message field " + field->full_name() + " in file " + + file->name() + " has a dependency on a type from proto2 file " + + file->name() + + ". Ruby doesn't support proto2 yet, so we must fail."; + return true; + } + } + + for (int i = 0; i < message->nested_type_count(); i++) { + if (UsesTypeFromFile(message->nested_type(i), file, error)) { + return true; + } + } + + return false; +} + +// Ruby doesn't currently support proto2. This causes a failure even for proto3 +// files that import proto2. But in some cases, the proto2 file is only being +// imported to extend another proto2 message. The prime example is declaring +// custom options by extending FileOptions/FieldOptions/etc. +// +// If the proto3 messages don't have any proto2 submessages, it is safe to omit +// the dependency completely. Users won't be able to use any proto2 extensions, +// but they already couldn't because proto2 messages aren't supported. +// +// If/when we add proto2 support, we should remove this. +bool MaybeEmitDependency(const FileDescriptor* import, + const FileDescriptor* from, + io::Printer* printer, + string* error) { + if (import->syntax() == FileDescriptor::SYNTAX_PROTO2) { + for (int i = 0; i < from->message_type_count(); i++) { + if (UsesTypeFromFile(from->message_type(i), import, error)) { + // Error text was already set by UsesTypeFromFile(). + return false; + } + } + + // Ok to omit this proto2 dependency -- so we won't print anything. + GOOGLE_LOG(WARNING) << "Omitting proto2 dependency '" << import->name() + << "' from proto3 output file '" + << GetOutputFilename(from->name()) + << "' because we don't support proto2 and no proto2 " + "types from that file are being used."; + return true; + } else { + printer->Print( + "require '$name$'\n", "name", StripDotProto(import->name())); + return true; + } +} + +bool GenerateFile(const FileDescriptor* file, io::Printer* printer, + string* error) { printer->Print( "# Generated by the protocol buffer compiler. DO NOT EDIT!\n" "# source: $filename$\n" @@ -343,9 +408,9 @@ void GenerateFile(const google::protobuf::FileDescriptor* file, "require 'google/protobuf'\n\n"); for (int i = 0; i < file->dependency_count(); i++) { - const std::string& name = file->dependency(i)->name(); - printer->Print( - "require '$name$'\n", "name", StripDotProto(name)); + if (!MaybeEmitDependency(file->dependency(i), file, printer, error)) { + return false; + } } printer->Print( @@ -369,6 +434,7 @@ void GenerateFile(const google::protobuf::FileDescriptor* file, GenerateEnumAssignment("", file->enum_type(i), printer); } EndPackageModules(levels, printer); + return true; } bool Generator::Generate( @@ -384,15 +450,11 @@ bool Generator::Generate( return false; } - std::string filename = - StripDotProto(file->name()) + ".rb"; scoped_ptr<io::ZeroCopyOutputStream> output( - generator_context->Open(filename)); + generator_context->Open(GetOutputFilename(file->name()))); io::Printer printer(output.get(), '$'); - GenerateFile(file, &printer); - - return true; + return GenerateFile(file, &printer, error); } } // namespace ruby diff --git a/src/google/protobuf/stubs/atomicops.h b/src/google/protobuf/stubs/atomicops.h index cb93227f..9b3d1e6b 100644 --- a/src/google/protobuf/stubs/atomicops.h +++ b/src/google/protobuf/stubs/atomicops.h @@ -214,6 +214,8 @@ Atomic64 Release_Load(volatile const Atomic64* ptr); #include <google/protobuf/stubs/atomicops_internals_power.h> #elif defined(__native_client__) #include <google/protobuf/stubs/atomicops_internals_pnacl.h> +#elif defined(GOOGLE_PROTOBUF_ARCH_PPC) +#include <google/protobuf/stubs/atomicops_internals_ppc_gcc.h> #elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) #include <google/protobuf/stubs/atomicops_internals_generic_gcc.h> #elif defined(__clang__) diff --git a/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h b/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h new file mode 100644 index 00000000..8231a578 --- /dev/null +++ b/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h @@ -0,0 +1,155 @@ +// 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. + +// Author: ogabbay@advaoptical.com (Oded Gabbay) +// Cleaned up by: bsilver16384@gmail.com (Brian Silverman) +// +// This file is an internal atomic implementation, use atomicops.h instead. + +#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PPC_GCC_H_ +#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PPC_GCC_H_ + +#define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory") + +namespace google { +namespace protobuf { +namespace internal { + +inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32 *ptr, + Atomic32 old_value, + Atomic32 new_value) { + Atomic32 prev; + + __asm__ __volatile__( + "0: \n\t" + "lwarx %[prev],0,%[ptr] \n\t" + "cmpw 0,%[prev],%[old_value] \n\t" + "bne- 1f \n\t" + "stwcx. %[new_value],0,%[ptr] \n\t" + "bne- 0b \n\t" + "1: \n\t" + : [prev] "=&r"(prev), "+m"(*ptr) + : [ptr] "r"(ptr), [old_value] "r"(old_value), [new_value] "r"(new_value) + : "cc", "memory"); + + return prev; +} + +inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32 *ptr, + Atomic32 new_value) { + Atomic32 old; + + __asm__ __volatile__( + "0: \n\t" + "lwarx %[old],0,%[ptr] \n\t" + "stwcx. %[new_value],0,%[ptr] \n\t" + "bne- 0b \n\t" + : [old] "=&r"(old), "+m"(*ptr) + : [ptr] "r"(ptr), [new_value] "r"(new_value) + : "cc", "memory"); + + return old; +} + +inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr, + Atomic32 increment) { + Atomic32 temp; + + __asm__ __volatile__( + "0: \n\t" + "lwarx %[temp],0,%[ptr] \n\t" + "add %[temp],%[increment],%[temp] \n\t" + "stwcx. %[temp],0,%[ptr] \n\t" + "bne- 0b \n\t" + : [temp] "=&r"(temp) + : [increment] "r"(increment), [ptr] "r"(ptr) + : "cc", "memory"); + + return temp; +} + +inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr, + Atomic32 increment) { + MemoryBarrier(); + Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment); + MemoryBarrier(); + return res; +} + +inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr, + Atomic32 old_value, Atomic32 new_value) { + Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); + MemoryBarrier(); + return res; +} + +inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr, + Atomic32 old_value, Atomic32 new_value) { + MemoryBarrier(); + Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); + return res; +} + +inline void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value) { + *ptr = value; +} + +inline void MemoryBarrier() { __asm__ __volatile__("sync" : : : "memory"); } + +inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) { + *ptr = value; + MemoryBarrier(); +} + +inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) { + MemoryBarrier(); + *ptr = value; +} + +inline Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr) { return *ptr; } + +inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) { + Atomic32 value = *ptr; + MemoryBarrier(); + return value; +} + +inline Atomic32 Release_Load(volatile const Atomic32 *ptr) { + MemoryBarrier(); + return *ptr; +} + +} // namespace internal +} // namespace protobuf +} // namespace google + +#undef ATOMICOPS_COMPILER_BARRIER + +#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PPC_GCC_H_ diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h index 22b35723..4ba4b348 100644 --- a/src/google/protobuf/stubs/platform_macros.h +++ b/src/google/protobuf/stubs/platform_macros.h @@ -73,6 +73,9 @@ #elif defined(_POWER) || defined(__powerpc64__) || defined(__PPC64__) #define GOOGLE_PROTOBUF_ARCH_POWER 1 #define GOOGLE_PROTOBUF_ARCH_64_BIT 1 +#elif defined(__PPC__) +#define GOOGLE_PROTOBUF_ARCH_PPC 1 +#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 #elif defined(__GNUC__) # if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) // We fallback to the generic Clang/GCC >= 4.7 implementation in atomicops.h diff --git a/util/python/BUILD b/util/python/BUILD index 358c381c..3ac03856 100644 --- a/util/python/BUILD +++ b/util/python/BUILD @@ -1,7 +1,17 @@ # This is a placeholder for python headers. Projects needing to use # fast cpp protos in protobuf's python interface should build with # --define=use_fast_cpp_protos=true, and in addition, provide -# //util/python:python_headers dependency that in turn provides Python.h. +# //external:python_headers dependency that in turn provides Python.h. +# +# Projects that include protobuf using a Bazel external repository will need to +# add a workspace rule to their WORKSPACE files to add an external workspace +# that includes the Python headers. For example, the protobuf WORKSPACE file +# includes the following local_repository rule that points to this directory: +# +# new_local_repository( +# name = "python", +# path = __workspace_dir__ + "/util/python", +# ) cc_library( name = "python_headers", visibility = ["//visibility:public"], |