PROTOBUF_SYNC_PIPER
pull/7698/head
Joshua Haberman 4 years ago
commit 6ba52411d0
  1. 3
      .gitignore
  2. 32
      Makefile.am
  3. 2
      Protobuf-C++.podspec
  4. 2
      configure.ac
  5. 53
      conformance/failure_list_php_c.txt
  6. 86
      conformance/failure_list_php_c_32.txt
  7. 4
      csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj
  8. 42
      csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs
  9. 418
      csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs
  10. 84
      csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
  11. 17
      csharp/src/Google.Protobuf.Test/ReadOnlySequenceFactory.cs
  12. BIN
      csharp/src/Google.Protobuf.Test/testprotos.pb
  13. 20
      csharp/src/Google.Protobuf/Collections/RepeatedField.cs
  14. 12
      csharp/src/Google.Protobuf/ParserInternalState.cs
  15. 182
      csharp/src/Google.Protobuf/ParsingPrimitives.cs
  16. 2
      generate_descriptor_proto.sh
  17. 34
      js/gulpfile.js
  18. 2
      js/package.json
  19. 234
      js/proto3_test.js
  20. 58
      js/proto3_test.proto
  21. 0
      php/ext/google/protobuf/arena.c
  22. 0
      php/ext/google/protobuf/arena.h
  23. 777
      php/ext/google/protobuf/array.c
  24. 0
      php/ext/google/protobuf/array.h
  25. 635
      php/ext/google/protobuf/builtin_descriptors.inc
  26. 0
      php/ext/google/protobuf/bundled_php.h
  27. 2
      php/ext/google/protobuf/config.m4
  28. 0
      php/ext/google/protobuf/convert.c
  29. 0
      php/ext/google/protobuf/convert.h
  30. 1578
      php/ext/google/protobuf/def.c
  31. 0
      php/ext/google/protobuf/def.h
  32. 2283
      php/ext/google/protobuf/encode_decode.c
  33. 2
      php/ext/google/protobuf/make-preload.php
  34. 918
      php/ext/google/protobuf/map.c
  35. 0
      php/ext/google/protobuf/map.h
  36. 3231
      php/ext/google/protobuf/message.c
  37. 0
      php/ext/google/protobuf/message.h
  38. 0
      php/ext/google/protobuf/names.c
  39. 0
      php/ext/google/protobuf/names.h
  40. 22
      php/ext/google/protobuf/package.xml
  41. 0
      php/ext/google/protobuf/php-upb.c
  42. 0
      php/ext/google/protobuf/php-upb.h
  43. 730
      php/ext/google/protobuf/protobuf.c
  44. 1586
      php/ext/google/protobuf/protobuf.h
  45. 1180
      php/ext/google/protobuf/storage.c
  46. 680
      php/ext/google/protobuf/type_check.c
  47. 13840
      php/ext/google/protobuf/upb.c
  48. 6796
      php/ext/google/protobuf/upb.h
  49. 68
      php/ext/google/protobuf/utf8.c
  50. 36
      php/ext/google/protobuf/utf8.h
  51. 602
      php/ext/google/protobuf2/array.c
  52. 10
      php/ext/google/protobuf2/config.m4
  53. 1085
      php/ext/google/protobuf2/def.c
  54. 590
      php/ext/google/protobuf2/map.c
  55. 841
      php/ext/google/protobuf2/message.c
  56. 349
      php/ext/google/protobuf2/protobuf.c
  57. 89
      php/ext/google/protobuf2/protobuf.h
  58. 2
      php/src/Google/Protobuf/Internal/Descriptor.php
  59. 4
      php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
  60. 4
      php/src/Google/Protobuf/Internal/FieldOptions.php
  61. 2
      php/src/Google/Protobuf/Internal/FileOptions.php
  62. 2
      php/src/Google/Protobuf/Internal/MethodOptions.php
  63. 11
      php/tests/compile_extension.sh
  64. 2
      php/tests/php_implementation_test.php
  65. 17
      php/tests/test.sh
  66. 2
      python/google/protobuf/__init__.py
  67. 2
      src/Makefile.am
  68. 2
      src/google/protobuf/any.pb.h
  69. 2
      src/google/protobuf/api.pb.h
  70. 8
      src/google/protobuf/compiler/command_line_interface.cc
  71. 9
      src/google/protobuf/compiler/importer.cc
  72. 42
      src/google/protobuf/compiler/js/js_generator.cc
  73. 17
      src/google/protobuf/compiler/js/js_generator.h
  74. 12
      src/google/protobuf/compiler/php/php_generator.cc
  75. 2
      src/google/protobuf/compiler/plugin.pb.h
  76. 2
      src/google/protobuf/compiler/python/python_generator.cc
  77. 2
      src/google/protobuf/descriptor.pb.h
  78. 2
      src/google/protobuf/duration.pb.h
  79. 2
      src/google/protobuf/empty.pb.h
  80. 2
      src/google/protobuf/field_mask.pb.h
  81. 4
      src/google/protobuf/generated_message_reflection.cc
  82. 2
      src/google/protobuf/generated_message_util.cc
  83. 10
      src/google/protobuf/port_def.inc
  84. 41
      src/google/protobuf/proto3_arena_unittest.cc
  85. 2
      src/google/protobuf/source_context.pb.h
  86. 2
      src/google/protobuf/struct.pb.h
  87. 2
      src/google/protobuf/stubs/common.h
  88. 2
      src/google/protobuf/timestamp.pb.h
  89. 2
      src/google/protobuf/type.pb.h
  90. 9
      src/google/protobuf/unittest_proto3_optional.proto
  91. 2
      src/google/protobuf/wrappers.pb.h

3
.gitignore vendored

@ -209,3 +209,6 @@ cmake/cmake-build-debug/
# IntelliJ
.idea
*.iml
# BenchmarkDotNet
BenchmarkDotNet.Artifacts/

@ -96,11 +96,14 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.Benchmarks/Program.cs \
csharp/src/Google.Protobuf.Benchmarks/wrapper_benchmark_messages.proto \
csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs \
csharp/src/Google.Protobuf.Benchmarks/WriteMessagesBenchmark.cs \
csharp/src/Google.Protobuf.Benchmarks/WriteRawPrimitivesBenchmark.cs \
csharp/src/Google.Protobuf.Conformance/Conformance.cs \
csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj \
csharp/src/Google.Protobuf.Conformance/Program.cs \
csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj \
csharp/src/Google.Protobuf.JsonDump/Program.cs \
csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs \
csharp/src/Google.Protobuf.Test/ByteStringTest.cs \
csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs \
csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs \
@ -127,6 +130,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs \
csharp/src/Google.Protobuf.Test/Proto3OptionalTest.cs \
csharp/src/Google.Protobuf.Test/ReadOnlySequenceFactory.cs \
csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs \
@ -258,6 +262,11 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs \
csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs \
csharp/src/Google.Protobuf/WireFormat.cs \
csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs \
csharp/src/Google.Protobuf/WritingPrimitives.cs \
csharp/src/Google.Protobuf/WriterInternalState.cs \
csharp/src/Google.Protobuf/WriteContext.cs \
csharp/src/Google.Protobuf/WriteBufferHelper.cs \
csharp/src/Google.Protobuf/UnknownField.cs \
csharp/src/Google.Protobuf/UnknownFieldSet.cs
@ -758,22 +767,28 @@ php_EXTRA_DIST= \
composer.json \
php/README.md \
php/composer.json \
php/ext/google/protobuf/arena.c \
php/ext/google/protobuf/arena.h \
php/ext/google/protobuf/array.c \
php/ext/google/protobuf/builtin_descriptors.inc \
php/ext/google/protobuf/array.h \
php/ext/google/protobuf/bundled_php.h \
php/ext/google/protobuf/config.m4 \
php/ext/google/protobuf/convert.c \
php/ext/google/protobuf/convert.h \
php/ext/google/protobuf/def.c \
php/ext/google/protobuf/encode_decode.c \
php/ext/google/protobuf/def.h \
php/ext/google/protobuf/make-preload.php \
php/ext/google/protobuf/map.c \
php/ext/google/protobuf/map.h \
php/ext/google/protobuf/message.c \
php/ext/google/protobuf/message.h \
php/ext/google/protobuf/names.c \
php/ext/google/protobuf/names.h \
php/ext/google/protobuf/package.xml \
php/ext/google/protobuf/php-upb.c \
php/ext/google/protobuf/php-upb.h \
php/ext/google/protobuf/protobuf.c \
php/ext/google/protobuf/protobuf.h \
php/ext/google/protobuf/storage.c \
php/ext/google/protobuf/type_check.c \
php/ext/google/protobuf/upb.c \
php/ext/google/protobuf/upb.h \
php/ext/google/protobuf/utf8.c \
php/ext/google/protobuf/utf8.h \
php/generate_descriptor_protos.sh \
php/phpunit.xml \
php/release.sh \
@ -908,6 +923,7 @@ php_EXTRA_DIST= \
php/tests/descriptors_test.php \
php/tests/encode_decode_test.php \
php/tests/gdb_test.sh \
php/tests/generate_protos.sh \
php/tests/generated_class_test.php \
php/tests/generated_phpdoc_test.php \
php/tests/generated_service_test.php \

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Protobuf-C++'
s.version = '3.12.2'
s.version = '3.12.3'
s.summary = 'Protocol Buffers v3 runtime library for C++.'
s.homepage = 'https://github.com/google/protobuf'
s.license = '3-Clause BSD License'

@ -17,7 +17,7 @@ AC_PREREQ(2.59)
# In the SVN trunk, the version should always be the next anticipated release
# version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed
# the size of one file name in the dist tarfile over the 99-char limit.)
AC_INIT([Protocol Buffers],[3.12.2],[protobuf@googlegroups.com],[protobuf])
AC_INIT([Protocol Buffers],[3.12.3],[protobuf@googlegroups.com],[protobuf])
AM_MAINTAINER_MODE([enable])

@ -1,23 +1,4 @@
Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput
Recommended.FieldMaskPathsDontRoundTrip.JsonOutput
Recommended.FieldMaskTooManyUnderscore.JsonOutput
Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.OneofZeroBytes.JsonOutput
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull
Recommended.Proto3.JsonInput.StringEndsWithEscapeChar
Recommended.Proto3.JsonInput.StringFieldSurrogateInWrongOrder
Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator
Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.DefaultOutput.ProtobufOutput
@ -28,10 +9,8 @@ Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.DefaultO
Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.DefaultOutput.ProtobufOutput
@ -76,36 +55,4 @@ Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOut
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[3].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput
Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput
Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput
Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput
Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput
Required.Proto3.JsonInput.DurationMinValue.JsonOutput
Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput
Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput
Required.Proto3.JsonInput.FloatFieldNan.JsonOutput
Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput
Required.Proto3.JsonInput.OneofFieldDuplicate
Required.Proto3.JsonInput.RejectTopLevelNull
Required.Proto3.JsonInput.StringFieldSurrogatePair.JsonOutput
Required.Proto3.JsonInput.StringFieldSurrogatePair.ProtobufOutput
Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput
Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput
Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput
Required.Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput
Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.BYTES.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.STRING.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput
Required.TimestampProtoInputTooLarge.JsonOutput
Required.TimestampProtoInputTooSmall.JsonOutput

@ -1,28 +1,4 @@
Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput
Recommended.FieldMaskPathsDontRoundTrip.JsonOutput
Recommended.FieldMaskTooManyUnderscore.JsonOutput
Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas9FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHasZeroFractionalDigit.Validator
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.OneofZeroBytes.JsonOutput
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull
Recommended.Proto3.JsonInput.StringEndsWithEscapeChar
Recommended.Proto3.JsonInput.StringFieldSurrogateInWrongOrder
Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas9FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHasZeroFractionalDigit.Validator
Recommended.Proto3.JsonInput.TimestampZeroNormalized.Validator
Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.DefaultOutput.ProtobufOutput
@ -33,10 +9,8 @@ Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.DefaultO
Recommended.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.DefaultOutput.ProtobufOutput
@ -81,64 +55,4 @@ Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOut
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[3].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput
Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput
Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput
Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput
Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput
Required.Proto3.JsonInput.DurationMaxValue.JsonOutput
Required.Proto3.JsonInput.DurationMaxValue.ProtobufOutput
Required.Proto3.JsonInput.DurationMinValue.JsonOutput
Required.Proto3.JsonInput.DurationMinValue.ProtobufOutput
Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput
Required.Proto3.JsonInput.DurationRepeatedValue.ProtobufOutput
Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput
Required.Proto3.JsonInput.FloatFieldNan.JsonOutput
Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput
Required.Proto3.JsonInput.Int64FieldMaxValue.JsonOutput
Required.Proto3.JsonInput.Int64FieldMaxValueNotQuoted.JsonOutput
Required.Proto3.JsonInput.Int64FieldMaxValueNotQuoted.ProtobufOutput
Required.Proto3.JsonInput.Int64FieldMaxValue.ProtobufOutput
Required.Proto3.JsonInput.Int64FieldMinValue.JsonOutput
Required.Proto3.JsonInput.Int64FieldMinValueNotQuoted.JsonOutput
Required.Proto3.JsonInput.Int64FieldMinValueNotQuoted.ProtobufOutput
Required.Proto3.JsonInput.Int64FieldMinValue.ProtobufOutput
Required.Proto3.JsonInput.OneofFieldDuplicate
Required.Proto3.JsonInput.RejectTopLevelNull
Required.Proto3.JsonInput.StringFieldSurrogatePair.JsonOutput
Required.Proto3.JsonInput.StringFieldSurrogatePair.ProtobufOutput
Required.Proto3.JsonInput.TimestampLeap.JsonOutput
Required.Proto3.JsonInput.TimestampLeap.ProtobufOutput
Required.Proto3.JsonInput.TimestampMaxValue.JsonOutput
Required.Proto3.JsonInput.TimestampMaxValue.ProtobufOutput
Required.Proto3.JsonInput.TimestampMinValue.JsonOutput
Required.Proto3.JsonInput.TimestampMinValue.ProtobufOutput
Required.Proto3.JsonInput.TimestampRepeatedValue.JsonOutput
Required.Proto3.JsonInput.TimestampRepeatedValue.ProtobufOutput
Required.Proto3.JsonInput.TimestampWithNegativeOffset.JsonOutput
Required.Proto3.JsonInput.TimestampWithNegativeOffset.ProtobufOutput
Required.Proto3.JsonInput.TimestampWithPositiveOffset.JsonOutput
Required.Proto3.JsonInput.TimestampWithPositiveOffset.ProtobufOutput
Required.Proto3.JsonInput.Uint64FieldMaxValue.JsonOutput
Required.Proto3.JsonInput.Uint64FieldMaxValueNotQuoted.JsonOutput
Required.Proto3.JsonInput.Uint64FieldMaxValueNotQuoted.ProtobufOutput
Required.Proto3.JsonInput.Uint64FieldMaxValue.ProtobufOutput
Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput
Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput
Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput
Required.Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput
Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.BYTES.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.STRING.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput
Required.TimestampProtoInputTooLarge.JsonOutput
Required.TimestampProtoInputTooSmall.JsonOutput

@ -11,6 +11,10 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Google.Protobuf.Test\ReadOnlySequenceFactory.cs" Link="ReadOnlySequenceFactory.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<ProjectReference Include="..\Google.Protobuf\Google.Protobuf.csproj" />

@ -54,10 +54,12 @@ namespace Google.Protobuf.Benchmarks
// key is the encodedSize of string values
Dictionary<int, byte[]> stringInputBuffers;
Dictionary<int, ReadOnlySequence<byte>> stringInputBuffersSegmented;
Random random = new Random(417384220); // random but deterministic seed
public IEnumerable<int> StringEncodedSizes => new[] { 1, 4, 10, 105, 10080 };
public IEnumerable<int> StringSegmentedEncodedSizes => new[] { 105, 10080 };
[GlobalSetup]
public void GlobalSetup()
@ -78,11 +80,18 @@ namespace Google.Protobuf.Benchmarks
fixedIntInputBuffer = CreateBufferWithRandomData(random, BytesToParse / sizeof(long), sizeof(long), paddingValueCount);
stringInputBuffers = new Dictionary<int, byte[]>();
foreach(var encodedSize in StringEncodedSizes)
foreach (var encodedSize in StringEncodedSizes)
{
byte[] buffer = CreateBufferWithStrings(BytesToParse / encodedSize, encodedSize, encodedSize < 10 ? 10 : 1 );
stringInputBuffers.Add(encodedSize, buffer);
}
stringInputBuffersSegmented = new Dictionary<int, ReadOnlySequence<byte>>();
foreach (var encodedSize in StringSegmentedEncodedSizes)
{
byte[] buffer = CreateBufferWithStrings(BytesToParse / encodedSize, encodedSize, encodedSize < 10 ? 10 : 1);
stringInputBuffersSegmented.Add(encodedSize, ReadOnlySequenceFactory.CreateWithContent(buffer, segmentSize: 128, addEmptySegmentDelimiters: false));
}
}
// Total number of bytes that each benchmark will parse.
@ -300,6 +309,19 @@ namespace Google.Protobuf.Benchmarks
return sum;
}
[Benchmark]
[ArgumentsSource(nameof(StringSegmentedEncodedSizes))]
public int ParseString_ParseContext_MultipleSegments(int encodedSize)
{
InitializeParseContext(stringInputBuffersSegmented[encodedSize], out ParseContext ctx);
int sum = 0;
for (int i = 0; i < BytesToParse / encodedSize; i++)
{
sum += ctx.ReadString().Length;
}
return sum;
}
[Benchmark]
[ArgumentsSource(nameof(StringEncodedSizes))]
public int ParseBytes_CodedInputStream(int encodedSize)
@ -326,11 +348,29 @@ namespace Google.Protobuf.Benchmarks
return sum;
}
[Benchmark]
[ArgumentsSource(nameof(StringSegmentedEncodedSizes))]
public int ParseBytes_ParseContext_MultipleSegments(int encodedSize)
{
InitializeParseContext(stringInputBuffersSegmented[encodedSize], out ParseContext ctx);
int sum = 0;
for (int i = 0; i < BytesToParse / encodedSize; i++)
{
sum += ctx.ReadBytes().Length;
}
return sum;
}
private static void InitializeParseContext(byte[] buffer, out ParseContext ctx)
{
ParseContext.Initialize(new ReadOnlySequence<byte>(buffer), out ctx);
}
private static void InitializeParseContext(ReadOnlySequence<byte> buffer, out ParseContext ctx)
{
ParseContext.Initialize(buffer, out ctx);
}
private static byte[] CreateBufferWithRandomVarints(Random random, int valueCount, int encodedSize, int paddingValueCount)
{
MemoryStream ms = new MemoryStream();

@ -55,12 +55,19 @@ namespace ProtobufUnittest {
"X2Jvb2xCEgoQX29wdGlvbmFsX3N0cmluZ0IRCg9fb3B0aW9uYWxfYnl0ZXNC",
"EAoOX29wdGlvbmFsX2NvcmRCGgoYX29wdGlvbmFsX25lc3RlZF9tZXNzYWdl",
"QhYKFF9sYXp5X25lc3RlZF9tZXNzYWdlQhcKFV9vcHRpb25hbF9uZXN0ZWRf",
"ZW51bUIlCiFjb20uZ29vZ2xlLnByb3RvYnVmLnRlc3RpbmcucHJvdG9QAWIG",
"cHJvdG8z"));
"ZW51bSKJAgoZVGVzdFByb3RvM09wdGlvbmFsTWVzc2FnZRJSCg5uZXN0ZWRf",
"bWVzc2FnZRgBIAEoCzI6LnByb3RvYnVmX3VuaXR0ZXN0LlRlc3RQcm90bzNP",
"cHRpb25hbE1lc3NhZ2UuTmVzdGVkTWVzc2FnZRJgChdvcHRpb25hbF9uZXN0",
"ZWRfbWVzc2FnZRgCIAEoCzI6LnByb3RvYnVmX3VuaXR0ZXN0LlRlc3RQcm90",
"bzNPcHRpb25hbE1lc3NhZ2UuTmVzdGVkTWVzc2FnZUgAiAEBGhoKDU5lc3Rl",
"ZE1lc3NhZ2USCQoBcxgBIAEoCUIaChhfb3B0aW9uYWxfbmVzdGVkX21lc3Nh",
"Z2VCJQohY29tLmdvb2dsZS5wcm90b2J1Zi50ZXN0aW5nLnByb3RvUAFiBnBy",
"b3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3Optional), global::ProtobufUnittest.TestProto3Optional.Parser, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalCord", "OptionalNestedMessage", "LazyNestedMessage", "OptionalNestedEnum", "SingularInt32", "SingularInt64" }, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalCord", "OptionalNestedMessage", "LazyNestedMessage", "OptionalNestedEnum" }, new[]{ typeof(global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3Optional.Types.NestedMessage), global::ProtobufUnittest.TestProto3Optional.Types.NestedMessage.Parser, new[]{ "Bb" }, new[]{ "Bb" }, null, null, null)})
new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3Optional), global::ProtobufUnittest.TestProto3Optional.Parser, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalCord", "OptionalNestedMessage", "LazyNestedMessage", "OptionalNestedEnum", "SingularInt32", "SingularInt64" }, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalCord", "OptionalNestedMessage", "LazyNestedMessage", "OptionalNestedEnum" }, new[]{ typeof(global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3Optional.Types.NestedMessage), global::ProtobufUnittest.TestProto3Optional.Types.NestedMessage.Parser, new[]{ "Bb" }, new[]{ "Bb" }, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3OptionalMessage), global::ProtobufUnittest.TestProto3OptionalMessage.Parser, new[]{ "NestedMessage", "OptionalNestedMessage" }, new[]{ "OptionalNestedMessage" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage), global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage.Parser, new[]{ "S" }, null, null, null, null)})
}));
}
#endregion
@ -1377,6 +1384,411 @@ namespace ProtobufUnittest {
}
public sealed partial class TestProto3OptionalMessage : pb::IMessage<TestProto3OptionalMessage>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<TestProto3OptionalMessage> _parser = new pb::MessageParser<TestProto3OptionalMessage>(() => new TestProto3OptionalMessage());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<TestProto3OptionalMessage> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::ProtobufUnittest.UnittestProto3OptionalReflection.Descriptor.MessageTypes[1]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public TestProto3OptionalMessage() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public TestProto3OptionalMessage(TestProto3OptionalMessage other) : this() {
nestedMessage_ = other.nestedMessage_ != null ? other.nestedMessage_.Clone() : null;
optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public TestProto3OptionalMessage Clone() {
return new TestProto3OptionalMessage(this);
}
/// <summary>Field number for the "nested_message" field.</summary>
public const int NestedMessageFieldNumber = 1;
private global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage nestedMessage_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage NestedMessage {
get { return nestedMessage_; }
set {
nestedMessage_ = value;
}
}
/// <summary>Field number for the "optional_nested_message" field.</summary>
public const int OptionalNestedMessageFieldNumber = 2;
private global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage optionalNestedMessage_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage OptionalNestedMessage {
get { return optionalNestedMessage_; }
set {
optionalNestedMessage_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as TestProto3OptionalMessage);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(TestProto3OptionalMessage other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (!object.Equals(NestedMessage, other.NestedMessage)) return false;
if (!object.Equals(OptionalNestedMessage, other.OptionalNestedMessage)) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (nestedMessage_ != null) hash ^= NestedMessage.GetHashCode();
if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (nestedMessage_ != null) {
output.WriteRawTag(10);
output.WriteMessage(NestedMessage);
}
if (optionalNestedMessage_ != null) {
output.WriteRawTag(18);
output.WriteMessage(OptionalNestedMessage);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (nestedMessage_ != null) {
output.WriteRawTag(10);
output.WriteMessage(NestedMessage);
}
if (optionalNestedMessage_ != null) {
output.WriteRawTag(18);
output.WriteMessage(OptionalNestedMessage);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (nestedMessage_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(NestedMessage);
}
if (optionalNestedMessage_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(TestProto3OptionalMessage other) {
if (other == null) {
return;
}
if (other.nestedMessage_ != null) {
if (nestedMessage_ == null) {
NestedMessage = new global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage();
}
NestedMessage.MergeFrom(other.NestedMessage);
}
if (other.optionalNestedMessage_ != null) {
if (optionalNestedMessage_ == null) {
OptionalNestedMessage = new global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage();
}
OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage);
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
if (nestedMessage_ == null) {
NestedMessage = new global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage();
}
input.ReadMessage(NestedMessage);
break;
}
case 18: {
if (optionalNestedMessage_ == null) {
OptionalNestedMessage = new global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage();
}
input.ReadMessage(OptionalNestedMessage);
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
if (nestedMessage_ == null) {
NestedMessage = new global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage();
}
input.ReadMessage(NestedMessage);
break;
}
case 18: {
if (optionalNestedMessage_ == null) {
OptionalNestedMessage = new global::ProtobufUnittest.TestProto3OptionalMessage.Types.NestedMessage();
}
input.ReadMessage(OptionalNestedMessage);
break;
}
}
}
}
#endif
#region Nested types
/// <summary>Container for nested types declared in the TestProto3OptionalMessage message type.</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static partial class Types {
public sealed partial class NestedMessage : pb::IMessage<NestedMessage>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::ProtobufUnittest.TestProto3OptionalMessage.Descriptor.NestedTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public NestedMessage() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public NestedMessage(NestedMessage other) : this() {
s_ = other.s_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public NestedMessage Clone() {
return new NestedMessage(this);
}
/// <summary>Field number for the "s" field.</summary>
public const int SFieldNumber = 1;
private string s_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string S {
get { return s_; }
set {
s_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as NestedMessage);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(NestedMessage other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (S != other.S) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (S.Length != 0) hash ^= S.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (S.Length != 0) {
output.WriteRawTag(10);
output.WriteString(S);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (S.Length != 0) {
output.WriteRawTag(10);
output.WriteString(S);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (S.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(S);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(NestedMessage other) {
if (other == null) {
return;
}
if (other.S.Length != 0) {
S = other.S;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
S = input.ReadString();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
S = input.ReadString();
break;
}
}
}
}
#endif
}
}
#endregion
}
#endregion
}

@ -324,7 +324,25 @@ namespace Google.Protobuf
Assert.AreEqual(message, message2);
}
}
[Test]
public void ReadWholeMessage_VaryingBlockSizes_FromSequence()
{
TestAllTypes message = SampleMessages.CreateFullTestAllTypes();
byte[] rawBytes = message.ToByteArray();
Assert.AreEqual(rawBytes.Length, message.CalculateSize());
TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(rawBytes);
Assert.AreEqual(message, message2);
// Try different block sizes.
for (int blockSize = 1; blockSize < 256; blockSize *= 2)
{
message2 = TestAllTypes.Parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(rawBytes, blockSize));
Assert.AreEqual(message, message2);
}
}
[Test]
public void ReadHugeBlob()
{
@ -365,6 +383,70 @@ namespace Google.Protobuf
Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes());
}
[Test]
public void ReadBlobGreaterThanCurrentLimit()
{
MemoryStream ms = new MemoryStream();
CodedOutputStream output = new CodedOutputStream(ms);
uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
output.WriteRawVarint32(tag);
output.WriteRawVarint32(4);
output.WriteRawBytes(new byte[4]); // Pad with a few random bytes.
output.Flush();
ms.Position = 0;
CodedInputStream input = new CodedInputStream(ms);
Assert.AreEqual(tag, input.ReadTag());
// Specify limit smaller than data length
input.PushLimit(3);
Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes());
AssertReadFromParseContext(new ReadOnlySequence<byte>(ms.ToArray()), (ref ParseContext ctx) =>
{
Assert.AreEqual(tag, ctx.ReadTag());
SegmentedBufferHelper.PushLimit(ref ctx.state, 3);
try
{
ctx.ReadBytes();
Assert.Fail();
}
catch (InvalidProtocolBufferException) {}
}, true);
}
[Test]
public void ReadStringGreaterThanCurrentLimit()
{
MemoryStream ms = new MemoryStream();
CodedOutputStream output = new CodedOutputStream(ms);
uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
output.WriteRawVarint32(tag);
output.WriteRawVarint32(4);
output.WriteRawBytes(new byte[4]); // Pad with a few random bytes.
output.Flush();
ms.Position = 0;
CodedInputStream input = new CodedInputStream(ms.ToArray());
Assert.AreEqual(tag, input.ReadTag());
// Specify limit smaller than data length
input.PushLimit(3);
Assert.Throws<InvalidProtocolBufferException>(() => input.ReadString());
AssertReadFromParseContext(new ReadOnlySequence<byte>(ms.ToArray()), (ref ParseContext ctx) =>
{
Assert.AreEqual(tag, ctx.ReadTag());
SegmentedBufferHelper.PushLimit(ref ctx.state, 3);
try
{
ctx.ReadString();
Assert.Fail();
}
catch (InvalidProtocolBufferException) { }
}, true);
}
// Representations of a tag for field 0 with various wire types
[Test]
[TestCase(0)]

@ -41,11 +41,18 @@ namespace Google.Protobuf
{
internal static class ReadOnlySequenceFactory
{
public static ReadOnlySequence<byte> CreateWithContent(byte[] data, int segmentSize = 1)
/// <summary>
/// Create a sequence from the specified data. The data will be divided up into segments in the sequence.
/// </summary>
public static ReadOnlySequence<byte> CreateWithContent(byte[] data, int segmentSize = 1, bool addEmptySegmentDelimiters = true)
{
var segments = new List<byte[]>();
segments.Add(new byte[0]);
if (addEmptySegmentDelimiters)
{
segments.Add(new byte[0]);
}
var currentIndex = 0;
while (currentIndex < data.Length)
{
@ -55,7 +62,11 @@ namespace Google.Protobuf
segment.Add(data[currentIndex++]);
}
segments.Add(segment.ToArray());
segments.Add(new byte[0]);
if (addEmptySegmentDelimiters)
{
segments.Add(new byte[0]);
}
}
return CreateSegments(segments.ToArray());

@ -133,7 +133,7 @@ namespace Google.Protobuf.Collections
//
// Check that the supplied length doesn't exceed the underlying buffer.
// That prevents a malicious length from initializing a very large collection.
if (codec.FixedSize > 0 && length % codec.FixedSize == 0 && IsDataAvailable(ref ctx, length))
if (codec.FixedSize > 0 && length % codec.FixedSize == 0 && ParsingPrimitives.IsDataAvailable(ref ctx.state, length))
{
EnsureSize(count + (length / codec.FixedSize));
@ -167,24 +167,6 @@ namespace Google.Protobuf.Collections
}
}
private bool IsDataAvailable(ref ParseContext ctx, int size)
{
// Data fits in remaining buffer
if (size <= ctx.state.bufferSize - ctx.state.bufferPos)
{
return true;
}
// Data fits in remaining source data.
// Note that this will never be true when reading from a stream as the total length is unknown.
if (size < ctx.state.segmentedBufferHelper.TotalLength - ctx.state.totalBytesRetired - ctx.state.bufferPos)
{
return true;
}
return false;
}
/// <summary>
/// Calculates the size of this collection based on the given codec.
/// </summary>

@ -43,7 +43,7 @@ using Google.Protobuf.Collections;
namespace Google.Protobuf
{
// warning: this is a mutable struct, so it needs to be only passed as a ref!
internal struct ParserInternalState
{
@ -54,12 +54,12 @@ namespace Google.Protobuf
/// The position within the current buffer (i.e. the next byte to read)
/// </summary>
internal int bufferPos;
/// <summary>
/// Size of the current buffer
/// </summary>
internal int bufferSize;
/// <summary>
/// If we are currently inside a length-delimited block, this is the number of
/// bytes in the buffer that are still available once we leave the delimited block.
@ -79,9 +79,9 @@ namespace Google.Protobuf
internal int totalBytesRetired;
internal int recursionDepth; // current recursion depth
internal SegmentedBufferHelper segmentedBufferHelper;
/// <summary>
/// The last tag we read. 0 indicates we've read to the end of the stream
/// (or haven't read anything yet).
@ -101,7 +101,7 @@ namespace Google.Protobuf
// If non-null, the top level parse method was started with given coded input stream as an argument
// which also means we can potentially fallback to calling MergeFrom(CodedInputStream cis) if needed.
internal CodedInputStream CodedInputStream => segmentedBufferHelper.CodedInputStream;
/// <summary>
/// Internal-only property; when set to true, unknown fields will be discarded while parsing.
/// </summary>

@ -34,6 +34,7 @@ using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -49,6 +50,7 @@ namespace Google.Protobuf
[SecuritySafeCritical]
internal static class ParsingPrimitives
{
private const int StackallocThreshold = 256;
/// <summary>
/// Reads a length for length-delimited data.
@ -58,7 +60,6 @@ namespace Google.Protobuf
/// to make the calling code clearer.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ParseLength(ref ReadOnlySpan<byte> buffer, ref ParserInternalState state)
{
return (int)ParseRawVarint32(ref buffer, ref state);
@ -437,14 +438,6 @@ namespace Google.Protobuf
throw InvalidProtocolBufferException.NegativeSize();
}
if (state.totalBytesRetired + state.bufferPos + size > state.currentLimit)
{
// Read to the end of the stream (up to the current limit) anyway.
SkipRawBytes(ref buffer, ref state, state.currentLimit - state.totalBytesRetired - state.bufferPos);
// Then fail.
throw InvalidProtocolBufferException.TruncatedMessage();
}
if (size <= state.bufferSize - state.bufferPos)
{
// We have all the bytes we need already.
@ -453,36 +446,22 @@ namespace Google.Protobuf
state.bufferPos += size;
return bytes;
}
else if (size < buffer.Length || size < state.segmentedBufferHelper.TotalLength)
return ReadRawBytesSlow(ref buffer, ref state, size);
}
private static byte[] ReadRawBytesSlow(ref ReadOnlySpan<byte> buffer, ref ParserInternalState state, int size)
{
ValidateCurrentLimit(ref buffer, ref state, size);
if ((!state.segmentedBufferHelper.TotalLength.HasValue && size < buffer.Length) ||
IsDataAvailableInSource(ref state, size))
{
// Reading more bytes than are in the buffer, but not an excessive number
// of bytes. We can safely allocate the resulting array ahead of time.
// First copy what we have.
byte[] bytes = new byte[size];
var bytesSpan = new Span<byte>(bytes);
int pos = state.bufferSize - state.bufferPos;
buffer.Slice(state.bufferPos, pos).CopyTo(bytesSpan.Slice(0, pos));
state.bufferPos = state.bufferSize;
// We want to use RefillBuffer() and then copy from the buffer into our
// byte array rather than reading directly into our byte array because
// the input may be unbuffered.
state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true);
while (size - pos > state.bufferSize)
{
buffer.Slice(0, state.bufferSize)
.CopyTo(bytesSpan.Slice(pos, state.bufferSize));
pos += state.bufferSize;
state.bufferPos = state.bufferSize;
state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true);
}
buffer.Slice(0, size - pos)
.CopyTo(bytesSpan.Slice(pos, size - pos));
state.bufferPos = size - pos;
ReadRawBytesIntoSpan(ref buffer, ref state, size, bytes);
return bytes;
}
else
@ -518,7 +497,7 @@ namespace Google.Protobuf
}
// OK, got everything. Now concatenate it all into one buffer.
byte[] bytes = new byte[size];
byte[] bytes = new byte[size];
int newPos = 0;
foreach (byte[] chunk in chunks)
{
@ -543,13 +522,7 @@ namespace Google.Protobuf
throw InvalidProtocolBufferException.NegativeSize();
}
if (state.totalBytesRetired + state.bufferPos + size > state.currentLimit)
{
// Read to the end of the stream anyway.
SkipRawBytes(ref buffer, ref state, state.currentLimit - state.totalBytesRetired - state.bufferPos);
// Then fail.
throw InvalidProtocolBufferException.TruncatedMessage();
}
ValidateCurrentLimit(ref buffer, ref state, size);
if (size <= state.bufferSize - state.bufferPos)
{
@ -619,7 +592,7 @@ namespace Google.Protobuf
}
#if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING
if (length <= state.bufferSize - state.bufferPos && length > 0)
if (length <= state.bufferSize - state.bufferPos)
{
// Fast path: all bytes to decode appear in the same span.
ReadOnlySpan<byte> data = buffer.Slice(state.bufferPos, length);
@ -638,20 +611,76 @@ namespace Google.Protobuf
}
#endif
var decoder = WritingPrimitives.Utf8Encoding.GetDecoder();
return ReadStringSlow(ref buffer, ref state, length);
}
// TODO: even if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING is not supported,
// we could still create a string efficiently by using Utf8Encoding.GetString(byte[] bytes, int index, int count)
// whenever the buffer is backed by a byte array (and avoid creating a new byte array), but the problem is
// there is no way to get the underlying byte array from a span.
/// <summary>
/// Reads a string assuming that it is spread across multiple spans in a <see cref="ReadOnlySequence{T}"/>.
/// </summary>
private static string ReadStringSlow(ref ReadOnlySpan<byte> buffer, ref ParserInternalState state, int length)
{
ValidateCurrentLimit(ref buffer, ref state, length);
#if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING
if (IsDataAvailable(ref state, length))
{
// Read string data into a temporary buffer, either stackalloc'ed or from ArrayPool
// Once all data is read then call Encoding.GetString on buffer and return to pool if needed.
// TODO: in case the string spans multiple buffer segments, creating a char[] and decoding into it and then
// creating a string from that array might be more efficient than creating a string from the copied bytes.
byte[] byteArray = null;
Span<byte> byteSpan = length <= StackallocThreshold ?
stackalloc byte[length] :
(byteArray = ArrayPool<byte>.Shared.Rent(length));
try
{
unsafe
{
fixed (byte* pByteSpan = &MemoryMarshal.GetReference(byteSpan))
{
// Compiler doesn't like that a potentially stackalloc'd Span<byte> is being used
// in a method with a "ref Span<byte> buffer" argument. If the stackalloc'd span was assigned
// to the ref argument then bad things would happen. We'll never do that so it is ok.
// Make compiler happy by passing a new span created from pointer.
var tempSpan = new Span<byte>(pByteSpan, byteSpan.Length);
ReadRawBytesIntoSpan(ref buffer, ref state, length, tempSpan);
return WritingPrimitives.Utf8Encoding.GetString(pByteSpan, length);
}
}
}
finally
{
if (byteArray != null)
{
ArrayPool<byte>.Shared.Return(byteArray);
}
}
}
#endif
// Slow path: Build a byte array first then copy it.
// This will be called when reading from a Stream because we don't know the length of the stream,
// or there is not enough data in the sequence. If there is not enough data then ReadRawBytes will
// throw an exception.
return WritingPrimitives.Utf8Encoding.GetString(ReadRawBytes(ref buffer, ref state, length), 0, length);
}
/// <summary>
/// Validates that the specified size doesn't exceed the current limit. If it does then remaining bytes
/// are skipped and an error is thrown.
/// </summary>
private static void ValidateCurrentLimit(ref ReadOnlySpan<byte> buffer, ref ParserInternalState state, int size)
{
if (state.totalBytesRetired + state.bufferPos + size > state.currentLimit)
{
// Read to the end of the stream (up to the current limit) anyway.
SkipRawBytes(ref buffer, ref state, state.currentLimit - state.totalBytesRetired - state.bufferPos);
// Then fail.
throw InvalidProtocolBufferException.TruncatedMessage();
}
}
[SecuritySafeCritical]
private static byte ReadRawByte(ref ReadOnlySpan<byte> buffer, ref ParserInternalState state)
{
@ -731,5 +760,56 @@ namespace Google.Protobuf
{
return (long)(n >> 1) ^ -(long)(n & 1);
}
/// <summary>
/// Checks whether there is known data available of the specified size remaining to parse.
/// When parsing from a Stream this can return false because we have no knowledge of the amount
/// of data remaining in the stream until it is read.
/// </summary>
public static bool IsDataAvailable(ref ParserInternalState state, int size)
{
// Data fits in remaining buffer
if (size <= state.bufferSize - state.bufferPos)
{
return true;
}
return IsDataAvailableInSource(ref state, size);
}
/// <summary>
/// Checks whether there is known data available of the specified size remaining to parse
/// in the underlying data source.
/// When parsing from a Stream this will return false because we have no knowledge of the amount
/// of data remaining in the stream until it is read.
/// </summary>
private static bool IsDataAvailableInSource(ref ParserInternalState state, int size)
{
// Data fits in remaining source data.
// Note that this will never be true when reading from a stream as the total length is unknown.
return size <= state.segmentedBufferHelper.TotalLength - state.totalBytesRetired - state.bufferPos;
}
/// <summary>
/// Read raw bytes of the specified length into a span. The amount of data available and the current limit should
/// be checked before calling this method.
/// </summary>
private static void ReadRawBytesIntoSpan(ref ReadOnlySpan<byte> buffer, ref ParserInternalState state, int length, Span<byte> byteSpan)
{
int remainingByteLength = length;
while (remainingByteLength > 0)
{
if (state.bufferSize - state.bufferPos == 0)
{
state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true);
}
ReadOnlySpan<byte> unreadSpan = buffer.Slice(state.bufferPos, Math.Min(remainingByteLength, state.bufferSize - state.bufferPos));
unreadSpan.CopyTo(byteSpan.Slice(length - remainingByteLength));
remainingByteLength -= unreadSpan.Length;
state.bufferPos += unreadSpan.Length;
}
}
}
}
}

@ -62,7 +62,7 @@ do
PROTOC=$BOOTSTRAP_PROTOC
BOOTSTRAP_PROTOC=""
else
make $@ protoc
make -j$(nproc) $@ protoc
if test $? -ne 0; then
echo "Failed to build protoc."
exit 1

@ -71,13 +71,16 @@ gulp.task('genproto_group1_closure', function (cb) {
});
});
gulp.task('genproto_group2_closure', function (cb) {
exec(protoc + ' --js_out=library=testproto_libs2,binary:. -I ../src -I . -I commonjs ' + group2Protos.join(' '),
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
gulp.task('genproto_group2_closure', function(cb) {
exec(
protoc +
' --experimental_allow_proto3_optional --js_out=library=testproto_libs2,binary:. -I ../src -I . -I commonjs ' +
group2Protos.join(' '),
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('genproto_well_known_types_commonjs', function (cb) {
@ -98,13 +101,16 @@ gulp.task('genproto_group1_commonjs', function (cb) {
});
});
gulp.task('genproto_group2_commonjs', function (cb) {
exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . ' + group2Protos.join(' '),
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
gulp.task('genproto_group2_commonjs', function(cb) {
exec(
'mkdir -p commonjs_out && ' + protoc +
' --experimental_allow_proto3_optional --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . ' +
group2Protos.join(' '),
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('genproto_commonjs_wellknowntypes', function (cb) {

@ -1,6 +1,6 @@
{
"name": "google-protobuf",
"version": "3.12.2",
"version": "3.12.3",
"description": "Protocol Buffers for JavaScript",
"main": "google-protobuf.js",
"files": [

@ -77,7 +77,7 @@ describe('proto3Test', function() {
it('testEqualsProto3', function() {
var msg1 = new proto.jspb.test.TestProto3();
var msg2 = new proto.jspb.test.TestProto3();
msg2.setOptionalString('');
msg2.setSingularString('');
assertTrue(jspb.Message.equals(msg1, msg2));
});
@ -90,12 +90,12 @@ describe('proto3Test', function() {
var msg = new proto.jspb.test.TestProto3();
// Setting should work normally.
msg.setOptionalString('optionalString');
assertEquals(msg.getOptionalString(), 'optionalString');
msg.setSingularString('optionalString');
assertEquals(msg.getSingularString(), 'optionalString');
// Clearing should work too ...
msg.setOptionalString('');
assertEquals(msg.getOptionalString(), '');
msg.setSingularString('');
assertEquals(msg.getSingularString(), '');
// ... and shouldn't affect the equality with a brand new message.
assertTrue(jspb.Message.equals(msg, new proto.jspb.test.TestProto3()));
@ -107,6 +107,58 @@ describe('proto3Test', function() {
it('testProto3FieldDefaults', function() {
var msg = new proto.jspb.test.TestProto3();
assertEquals(msg.getSingularInt32(), 0);
assertEquals(msg.getSingularInt64(), 0);
assertEquals(msg.getSingularUint32(), 0);
assertEquals(msg.getSingularUint64(), 0);
assertEquals(msg.getSingularSint32(), 0);
assertEquals(msg.getSingularSint64(), 0);
assertEquals(msg.getSingularFixed32(), 0);
assertEquals(msg.getSingularFixed64(), 0);
assertEquals(msg.getSingularSfixed32(), 0);
assertEquals(msg.getSingularSfixed64(), 0);
assertEquals(msg.getSingularFloat(), 0);
assertEquals(msg.getSingularDouble(), 0);
assertEquals(msg.getSingularString(), '');
// TODO(b/26173701): when we change bytes fields default getter to return
// Uint8Array, we'll want to switch this assertion to match the u8 case.
assertEquals(typeof msg.getSingularBytes(), 'string');
assertEquals(msg.getSingularBytes_asU8() instanceof Uint8Array, true);
assertEquals(typeof msg.getSingularBytes_asB64(), 'string');
assertEquals(msg.getSingularBytes().length, 0);
assertEquals(msg.getSingularBytes_asU8().length, 0);
assertEquals(msg.getSingularBytes_asB64(), '');
assertEquals(
msg.getSingularForeignEnum(), proto.jspb.test.Proto3Enum.PROTO3_FOO);
assertEquals(msg.getSingularForeignMessage(), undefined);
assertEquals(msg.getSingularForeignMessage(), undefined);
assertEquals(msg.getRepeatedInt32List().length, 0);
assertEquals(msg.getRepeatedInt64List().length, 0);
assertEquals(msg.getRepeatedUint32List().length, 0);
assertEquals(msg.getRepeatedUint64List().length, 0);
assertEquals(msg.getRepeatedSint32List().length, 0);
assertEquals(msg.getRepeatedSint64List().length, 0);
assertEquals(msg.getRepeatedFixed32List().length, 0);
assertEquals(msg.getRepeatedFixed64List().length, 0);
assertEquals(msg.getRepeatedSfixed32List().length, 0);
assertEquals(msg.getRepeatedSfixed64List().length, 0);
assertEquals(msg.getRepeatedFloatList().length, 0);
assertEquals(msg.getRepeatedDoubleList().length, 0);
assertEquals(msg.getRepeatedStringList().length, 0);
assertEquals(msg.getRepeatedBytesList().length, 0);
assertEquals(msg.getRepeatedForeignEnumList().length, 0);
assertEquals(msg.getRepeatedForeignMessageList().length, 0);
});
/**
* Test presence for proto3 optional fields.
*/
it('testProto3Optional', function() {
var msg = new proto.jspb.test.TestProto3();
assertEquals(msg.getOptionalInt32(), 0);
assertEquals(msg.getOptionalInt64(), 0);
assertEquals(msg.getOptionalUint32(), 0);
@ -135,51 +187,65 @@ describe('proto3Test', function() {
assertEquals(msg.getOptionalForeignMessage(), undefined);
assertEquals(msg.getOptionalForeignMessage(), undefined);
assertEquals(msg.getRepeatedInt32List().length, 0);
assertEquals(msg.getRepeatedInt64List().length, 0);
assertEquals(msg.getRepeatedUint32List().length, 0);
assertEquals(msg.getRepeatedUint64List().length, 0);
assertEquals(msg.getRepeatedSint32List().length, 0);
assertEquals(msg.getRepeatedSint64List().length, 0);
assertEquals(msg.getRepeatedFixed32List().length, 0);
assertEquals(msg.getRepeatedFixed64List().length, 0);
assertEquals(msg.getRepeatedSfixed32List().length, 0);
assertEquals(msg.getRepeatedSfixed64List().length, 0);
assertEquals(msg.getRepeatedFloatList().length, 0);
assertEquals(msg.getRepeatedDoubleList().length, 0);
assertEquals(msg.getRepeatedStringList().length, 0);
assertEquals(msg.getRepeatedBytesList().length, 0);
assertEquals(msg.getRepeatedForeignEnumList().length, 0);
assertEquals(msg.getRepeatedForeignMessageList().length, 0);
// Serializing an empty proto yields the empty string.
assertEquals(msg.serializeBinary().length, 0);
});
// Values start as unset, but can be explicitly set even to default values
// like 0.
assertFalse(msg.hasOptionalInt32());
msg.setOptionalInt32(0);
assertTrue(msg.hasOptionalInt32());
assertFalse(msg.hasOptionalInt64());
msg.setOptionalInt64(0);
assertTrue(msg.hasOptionalInt64());
assertFalse(msg.hasOptionalString());
msg.setOptionalString('');
assertTrue(msg.hasOptionalString());
// Now the proto will have a non-zero size, even though its values are 0.
var serialized = msg.serializeBinary();
assertNotEquals(serialized.length, 0);
var msg2 = proto.jspb.test.TestProto3.deserializeBinary(serialized);
assertTrue(msg2.hasOptionalInt32());
assertTrue(msg2.hasOptionalInt64());
assertTrue(msg2.hasOptionalString());
// We can clear fields to go back to empty.
msg2.clearOptionalInt32();
assertFalse(msg2.hasOptionalInt32());
msg2.clearOptionalString();
assertFalse(msg2.hasOptionalString());
});
/**
* Test that all fields can be set and read via a serialization roundtrip.
* Test that all fields can be set ,and read via a serialization roundtrip.
*/
it('testProto3FieldSetGet', function() {
var msg = new proto.jspb.test.TestProto3();
msg.setOptionalInt32(-42);
msg.setOptionalInt64(-0x7fffffff00000000);
msg.setOptionalUint32(0x80000000);
msg.setOptionalUint64(0xf000000000000000);
msg.setOptionalSint32(-100);
msg.setOptionalSint64(-0x8000000000000000);
msg.setOptionalFixed32(1234);
msg.setOptionalFixed64(0x1234567800000000);
msg.setOptionalSfixed32(-1234);
msg.setOptionalSfixed64(-0x1234567800000000);
msg.setOptionalFloat(1.5);
msg.setOptionalDouble(-1.5);
msg.setOptionalBool(true);
msg.setOptionalString('hello world');
msg.setOptionalBytes(BYTES);
msg.setSingularInt32(-42);
msg.setSingularInt64(-0x7fffffff00000000);
msg.setSingularUint32(0x80000000);
msg.setSingularUint64(0xf000000000000000);
msg.setSingularSint32(-100);
msg.setSingularSint64(-0x8000000000000000);
msg.setSingularFixed32(1234);
msg.setSingularFixed64(0x1234567800000000);
msg.setSingularSfixed32(-1234);
msg.setSingularSfixed64(-0x1234567800000000);
msg.setSingularFloat(1.5);
msg.setSingularDouble(-1.5);
msg.setSingularBool(true);
msg.setSingularString('hello world');
msg.setSingularBytes(BYTES);
var submsg = new proto.jspb.test.ForeignMessage();
submsg.setC(16);
msg.setOptionalForeignMessage(submsg);
msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR);
msg.setSingularForeignMessage(submsg);
msg.setSingularForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR);
msg.setRepeatedInt32List([-42]);
msg.setRepeatedInt64List([-0x7fffffff00000000]);
@ -206,24 +272,24 @@ describe('proto3Test', function() {
var serialized = msg.serializeBinary();
msg = proto.jspb.test.TestProto3.deserializeBinary(serialized);
assertEquals(msg.getOptionalInt32(), -42);
assertEquals(msg.getOptionalInt64(), -0x7fffffff00000000);
assertEquals(msg.getOptionalUint32(), 0x80000000);
assertEquals(msg.getOptionalUint64(), 0xf000000000000000);
assertEquals(msg.getOptionalSint32(), -100);
assertEquals(msg.getOptionalSint64(), -0x8000000000000000);
assertEquals(msg.getOptionalFixed32(), 1234);
assertEquals(msg.getOptionalFixed64(), 0x1234567800000000);
assertEquals(msg.getOptionalSfixed32(), -1234);
assertEquals(msg.getOptionalSfixed64(), -0x1234567800000000);
assertEquals(msg.getOptionalFloat(), 1.5);
assertEquals(msg.getOptionalDouble(), -1.5);
assertEquals(msg.getOptionalBool(), true);
assertEquals(msg.getOptionalString(), 'hello world');
assertEquals(true, bytesCompare(msg.getOptionalBytes(), BYTES));
assertEquals(msg.getOptionalForeignMessage().getC(), 16);
assertEquals(msg.getOptionalForeignEnum(),
proto.jspb.test.Proto3Enum.PROTO3_BAR);
assertEquals(msg.getSingularInt32(), -42);
assertEquals(msg.getSingularInt64(), -0x7fffffff00000000);
assertEquals(msg.getSingularUint32(), 0x80000000);
assertEquals(msg.getSingularUint64(), 0xf000000000000000);
assertEquals(msg.getSingularSint32(), -100);
assertEquals(msg.getSingularSint64(), -0x8000000000000000);
assertEquals(msg.getSingularFixed32(), 1234);
assertEquals(msg.getSingularFixed64(), 0x1234567800000000);
assertEquals(msg.getSingularSfixed32(), -1234);
assertEquals(msg.getSingularSfixed64(), -0x1234567800000000);
assertEquals(msg.getSingularFloat(), 1.5);
assertEquals(msg.getSingularDouble(), -1.5);
assertEquals(msg.getSingularBool(), true);
assertEquals(msg.getSingularString(), 'hello world');
assertEquals(true, bytesCompare(msg.getSingularBytes(), BYTES));
assertEquals(msg.getSingularForeignMessage().getC(), 16);
assertEquals(
msg.getSingularForeignEnum(), proto.jspb.test.Proto3Enum.PROTO3_BAR);
assertElementsEquals(msg.getRepeatedInt32List(), [-42]);
assertElementsEquals(msg.getRepeatedInt64List(), [-0x7fffffff00000000]);
@ -327,20 +393,20 @@ describe('proto3Test', function() {
// Set each primitive to a non-default value, then back to its default, to
// ensure that the serialization is actually checking the value and not just
// whether it has ever been set.
msg.setOptionalInt32(42);
msg.setOptionalInt32(0);
msg.setOptionalDouble(3.14);
msg.setOptionalDouble(0.0);
msg.setOptionalBool(true);
msg.setOptionalBool(false);
msg.setOptionalString('hello world');
msg.setOptionalString('');
msg.setOptionalBytes(goog.crypt.base64.encodeString('\u00FF\u00FF'));
msg.setOptionalBytes('');
msg.setOptionalForeignMessage(new proto.jspb.test.ForeignMessage());
msg.setOptionalForeignMessage(null);
msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR);
msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_FOO);
msg.setSingularInt32(42);
msg.setSingularInt32(0);
msg.setSingularDouble(3.14);
msg.setSingularDouble(0.0);
msg.setSingularBool(true);
msg.setSingularBool(false);
msg.setSingularString('hello world');
msg.setSingularString('');
msg.setSingularBytes(goog.crypt.base64.encodeString('\u00FF\u00FF'));
msg.setSingularBytes('');
msg.setSingularForeignMessage(new proto.jspb.test.ForeignMessage());
msg.setSingularForeignMessage(null);
msg.setSingularForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR);
msg.setSingularForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_FOO);
msg.setOneofUint32(32);
msg.clearOneofUint32();
@ -355,27 +421,25 @@ describe('proto3Test', function() {
it('testBytesFieldsInterop', function() {
var msg = new proto.jspb.test.TestProto3();
// Set as a base64 string and check all the getters work.
msg.setOptionalBytes(BYTES_B64);
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
msg.setSingularBytes(BYTES_B64);
assertTrue(bytesCompare(msg.getSingularBytes_asU8(), BYTES));
assertTrue(bytesCompare(msg.getSingularBytes_asB64(), BYTES));
assertTrue(bytesCompare(msg.getSingularBytes(), BYTES));
// Test binary serialize round trip doesn't break it.
msg = proto.jspb.test.TestProto3.deserializeBinary(msg.serializeBinary());
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
assertTrue(bytesCompare(msg.getSingularBytes_asU8(), BYTES));
assertTrue(bytesCompare(msg.getSingularBytes_asB64(), BYTES));
assertTrue(bytesCompare(msg.getSingularBytes(), BYTES));
msg = new proto.jspb.test.TestProto3();
// Set as a Uint8Array and check all the getters work.
msg.setOptionalBytes(BYTES);
assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
msg.setSingularBytes(BYTES);
assertTrue(bytesCompare(msg.getSingularBytes_asU8(), BYTES));
assertTrue(bytesCompare(msg.getSingularBytes_asB64(), BYTES));
assertTrue(bytesCompare(msg.getSingularBytes(), BYTES));
});
it('testTimestampWellKnownType', function() {
var msg = new proto.google.protobuf.Timestamp();
msg.fromDate(new Date(123456789));

@ -30,29 +30,48 @@
syntax = "proto3";
import "testbinary.proto";
package jspb.test;
import "testbinary.proto";
message TestProto3 {
int32 optional_int32 = 1;
int64 optional_int64 = 2;
uint32 optional_uint32 = 3;
uint64 optional_uint64 = 4;
sint32 optional_sint32 = 5;
sint64 optional_sint64 = 6;
fixed32 optional_fixed32 = 7;
fixed64 optional_fixed64 = 8;
sfixed32 optional_sfixed32 = 9;
sfixed64 optional_sfixed64 = 10;
float optional_float = 11;
double optional_double = 12;
bool optional_bool = 13;
string optional_string = 14;
bytes optional_bytes = 15;
int32 singular_int32 = 1;
int64 singular_int64 = 2;
uint32 singular_uint32 = 3;
uint64 singular_uint64 = 4;
sint32 singular_sint32 = 5;
sint64 singular_sint64 = 6;
fixed32 singular_fixed32 = 7;
fixed64 singular_fixed64 = 8;
sfixed32 singular_sfixed32 = 9;
sfixed64 singular_sfixed64 = 10;
float singular_float = 11;
double singular_double = 12;
bool singular_bool = 13;
string singular_string = 14;
bytes singular_bytes = 15;
ForeignMessage optional_foreign_message = 19;
Proto3Enum optional_foreign_enum = 22;
ForeignMessage singular_foreign_message = 19;
Proto3Enum singular_foreign_enum = 22;
optional int32 optional_int32 = 121;
optional int64 optional_int64 = 122;
optional uint32 optional_uint32 = 123;
optional uint64 optional_uint64 = 124;
optional sint32 optional_sint32 = 125;
optional sint64 optional_sint64 = 126;
optional fixed32 optional_fixed32 = 127;
optional fixed64 optional_fixed64 = 128;
optional sfixed32 optional_sfixed32 = 129;
optional sfixed64 optional_sfixed64 = 130;
optional float optional_float = 131;
optional double optional_double = 132;
optional bool optional_bool = 133;
optional string optional_string = 134;
optional bytes optional_bytes = 135;
optional ForeignMessage optional_foreign_message = 136;
optional Proto3Enum optional_foreign_enum = 137;
repeated int32 repeated_int32 = 31;
repeated int64 repeated_int64 = 32;
@ -73,7 +92,6 @@ message TestProto3 {
repeated ForeignMessage repeated_foreign_message = 49;
repeated Proto3Enum repeated_foreign_enum = 52;
oneof oneof_field {
uint32 oneof_uint32 = 111;
ForeignMessage oneof_foreign_message = 112;

@ -28,389 +28,268 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ext/spl/spl_iterators.h>
#include "array.h"
#include <Zend/zend_API.h>
#include <Zend/zend_interfaces.h>
#include "protobuf.h"
#include <ext/spl/spl_iterators.h>
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
// This is not self-contained: it must be after other Zend includes.
#include <Zend/zend_exceptions.h>
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()
#include "arena.h"
#include "convert.h"
#include "def.h"
#include "php-upb.h"
#include "protobuf.h"
ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()
static void RepeatedFieldIter_make(zval *val, zval *repeated_field);
static zend_function_entry repeated_field_methods[] = {
PHP_ME(RepeatedField, __construct, NULL, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, append, NULL, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// RepeatedField
// -----------------------------------------------------------------------------
static zend_function_entry repeated_field_iter_methods[] = {
PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
typedef struct {
zend_object std;
zval arena;
upb_array *array;
upb_fieldtype_t type;
const Descriptor* desc; // When values are messages.
} RepeatedField;
// Forward declare static functions.
static int repeated_field_array_init(zval *array, upb_fieldtype_t type,
uint size ZEND_FILE_LINE_DC);
static void repeated_field_write_dimension(zval *object, zval *offset,
zval *value TSRMLS_DC);
static HashTable *repeated_field_get_gc(zval *object, CACHED_VALUE **table,
int *n TSRMLS_DC);
#if PHP_MAJOR_VERSION < 7
static zend_object_value repeated_field_create(zend_class_entry *ce TSRMLS_DC);
static zend_object_value repeated_field_iter_create(zend_class_entry *ce TSRMLS_DC);
#else
static zend_object *repeated_field_create(zend_class_entry *ce TSRMLS_DC);
static zend_object *repeated_field_iter_create(zend_class_entry *ce TSRMLS_DC);
#endif
zend_class_entry *RepeatedField_class_entry;
static zend_object_handlers RepeatedField_object_handlers;
// -----------------------------------------------------------------------------
// RepeatedField creation/destruction
// -----------------------------------------------------------------------------
// PHP Object Handlers /////////////////////////////////////////////////////////
zend_class_entry* repeated_field_type;
zend_class_entry* repeated_field_iter_type;
zend_object_handlers* repeated_field_handlers;
zend_object_handlers* repeated_field_iter_handlers;
// Define object free method.
PHP_PROTO_OBJECT_FREE_START(RepeatedField, repeated_field)
#if PHP_MAJOR_VERSION < 7
php_proto_zval_ptr_dtor(intern->array);
#else
php_proto_zval_ptr_dtor(&intern->array);
#endif
PHP_PROTO_OBJECT_FREE_END
PHP_PROTO_OBJECT_EMPTY_DTOR_START(RepeatedField, repeated_field)
PHP_PROTO_OBJECT_DTOR_END
// Define object create method.
PHP_PROTO_OBJECT_CREATE_START(RepeatedField, repeated_field)
#if PHP_MAJOR_VERSION < 7
intern->array = NULL;
#endif
intern->type = 0;
intern->msg_ce = NULL;
PHP_PROTO_OBJECT_CREATE_END(RepeatedField, repeated_field)
// Init class entry.
PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\RepeatedField",
RepeatedField, repeated_field)
zend_class_implements(repeated_field_type TSRMLS_CC, 3, spl_ce_ArrayAccess,
zend_ce_aggregate, spl_ce_Countable);
repeated_field_handlers->write_dimension = repeated_field_write_dimension;
repeated_field_handlers->get_gc = repeated_field_get_gc;
PHP_PROTO_INIT_CLASS_END
// Define array element free function.
#if PHP_MAJOR_VERSION < 7
static inline void php_proto_array_string_release(void *value) {
zval_ptr_dtor(value);
/**
* RepeatedField_create()
*
* PHP class entry function to allocate and initialize a new RepeatedField
* object.
*/
static zend_object* RepeatedField_create(zend_class_entry *class_type) {
RepeatedField *intern = emalloc(sizeof(RepeatedField));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &RepeatedField_object_handlers;
Arena_Init(&intern->arena);
intern->array = NULL;
intern->desc = NULL;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
static inline void php_proto_array_object_release(void *value) {
zval_ptr_dtor(value);
}
static inline void php_proto_array_default_release(void *value) {
}
#else
static inline void php_proto_array_string_release(zval *value) {
void* ptr = Z_PTR_P(value);
zend_string* object = *(zend_string**)ptr;
zend_string_release(object);
efree(ptr);
}
static inline void php_proto_array_object_release(zval *value) {
zval_ptr_dtor(value);
}
static void php_proto_array_default_release(zval* value) {
void* ptr = Z_PTR_P(value);
efree(ptr);
}
#endif
static int repeated_field_array_init(zval *array, upb_fieldtype_t type,
uint size ZEND_FILE_LINE_DC) {
PHP_PROTO_ALLOC_ARRAY(array);
switch (type) {
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
zend_hash_init(Z_ARRVAL_P(array), size, NULL,
php_proto_array_string_release, 0);
break;
case UPB_TYPE_MESSAGE:
zend_hash_init(Z_ARRVAL_P(array), size, NULL,
php_proto_array_object_release, 0);
break;
default:
zend_hash_init(Z_ARRVAL_P(array), size, NULL,
php_proto_array_default_release, 0);
}
return SUCCESS;
/**
* RepeatedField_dtor()
*
* Object handler to destroy a RepeatedField. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void RepeatedField_destructor(zend_object* obj) {
RepeatedField* intern = (RepeatedField*)obj;
ObjCache_Delete(intern->array);
zval_ptr_dtor(&intern->arena);
zend_object_std_dtor(&intern->std);
}
// -----------------------------------------------------------------------------
// RepeatedField Handlers
// -----------------------------------------------------------------------------
static HashTable *RepeatedField_GetProperties(zval *object TSRMLS_DC) {
return NULL; // We do not have a properties table.
}
static void repeated_field_write_dimension(zval *object, zval *offset,
zval *value TSRMLS_DC) {
uint64_t index;
static zval *RepeatedField_GetPropertyPtrPtr(zval *object, zval *member,
int type, void **cache_slot) {
return NULL; // We don't offer direct references to our properties.
}
RepeatedField *intern = UNBOX(RepeatedField, object);
HashTable *ht = PHP_PROTO_HASH_OF(intern->array);
int size = native_slot_size(intern->type);
// C Functions from array.h ////////////////////////////////////////////////////
unsigned char memory[NATIVE_SLOT_MAX_SIZE];
memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
// These are documented in the header file.
if (!native_slot_set_by_array(intern->type, intern->msg_ce, memory,
value TSRMLS_CC)) {
void RepeatedField_GetPhpWrapper(zval *val, upb_array *arr,
const upb_fielddef *f, zval *arena) {
if (!arr) {
ZVAL_NULL(val);
return;
}
if (!offset || Z_TYPE_P(offset) == IS_NULL) {
index = zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array));
} else {
if (protobuf_convert_to_uint64(offset, &index)) {
if (!zend_hash_index_exists(ht, index)) {
zend_error(E_USER_ERROR, "Element at %llu doesn't exist.\n",
(long long unsigned int)index);
return;
}
} else {
return;
}
if (!ObjCache_Get(arr, val)) {
RepeatedField *intern = emalloc(sizeof(RepeatedField));
zend_object_std_init(&intern->std, RepeatedField_class_entry);
intern->std.handlers = &RepeatedField_object_handlers;
ZVAL_COPY(&intern->arena, arena);
intern->array = arr;
intern->type = upb_fielddef_type(f);
intern->desc = Descriptor_GetFromFieldDef(f);
// Skip object_properties_init(), we don't allow derived classes.
ObjCache_Add(intern->array, &intern->std);
ZVAL_OBJ(val, &intern->std);
}
}
if (intern->type == UPB_TYPE_MESSAGE) {
php_proto_zend_hash_index_update_zval(ht, index, *(zval**)memory);
} else {
php_proto_zend_hash_index_update_mem(ht, index, memory, size, NULL);
upb_array *RepeatedField_GetUpbArray(zval *val, const upb_fielddef *f,
upb_arena *arena) {
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
}
#if PHP_MAJOR_VERSION < 7
static HashTable *repeated_field_get_gc(zval *object, zval ***table,
int *n TSRMLS_DC) {
#else
static HashTable *repeated_field_get_gc(zval *object, zval **table, int *n) {
#endif
*table = NULL;
*n = 0;
RepeatedField *intern = UNBOX(RepeatedField, object);
return PHP_PROTO_HASH_OF(intern->array);
}
if (Z_TYPE_P(val) == IS_ARRAY) {
// Auto-construct, eg. [1, 2, 3] -> upb_array([1, 2, 3]).
upb_array *arr = upb_array_new(arena, upb_fielddef_type(f));
HashTable *table = HASH_OF(val);
HashPosition pos;
upb_fieldtype_t type = upb_fielddef_type(f);
const Descriptor *desc = Descriptor_GetFromFieldDef(f);
// -----------------------------------------------------------------------------
// C RepeatedField Utilities
// -----------------------------------------------------------------------------
zend_hash_internal_pointer_reset_ex(table, &pos);
while (true) {
zval *zv = zend_hash_get_current_data_ex(table, &pos);
upb_msgval val;
void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC) {
HashTable *ht = PHP_PROTO_HASH_OF(intern->array);
void *value;
if (!zv) return arr;
if (intern->type == UPB_TYPE_MESSAGE) {
if (php_proto_zend_hash_index_find_zval(ht, index, (void **)&value) ==
FAILURE) {
zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index);
return NULL;
if (!Convert_PhpToUpbAutoWrap(zv, &val, type, desc, arena)) {
return NULL;
}
upb_array_append(arr, val, arena);
zend_hash_move_forward_ex(table, &pos);
}
} else {
if (php_proto_zend_hash_index_find_mem(ht, index, (void **)&value) ==
FAILURE) {
zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index);
return NULL;
} else if (Z_TYPE_P(val) == IS_OBJECT &&
Z_OBJCE_P(val) == RepeatedField_class_entry) {
// Unwrap existing RepeatedField object to get the upb_array* inside.
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(val);
const Descriptor *desc = Descriptor_GetFromFieldDef(f);
if (intern->type != upb_fielddef_type(f) || intern->desc != desc) {
php_error_docref(NULL, E_USER_ERROR,
"Wrong type for this repeated field.");
}
}
return value;
}
void repeated_field_push_native(RepeatedField *intern, void *value) {
HashTable *ht = PHP_PROTO_HASH_OF(intern->array);
int size = native_slot_size(intern->type);
if (intern->type == UPB_TYPE_MESSAGE) {
php_proto_zend_hash_next_index_insert_zval(ht, value);
upb_arena_fuse(arena, Arena_Get(&intern->arena));
return intern->array;
} else {
php_proto_zend_hash_next_index_insert_mem(ht, (void **)value, size, NULL);
php_error_docref(NULL, E_USER_ERROR, "Must be a repeated field");
return NULL;
}
}
void repeated_field_ensure_created(
const upb_fielddef *field,
CACHED_VALUE *repeated_field PHP_PROTO_TSRMLS_DC) {
if (ZVAL_IS_NULL(CACHED_PTR_TO_ZVAL_PTR(repeated_field))) {
zval_ptr_dtor(repeated_field);
#if PHP_MAJOR_VERSION < 7
MAKE_STD_ZVAL(CACHED_PTR_TO_ZVAL_PTR(repeated_field));
#endif
repeated_field_create_with_field(repeated_field_type, field,
repeated_field PHP_PROTO_TSRMLS_CC);
}
}
void repeated_field_create_with_field(
zend_class_entry *ce, const upb_fielddef *field,
CACHED_VALUE *repeated_field PHP_PROTO_TSRMLS_DC) {
upb_fieldtype_t type = upb_fielddef_type(field);
const zend_class_entry *msg_ce = field_type_class(field PHP_PROTO_TSRMLS_CC);
repeated_field_create_with_type(ce, type, msg_ce,
repeated_field PHP_PROTO_TSRMLS_CC);
}
void repeated_field_create_with_type(
zend_class_entry *ce, upb_fieldtype_t type, const zend_class_entry *msg_ce,
CACHED_VALUE *repeated_field PHP_PROTO_TSRMLS_DC) {
CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(CACHED_PTR_TO_ZVAL_PTR(repeated_field),
repeated_field_type);
RepeatedField *intern =
UNBOX(RepeatedField, CACHED_TO_ZVAL_PTR(*repeated_field));
intern->type = type;
intern->msg_ce = msg_ce;
#if PHP_MAJOR_VERSION < 7
MAKE_STD_ZVAL(intern->array);
repeated_field_array_init(intern->array, intern->type, 0 ZEND_FILE_LINE_CC);
#else
repeated_field_array_init(&intern->array, intern->type, 0 ZEND_FILE_LINE_CC);
#endif
// TODO(teboring): Link class entry for message and enum
}
// -----------------------------------------------------------------------------
// PHP RepeatedField Methods
// -----------------------------------------------------------------------------
// RepeatedField PHP methods ///////////////////////////////////////////////////
/**
* RepeatedField::__construct()
*
* Constructs an instance of RepeatedField.
* @param long Type of the stored element.
* @param string Message/Enum class name (message/enum fields only).
* @param string Message/Enum class.
*/
PHP_METHOD(RepeatedField, __construct) {
long type;
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
zend_long type;
zend_class_entry* klass = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|C", &type, &klass) ==
FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|C", &type, &klass) != SUCCESS) {
return;
}
RepeatedField *intern = UNBOX(RepeatedField, getThis());
intern->type = to_fieldtype(type);
intern->msg_ce = klass;
#if PHP_MAJOR_VERSION < 7
MAKE_STD_ZVAL(intern->array);
repeated_field_array_init(intern->array, intern->type, 0 ZEND_FILE_LINE_CC);
#else
repeated_field_array_init(&intern->array, intern->type, 0 ZEND_FILE_LINE_CC);
#endif
intern->type = pbphp_dtype_to_type(type);
intern->desc = Descriptor_GetFromClassEntry(klass);
if (intern->type == UPB_TYPE_MESSAGE && klass == NULL) {
zend_error(E_USER_ERROR, "Message type must have concrete class.");
php_error_docref(NULL, E_USER_ERROR,
"Message/enum type must have concrete class.");
return;
}
// TODO(teboring): Consider enum.
intern->array = upb_array_new(arena, intern->type);
ObjCache_Add(intern->array, &intern->std);
}
/**
* RepeatedField::append()
*
* Append element to the end of the repeated field.
* @param object The element to be added.
*/
PHP_METHOD(RepeatedField, append) {
zval *value;
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
zval *php_val;
upb_msgval msgval;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) ==
FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &php_val) != SUCCESS ||
!Convert_PhpToUpb(php_val, &msgval, intern->type, intern->desc, arena)) {
return;
}
repeated_field_write_dimension(getThis(), NULL, value TSRMLS_CC);
upb_array_append(intern->array, msgval, arena);
}
/**
* Check whether the element at given index exists.
* RepeatedField::offsetExists()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* isset($arr[$idx]);
* empty($arr[$idx]);
*
* @param long The index to be checked.
* @return bool True if the element at the given index exists.
*/
PHP_METHOD(RepeatedField, offsetExists) {
long index;
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
return;
}
RepeatedField *intern = UNBOX(RepeatedField, getThis());
RETURN_BOOL(index >= 0 &&
index < zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array)));
RETURN_BOOL(index >= 0 && index < upb_array_size(intern->array));
}
/**
* Return the element at the given index.
* This will also be called for: $ele = $arr[0]
* RepeatedField::offsetGet()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $x = $arr[$idx];
*
* @param long The index of the element to be fetched.
* @return object The stored element at given index.
* @exception Invalid type for index.
* @exception Non-existing index.
*/
PHP_METHOD(RepeatedField, offsetGet) {
long index;
void *memory;
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
upb_msgval msgval;
zval ret;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
return;
}
RepeatedField *intern = UNBOX(RepeatedField, getThis());
HashTable *table = PHP_PROTO_HASH_OF(intern->array);
if (intern->type == UPB_TYPE_MESSAGE) {
if (php_proto_zend_hash_index_find_zval(table, index, (void **)&memory) ==
FAILURE) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
return;
}
} else {
if (php_proto_zend_hash_index_find_mem(table, index, (void **)&memory) ==
FAILURE) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
return;
}
if (index < 0 || index >= upb_array_size(intern->array)) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
return;
}
native_slot_get_by_array(intern->type, memory,
ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC);
msgval = upb_array_get(intern->array, index);
Convert_UpbToPhp(msgval, &ret, intern->type, intern->desc, &intern->arena);
RETURN_ZVAL(&ret, 0, 1);
}
/**
* Assign the element at the given index.
* This will also be called for: $arr []= $ele and $arr[0] = ele
* RepeatedField::offsetSet()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $arr[$idx] = $x;
* $arr []= $x; // Append
*
* @param long The index of the element to be assigned.
* @param object The element to be assigned.
* @exception Invalid type for index.
@ -418,140 +297,306 @@ PHP_METHOD(RepeatedField, offsetGet) {
* @exception Incorrect type of the element.
*/
PHP_METHOD(RepeatedField, offsetSet) {
zval *index, *value;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &index, &value) ==
FAILURE) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
size_t size = upb_array_size(intern->array);
zval *offset, *val;
int64_t index;
upb_msgval msgval;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &offset, &val) != SUCCESS) {
return;
}
if (Z_TYPE_P(offset) == IS_NULL) {
index = size;
} else if (!Convert_PhpToInt64(offset, &index)) {
return;
}
repeated_field_write_dimension(getThis(), index, value TSRMLS_CC);
if (!Convert_PhpToUpb(val, &msgval, intern->type, intern->desc, arena)) {
return;
}
if (index > size) {
zend_error(E_USER_ERROR, "Element at index %ld doesn't exist.\n", index);
} else if (index == size) {
upb_array_append(intern->array, msgval, Arena_Get(&intern->arena));
} else {
upb_array_set(intern->array, index, msgval);
}
}
/**
* Remove the element at the given index.
* This will also be called for: unset($arr)
* RepeatedField::offsetUnset()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* unset($arr[$idx]);
*
* @param long The index of the element to be removed.
* @exception Invalid type for index.
* @exception The element to be removed is not at the end of the RepeatedField.
*/
PHP_METHOD(RepeatedField, offsetUnset) {
long index;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
FAILURE) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
zend_long size = upb_array_size(intern->array);
// Only the element at the end of the array can be removed.
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) != SUCCESS) {
return;
}
RepeatedField *intern = UNBOX(RepeatedField, getThis());
// Only the element at the end of the array can be removed.
if (index == -1 ||
index != (zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array)) - 1)) {
zend_error(E_USER_ERROR, "Cannot remove element at %ld.\n", index);
if (size == 0 || index != size - 1) {
php_error_docref(NULL, E_USER_ERROR, "Cannot remove element at %ld.\n",
index);
return;
}
zend_hash_index_del(PHP_PROTO_HASH_OF(intern->array), index);
upb_array_resize(intern->array, size - 1, Arena_Get(&intern->arena));
}
/**
* RepeatedField::count()
*
* Implements the Countable interface. Invoked when PHP code calls:
*
* $len = count($arr);
* Return the number of stored elements.
* This will also be called for: count($arr)
* @return long The number of stored elements.
*/
PHP_METHOD(RepeatedField, count) {
RepeatedField *intern = UNBOX(RepeatedField, getThis());
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array)));
RETURN_LONG(upb_array_size(intern->array));
}
/**
* Return the beginning iterator.
* This will also be called for: foreach($arr)
* RepeatedField::getIterator()
*
* Implements the IteratorAggregate interface. Invoked when PHP code calls:
*
* foreach ($arr) {}
*
* @return object Beginning iterator.
*/
PHP_METHOD(RepeatedField, getIterator) {
CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(return_value,
repeated_field_iter_type);
RepeatedField *intern = UNBOX(RepeatedField, getThis());
RepeatedFieldIter *iter = UNBOX(RepeatedFieldIter, return_value);
iter->repeated_field = intern;
iter->position = 0;
zval ret;
RepeatedFieldIter_make(&ret, getThis());
RETURN_ZVAL(&ret, 0, 1);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()
static zend_function_entry repeated_field_methods[] = {
PHP_ME(RepeatedField, __construct, NULL, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, append, NULL, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// RepeatedFieldIter creation/destruction
// PHP RepeatedFieldIter
// -----------------------------------------------------------------------------
// Define object free method.
PHP_PROTO_OBJECT_EMPTY_FREE_START(RepeatedFieldIter, repeated_field_iter)
PHP_PROTO_OBJECT_FREE_END
typedef struct {
zend_object std;
zval repeated_field;
zend_long position;
} RepeatedFieldIter;
PHP_PROTO_OBJECT_EMPTY_DTOR_START(RepeatedFieldIter, repeated_field_iter)
PHP_PROTO_OBJECT_DTOR_END
zend_class_entry *RepeatedFieldIter_class_entry;
static zend_object_handlers repeated_field_iter_object_handlers;
// Define object create method.
PHP_PROTO_OBJECT_CREATE_START(RepeatedFieldIter, repeated_field_iter)
intern->repeated_field = NULL;
intern->position = 0;
PHP_PROTO_OBJECT_CREATE_END(RepeatedFieldIter, repeated_field_iter)
/**
* RepeatedFieldIter_create()
*
* PHP class entry function to allocate and initialize a new RepeatedFieldIter
* object.
*/
zend_object* RepeatedFieldIter_create(zend_class_entry *class_type) {
RepeatedFieldIter *intern = emalloc(sizeof(RepeatedFieldIter));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &repeated_field_iter_object_handlers;
ZVAL_NULL(&intern->repeated_field);
intern->position = 0;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
// Init class entry.
PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\RepeatedFieldIter",
RepeatedFieldIter, repeated_field_iter)
zend_class_implements(repeated_field_iter_type TSRMLS_CC, 1, zend_ce_iterator);
PHP_PROTO_INIT_CLASS_END
/**
* RepeatedFieldIter_dtor()
*
* Object handler to destroy a RepeatedFieldIter. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void RepeatedFieldIter_dtor(zend_object* obj) {
RepeatedFieldIter* intern = (RepeatedFieldIter*)obj;
zval_ptr_dtor(&intern->repeated_field);
zend_object_std_dtor(&intern->std);
}
// -----------------------------------------------------------------------------
// PHP RepeatedFieldIter Methods
// -----------------------------------------------------------------------------
/**
* RepeatedFieldIter_make()
*
* C function to create a RepeatedFieldIter.
*/
static void RepeatedFieldIter_make(zval *val, zval *repeated_field) {
RepeatedFieldIter *iter;
ZVAL_OBJ(val, RepeatedFieldIter_class_entry->create_object(
RepeatedFieldIter_class_entry));
iter = (RepeatedFieldIter*)Z_OBJ_P(val);
ZVAL_COPY(&iter->repeated_field, repeated_field);
}
/*
* When a user writes:
*
* foreach($arr as $key => $val) {}
*
* PHP's iterator protocol is:
*
* $iter = $arr->getIterator();
* for ($iter->rewind(); $iter->valid(); $iter->next()) {
* $key = $iter->key();
* $val = $iter->current();
* }
*/
/**
* RepeatedFieldIter::rewind()
*
* Implements the Iterator interface. Sets the iterator to the first element.
*/
PHP_METHOD(RepeatedFieldIter, rewind) {
RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis());
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
intern->position = 0;
}
/**
* RepeatedFieldIter::current()
*
* Implements the Iterator interface. Returns the current value.
*/
PHP_METHOD(RepeatedFieldIter, current) {
RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis());
RepeatedField *repeated_field = intern->repeated_field;
long index = 0;
void *memory;
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
upb_array *array = field->array;
zend_long index = intern->position;
upb_msgval msgval;
zval ret;
if (index < 0 || index >= upb_array_size(array)) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
}
HashTable *table = PHP_PROTO_HASH_OF(repeated_field->array);
msgval = upb_array_get(array, index);
if (repeated_field->type == UPB_TYPE_MESSAGE) {
if (php_proto_zend_hash_index_find_zval(table, intern->position,
(void **)&memory) == FAILURE) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
return;
}
} else {
if (php_proto_zend_hash_index_find_mem(table, intern->position,
(void **)&memory) == FAILURE) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
return;
}
}
native_slot_get_by_array(repeated_field->type, memory,
ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC);
Convert_UpbToPhp(msgval, &ret, field->type, field->desc, &field->arena);
RETURN_ZVAL(&ret, 0, 1);
}
/**
* RepeatedFieldIter::key()
*
* Implements the Iterator interface. Returns the current key.
*/
PHP_METHOD(RepeatedFieldIter, key) {
RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis());
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RETURN_LONG(intern->position);
}
/**
* RepeatedFieldIter::next()
*
* Implements the Iterator interface. Advances to the next element.
*/
PHP_METHOD(RepeatedFieldIter, next) {
RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis());
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
++intern->position;
}
/**
* RepeatedFieldIter::valid()
*
* Implements the Iterator interface. Returns true if this is a valid element.
*/
PHP_METHOD(RepeatedFieldIter, valid) {
RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis());
RETURN_BOOL(zend_hash_num_elements(PHP_PROTO_HASH_OF(
intern->repeated_field->array)) > intern->position);
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
RETURN_BOOL(intern->position < upb_array_size(field->array));
}
static zend_function_entry repeated_field_iter_methods[] = {
PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
/**
* Array_ModuleInit()
*
* Called when the C extension is loaded to register all types.
*/
void Array_ModuleInit() {
zend_class_entry tmp_ce;
zend_object_handlers *h;
// RepeatedField.
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedField",
repeated_field_methods);
RepeatedField_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(RepeatedField_class_entry, 3, spl_ce_ArrayAccess,
zend_ce_aggregate, spl_ce_Countable);
RepeatedField_class_entry->ce_flags |= ZEND_ACC_FINAL;
RepeatedField_class_entry->create_object = RepeatedField_create;
h = &RepeatedField_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = RepeatedField_destructor;
h->get_properties = RepeatedField_GetProperties;
h->get_property_ptr_ptr = RepeatedField_GetPropertyPtrPtr;
// RepeatedFieldIter
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedFieldIter",
repeated_field_iter_methods);
RepeatedFieldIter_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(RepeatedFieldIter_class_entry, 1, zend_ce_iterator);
RepeatedFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
RepeatedFieldIter_class_entry->create_object = RepeatedFieldIter_create;
h = &repeated_field_iter_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = RepeatedFieldIter_dtor;
}

@ -1,635 +0,0 @@
unsigned char descriptor_proto[] = {
0x0a, 0x9b, 0x3b, 0x0a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x0f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x22, 0x4d, 0x0a, 0x11, 0x46, 0x69,
0x6c, 0x65, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72,
0x53, 0x65, 0x74, 0x12, 0x38, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18,
0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x46, 0x69, 0x6c, 0x65, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x04, 0x66, 0x69, 0x6c,
0x65, 0x22, 0xe4, 0x04, 0x0a, 0x13, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a,
0x07, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x07, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x12,
0x1e, 0x0a, 0x0a, 0x64, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63,
0x79, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x64, 0x65, 0x70,
0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x2b, 0x0a, 0x11, 0x70,
0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x64, 0x65, 0x70, 0x65, 0x6e, 0x64,
0x65, 0x6e, 0x63, 0x79, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x05, 0x52, 0x10,
0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64,
0x65, 0x6e, 0x63, 0x79, 0x12, 0x27, 0x0a, 0x0f, 0x77, 0x65, 0x61, 0x6b,
0x5f, 0x64, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, 0x18,
0x0b, 0x20, 0x03, 0x28, 0x05, 0x52, 0x0e, 0x77, 0x65, 0x61, 0x6b, 0x44,
0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x43, 0x0a,
0x0c, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x74, 0x79, 0x70,
0x65, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x67, 0x6f,
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2e, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72,
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x0b, 0x6d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x41, 0x0a, 0x09, 0x65, 0x6e,
0x75, 0x6d, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x03, 0x28,
0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6e, 0x75, 0x6d,
0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72,
0x6f, 0x74, 0x6f, 0x52, 0x08, 0x65, 0x6e, 0x75, 0x6d, 0x54, 0x79, 0x70,
0x65, 0x12, 0x41, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63,
0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52,
0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x43, 0x0a, 0x09,
0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x07, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69,
0x65, 0x6c, 0x64, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f,
0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x09, 0x65, 0x78, 0x74, 0x65,
0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x36, 0x0a, 0x07, 0x6f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c,
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x73, 0x12, 0x49, 0x0a, 0x10, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f,
0x63, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x09, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x6f,
0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f,
0x52, 0x0e, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x64, 0x65,
0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6e, 0x74,
0x61, 0x78, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x79,
0x6e, 0x74, 0x61, 0x78, 0x22, 0xb9, 0x06, 0x0a, 0x0f, 0x44, 0x65, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f,
0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x3b, 0x0a, 0x05,
0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x25, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x44,
0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f,
0x74, 0x6f, 0x52, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x43, 0x0a,
0x09, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x06,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46,
0x69, 0x65, 0x6c, 0x64, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x09, 0x65, 0x78, 0x74,
0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x41, 0x0a, 0x0b, 0x6e, 0x65,
0x73, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x52, 0x0a, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x54, 0x79, 0x70,
0x65, 0x12, 0x41, 0x0a, 0x09, 0x65, 0x6e, 0x75, 0x6d, 0x5f, 0x74, 0x79,
0x70, 0x65, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67,
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x44, 0x65, 0x73, 0x63, 0x72,
0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x08,
0x65, 0x6e, 0x75, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x12, 0x58, 0x0a, 0x0f,
0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x72, 0x61,
0x6e, 0x67, 0x65, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2f, 0x2e,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2e, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x78, 0x74, 0x65,
0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0e,
0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x61, 0x6e,
0x67, 0x65, 0x12, 0x44, 0x0a, 0x0a, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x5f,
0x64, 0x65, 0x63, 0x6c, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25,
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4f, 0x6e, 0x65, 0x6f, 0x66, 0x44, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x52, 0x09, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x44, 0x65, 0x63, 0x6c,
0x12, 0x39, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18,
0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f,
0x6e, 0x73, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12,
0x55, 0x0a, 0x0e, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x5f,
0x72, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x2e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65,
0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x52,
0x0d, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x61, 0x6e,
0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76,
0x65, 0x64, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x03, 0x28,
0x09, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x4e,
0x61, 0x6d, 0x65, 0x1a, 0x7a, 0x0a, 0x0e, 0x45, 0x78, 0x74, 0x65, 0x6e,
0x73, 0x69, 0x6f, 0x6e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x14, 0x0a,
0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x65,
0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x6e,
0x64, 0x12, 0x40, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
0x2e, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x61,
0x6e, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07,
0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x37, 0x0a, 0x0d, 0x52,
0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65,
0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20,
0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10,
0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52,
0x03, 0x65, 0x6e, 0x64, 0x22, 0x7c, 0x0a, 0x15, 0x45, 0x78, 0x74, 0x65,
0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x4f, 0x70,
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x58, 0x0a, 0x14, 0x75, 0x6e, 0x69,
0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x5f, 0x6f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0xe7, 0x07, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x6e, 0x69, 0x6e, 0x74,
0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74, 0x69,
0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70,
0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x2a,
0x09, 0x08, 0xe8, 0x07, 0x10, 0x80, 0x80, 0x80, 0x80, 0x02, 0x22, 0x98,
0x06, 0x0a, 0x14, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x44, 0x65, 0x73, 0x63,
0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12,
0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6e,
0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52,
0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x05, 0x6c,
0x61, 0x62, 0x65, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2b,
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x44, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x52, 0x05, 0x6c, 0x61, 0x62,
0x65, 0x6c, 0x12, 0x3e, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05,
0x20, 0x01, 0x28, 0x0e, 0x32, 0x2a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46,
0x69, 0x65, 0x6c, 0x64, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x79, 0x70, 0x65,
0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x74, 0x79,
0x70, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28,
0x09, 0x52, 0x08, 0x74, 0x79, 0x70, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12,
0x1a, 0x0a, 0x08, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x65, 0x65, 0x18,
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x65, 0x78, 0x74, 0x65, 0x6e,
0x64, 0x65, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x64, 0x65, 0x66, 0x61, 0x75,
0x6c, 0x74, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x07, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0c, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x56,
0x61, 0x6c, 0x75, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x6e, 0x65, 0x6f,
0x66, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x09, 0x20, 0x01, 0x28,
0x05, 0x52, 0x0a, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x49, 0x6e, 0x64, 0x65,
0x78, 0x12, 0x1b, 0x0a, 0x09, 0x6a, 0x73, 0x6f, 0x6e, 0x5f, 0x6e, 0x61,
0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6a, 0x73,
0x6f, 0x6e, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x37, 0x0a, 0x07, 0x6f, 0x70,
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69,
0x6f, 0x6e, 0x73, 0x22, 0xb6, 0x02, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65,
0x12, 0x0f, 0x0a, 0x0b, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x44, 0x4f, 0x55,
0x42, 0x4c, 0x45, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x54, 0x59, 0x50,
0x45, 0x5f, 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x10, 0x02, 0x12, 0x0e, 0x0a,
0x0a, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x4e, 0x54, 0x36, 0x34, 0x10,
0x03, 0x12, 0x0f, 0x0a, 0x0b, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x49,
0x4e, 0x54, 0x36, 0x34, 0x10, 0x04, 0x12, 0x0e, 0x0a, 0x0a, 0x54, 0x59,
0x50, 0x45, 0x5f, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x10, 0x05, 0x12, 0x10,
0x0a, 0x0c, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x46, 0x49, 0x58, 0x45, 0x44,
0x36, 0x34, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x54, 0x59, 0x50, 0x45,
0x5f, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x10, 0x07, 0x12, 0x0d,
0x0a, 0x09, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x42, 0x4f, 0x4f, 0x4c, 0x10,
0x08, 0x12, 0x0f, 0x0a, 0x0b, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x54,
0x52, 0x49, 0x4e, 0x47, 0x10, 0x09, 0x12, 0x0e, 0x0a, 0x0a, 0x54, 0x59,
0x50, 0x45, 0x5f, 0x47, 0x52, 0x4f, 0x55, 0x50, 0x10, 0x0a, 0x12, 0x10,
0x0a, 0x0c, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x4d, 0x45, 0x53, 0x53, 0x41,
0x47, 0x45, 0x10, 0x0b, 0x12, 0x0e, 0x0a, 0x0a, 0x54, 0x59, 0x50, 0x45,
0x5f, 0x42, 0x59, 0x54, 0x45, 0x53, 0x10, 0x0c, 0x12, 0x0f, 0x0a, 0x0b,
0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x10,
0x0d, 0x12, 0x0d, 0x0a, 0x09, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x45, 0x4e,
0x55, 0x4d, 0x10, 0x0e, 0x12, 0x11, 0x0a, 0x0d, 0x54, 0x59, 0x50, 0x45,
0x5f, 0x53, 0x46, 0x49, 0x58, 0x45, 0x44, 0x33, 0x32, 0x10, 0x0f, 0x12,
0x11, 0x0a, 0x0d, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x46, 0x49, 0x58,
0x45, 0x44, 0x36, 0x34, 0x10, 0x10, 0x12, 0x0f, 0x0a, 0x0b, 0x54, 0x59,
0x50, 0x45, 0x5f, 0x53, 0x49, 0x4e, 0x54, 0x33, 0x32, 0x10, 0x11, 0x12,
0x0f, 0x0a, 0x0b, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x49, 0x4e, 0x54,
0x36, 0x34, 0x10, 0x12, 0x22, 0x43, 0x0a, 0x05, 0x4c, 0x61, 0x62, 0x65,
0x6c, 0x12, 0x12, 0x0a, 0x0e, 0x4c, 0x41, 0x42, 0x45, 0x4c, 0x5f, 0x4f,
0x50, 0x54, 0x49, 0x4f, 0x4e, 0x41, 0x4c, 0x10, 0x01, 0x12, 0x12, 0x0a,
0x0e, 0x4c, 0x41, 0x42, 0x45, 0x4c, 0x5f, 0x52, 0x45, 0x51, 0x55, 0x49,
0x52, 0x45, 0x44, 0x10, 0x02, 0x12, 0x12, 0x0a, 0x0e, 0x4c, 0x41, 0x42,
0x45, 0x4c, 0x5f, 0x52, 0x45, 0x50, 0x45, 0x41, 0x54, 0x45, 0x44, 0x10,
0x03, 0x22, 0x63, 0x0a, 0x14, 0x4f, 0x6e, 0x65, 0x6f, 0x66, 0x44, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x37, 0x0a,
0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4f, 0x6e, 0x65,
0x6f, 0x66, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xe3, 0x02, 0x0a, 0x13, 0x45,
0x6e, 0x75, 0x6d, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f,
0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61,
0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
0x6d, 0x65, 0x12, 0x3f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18,
0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x45, 0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x65, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f,
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x36, 0x0a, 0x07, 0x6f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x4f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69,
0x6f, 0x6e, 0x73, 0x12, 0x5d, 0x0a, 0x0e, 0x72, 0x65, 0x73, 0x65, 0x72,
0x76, 0x65, 0x64, 0x5f, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x04, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x36, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6e,
0x75, 0x6d, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72,
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x65,
0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x52,
0x0d, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x61, 0x6e,
0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76,
0x65, 0x64, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x03, 0x28,
0x09, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x4e,
0x61, 0x6d, 0x65, 0x1a, 0x3b, 0x0a, 0x11, 0x45, 0x6e, 0x75, 0x6d, 0x52,
0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65,
0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20,
0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10,
0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52,
0x03, 0x65, 0x6e, 0x64, 0x22, 0x83, 0x01, 0x0a, 0x18, 0x45, 0x6e, 0x75,
0x6d, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x0a,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d,
0x62, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e,
0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x3b, 0x0a, 0x07, 0x6f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21,
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c,
0x75, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xa7, 0x01, 0x0a, 0x16, 0x53,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x0a,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x3e, 0x0a, 0x06, 0x6d, 0x65, 0x74,
0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x26, 0x2e,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x44, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x39, 0x0a,
0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52,
0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x89, 0x02, 0x0a,
0x15, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x44, 0x65, 0x73, 0x63, 0x72,
0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12,
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6e,
0x70, 0x75, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x09, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x54, 0x79, 0x70,
0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f,
0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x38,
0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x04, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65,
0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52,
0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x30, 0x0a, 0x10,
0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61,
0x6d, 0x69, 0x6e, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x3a, 0x05,
0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x0f, 0x63, 0x6c, 0x69, 0x65, 0x6e,
0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x12, 0x30,
0x0a, 0x10, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x73, 0x74, 0x72,
0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08,
0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x0f, 0x73, 0x65, 0x72,
0x76, 0x65, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67,
0x22, 0x92, 0x09, 0x0a, 0x0b, 0x46, 0x69, 0x6c, 0x65, 0x4f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x6a, 0x61, 0x76, 0x61,
0x5f, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0b, 0x6a, 0x61, 0x76, 0x61, 0x50, 0x61, 0x63, 0x6b,
0x61, 0x67, 0x65, 0x12, 0x30, 0x0a, 0x14, 0x6a, 0x61, 0x76, 0x61, 0x5f,
0x6f, 0x75, 0x74, 0x65, 0x72, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x6e,
0x61, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x6a,
0x61, 0x76, 0x61, 0x4f, 0x75, 0x74, 0x65, 0x72, 0x43, 0x6c, 0x61, 0x73,
0x73, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x35, 0x0a, 0x13, 0x6a, 0x61, 0x76,
0x61, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x5f, 0x66,
0x69, 0x6c, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x3a, 0x05,
0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x11, 0x6a, 0x61, 0x76, 0x61, 0x4d,
0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x73,
0x12, 0x44, 0x0a, 0x1d, 0x6a, 0x61, 0x76, 0x61, 0x5f, 0x67, 0x65, 0x6e,
0x65, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x65, 0x71, 0x75, 0x61, 0x6c, 0x73,
0x5f, 0x61, 0x6e, 0x64, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x14, 0x20,
0x01, 0x28, 0x08, 0x42, 0x02, 0x18, 0x01, 0x52, 0x19, 0x6a, 0x61, 0x76,
0x61, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x45, 0x71, 0x75,
0x61, 0x6c, 0x73, 0x41, 0x6e, 0x64, 0x48, 0x61, 0x73, 0x68, 0x12, 0x3a,
0x0a, 0x16, 0x6a, 0x61, 0x76, 0x61, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e,
0x67, 0x5f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x75, 0x74, 0x66, 0x38,
0x18, 0x1b, 0x20, 0x01, 0x28, 0x08, 0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73,
0x65, 0x52, 0x13, 0x6a, 0x61, 0x76, 0x61, 0x53, 0x74, 0x72, 0x69, 0x6e,
0x67, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x55, 0x74, 0x66, 0x38, 0x12, 0x53,
0x0a, 0x0c, 0x6f, 0x70, 0x74, 0x69, 0x6d, 0x69, 0x7a, 0x65, 0x5f, 0x66,
0x6f, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x29, 0x2e, 0x67,
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f,
0x6e, 0x73, 0x2e, 0x4f, 0x70, 0x74, 0x69, 0x6d, 0x69, 0x7a, 0x65, 0x4d,
0x6f, 0x64, 0x65, 0x3a, 0x05, 0x53, 0x50, 0x45, 0x45, 0x44, 0x52, 0x0b,
0x6f, 0x70, 0x74, 0x69, 0x6d, 0x69, 0x7a, 0x65, 0x46, 0x6f, 0x72, 0x12,
0x1d, 0x0a, 0x0a, 0x67, 0x6f, 0x5f, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67,
0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x67, 0x6f, 0x50,
0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x12, 0x35, 0x0a, 0x13, 0x63, 0x63,
0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x5f, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x08, 0x3a,
0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x11, 0x63, 0x63, 0x47, 0x65,
0x6e, 0x65, 0x72, 0x69, 0x63, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x73, 0x12, 0x39, 0x0a, 0x15, 0x6a, 0x61, 0x76, 0x61, 0x5f, 0x67, 0x65,
0x6e, 0x65, 0x72, 0x69, 0x63, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x73, 0x18, 0x11, 0x20, 0x01, 0x28, 0x08, 0x3a, 0x05, 0x66, 0x61,
0x6c, 0x73, 0x65, 0x52, 0x13, 0x6a, 0x61, 0x76, 0x61, 0x47, 0x65, 0x6e,
0x65, 0x72, 0x69, 0x63, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73,
0x12, 0x35, 0x0a, 0x13, 0x70, 0x79, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72,
0x69, 0x63, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18,
0x12, 0x20, 0x01, 0x28, 0x08, 0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65,
0x52, 0x11, 0x70, 0x79, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x53,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x37, 0x0a, 0x14, 0x70,
0x68, 0x70, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x5f, 0x73,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x2a, 0x20, 0x01, 0x28,
0x08, 0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x12, 0x70, 0x68,
0x70, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x53, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x73, 0x12, 0x25, 0x0a, 0x0a, 0x64, 0x65, 0x70, 0x72,
0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x17, 0x20, 0x01, 0x28, 0x08,
0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x0a, 0x64, 0x65, 0x70,
0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x12, 0x2f, 0x0a, 0x10, 0x63,
0x63, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x61, 0x72, 0x65,
0x6e, 0x61, 0x73, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x08, 0x3a, 0x05, 0x66,
0x61, 0x6c, 0x73, 0x65, 0x52, 0x0e, 0x63, 0x63, 0x45, 0x6e, 0x61, 0x62,
0x6c, 0x65, 0x41, 0x72, 0x65, 0x6e, 0x61, 0x73, 0x12, 0x2a, 0x0a, 0x11,
0x6f, 0x62, 0x6a, 0x63, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x5f, 0x70,
0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x24, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0f, 0x6f, 0x62, 0x6a, 0x63, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x50, 0x72,
0x65, 0x66, 0x69, 0x78, 0x12, 0x29, 0x0a, 0x10, 0x63, 0x73, 0x68, 0x61,
0x72, 0x70, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65,
0x18, 0x25, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x63, 0x73, 0x68, 0x61,
0x72, 0x70, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12,
0x21, 0x0a, 0x0c, 0x73, 0x77, 0x69, 0x66, 0x74, 0x5f, 0x70, 0x72, 0x65,
0x66, 0x69, 0x78, 0x18, 0x27, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73,
0x77, 0x69, 0x66, 0x74, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x28,
0x0a, 0x10, 0x70, 0x68, 0x70, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x5f,
0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x28, 0x20, 0x01, 0x28, 0x09,
0x52, 0x0e, 0x70, 0x68, 0x70, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x50, 0x72,
0x65, 0x66, 0x69, 0x78, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x68, 0x70, 0x5f,
0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x29, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x68, 0x70, 0x4e, 0x61, 0x6d, 0x65,
0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x16, 0x70, 0x68, 0x70,
0x5f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x6e, 0x61,
0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x2c, 0x20, 0x01, 0x28,
0x09, 0x52, 0x14, 0x70, 0x68, 0x70, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61,
0x74, 0x61, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12,
0x21, 0x0a, 0x0c, 0x72, 0x75, 0x62, 0x79, 0x5f, 0x70, 0x61, 0x63, 0x6b,
0x61, 0x67, 0x65, 0x18, 0x2d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x72,
0x75, 0x62, 0x79, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x12, 0x58,
0x0a, 0x14, 0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65,
0x74, 0x65, 0x64, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0xe7,
0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x55, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65,
0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e, 0x69,
0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70,
0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x0a, 0x0c, 0x4f, 0x70, 0x74, 0x69,
0x6d, 0x69, 0x7a, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x09, 0x0a, 0x05,
0x53, 0x50, 0x45, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x43,
0x4f, 0x44, 0x45, 0x5f, 0x53, 0x49, 0x5a, 0x45, 0x10, 0x02, 0x12, 0x10,
0x0a, 0x0c, 0x4c, 0x49, 0x54, 0x45, 0x5f, 0x52, 0x55, 0x4e, 0x54, 0x49,
0x4d, 0x45, 0x10, 0x03, 0x2a, 0x09, 0x08, 0xe8, 0x07, 0x10, 0x80, 0x80,
0x80, 0x80, 0x02, 0x4a, 0x04, 0x08, 0x26, 0x10, 0x27, 0x22, 0xd1, 0x02,
0x0a, 0x0e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x12, 0x3c, 0x0a, 0x17, 0x6d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x77, 0x69, 0x72, 0x65,
0x5f, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
0x08, 0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x14, 0x6d, 0x65,
0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x57, 0x69, 0x72, 0x65,
0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x12, 0x4c, 0x0a, 0x1f, 0x6e, 0x6f,
0x5f, 0x73, 0x74, 0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x5f, 0x64, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x5f, 0x61, 0x63, 0x63,
0x65, 0x73, 0x73, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x3a,
0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x1c, 0x6e, 0x6f, 0x53, 0x74,
0x61, 0x6e, 0x64, 0x61, 0x72, 0x64, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x6f, 0x72, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x6f, 0x72,
0x12, 0x25, 0x0a, 0x0a, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74,
0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x3a, 0x05, 0x66, 0x61,
0x6c, 0x73, 0x65, 0x52, 0x0a, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61,
0x74, 0x65, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x6d, 0x61, 0x70, 0x5f, 0x65,
0x6e, 0x74, 0x72, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08,
0x6d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x58, 0x0a, 0x14,
0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65,
0x64, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0xe7, 0x07, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x6e,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e, 0x69, 0x6e, 0x74,
0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74, 0x69,
0x6f, 0x6e, 0x2a, 0x09, 0x08, 0xe8, 0x07, 0x10, 0x80, 0x80, 0x80, 0x80,
0x02, 0x4a, 0x04, 0x08, 0x08, 0x10, 0x09, 0x4a, 0x04, 0x08, 0x09, 0x10,
0x0a, 0x22, 0xe2, 0x03, 0x0a, 0x0c, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x41, 0x0a, 0x05, 0x63, 0x74,
0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x06,
0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x52, 0x05, 0x63, 0x74, 0x79, 0x70,
0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x18,
0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x70, 0x61, 0x63, 0x6b, 0x65,
0x64, 0x12, 0x47, 0x0a, 0x06, 0x6a, 0x73, 0x74, 0x79, 0x70, 0x65, 0x18,
0x06, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73,
0x2e, 0x4a, 0x53, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x09, 0x4a, 0x53, 0x5f,
0x4e, 0x4f, 0x52, 0x4d, 0x41, 0x4c, 0x52, 0x06, 0x6a, 0x73, 0x74, 0x79,
0x70, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x6c, 0x61, 0x7a, 0x79, 0x18, 0x05,
0x20, 0x01, 0x28, 0x08, 0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52,
0x04, 0x6c, 0x61, 0x7a, 0x79, 0x12, 0x25, 0x0a, 0x0a, 0x64, 0x65, 0x70,
0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
0x08, 0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x0a, 0x64, 0x65,
0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x04,
0x77, 0x65, 0x61, 0x6b, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x3a, 0x05,
0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x04, 0x77, 0x65, 0x61, 0x6b, 0x12,
0x58, 0x0a, 0x14, 0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72,
0x65, 0x74, 0x65, 0x64, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18,
0xe7, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
0x2e, 0x55, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74,
0x65, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x2f, 0x0a, 0x05, 0x43, 0x54, 0x79,
0x70, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47,
0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x4f, 0x52, 0x44, 0x10, 0x01,
0x12, 0x10, 0x0a, 0x0c, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x5f, 0x50,
0x49, 0x45, 0x43, 0x45, 0x10, 0x02, 0x22, 0x35, 0x0a, 0x06, 0x4a, 0x53,
0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x09, 0x4a, 0x53, 0x5f, 0x4e,
0x4f, 0x52, 0x4d, 0x41, 0x4c, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x4a,
0x53, 0x5f, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x0d,
0x0a, 0x09, 0x4a, 0x53, 0x5f, 0x4e, 0x55, 0x4d, 0x42, 0x45, 0x52, 0x10,
0x02, 0x2a, 0x09, 0x08, 0xe8, 0x07, 0x10, 0x80, 0x80, 0x80, 0x80, 0x02,
0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, 0x22, 0x73, 0x0a, 0x0c, 0x4f, 0x6e,
0x65, 0x6f, 0x66, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x58,
0x0a, 0x14, 0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65,
0x74, 0x65, 0x64, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0xe7,
0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x55, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65,
0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e, 0x69,
0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70,
0x74, 0x69, 0x6f, 0x6e, 0x2a, 0x09, 0x08, 0xe8, 0x07, 0x10, 0x80, 0x80,
0x80, 0x80, 0x02, 0x22, 0xc0, 0x01, 0x0a, 0x0b, 0x45, 0x6e, 0x75, 0x6d,
0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x61,
0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x18, 0x02,
0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x41,
0x6c, 0x69, 0x61, 0x73, 0x12, 0x25, 0x0a, 0x0a, 0x64, 0x65, 0x70, 0x72,
0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08,
0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x0a, 0x64, 0x65, 0x70,
0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x12, 0x58, 0x0a, 0x14, 0x75,
0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64,
0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0xe7, 0x07, 0x20, 0x03,
0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x6e, 0x69,
0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70,
0x74, 0x69, 0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65,
0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f,
0x6e, 0x2a, 0x09, 0x08, 0xe8, 0x07, 0x10, 0x80, 0x80, 0x80, 0x80, 0x02,
0x4a, 0x04, 0x08, 0x05, 0x10, 0x06, 0x22, 0x9e, 0x01, 0x0a, 0x10, 0x45,
0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x70, 0x74, 0x69,
0x6f, 0x6e, 0x73, 0x12, 0x25, 0x0a, 0x0a, 0x64, 0x65, 0x70, 0x72, 0x65,
0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x3a,
0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x0a, 0x64, 0x65, 0x70, 0x72,
0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x12, 0x58, 0x0a, 0x14, 0x75, 0x6e,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x5f,
0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0xe7, 0x07, 0x20, 0x03, 0x28,
0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x6e, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72,
0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x2a, 0x09, 0x08, 0xe8, 0x07, 0x10, 0x80, 0x80, 0x80, 0x80, 0x02, 0x22,
0x9c, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x25, 0x0a, 0x0a, 0x64, 0x65,
0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x21, 0x20, 0x01,
0x28, 0x08, 0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52, 0x0a, 0x64,
0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x12, 0x58, 0x0a,
0x14, 0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74,
0x65, 0x64, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0xe7, 0x07,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55,
0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64,
0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x2a, 0x09, 0x08, 0xe8, 0x07, 0x10, 0x80, 0x80, 0x80,
0x80, 0x02, 0x22, 0xe0, 0x02, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x68, 0x6f,
0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x25, 0x0a, 0x0a,
0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x21,
0x20, 0x01, 0x28, 0x08, 0x3a, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x52,
0x0a, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x12,
0x71, 0x0a, 0x11, 0x69, 0x64, 0x65, 0x6d, 0x70, 0x6f, 0x74, 0x65, 0x6e,
0x63, 0x79, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x22, 0x20, 0x01,
0x28, 0x0e, 0x32, 0x2f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74,
0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x49,
0x64, 0x65, 0x6d, 0x70, 0x6f, 0x74, 0x65, 0x6e, 0x63, 0x79, 0x4c, 0x65,
0x76, 0x65, 0x6c, 0x3a, 0x13, 0x49, 0x44, 0x45, 0x4d, 0x50, 0x4f, 0x54,
0x45, 0x4e, 0x43, 0x59, 0x5f, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e,
0x52, 0x10, 0x69, 0x64, 0x65, 0x6d, 0x70, 0x6f, 0x74, 0x65, 0x6e, 0x63,
0x79, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x58, 0x0a, 0x14, 0x75, 0x6e,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x5f,
0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0xe7, 0x07, 0x20, 0x03, 0x28,
0x0b, 0x32, 0x24, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x6e, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x52, 0x13, 0x75, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72,
0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x22, 0x50, 0x0a, 0x10, 0x49, 0x64, 0x65, 0x6d, 0x70, 0x6f, 0x74, 0x65,
0x6e, 0x63, 0x79, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x17, 0x0a, 0x13,
0x49, 0x44, 0x45, 0x4d, 0x50, 0x4f, 0x54, 0x45, 0x4e, 0x43, 0x59, 0x5f,
0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x13, 0x0a,
0x0f, 0x4e, 0x4f, 0x5f, 0x53, 0x49, 0x44, 0x45, 0x5f, 0x45, 0x46, 0x46,
0x45, 0x43, 0x54, 0x53, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x49, 0x44,
0x45, 0x4d, 0x50, 0x4f, 0x54, 0x45, 0x4e, 0x54, 0x10, 0x02, 0x2a, 0x09,
0x08, 0xe8, 0x07, 0x10, 0x80, 0x80, 0x80, 0x80, 0x02, 0x22, 0x9a, 0x03,
0x0a, 0x13, 0x55, 0x6e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65,
0x74, 0x65, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x41, 0x0a,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x2d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x6e, 0x69, 0x6e, 0x74, 0x65,
0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f,
0x6e, 0x2e, 0x4e, 0x61, 0x6d, 0x65, 0x50, 0x61, 0x72, 0x74, 0x52, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x69, 0x64, 0x65, 0x6e,
0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x69, 0x64, 0x65, 0x6e,
0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12,
0x2c, 0x0a, 0x12, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x5f,
0x69, 0x6e, 0x74, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x04, 0x20,
0x01, 0x28, 0x04, 0x52, 0x10, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x76,
0x65, 0x49, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x2c, 0x0a,
0x12, 0x6e, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x69, 0x6e,
0x74, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28,
0x03, 0x52, 0x10, 0x6e, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65, 0x49,
0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x64,
0x6f, 0x75, 0x62, 0x6c, 0x65, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18,
0x06, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0b, 0x64, 0x6f, 0x75, 0x62, 0x6c,
0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x74,
0x72, 0x69, 0x6e, 0x67, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x07,
0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67,
0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x61, 0x67, 0x67,
0x72, 0x65, 0x67, 0x61, 0x74, 0x65, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x61, 0x67, 0x67, 0x72,
0x65, 0x67, 0x61, 0x74, 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x1a, 0x4a,
0x0a, 0x08, 0x4e, 0x61, 0x6d, 0x65, 0x50, 0x61, 0x72, 0x74, 0x12, 0x1b,
0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x70, 0x61, 0x72, 0x74, 0x18,
0x01, 0x20, 0x02, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x61, 0x6d, 0x65, 0x50,
0x61, 0x72, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x69, 0x73, 0x5f, 0x65, 0x78,
0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x02, 0x28,
0x08, 0x52, 0x0b, 0x69, 0x73, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69,
0x6f, 0x6e, 0x22, 0xa7, 0x02, 0x0a, 0x0e, 0x53, 0x6f, 0x75, 0x72, 0x63,
0x65, 0x43, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x44, 0x0a,
0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x6f,
0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f,
0x2e, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x6c,
0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0xce, 0x01, 0x0a, 0x08,
0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x04,
0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x03, 0x28, 0x05, 0x42, 0x02,
0x10, 0x01, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x04,
0x73, 0x70, 0x61, 0x6e, 0x18, 0x02, 0x20, 0x03, 0x28, 0x05, 0x42, 0x02,
0x10, 0x01, 0x52, 0x04, 0x73, 0x70, 0x61, 0x6e, 0x12, 0x29, 0x0a, 0x10,
0x6c, 0x65, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x63, 0x6f, 0x6d, 0x6d,
0x65, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f,
0x6c, 0x65, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6d, 0x6d, 0x65,
0x6e, 0x74, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x74, 0x72, 0x61, 0x69, 0x6c,
0x69, 0x6e, 0x67, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73,
0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x74, 0x72, 0x61, 0x69,
0x6c, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73,
0x12, 0x3a, 0x0a, 0x19, 0x6c, 0x65, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x5f,
0x64, 0x65, 0x74, 0x61, 0x63, 0x68, 0x65, 0x64, 0x5f, 0x63, 0x6f, 0x6d,
0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52,
0x17, 0x6c, 0x65, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x44, 0x65, 0x74, 0x61,
0x63, 0x68, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73,
0x22, 0xd1, 0x01, 0x0a, 0x11, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74,
0x65, 0x64, 0x43, 0x6f, 0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x4d,
0x0a, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x43, 0x6f,
0x64, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x41, 0x6e, 0x6e, 0x6f, 0x74,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, 0x74,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x6d, 0x0a, 0x0a, 0x41, 0x6e, 0x6e,
0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x04, 0x70,
0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x03, 0x28, 0x05, 0x42, 0x02, 0x10,
0x01, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x1f, 0x0a, 0x0b, 0x73,
0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x46, 0x69, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x65, 0x67, 0x69,
0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x62, 0x65, 0x67,
0x69, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x04, 0x20,
0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x42, 0x8f, 0x01, 0x0a,
0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x42, 0x10, 0x44, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x73, 0x48, 0x01, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2f,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x67, 0x6f, 0x2f, 0x64,
0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x3b, 0x64, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0xf8, 0x01, 0x01, 0xa2,
0x02, 0x03, 0x47, 0x50, 0x42, 0xaa, 0x02, 0x1a, 0x47, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x52, 0x65, 0x66, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e
};
unsigned int descriptor_proto_len = 7582;

@ -4,7 +4,7 @@ if test "$PHP_PROTOBUF" != "no"; then
PHP_NEW_EXTENSION(
protobuf,
array.c def.c encode_decode.c map.c message.c protobuf.c storage.c type_check.c upb.c utf8.c,
arena.c array.c bundled_php.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c,
$ext_shared)
fi

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -8,7 +8,7 @@ $handle = popen($cmd, 'r');
$filenames = explode("\n", stream_get_contents($handle));
array_pop($filenames); // empty string after last '\n'
$filenames[] = "Google/Protobuf/DescriptorPool.php";
$output = "../ext/google/protobuf2/bundled_php.c";
$output = "../ext/google/protobuf/bundled_php.c";
function stripSuffix($str, $suffix) {
return substr($str, 0, strlen($str) - strlen($suffix));

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -25,20 +25,26 @@
<contents>
<dir baseinstalldir="/" name="/">
<file baseinstalldir="/" name="config.m4" role="src"/>
<file baseinstalldir="/" name="arena.c" role="src"/>
<file baseinstalldir="/" name="arena.h" role="src"/>
<file baseinstalldir="/" name="array.c" role="src"/>
<file baseinstalldir="/" name="builtin_descriptors.inc" role="src"/>
<file baseinstalldir="/" name="array.h" role="src"/>
<file baseinstalldir="/" name="bundled_php.c" role="src"/>
<file baseinstalldir="/" name="bundled_php.h" role="src"/>
<file baseinstalldir="/" name="convert.c" role="src"/>
<file baseinstalldir="/" name="convert.h" role="src"/>
<file baseinstalldir="/" name="def.c" role="src"/>
<file baseinstalldir="/" name="encode_decode.c" role="src"/>
<file baseinstalldir="/" name="def.h" role="src"/>
<file baseinstalldir="/" name="map.c" role="src"/>
<file baseinstalldir="/" name="map.h" role="src"/>
<file baseinstalldir="/" name="message.c" role="src"/>
<file baseinstalldir="/" name="message.h" role="src"/>
<file baseinstalldir="/" name="names.c" role="src"/>
<file baseinstalldir="/" name="names.h" role="src"/>
<file baseinstalldir="/" name="php-upb.c" role="src"/>
<file baseinstalldir="/" name="php-upb.h" role="src"/>
<file baseinstalldir="/" name="protobuf.c" role="src"/>
<file baseinstalldir="/" name="protobuf.h" role="src"/>
<file baseinstalldir="/" name="storage.c" role="src"/>
<file baseinstalldir="/" name="type_check.c" role="src"/>
<file baseinstalldir="/" name="upb.c" role="src"/>
<file baseinstalldir="/" name="upb.h" role="src"/>
<file baseinstalldir="/" name="utf8.c" role="src"/>
<file baseinstalldir="/" name="utf8.h" role="src"/>
<file baseinstalldir="/" name="LICENSE" role="doc"/>
</dir>
</contents>

@ -30,481 +30,281 @@
#include "protobuf.h"
#include <zend_hash.h>
static PHP_GINIT_FUNCTION(protobuf);
static PHP_GSHUTDOWN_FUNCTION(protobuf);
static PHP_RINIT_FUNCTION(protobuf);
static PHP_RSHUTDOWN_FUNCTION(protobuf);
static PHP_MINIT_FUNCTION(protobuf);
static PHP_MSHUTDOWN_FUNCTION(protobuf);
ZEND_DECLARE_MODULE_GLOBALS(protobuf)
// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
// instances.
static HashTable* upb_def_to_php_obj_map;
static upb_inttable upb_def_to_desc_map_persistent;
static upb_inttable upb_def_to_enumdesc_map_persistent;
// Global map from message/enum's php class entry to corresponding wrapper
// Descriptor/EnumDescriptor instances.
static HashTable* ce_to_php_obj_map;
static upb_strtable ce_to_desc_map_persistent;
static upb_strtable ce_to_enumdesc_map_persistent;
// Global map from message/enum's proto fully-qualified name to corresponding
// wrapper Descriptor/EnumDescriptor instances.
static upb_strtable proto_to_desc_map_persistent;
static upb_strtable class_to_desc_map_persistent;
upb_strtable reserved_names;
#include <php.h>
#include <Zend/zend_interfaces.h>
#include "arena.h"
#include "array.h"
#include "bundled_php.h"
#include "convert.h"
#include "def.h"
#include "map.h"
#include "message.h"
#include "names.h"
// -----------------------------------------------------------------------------
// Global maps.
// Module "globals"
// -----------------------------------------------------------------------------
static void add_to_table(HashTable* t, const void* def, void* value) {
zval* pDest = NULL;
php_proto_zend_hash_index_update_mem(t, (zend_ulong)def, &value,
sizeof(zval*), (void**)&pDest);
}
// Despite the name, module "globals" are really thread-locals:
// * PROTOBUF_G(var) accesses the thread-local variable for 'var'. Either:
// * PROTOBUF_G(var) -> protobuf_globals.var (Non-ZTS / non-thread-safe)
// * PROTOBUF_G(var) -> <Zend magic> (ZTS / thread-safe builds)
static void* get_from_table(const HashTable* t, const void* def) {
void** value;
if (php_proto_zend_hash_index_find_mem(t, (zend_ulong)def, (void**)&value) ==
FAILURE) {
return NULL;
}
return *value;
}
#define PROTOBUF_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(protobuf, v)
void add_def_obj(const void* def, PHP_PROTO_HASHTABLE_VALUE value) {
#if PHP_MAJOR_VERSION < 7
Z_ADDREF_P(value);
#else
GC_ADDREF(value);
#endif
add_to_table(upb_def_to_php_obj_map, def, value);
}
ZEND_BEGIN_MODULE_GLOBALS(protobuf)
// Set by the user to make the descriptor pool persist between requests.
zend_bool keep_descriptor_pool_after_request;
PHP_PROTO_HASHTABLE_VALUE get_def_obj(const void* def) {
return (PHP_PROTO_HASHTABLE_VALUE)get_from_table(upb_def_to_php_obj_map, def);
}
// Currently we make the generated pool a "global", which means that if a user
// does explicitly create threads within their request, the other threads will
// get different results from DescriptorPool::getGeneratedPool(). We require
// that all descriptors are loaded from the main thread.
zval generated_pool;
void add_msgdef_desc(const upb_msgdef* m, DescriptorInternal* desc) {
upb_inttable_insertptr(&upb_def_to_desc_map_persistent,
m, upb_value_ptr(desc));
}
// A upb_symtab that we are saving for the next request so that we don't have
// to rebuild it from scratch. When keep_descriptor_pool_after_request==true,
// we steal the upb_symtab from the global DescriptorPool object just before
// destroying it.
upb_symtab *saved_symtab;
DescriptorInternal* get_msgdef_desc(const upb_msgdef* m) {
upb_value v;
#ifndef NDEBUG
v.ctype = UPB_CTYPE_PTR;
#endif
if (!upb_inttable_lookupptr(&upb_def_to_desc_map_persistent, m, &v)) {
return NULL;
} else {
return upb_value_getptr(v);
}
}
void add_enumdef_enumdesc(const upb_enumdef* e, EnumDescriptorInternal* desc) {
upb_inttable_insertptr(&upb_def_to_enumdesc_map_persistent,
e, upb_value_ptr(desc));
}
EnumDescriptorInternal* get_enumdef_enumdesc(const upb_enumdef* e) {
upb_value v;
#ifndef NDEBUG
v.ctype = UPB_CTYPE_PTR;
#endif
if (!upb_inttable_lookupptr(&upb_def_to_enumdesc_map_persistent, e, &v)) {
return NULL;
} else {
return upb_value_getptr(v);
}
}
// Object cache (see interface in protobuf.h).
HashTable object_cache;
void add_ce_obj(const void* ce, PHP_PROTO_HASHTABLE_VALUE value) {
#if PHP_MAJOR_VERSION < 7
Z_ADDREF_P(value);
#else
GC_ADDREF(value);
#endif
add_to_table(ce_to_php_obj_map, ce, value);
}
// Name cache (see interface in protobuf.h).
HashTable name_msg_cache;
HashTable name_enum_cache;
ZEND_END_MODULE_GLOBALS(protobuf)
PHP_PROTO_HASHTABLE_VALUE get_ce_obj(const void* ce) {
return (PHP_PROTO_HASHTABLE_VALUE)get_from_table(ce_to_php_obj_map, ce);
}
ZEND_DECLARE_MODULE_GLOBALS(protobuf)
void add_ce_desc(const zend_class_entry* ce, DescriptorInternal* desc) {
#if PHP_MAJOR_VERSION < 7
const char* klass = ce->name;
#else
const char* klass = ZSTR_VAL(ce->name);
#endif
upb_strtable_insert(&ce_to_desc_map_persistent, klass,
upb_value_ptr(desc));
const zval *get_generated_pool() {
return &PROTOBUF_G(generated_pool);
}
DescriptorInternal* get_ce_desc(const zend_class_entry* ce) {
#if PHP_MAJOR_VERSION < 7
const char* klass = ce->name;
#else
const char* klass = ZSTR_VAL(ce->name);
#endif
upb_value v;
#ifndef NDEBUG
v.ctype = UPB_CTYPE_PTR;
#endif
// This is a PHP extension (not a Zend extension). What follows is a summary of
// a PHP extension's lifetime and when various handlers are called.
//
// * PHP_GINIT_FUNCTION(protobuf) / PHP_GSHUTDOWN_FUNCTION(protobuf)
// are the constructor/destructor for the globals. The sequence over the
// course of a process lifetime is:
//
// # Process startup
// GINIT(<Main Thread Globals>)
// MINIT
//
// foreach request:
// RINIT
// # Request is processed here.
// RSHUTDOWN
//
// foreach thread:
// GINIT(<This Thread Globals>)
// # Code for the thread runs here.
// GSHUTDOWN(<This Thread Globals>)
//
// # Process Shutdown
// #
// # These should be running per the docs, but I have not been able to
// # actually get the process-wide shutdown functions to run.
// #
// # MSHUTDOWN
// # GSHUTDOWN(<Main Thread Globals>)
//
// * Threads can be created either explicitly by the user, inside a request,
// or implicitly by the runtime, to process multiple requests concurrently.
// If the latter is being used, then the "foreach thread" block above
// actually looks like this:
//
// foreach thread:
// GINIT(<This Thread Globals>)
// # A non-main thread will only receive requests when using a threaded
// # MPM with Apache
// foreach request:
// RINIT
// # Request is processed here.
// RSHUTDOWN
// GSHUTDOWN(<This Thread Globals>)
//
// That said, it appears that few people use threads with PHP:
// * The pthread package documented at
// https://www.php.net/manual/en/class.thread.php nas not been released
// since 2016, and the current release fails to compile against any PHP
// newer than 7.0.33.
// * The GitHub master branch supports 7.2+, but this has not been released
// to PECL.
// * Its owner has disavowed it as "broken by design" and "in an untenable
// position for the future": https://github.com/krakjoe/pthreads/issues/929
// * The only way to use PHP with requests in different threads is to use the
// Apache 2 mod_php with the "worker" MPM. But this is explicitly
// discouraged by the documentation: https://serverfault.com/a/231660
if (!upb_strtable_lookup(&ce_to_desc_map_persistent, klass, &v)) {
return NULL;
} else {
return upb_value_getptr(v);
static PHP_GSHUTDOWN_FUNCTION(protobuf) {
if (protobuf_globals->saved_symtab) {
upb_symtab_free(protobuf_globals->saved_symtab);
}
}
void add_ce_enumdesc(const zend_class_entry* ce, EnumDescriptorInternal* desc) {
#if PHP_MAJOR_VERSION < 7
const char* klass = ce->name;
#else
const char* klass = ZSTR_VAL(ce->name);
#endif
upb_strtable_insert(&ce_to_enumdesc_map_persistent, klass,
upb_value_ptr(desc));
}
EnumDescriptorInternal* get_ce_enumdesc(const zend_class_entry* ce) {
#if PHP_MAJOR_VERSION < 7
const char* klass = ce->name;
#else
const char* klass = ZSTR_VAL(ce->name);
#endif
upb_value v;
#ifndef NDEBUG
v.ctype = UPB_CTYPE_PTR;
#endif
if (!upb_strtable_lookup(&ce_to_enumdesc_map_persistent, klass, &v)) {
return NULL;
} else {
return upb_value_getptr(v);
}
static PHP_GINIT_FUNCTION(protobuf) {
ZVAL_NULL(&protobuf_globals->generated_pool);
protobuf_globals->saved_symtab = NULL;
}
bool class_added(const void* ce) {
return get_ce_desc(ce) != NULL;
}
/**
* PHP_RINIT_FUNCTION(protobuf)
*
* This function is run at the beginning of processing each request.
*/
static PHP_RINIT_FUNCTION(protobuf) {
// Create the global generated pool.
// Reuse the symtab (if any) left to us by the last request.
upb_symtab *symtab = PROTOBUF_G(saved_symtab);
DescriptorPool_CreateWithSymbolTable(&PROTOBUF_G(generated_pool), symtab);
void add_proto_desc(const char* proto, DescriptorInternal* desc) {
upb_strtable_insert(&proto_to_desc_map_persistent, proto,
upb_value_ptr(desc));
}
// Set up autoloader for bundled sources.
zend_eval_string("spl_autoload_register('protobuf_internal_loadbundled');",
NULL, "autoload_register.php");
DescriptorInternal* get_proto_desc(const char* proto) {
upb_value v;
#ifndef NDEBUG
v.ctype = UPB_CTYPE_PTR;
#endif
if (!upb_strtable_lookup(&proto_to_desc_map_persistent, proto, &v)) {
return NULL;
} else {
return upb_value_getptr(v);
}
}
zend_hash_init(&PROTOBUF_G(object_cache), 64, NULL, NULL, 0);
zend_hash_init(&PROTOBUF_G(name_msg_cache), 64, NULL, NULL, 0);
zend_hash_init(&PROTOBUF_G(name_enum_cache), 64, NULL, NULL, 0);
void add_class_desc(const char* klass, DescriptorInternal* desc) {
upb_strtable_insert(&class_to_desc_map_persistent, klass,
upb_value_ptr(desc));
return SUCCESS;
}
DescriptorInternal* get_class_desc(const char* klass) {
upb_value v;
#ifndef NDEBUG
v.ctype = UPB_CTYPE_PTR;
#endif
if (!upb_strtable_lookup(&class_to_desc_map_persistent, klass, &v)) {
return NULL;
} else {
return upb_value_getptr(v);
/**
* PHP_RSHUTDOWN_FUNCTION(protobuf)
*
* This function is run at the end of processing each request.
*/
static PHP_RSHUTDOWN_FUNCTION(protobuf) {
// Preserve the symtab if requested.
if (PROTOBUF_G(keep_descriptor_pool_after_request)) {
zval *zv = &PROTOBUF_G(generated_pool);
PROTOBUF_G(saved_symtab) = DescriptorPool_Steal(zv);
}
}
void add_class_enumdesc(const char* klass, EnumDescriptorInternal* desc) {
upb_strtable_insert(&class_to_desc_map_persistent, klass,
upb_value_ptr(desc));
}
zval_dtor(&PROTOBUF_G(generated_pool));
zend_hash_destroy(&PROTOBUF_G(object_cache));
zend_hash_destroy(&PROTOBUF_G(name_msg_cache));
zend_hash_destroy(&PROTOBUF_G(name_enum_cache));
EnumDescriptorInternal* get_class_enumdesc(const char* klass) {
upb_value v;
#ifndef NDEBUG
v.ctype = UPB_CTYPE_PTR;
#endif
if (!upb_strtable_lookup(&class_to_desc_map_persistent, klass, &v)) {
return NULL;
} else {
return upb_value_getptr(v);
}
return SUCCESS;
}
// -----------------------------------------------------------------------------
// Well Known Types.
// Bundled PHP sources
// -----------------------------------------------------------------------------
bool is_inited_file_any;
bool is_inited_file_api;
bool is_inited_file_duration;
bool is_inited_file_field_mask;
bool is_inited_file_empty;
bool is_inited_file_source_context;
bool is_inited_file_struct;
bool is_inited_file_timestamp;
bool is_inited_file_type;
bool is_inited_file_wrappers;
// We bundle PHP sources for well-known types into the C extension. There is no
// need to implement these in C.
// -----------------------------------------------------------------------------
// Reserved Name.
// -----------------------------------------------------------------------------
static PHP_FUNCTION(protobuf_internal_loadbundled) {
char *name = NULL;
zend_long size;
BundledPhp_File *file;
// Although we already have kReservedNames, we still add them to hash table to
// speed up look up.
const char *const kReservedNames[] = {
"abstract", "and", "array", "as", "break",
"callable", "case", "catch", "class", "clone",
"const", "continue", "declare", "default", "die",
"do", "echo", "else", "elseif", "empty",
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
"endwhile", "eval", "exit", "extends", "final",
"for", "foreach", "function", "global", "goto",
"if", "implements", "include", "include_once", "instanceof",
"insteadof", "interface", "isset", "list", "namespace",
"new", "or", "print", "private", "protected",
"public", "require", "require_once", "return", "static",
"switch", "throw", "trait", "try", "unset",
"use", "var", "while", "xor", "int",
"float", "bool", "string", "true", "false",
"null", "void", "iterable"};
const int kReservedNamesSize = 73;
bool is_reserved_name(const char* name) {
upb_value v;
#ifndef NDEBUG
v.ctype = UPB_CTYPE_UINT64;
#endif
return upb_strtable_lookup2(&reserved_names, name, strlen(name), &v);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &size) != SUCCESS) {
return;
}
for (file = bundled_files; file->filename; file++) {
if (strcmp(file->filename, name) == 0) {
zend_eval_string((char*)file->contents, NULL, (char*)file->filename);
return;
}
}
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_load_bundled_source, 0, 0, 1)
ZEND_ARG_INFO(0, class_name)
ZEND_END_ARG_INFO()
// -----------------------------------------------------------------------------
// Utilities.
// Object Cache.
// -----------------------------------------------------------------------------
zend_function_entry protobuf_functions[] = {
ZEND_FE_END
};
static const zend_module_dep protobuf_deps[] = {
ZEND_MOD_OPTIONAL("date")
ZEND_MOD_END
};
zend_module_entry protobuf_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
protobuf_deps,
PHP_PROTOBUF_EXTNAME, // extension name
protobuf_functions, // function list
PHP_MINIT(protobuf), // process startup
PHP_MSHUTDOWN(protobuf), // process shutdown
PHP_RINIT(protobuf), // request shutdown
PHP_RSHUTDOWN(protobuf), // request shutdown
NULL, // extension info
PHP_PROTOBUF_VERSION, // extension version
PHP_MODULE_GLOBALS(protobuf), // globals descriptor
PHP_GINIT(protobuf), // globals ctor
PHP_GSHUTDOWN(protobuf), // globals dtor
NULL, // post deactivate
STANDARD_MODULE_PROPERTIES_EX
};
// install module
ZEND_GET_MODULE(protobuf)
// global variables
static PHP_GINIT_FUNCTION(protobuf) {
void ObjCache_Add(const void *upb_obj, zend_object *php_obj) {
zend_ulong k = (zend_ulong)upb_obj;
zend_hash_index_add_ptr(&PROTOBUF_G(object_cache), k, php_obj);
}
static PHP_GSHUTDOWN_FUNCTION(protobuf) {
}
#if PHP_MAJOR_VERSION >= 7
static void php_proto_hashtable_descriptor_release(zval* value) {
void* ptr = Z_PTR_P(value);
zend_object* object = *(zend_object**)ptr;
GC_DELREF(object);
if(GC_REFCOUNT(object) == 0) {
zend_objects_store_del(object);
void ObjCache_Delete(const void *upb_obj) {
if (upb_obj) {
zend_ulong k = (zend_ulong)upb_obj;
int ret = zend_hash_index_del(&PROTOBUF_G(object_cache), k);
PBPHP_ASSERT(ret == SUCCESS);
}
efree(ptr);
}
#endif
static void initialize_persistent_descriptor_pool(TSRMLS_D) {
upb_inttable_init(&upb_def_to_desc_map_persistent, UPB_CTYPE_PTR);
upb_inttable_init(&upb_def_to_enumdesc_map_persistent, UPB_CTYPE_PTR);
upb_strtable_init(&ce_to_desc_map_persistent, UPB_CTYPE_PTR);
upb_strtable_init(&ce_to_enumdesc_map_persistent, UPB_CTYPE_PTR);
upb_strtable_init(&proto_to_desc_map_persistent, UPB_CTYPE_PTR);
upb_strtable_init(&class_to_desc_map_persistent, UPB_CTYPE_PTR);
internal_descriptor_pool_impl_init(&generated_pool_impl TSRMLS_CC);
is_inited_file_any = false;
is_inited_file_api = false;
is_inited_file_duration = false;
is_inited_file_field_mask = false;
is_inited_file_empty = false;
is_inited_file_source_context = false;
is_inited_file_struct = false;
is_inited_file_timestamp = false;
is_inited_file_type = false;
is_inited_file_wrappers = false;
}
static PHP_RINIT_FUNCTION(protobuf) {
ALLOC_HASHTABLE(upb_def_to_php_obj_map);
zend_hash_init(upb_def_to_php_obj_map, 16, NULL, HASHTABLE_VALUE_DTOR, 0);
ALLOC_HASHTABLE(ce_to_php_obj_map);
zend_hash_init(ce_to_php_obj_map, 16, NULL, HASHTABLE_VALUE_DTOR, 0);
generated_pool = NULL;
generated_pool_php = NULL;
internal_generated_pool_php = NULL;
if (PROTOBUF_G(keep_descriptor_pool_after_request)) {
// Needs to clean up obsolete class entry
upb_strtable_iter i;
upb_value v;
DescriptorInternal* desc;
for(upb_strtable_begin(&i, &ce_to_desc_map_persistent);
!upb_strtable_done(&i);
upb_strtable_next(&i)) {
v = upb_strtable_iter_value(&i);
desc = upb_value_getptr(v);
desc->klass = NULL;
}
bool ObjCache_Get(const void *upb_obj, zval *val) {
zend_ulong k = (zend_ulong)upb_obj;
zend_object *obj = zend_hash_index_find_ptr(&PROTOBUF_G(object_cache), k);
EnumDescriptorInternal* enumdesc;
for(upb_strtable_begin(&i, &ce_to_enumdesc_map_persistent);
!upb_strtable_done(&i);
upb_strtable_next(&i)) {
v = upb_strtable_iter_value(&i);
enumdesc = upb_value_getptr(v);
enumdesc->klass = NULL;
}
if (obj) {
GC_ADDREF(obj);
ZVAL_OBJ(val, obj);
return true;
} else {
initialize_persistent_descriptor_pool(TSRMLS_C);
ZVAL_NULL(val);
return false;
}
return 0;
}
static void cleanup_desc_table(upb_inttable* t) {
upb_inttable_iter i;
upb_value v;
DescriptorInternal* desc;
for(upb_inttable_begin(&i, t);
!upb_inttable_done(&i);
upb_inttable_next(&i)) {
v = upb_inttable_iter_value(&i);
desc = upb_value_getptr(v);
if (desc->layout) {
free_layout(desc->layout);
desc->layout = NULL;
}
free(desc->classname);
SYS_FREE(desc);
}
}
// -----------------------------------------------------------------------------
// Name Cache.
// -----------------------------------------------------------------------------
static void cleanup_enumdesc_table(upb_inttable* t) {
upb_inttable_iter i;
upb_value v;
EnumDescriptorInternal* desc;
for(upb_inttable_begin(&i, t);
!upb_inttable_done(&i);
upb_inttable_next(&i)) {
v = upb_inttable_iter_value(&i);
desc = upb_value_getptr(v);
free(desc->classname);
SYS_FREE(desc);
}
void NameMap_AddMessage(const upb_msgdef *m) {
char *k = GetPhpClassname(upb_msgdef_file(m), upb_msgdef_fullname(m));
zend_hash_str_add_ptr(&PROTOBUF_G(name_msg_cache), k, strlen(k), (void*)m);
free(k);
}
static void cleanup_persistent_descriptor_pool(TSRMLS_D) {
// Clean up
// Only needs to clean one map out of three (def=>desc, ce=>desc, proto=>desc)
cleanup_desc_table(&upb_def_to_desc_map_persistent);
cleanup_enumdesc_table(&upb_def_to_enumdesc_map_persistent);
internal_descriptor_pool_impl_destroy(&generated_pool_impl TSRMLS_CC);
upb_inttable_uninit(&upb_def_to_desc_map_persistent);
upb_inttable_uninit(&upb_def_to_enumdesc_map_persistent);
upb_strtable_uninit(&ce_to_desc_map_persistent);
upb_strtable_uninit(&ce_to_enumdesc_map_persistent);
upb_strtable_uninit(&proto_to_desc_map_persistent);
upb_strtable_uninit(&class_to_desc_map_persistent);
void NameMap_AddEnum(const upb_enumdef *e) {
char *k = GetPhpClassname(upb_enumdef_file(e), upb_enumdef_fullname(e));
zend_hash_str_add_ptr(&PROTOBUF_G(name_enum_cache), k, strlen(k), (void*)e);
free(k);
}
static PHP_RSHUTDOWN_FUNCTION(protobuf) {
zend_hash_destroy(upb_def_to_php_obj_map);
FREE_HASHTABLE(upb_def_to_php_obj_map);
zend_hash_destroy(ce_to_php_obj_map);
FREE_HASHTABLE(ce_to_php_obj_map);
const upb_msgdef *NameMap_GetMessage(zend_class_entry *ce) {
const upb_msgdef *ret =
zend_hash_find_ptr(&PROTOBUF_G(name_msg_cache), ce->name);
#if PHP_MAJOR_VERSION < 7
if (generated_pool_php != NULL) {
zval_dtor(generated_pool_php);
FREE_ZVAL(generated_pool_php);
}
if (internal_generated_pool_php != NULL) {
zval_dtor(internal_generated_pool_php);
FREE_ZVAL(internal_generated_pool_php);
}
#else
if (generated_pool_php != NULL) {
if (!ret && ce->create_object) {
zval tmp;
ZVAL_OBJ(&tmp, generated_pool_php);
zval_dtor(&tmp);
}
if (internal_generated_pool_php != NULL) {
zval tmp;
ZVAL_OBJ(&tmp, internal_generated_pool_php);
zval_dtor(&tmp);
}
#endif
if (!PROTOBUF_G(keep_descriptor_pool_after_request)) {
cleanup_persistent_descriptor_pool(TSRMLS_C);
zval zv;
ZVAL_OBJ(&tmp, ce->create_object(ce));
zend_call_method_with_0_params(&tmp, ce, NULL, "__construct", &zv);
zval_ptr_dtor(&tmp);
zval_ptr_dtor(&zv);
ret = zend_hash_find_ptr(&PROTOBUF_G(name_msg_cache), ce->name);
}
return 0;
return ret;
}
static void reserved_names_init() {
size_t i;
upb_value v = upb_value_bool(false);
for (i = 0; i < kReservedNamesSize; i++) {
upb_strtable_insert2(&reserved_names, kReservedNames[i],
strlen(kReservedNames[i]), v);
}
const upb_enumdef *NameMap_GetEnum(zend_class_entry *ce) {
const upb_enumdef *ret =
zend_hash_find_ptr(&PROTOBUF_G(name_enum_cache), ce->name);
return ret;
}
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
zend_function_entry protobuf_functions[] = {
PHP_FE(protobuf_internal_loadbundled, arginfo_load_bundled_source)
ZEND_FE_END
};
static const zend_module_dep protobuf_deps[] = {
ZEND_MOD_OPTIONAL("date")
ZEND_MOD_END
};
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("protobuf.keep_descriptor_pool_after_request", "0",
PHP_INI_SYSTEM, OnUpdateBool,
@ -514,86 +314,36 @@ PHP_INI_END()
static PHP_MINIT_FUNCTION(protobuf) {
REGISTER_INI_ENTRIES();
upb_strtable_init(&reserved_names, UPB_CTYPE_UINT64);
reserved_names_init();
if (PROTOBUF_G(keep_descriptor_pool_after_request)) {
initialize_persistent_descriptor_pool(TSRMLS_C);
}
descriptor_pool_init(TSRMLS_C);
descriptor_init(TSRMLS_C);
enum_descriptor_init(TSRMLS_C);
enum_value_descriptor_init(TSRMLS_C);
field_descriptor_init(TSRMLS_C);
gpb_type_init(TSRMLS_C);
internal_descriptor_pool_init(TSRMLS_C);
map_field_init(TSRMLS_C);
map_field_iter_init(TSRMLS_C);
message_init(TSRMLS_C);
oneof_descriptor_init(TSRMLS_C);
repeated_field_init(TSRMLS_C);
repeated_field_iter_init(TSRMLS_C);
util_init(TSRMLS_C);
gpb_metadata_any_init(TSRMLS_C);
gpb_metadata_api_init(TSRMLS_C);
gpb_metadata_duration_init(TSRMLS_C);
gpb_metadata_field_mask_init(TSRMLS_C);
gpb_metadata_empty_init(TSRMLS_C);
gpb_metadata_source_context_init(TSRMLS_C);
gpb_metadata_struct_init(TSRMLS_C);
gpb_metadata_timestamp_init(TSRMLS_C);
gpb_metadata_type_init(TSRMLS_C);
gpb_metadata_wrappers_init(TSRMLS_C);
any_init(TSRMLS_C);
api_init(TSRMLS_C);
bool_value_init(TSRMLS_C);
bytes_value_init(TSRMLS_C);
double_value_init(TSRMLS_C);
duration_init(TSRMLS_C);
enum_init(TSRMLS_C);
enum_value_init(TSRMLS_C);
field_cardinality_init(TSRMLS_C);
field_init(TSRMLS_C);
field_kind_init(TSRMLS_C);
field_mask_init(TSRMLS_C);
float_value_init(TSRMLS_C);
empty_init(TSRMLS_C);
int32_value_init(TSRMLS_C);
int64_value_init(TSRMLS_C);
list_value_init(TSRMLS_C);
method_init(TSRMLS_C);
mixin_init(TSRMLS_C);
null_value_init(TSRMLS_C);
option_init(TSRMLS_C);
source_context_init(TSRMLS_C);
string_value_init(TSRMLS_C);
struct_init(TSRMLS_C);
syntax_init(TSRMLS_C);
timestamp_init(TSRMLS_C);
type_init(TSRMLS_C);
u_int32_value_init(TSRMLS_C);
u_int64_value_init(TSRMLS_C);
value_init(TSRMLS_C);
return 0;
Arena_ModuleInit();
Array_ModuleInit();
Convert_ModuleInit();
Def_ModuleInit();
Map_ModuleInit();
Message_ModuleInit();
return SUCCESS;
}
static PHP_MSHUTDOWN_FUNCTION(protobuf) {
if (PROTOBUF_G(keep_descriptor_pool_after_request)) {
cleanup_persistent_descriptor_pool(TSRMLS_C);
}
upb_strtable_uninit(&reserved_names);
return SUCCESS;
}
PEFREE(message_handlers);
PEFREE(repeated_field_handlers);
PEFREE(repeated_field_iter_handlers);
PEFREE(map_field_handlers);
PEFREE(map_field_iter_handlers);
zend_module_entry protobuf_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
protobuf_deps,
"protobuf", // extension name
protobuf_functions, // function list
PHP_MINIT(protobuf), // process startup
PHP_MSHUTDOWN(protobuf), // process shutdown
PHP_RINIT(protobuf), // request shutdown
PHP_RSHUTDOWN(protobuf), // request shutdown
NULL, // extension info
"3.13.0", // extension version
PHP_MODULE_GLOBALS(protobuf), // globals descriptor
PHP_GINIT(protobuf), // globals ctor
PHP_GSHUTDOWN(protobuf), // globals dtor
NULL, // post deactivate
STANDARD_MODULE_PROPERTIES_EX
};
return 0;
}
ZEND_GET_MODULE(protobuf)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,680 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// The Zend Engine License, version 2.00
// Copyright (c) 1999-2002 Zend Technologies Ltd. All rights reserved.
// --------------------------------------------------------------------
//
// Redistribution and use in source and binary forms, with or without
// modification, is permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. 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.
//
// 3. The names "Zend" and "Zend Engine" must not be used to endorse
// or promote products derived from this software without prior
// permission from Zend Technologies Ltd. For written permission,
// please contact license@zend.com.
//
// 4. Zend Technologies Ltd. may publish revised and/or new versions
// of the license from time to time. Each version will be given a
// distinguishing version number.
// Once covered code has been published under a particular version
// of the license, you may always continue to use it under the
// terms of that version. You may also choose to use such covered
// code under the terms of any subsequent version of the license
// published by Zend Technologies Ltd. No one other than Zend
// Technologies Ltd. has the right to modify the terms applicable
// to covered code created under this License.
//
// 5. Redistributions of any form whatsoever must retain the following
// acknowledgment:
// "This product includes the Zend Engine, freely available at
// http://www.zend.com"
//
// 6. All advertising materials mentioning features or use of this
// software must display the following acknowledgment:
// "The Zend Engine is freely available at http://www.zend.com"
//
// THIS SOFTWARE IS PROVIDED BY ZEND TECHNOLOGIES LTD. ``AS IS'' AND
// ANY EXPRESSED 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 ZEND
// TECHNOLOGIES LTD. 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.
#include <Zend/zend_operators.h>
#include <Zend/zend_exceptions.h>
#include "protobuf.h"
#include "utf8.h"
static zend_class_entry* util_type;
static const char int64_min_digits[] = "9223372036854775808";
ZEND_BEGIN_ARG_INFO_EX(arg_check_optional, 0, 0, 1)
ZEND_ARG_INFO(1, val)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arg_check_message, 0, 0, 2)
ZEND_ARG_INFO(1, val)
ZEND_ARG_INFO(0, klass)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arg_check_repeated, 0, 0, 2)
ZEND_ARG_INFO(1, val)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, klass)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arg_check_map, 0, 0, 3)
ZEND_ARG_INFO(1, val)
ZEND_ARG_INFO(0, key_type)
ZEND_ARG_INFO(0, value_type)
ZEND_ARG_INFO(0, klass)
ZEND_END_ARG_INFO()
static zend_function_entry util_methods[] = {
PHP_ME(Util, checkInt32, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkUint32, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkInt64, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkUint64, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkEnum, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkFloat, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkDouble, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkBool, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkString, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkBytes, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkMessage, arg_check_message, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkMapField, arg_check_map, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkRepeatedField, arg_check_repeated,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_FE_END
};
void util_init(TSRMLS_D) {
zend_class_entry class_type;
INIT_CLASS_ENTRY(class_type, "Google\\Protobuf\\Internal\\GPBUtil",
util_methods);
util_type = zend_register_internal_class(&class_type TSRMLS_CC);
}
// -----------------------------------------------------------------------------
// Type checking/conversion.
// -----------------------------------------------------------------------------
// This is modified from is_numeric_string in zend_operators.h. The behavior of
// this function is the same as is_numeric_string, except that this takes
// int64_t as input instead of long.
static zend_uchar convert_numeric_string(
const char *str, int length, int64_t *lval, double *dval) {
const char *ptr;
int base = 10, digits = 0, dp_or_e = 0;
double local_dval = 0.0;
zend_uchar type;
if (length == 0) {
return IS_NULL;
}
while (*str == ' ' || *str == '\t' || *str == '\n' ||
*str == '\r' || *str == '\v' || *str == '\f') {
str++;
length--;
}
ptr = str;
if (*ptr == '-' || *ptr == '+') {
ptr++;
}
if (ZEND_IS_DIGIT(*ptr)) {
// Handle hex numbers
// str is used instead of ptr to disallow signs and keep old behavior.
if (length > 2 && *str == '0' && (str[1] == 'x' || str[1] == 'X')) {
base = 16;
ptr += 2;
}
// Skip any leading 0s.
while (*ptr == '0') {
ptr++;
}
// Count the number of digits. If a decimal point/exponent is found,
// it's a double. Otherwise, if there's a dval or no need to check for
// a full match, stop when there are too many digits for a int64 */
for (type = IS_LONG;
!(digits >= MAX_LENGTH_OF_INT64 && dval);
digits++, ptr++) {
check_digits:
if (ZEND_IS_DIGIT(*ptr) || (base == 16 && ZEND_IS_XDIGIT(*ptr))) {
continue;
} else if (base == 10) {
if (*ptr == '.' && dp_or_e < 1) {
goto process_double;
} else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) {
const char *e = ptr + 1;
if (*e == '-' || *e == '+') {
ptr = e++;
}
if (ZEND_IS_DIGIT(*e)) {
goto process_double;
}
}
}
break;
}
if (base == 10) {
if (digits >= MAX_LENGTH_OF_INT64) {
dp_or_e = -1;
goto process_double;
}
} else if (!(digits < SIZEOF_INT64 * 2 ||
(digits == SIZEOF_INT64 * 2 && ptr[-digits] <= '7'))) {
if (dval) {
local_dval = zend_hex_strtod(str, &ptr);
}
type = IS_DOUBLE;
}
} else if (*ptr == '.' && ZEND_IS_DIGIT(ptr[1])) {
process_double:
type = IS_DOUBLE;
// If there's a dval, do the conversion; else continue checking
// the digits if we need to check for a full match.
if (dval) {
local_dval = zend_strtod(str, &ptr);
} else if (dp_or_e != -1) {
dp_or_e = (*ptr++ == '.') ? 1 : 2;
goto check_digits;
}
} else {
return IS_NULL;
}
if (ptr != str + length) {
zend_error(E_NOTICE, "A non well formed numeric value encountered");
return 0;
}
if (type == IS_LONG) {
if (digits == MAX_LENGTH_OF_INT64 - 1) {
int cmp = strcmp(&ptr[-digits], int64_min_digits);
if (!(cmp < 0 || (cmp == 0 && *str == '-'))) {
if (dval) {
*dval = zend_strtod(str, NULL);
}
return IS_DOUBLE;
}
}
if (lval) {
*lval = strtoll(str, NULL, base);
}
return IS_LONG;
} else {
if (dval) {
*dval = local_dval;
}
return IS_DOUBLE;
}
}
#define CONVERT_TO_INTEGER(type) \
static bool convert_int64_to_##type(int64_t val, type##_t* type##_value) { \
*type##_value = (type##_t)val; \
return true; \
} \
\
static bool convert_double_to_##type(double val, type##_t* type##_value) { \
*type##_value = (type##_t)zend_dval_to_lval(val); \
return true; \
} \
\
static bool convert_string_to_##type(const char* val, int len, \
type##_t* type##_value) { \
int64_t lval; \
double dval; \
TSRMLS_FETCH(); \
switch (convert_numeric_string(val, len, &lval, &dval)) { \
case IS_DOUBLE: { \
return convert_double_to_##type(dval, type##_value); \
} \
case IS_LONG: { \
return convert_int64_to_##type(lval, type##_value); \
} \
default: \
zend_throw_exception(NULL, \
"Given string value cannot be converted to integer.", \
0 TSRMLS_CC); \
return false; \
} \
} \
\
bool protobuf_convert_to_##type(zval* from, type##_t* to) { \
TSRMLS_FETCH(); \
switch (Z_TYPE_P(from)) { \
case IS_LONG: { \
return convert_int64_to_##type(Z_LVAL_P(from), to); \
} \
case IS_DOUBLE: { \
return convert_double_to_##type(Z_DVAL_P(from), to); \
} \
case IS_STRING: { \
return convert_string_to_##type(Z_STRVAL_P(from), Z_STRLEN_P(from), \
to); \
} \
default: { \
zend_throw_exception(NULL, \
"Given value cannot be converted to integer.", \
0 TSRMLS_CC); \
return false; \
} \
} \
return false; \
}
CONVERT_TO_INTEGER(int32);
CONVERT_TO_INTEGER(uint32);
CONVERT_TO_INTEGER(int64);
CONVERT_TO_INTEGER(uint64);
#undef CONVERT_TO_INTEGER
#define CONVERT_TO_FLOAT(type) \
static bool convert_int64_to_##type(int64_t val, type* type##_value) { \
*type##_value = (type)val; \
return true; \
} \
\
static bool convert_double_to_##type(double val, type* type##_value) { \
*type##_value = (type)val; \
return true; \
} \
\
static bool convert_string_to_##type(const char* val, int len, \
type* type##_value) { \
int64_t lval; \
double dval; \
\
TSRMLS_FETCH(); \
switch (convert_numeric_string(val, len, &lval, &dval)) { \
case IS_DOUBLE: { \
*type##_value = (type)dval; \
return true; \
} \
case IS_LONG: { \
*type##_value = (type)lval; \
return true; \
} \
default: \
zend_throw_exception(NULL, \
"Given string value cannot be converted to integer.", \
0 TSRMLS_CC); \
return false; \
} \
} \
\
bool protobuf_convert_to_##type(zval* from, type* to) { \
TSRMLS_FETCH(); \
switch (Z_TYPE_P(from)) { \
case IS_LONG: { \
return convert_int64_to_##type(Z_LVAL_P(from), to); \
} \
case IS_DOUBLE: { \
return convert_double_to_##type(Z_DVAL_P(from), to); \
} \
case IS_STRING: { \
return convert_string_to_##type(Z_STRVAL_P(from), Z_STRLEN_P(from), \
to); \
} \
default: { \
zend_throw_exception(NULL, \
"Given value cannot be converted to integer.", \
0 TSRMLS_CC); \
return false; \
} \
} \
return false; \
}
CONVERT_TO_FLOAT(float);
CONVERT_TO_FLOAT(double);
#undef CONVERT_TO_FLOAT
bool protobuf_convert_to_bool(zval* from, int8_t* to) {
TSRMLS_FETCH();
switch (Z_TYPE_P(from)) {
#if PHP_MAJOR_VERSION < 7
case IS_BOOL:
*to = (int8_t)Z_BVAL_P(from);
break;
#else
case IS_TRUE:
*to = 1;
break;
case IS_FALSE:
*to = 0;
break;
#endif
case IS_LONG:
*to = (int8_t)(Z_LVAL_P(from) != 0);
break;
case IS_DOUBLE:
*to = (int8_t)(Z_LVAL_P(from) != 0);
break;
case IS_STRING: {
if (Z_STRLEN_P(from) == 0 ||
(Z_STRLEN_P(from) == 1 && Z_STRVAL_P(from)[0] == '0')) {
*to = 0;
} else {
*to = 1;
}
} break;
default: {
zend_throw_exception(
NULL, "Given value cannot be converted to bool.",
0 TSRMLS_CC);
return false;
}
}
return true;
}
bool protobuf_convert_to_string(zval* from) {
#if PHP_MAJOR_VERSION >= 7
if (Z_ISREF_P(from)) {
ZVAL_DEREF(from);
}
#endif
TSRMLS_FETCH();
switch (Z_TYPE_P(from)) {
case IS_STRING: {
return true;
}
#if PHP_MAJOR_VERSION < 7
case IS_BOOL:
#else
case IS_TRUE:
case IS_FALSE:
#endif
case IS_LONG:
case IS_DOUBLE: {
zval tmp;
php_proto_zend_make_printable_zval(from, &tmp);
ZVAL_COPY_VALUE(from, &tmp);
return true;
}
default:
zend_throw_exception(
NULL, "Given value cannot be converted to string.",
0 TSRMLS_CC);
return false;
}
}
// -----------------------------------------------------------------------------
// PHP Functions.
// -----------------------------------------------------------------------------
// The implementation of type checking for primitive fields is empty. This is
// because type checking is done when direct assigning message fields (e.g.,
// foo->a = 1). Functions defined here are place holders in generated code for
// pure PHP implementation (c extension and pure PHP share the same generated
// code).
#define PHP_TYPE_CHECK(type) \
PHP_METHOD(Util, check##type) {}
PHP_TYPE_CHECK(Int32)
PHP_TYPE_CHECK(Uint32)
PHP_TYPE_CHECK(Int64)
PHP_TYPE_CHECK(Uint64)
PHP_TYPE_CHECK(Enum)
PHP_TYPE_CHECK(Float)
PHP_TYPE_CHECK(Double)
PHP_TYPE_CHECK(Bool)
PHP_TYPE_CHECK(String)
PHP_TYPE_CHECK(Bytes)
#undef PHP_TYPE_CHECK
PHP_METHOD(Util, checkMessage) {
zval* val;
zend_class_entry* klass = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o!C", &val, &klass) ==
FAILURE) {
return;
}
if (val == NULL) {
RETURN_NULL();
}
if (!instanceof_function(Z_OBJCE_P(val), klass TSRMLS_CC)) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
"Given value is not an instance of %s.",
#if PHP_MAJOR_VERSION < 7
klass->name);
#else
ZSTR_VAL(klass->name));
#endif
return;
}
RETURN_ZVAL(val, 1, 0);
}
void check_repeated_field(const zend_class_entry* klass, PHP_PROTO_LONG type,
zval* val, zval* return_value) {
#if PHP_MAJOR_VERSION >= 7
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
#endif
TSRMLS_FETCH();
if (Z_TYPE_P(val) == IS_ARRAY) {
HashTable* table = HASH_OF(val);
HashPosition pointer;
void* memory;
#if PHP_MAJOR_VERSION < 7
zval* repeated_field;
MAKE_STD_ZVAL(repeated_field);
#else
zval repeated_field;
#endif
repeated_field_create_with_type(repeated_field_type, to_fieldtype(type),
klass, &repeated_field TSRMLS_CC);
for (zend_hash_internal_pointer_reset_ex(table, &pointer);
php_proto_zend_hash_get_current_data_ex(table, (void**)&memory,
&pointer) == SUCCESS;
zend_hash_move_forward_ex(table, &pointer)) {
repeated_field_handlers->write_dimension(
CACHED_TO_ZVAL_PTR(repeated_field), NULL,
CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC);
}
RETURN_ZVAL(CACHED_TO_ZVAL_PTR(repeated_field), 1, 1);
} else if (Z_TYPE_P(val) == IS_OBJECT) {
if (!instanceof_function(Z_OBJCE_P(val), repeated_field_type TSRMLS_CC)) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
"Given value is not an instance of %s.",
#if PHP_MAJOR_VERSION < 7
repeated_field_type->name);
#else
ZSTR_VAL(repeated_field_type->name));
#endif
return;
}
RepeatedField* intern = UNBOX(RepeatedField, val);
if (to_fieldtype(type) != intern->type) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
"Incorrect repeated field type.");
return;
}
if (klass != NULL && intern->msg_ce != klass) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
"Expect a repeated field of %s, but %s is given.",
#if PHP_MAJOR_VERSION < 7
klass->name, intern->msg_ce->name);
#else
ZSTR_VAL(klass->name),
ZSTR_VAL(intern->msg_ce->name));
#endif
return;
}
RETURN_ZVAL(val, 1, 0);
} else {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
"Incorrect repeated field type.");
return;
}
}
PHP_METHOD(Util, checkRepeatedField) {
zval* val;
PHP_PROTO_LONG type;
const zend_class_entry* klass = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl|C", &val, &type,
&klass) == FAILURE) {
return;
}
RETURN_ZVAL(val, 1, 0);
}
void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type,
PHP_PROTO_LONG value_type, zval* val, zval* return_value) {
#if PHP_MAJOR_VERSION >= 7
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
#endif
TSRMLS_FETCH();
if (Z_TYPE_P(val) == IS_ARRAY) {
HashTable* table = Z_ARRVAL_P(val);
HashPosition pointer;
zval key;
void* value;
#if PHP_MAJOR_VERSION < 7
zval* map_field;
MAKE_STD_ZVAL(map_field);
#else
zval map_field;
#endif
map_field_create_with_type(map_field_type, to_fieldtype(key_type),
to_fieldtype(value_type), klass,
&map_field TSRMLS_CC);
for (zend_hash_internal_pointer_reset_ex(table, &pointer);
php_proto_zend_hash_get_current_data_ex(table, (void**)&value,
&pointer) == SUCCESS;
zend_hash_move_forward_ex(table, &pointer)) {
zend_hash_get_current_key_zval_ex(table, &key, &pointer);
map_field_handlers->write_dimension(
CACHED_TO_ZVAL_PTR(map_field), &key,
CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)value) TSRMLS_CC);
zval_dtor(&key);
}
RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 1);
} else if (Z_TYPE_P(val) == IS_OBJECT) {
if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
"Given value is not an instance of %s.",
#if PHP_MAJOR_VERSION < 7
map_field_type->name);
#else
ZSTR_VAL(map_field_type->name));
#endif
return;
}
Map* intern = UNBOX(Map, val);
if (to_fieldtype(key_type) != intern->key_type) {
zend_throw_exception(
NULL, "Incorrect map field key type.",
0 TSRMLS_CC);
return;
}
if (to_fieldtype(value_type) != intern->value_type) {
zend_throw_exception(
NULL, "Incorrect map field value type.",
0 TSRMLS_CC);
return;
}
if (klass != NULL && intern->msg_ce != klass) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
"Expect a map field of %s, but %s is given.",
#if PHP_MAJOR_VERSION < 7
klass->name, intern->msg_ce->name);
#else
ZSTR_VAL(klass->name),
ZSTR_VAL(intern->msg_ce->name));
#endif
return;
}
RETURN_ZVAL(val, 1, 0);
} else {
zend_throw_exception(
NULL, "Incorrect map field type.",
0 TSRMLS_CC);
return;
}
}
PHP_METHOD(Util, checkMapField) {
zval* val;
PHP_PROTO_LONG key_type, value_type;
const zend_class_entry* klass = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll|C", &val, &key_type,
&value_type, &klass) == FAILURE) {
return;
}
RETURN_ZVAL(val, 1, 0);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,68 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdbool.h>
#include <stdint.h>
#include "utf8.h"
static const uint8_t utf8_offset[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0,
};
bool is_structurally_valid_utf8(const char* buf, int len) {
int i, j;
uint8_t offset;
i = 0;
while (i < len) {
offset = utf8_offset[(uint8_t)buf[i]];
if (offset == 0 || i + offset > len) {
return false;
}
for (j = i + 1; j < i + offset; j++) {
if ((buf[j] & 0xc0) != 0x80) {
return false;
}
}
i += offset;
}
return i == len;
}

@ -1,36 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GOOGLE_PROTOBUF_UTF8_H_
#define GOOGLE_PROTOBUF_UTF8_H_
bool is_structurally_valid_utf8(const char* buf, int len);
#endif // GOOGLE_PROTOBUF_UTF8_H_

@ -1,602 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "array.h"
#include <Zend/zend_API.h>
#include <Zend/zend_interfaces.h>
#include <ext/spl/spl_iterators.h>
// This is not self-contained: it must be after other Zend includes.
#include <Zend/zend_exceptions.h>
#include "arena.h"
#include "convert.h"
#include "def.h"
#include "php-upb.h"
#include "protobuf.h"
static void RepeatedFieldIter_make(zval *val, zval *repeated_field);
// -----------------------------------------------------------------------------
// RepeatedField
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval arena;
upb_array *array;
upb_fieldtype_t type;
const Descriptor* desc; // When values are messages.
} RepeatedField;
zend_class_entry *RepeatedField_class_entry;
static zend_object_handlers RepeatedField_object_handlers;
// PHP Object Handlers /////////////////////////////////////////////////////////
/**
* RepeatedField_create()
*
* PHP class entry function to allocate and initialize a new RepeatedField
* object.
*/
static zend_object* RepeatedField_create(zend_class_entry *class_type) {
RepeatedField *intern = emalloc(sizeof(RepeatedField));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &RepeatedField_object_handlers;
Arena_Init(&intern->arena);
intern->array = NULL;
intern->desc = NULL;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
/**
* RepeatedField_dtor()
*
* Object handler to destroy a RepeatedField. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void RepeatedField_destructor(zend_object* obj) {
RepeatedField* intern = (RepeatedField*)obj;
ObjCache_Delete(intern->array);
zval_ptr_dtor(&intern->arena);
zend_object_std_dtor(&intern->std);
}
static HashTable *RepeatedField_GetProperties(zval *object TSRMLS_DC) {
return NULL; // We do not have a properties table.
}
static zval *RepeatedField_GetPropertyPtrPtr(zval *object, zval *member,
int type, void **cache_slot) {
return NULL; // We don't offer direct references to our properties.
}
// C Functions from array.h ////////////////////////////////////////////////////
// These are documented in the header file.
void RepeatedField_GetPhpWrapper(zval *val, upb_array *arr,
const upb_fielddef *f, zval *arena) {
if (!arr) {
ZVAL_NULL(val);
return;
}
if (!ObjCache_Get(arr, val)) {
RepeatedField *intern = emalloc(sizeof(RepeatedField));
zend_object_std_init(&intern->std, RepeatedField_class_entry);
intern->std.handlers = &RepeatedField_object_handlers;
ZVAL_COPY(&intern->arena, arena);
intern->array = arr;
intern->type = upb_fielddef_type(f);
intern->desc = Descriptor_GetFromFieldDef(f);
// Skip object_properties_init(), we don't allow derived classes.
ObjCache_Add(intern->array, &intern->std);
ZVAL_OBJ(val, &intern->std);
}
}
upb_array *RepeatedField_GetUpbArray(zval *val, const upb_fielddef *f,
upb_arena *arena) {
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
if (Z_TYPE_P(val) == IS_ARRAY) {
// Auto-construct, eg. [1, 2, 3] -> upb_array([1, 2, 3]).
upb_array *arr = upb_array_new(arena, upb_fielddef_type(f));
HashTable *table = HASH_OF(val);
HashPosition pos;
upb_fieldtype_t type = upb_fielddef_type(f);
const Descriptor *desc = Descriptor_GetFromFieldDef(f);
zend_hash_internal_pointer_reset_ex(table, &pos);
while (true) {
zval *zv = zend_hash_get_current_data_ex(table, &pos);
upb_msgval val;
if (!zv) return arr;
if (!Convert_PhpToUpbAutoWrap(zv, &val, type, desc, arena)) {
return NULL;
}
upb_array_append(arr, val, arena);
zend_hash_move_forward_ex(table, &pos);
}
} else if (Z_TYPE_P(val) == IS_OBJECT &&
Z_OBJCE_P(val) == RepeatedField_class_entry) {
// Unwrap existing RepeatedField object to get the upb_array* inside.
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(val);
const Descriptor *desc = Descriptor_GetFromFieldDef(f);
if (intern->type != upb_fielddef_type(f) || intern->desc != desc) {
php_error_docref(NULL, E_USER_ERROR,
"Wrong type for this repeated field.");
}
upb_arena_fuse(arena, Arena_Get(&intern->arena));
return intern->array;
} else {
php_error_docref(NULL, E_USER_ERROR, "Must be a repeated field");
return NULL;
}
}
// RepeatedField PHP methods ///////////////////////////////////////////////////
/**
* RepeatedField::__construct()
*
* Constructs an instance of RepeatedField.
* @param long Type of the stored element.
* @param string Message/Enum class.
*/
PHP_METHOD(RepeatedField, __construct) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
zend_long type;
zend_class_entry* klass = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|C", &type, &klass) != SUCCESS) {
return;
}
intern->type = pbphp_dtype_to_type(type);
intern->desc = Descriptor_GetFromClassEntry(klass);
if (intern->type == UPB_TYPE_MESSAGE && klass == NULL) {
php_error_docref(NULL, E_USER_ERROR,
"Message/enum type must have concrete class.");
return;
}
intern->array = upb_array_new(arena, intern->type);
ObjCache_Add(intern->array, &intern->std);
}
/**
* RepeatedField::append()
*
* Append element to the end of the repeated field.
* @param object The element to be added.
*/
PHP_METHOD(RepeatedField, append) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
zval *php_val;
upb_msgval msgval;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &php_val) != SUCCESS ||
!Convert_PhpToUpb(php_val, &msgval, intern->type, intern->desc, arena)) {
return;
}
upb_array_append(intern->array, msgval, arena);
}
/**
* RepeatedField::offsetExists()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* isset($arr[$idx]);
* empty($arr[$idx]);
*
* @param long The index to be checked.
* @return bool True if the element at the given index exists.
*/
PHP_METHOD(RepeatedField, offsetExists) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
return;
}
RETURN_BOOL(index >= 0 && index < upb_array_size(intern->array));
}
/**
* RepeatedField::offsetGet()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $x = $arr[$idx];
*
* @param long The index of the element to be fetched.
* @return object The stored element at given index.
* @exception Invalid type for index.
* @exception Non-existing index.
*/
PHP_METHOD(RepeatedField, offsetGet) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
upb_msgval msgval;
zval ret;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
return;
}
if (index < 0 || index >= upb_array_size(intern->array)) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
return;
}
msgval = upb_array_get(intern->array, index);
Convert_UpbToPhp(msgval, &ret, intern->type, intern->desc, &intern->arena);
RETURN_ZVAL(&ret, 0, 1);
}
/**
* RepeatedField::offsetSet()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $arr[$idx] = $x;
* $arr []= $x; // Append
*
* @param long The index of the element to be assigned.
* @param object The element to be assigned.
* @exception Invalid type for index.
* @exception Non-existing index.
* @exception Incorrect type of the element.
*/
PHP_METHOD(RepeatedField, offsetSet) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
size_t size = upb_array_size(intern->array);
zval *offset, *val;
int64_t index;
upb_msgval msgval;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &offset, &val) != SUCCESS) {
return;
}
if (Z_TYPE_P(offset) == IS_NULL) {
index = size;
} else if (!Convert_PhpToInt64(offset, &index)) {
return;
}
if (!Convert_PhpToUpb(val, &msgval, intern->type, intern->desc, arena)) {
return;
}
if (index > size) {
zend_error(E_USER_ERROR, "Element at index %ld doesn't exist.\n", index);
} else if (index == size) {
upb_array_append(intern->array, msgval, Arena_Get(&intern->arena));
} else {
upb_array_set(intern->array, index, msgval);
}
}
/**
* RepeatedField::offsetUnset()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* unset($arr[$idx]);
*
* @param long The index of the element to be removed.
* @exception Invalid type for index.
* @exception The element to be removed is not at the end of the RepeatedField.
*/
PHP_METHOD(RepeatedField, offsetUnset) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
zend_long size = upb_array_size(intern->array);
// Only the element at the end of the array can be removed.
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) != SUCCESS) {
return;
}
if (size == 0 || index != size - 1) {
php_error_docref(NULL, E_USER_ERROR, "Cannot remove element at %ld.\n",
index);
return;
}
upb_array_resize(intern->array, size - 1, Arena_Get(&intern->arena));
}
/**
* RepeatedField::count()
*
* Implements the Countable interface. Invoked when PHP code calls:
*
* $len = count($arr);
* Return the number of stored elements.
* This will also be called for: count($arr)
* @return long The number of stored elements.
*/
PHP_METHOD(RepeatedField, count) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(upb_array_size(intern->array));
}
/**
* RepeatedField::getIterator()
*
* Implements the IteratorAggregate interface. Invoked when PHP code calls:
*
* foreach ($arr) {}
*
* @return object Beginning iterator.
*/
PHP_METHOD(RepeatedField, getIterator) {
zval ret;
RepeatedFieldIter_make(&ret, getThis());
RETURN_ZVAL(&ret, 0, 1);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()
static zend_function_entry repeated_field_methods[] = {
PHP_ME(RepeatedField, __construct, NULL, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, append, NULL, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// PHP RepeatedFieldIter
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval repeated_field;
zend_long position;
} RepeatedFieldIter;
zend_class_entry *RepeatedFieldIter_class_entry;
static zend_object_handlers repeated_field_iter_object_handlers;
/**
* RepeatedFieldIter_create()
*
* PHP class entry function to allocate and initialize a new RepeatedFieldIter
* object.
*/
zend_object* RepeatedFieldIter_create(zend_class_entry *class_type) {
RepeatedFieldIter *intern = emalloc(sizeof(RepeatedFieldIter));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &repeated_field_iter_object_handlers;
ZVAL_NULL(&intern->repeated_field);
intern->position = 0;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
/**
* RepeatedFieldIter_dtor()
*
* Object handler to destroy a RepeatedFieldIter. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void RepeatedFieldIter_dtor(zend_object* obj) {
RepeatedFieldIter* intern = (RepeatedFieldIter*)obj;
zval_ptr_dtor(&intern->repeated_field);
zend_object_std_dtor(&intern->std);
}
/**
* RepeatedFieldIter_make()
*
* C function to create a RepeatedFieldIter.
*/
static void RepeatedFieldIter_make(zval *val, zval *repeated_field) {
RepeatedFieldIter *iter;
ZVAL_OBJ(val, RepeatedFieldIter_class_entry->create_object(
RepeatedFieldIter_class_entry));
iter = (RepeatedFieldIter*)Z_OBJ_P(val);
ZVAL_COPY(&iter->repeated_field, repeated_field);
}
/*
* When a user writes:
*
* foreach($arr as $key => $val) {}
*
* PHP's iterator protocol is:
*
* $iter = $arr->getIterator();
* for ($iter->rewind(); $iter->valid(); $iter->next()) {
* $key = $iter->key();
* $val = $iter->current();
* }
*/
/**
* RepeatedFieldIter::rewind()
*
* Implements the Iterator interface. Sets the iterator to the first element.
*/
PHP_METHOD(RepeatedFieldIter, rewind) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
intern->position = 0;
}
/**
* RepeatedFieldIter::current()
*
* Implements the Iterator interface. Returns the current value.
*/
PHP_METHOD(RepeatedFieldIter, current) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
upb_array *array = field->array;
zend_long index = intern->position;
upb_msgval msgval;
zval ret;
if (index < 0 || index >= upb_array_size(array)) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
}
msgval = upb_array_get(array, index);
Convert_UpbToPhp(msgval, &ret, field->type, field->desc, &field->arena);
RETURN_ZVAL(&ret, 0, 1);
}
/**
* RepeatedFieldIter::key()
*
* Implements the Iterator interface. Returns the current key.
*/
PHP_METHOD(RepeatedFieldIter, key) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RETURN_LONG(intern->position);
}
/**
* RepeatedFieldIter::next()
*
* Implements the Iterator interface. Advances to the next element.
*/
PHP_METHOD(RepeatedFieldIter, next) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
++intern->position;
}
/**
* RepeatedFieldIter::valid()
*
* Implements the Iterator interface. Returns true if this is a valid element.
*/
PHP_METHOD(RepeatedFieldIter, valid) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
RETURN_BOOL(intern->position < upb_array_size(field->array));
}
static zend_function_entry repeated_field_iter_methods[] = {
PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
/**
* Array_ModuleInit()
*
* Called when the C extension is loaded to register all types.
*/
void Array_ModuleInit() {
zend_class_entry tmp_ce;
zend_object_handlers *h;
// RepeatedField.
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedField",
repeated_field_methods);
RepeatedField_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(RepeatedField_class_entry, 3, spl_ce_ArrayAccess,
zend_ce_aggregate, spl_ce_Countable);
RepeatedField_class_entry->ce_flags |= ZEND_ACC_FINAL;
RepeatedField_class_entry->create_object = RepeatedField_create;
h = &RepeatedField_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = RepeatedField_destructor;
h->get_properties = RepeatedField_GetProperties;
h->get_property_ptr_ptr = RepeatedField_GetPropertyPtrPtr;
// RepeatedFieldIter
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedFieldIter",
repeated_field_iter_methods);
RepeatedFieldIter_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(RepeatedFieldIter_class_entry, 1, zend_ce_iterator);
RepeatedFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
RepeatedFieldIter_class_entry->create_object = RepeatedFieldIter_create;
h = &repeated_field_iter_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = RepeatedFieldIter_dtor;
}

@ -1,10 +0,0 @@
PHP_ARG_ENABLE(protobuf, whether to enable Protobuf extension, [ --enable-protobuf Enable Protobuf extension])
if test "$PHP_PROTOBUF" != "no"; then
PHP_NEW_EXTENSION(
protobuf,
arena.c array.c bundled_php.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c,
$ext_shared)
fi

File diff suppressed because it is too large Load Diff

@ -1,590 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "map.h"
#include <Zend/zend_API.h>
#include <Zend/zend_interfaces.h>
#include <ext/spl/spl_iterators.h>
#include "arena.h"
#include "convert.h"
#include "php-upb.h"
#include "protobuf.h"
static void MapFieldIter_make(zval *val, zval *map_field);
// -----------------------------------------------------------------------------
// MapField
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval arena;
upb_map *map;
upb_fieldtype_t key_type;
upb_fieldtype_t val_type;
const Descriptor* desc; // When values are messages.
} MapField;
zend_class_entry *MapField_class_entry;
static zend_object_handlers MapField_object_handlers;
// PHP Object Handlers /////////////////////////////////////////////////////////
/**
* MapField_create()
*
* PHP class entry function to allocate and initialize a new MapField
* object.
*/
static zend_object* MapField_create(zend_class_entry *class_type) {
MapField *intern = emalloc(sizeof(MapField));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &MapField_object_handlers;
Arena_Init(&intern->arena);
intern->map = NULL;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
/**
* MapField_dtor()
*
* Object handler to destroy a MapField. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void MapField_destructor(zend_object* obj) {
MapField* intern = (MapField*)obj;
ObjCache_Delete(intern->map);
zval_ptr_dtor(&intern->arena);
zend_object_std_dtor(&intern->std);
}
static zval *Map_GetPropertyPtrPtr(zval *object, zval *member, int type,
void **cache_slot) {
return NULL; // We don't offer direct references to our properties.
}
static HashTable *map_get_properties(zval *object TSRMLS_DC) {
return NULL; // We do not have a properties table.
}
// C Functions from map.h //////////////////////////////////////////////////////
// These are documented in the header file.
void MapField_GetPhpWrapper(zval *val, upb_map *map, const upb_fielddef *f,
zval *arena) {
if (!map) {
ZVAL_NULL(val);
return;
}
if (!ObjCache_Get(map, val)) {
const upb_msgdef *ent = upb_fielddef_msgsubdef(f);
const upb_fielddef *key_f = upb_msgdef_itof(ent, 1);
const upb_fielddef *val_f = upb_msgdef_itof(ent, 2);
MapField *intern = emalloc(sizeof(MapField));
zend_object_std_init(&intern->std, MapField_class_entry);
intern->std.handlers = &MapField_object_handlers;
ZVAL_COPY(&intern->arena, arena);
intern->map = map;
intern->key_type = upb_fielddef_type(key_f);
intern->val_type = upb_fielddef_type(val_f);
intern->desc = Descriptor_GetFromFieldDef(val_f);
// Skip object_properties_init(), we don't allow derived classes.
ObjCache_Add(intern->map, &intern->std);
ZVAL_OBJ(val, &intern->std);
}
}
upb_map *MapField_GetUpbMap(zval *val, const upb_fielddef *f, upb_arena *arena) {
const upb_msgdef *ent = upb_fielddef_msgsubdef(f);
const upb_fielddef *key_f = upb_msgdef_itof(ent, 1);
const upb_fielddef *val_f = upb_msgdef_itof(ent, 2);
upb_fieldtype_t key_type = upb_fielddef_type(key_f);
upb_fieldtype_t val_type = upb_fielddef_type(val_f);
const Descriptor *desc = Descriptor_GetFromFieldDef(val_f);
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
if (Z_TYPE_P(val) == IS_ARRAY) {
upb_map *map = upb_map_new(arena, key_type, val_type);
HashTable *table = HASH_OF(val);
HashPosition pos;
zend_hash_internal_pointer_reset_ex(table, &pos);
while (true) {
zval php_key;
zval *php_val;
upb_msgval upb_key;
upb_msgval upb_val;
zend_hash_get_current_key_zval_ex(table, &php_key, &pos);
php_val = zend_hash_get_current_data_ex(table, &pos);
if (!php_val) return map;
if (!Convert_PhpToUpb(&php_key, &upb_key, key_type, NULL, arena) ||
!Convert_PhpToUpbAutoWrap(php_val, &upb_val, val_type, desc, arena)) {
return NULL;
}
upb_map_set(map, upb_key, upb_val, arena);
zend_hash_move_forward_ex(table, &pos);
zval_dtor(&php_key);
}
} else if (Z_TYPE_P(val) == IS_OBJECT &&
Z_OBJCE_P(val) == MapField_class_entry) {
MapField *intern = (MapField*)Z_OBJ_P(val);
if (intern->key_type != key_type || intern->val_type != val_type ||
intern->desc != desc) {
php_error_docref(NULL, E_USER_ERROR, "Wrong type for this map field.");
return NULL;
}
upb_arena_fuse(arena, Arena_Get(&intern->arena));
return intern->map;
} else {
php_error_docref(NULL, E_USER_ERROR, "Must be a map");
return NULL;
}
}
// MapField PHP methods ////////////////////////////////////////////////////////
/**
* MapField::__construct()
*
* Constructs an instance of MapField.
* @param long Key type.
* @param long Value type.
* @param string Message/Enum class (message/enum value types only).
*/
PHP_METHOD(MapField, __construct) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
zend_long key_type, val_type;
zend_class_entry* klass = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|C", &key_type, &val_type,
&klass) != SUCCESS) {
return;
}
intern->key_type = pbphp_dtype_to_type(key_type);
intern->val_type = pbphp_dtype_to_type(val_type);
intern->desc = Descriptor_GetFromClassEntry(klass);
// Check that the key type is an allowed type.
switch (intern->key_type) {
case UPB_TYPE_INT32:
case UPB_TYPE_INT64:
case UPB_TYPE_UINT32:
case UPB_TYPE_UINT64:
case UPB_TYPE_BOOL:
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
// These are OK.
break;
default:
zend_error(E_USER_ERROR, "Invalid key type for map.");
}
if (intern->val_type == UPB_TYPE_MESSAGE && klass == NULL) {
php_error_docref(NULL, E_USER_ERROR,
"Message/enum type must have concrete class.");
return;
}
intern->map = upb_map_new(arena, intern->key_type, intern->val_type);
ObjCache_Add(intern->map, &intern->std);
}
/**
* MapField::offsetExists()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* isset($map[$idx]);
* empty($map[$idx]);
*
* @param long The index to be checked.
* @return bool True if the element at the given index exists.
*/
PHP_METHOD(MapField, offsetExists) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
zval *key;
upb_msgval upb_key;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
!Convert_PhpToUpb(key, &upb_key, intern->key_type, intern->desc, NULL)) {
return;
}
RETURN_BOOL(upb_map_get(intern->map, upb_key, NULL));
}
/**
* MapField::offsetGet()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $x = $map[$idx];
*
* @param long The index of the element to be fetched.
* @return object The stored element at given index.
* @exception Invalid type for index.
* @exception Non-existing index.
*/
PHP_METHOD(MapField, offsetGet) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
zval *key;
zval ret;
upb_msgval upb_key, upb_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
!Convert_PhpToUpb(key, &upb_key, intern->key_type, intern->desc, NULL)) {
return;
}
if (!upb_map_get(intern->map, upb_key, &upb_val)) {
zend_error(E_USER_ERROR, "Given key doesn't exist.");
return;
}
Convert_UpbToPhp(upb_val, &ret, intern->val_type, intern->desc, &intern->arena);
RETURN_ZVAL(&ret, 0, 1);
}
/**
* MapField::offsetSet()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $map[$idx] = $x;
*
* @param long The index of the element to be assigned.
* @param object The element to be assigned.
* @exception Invalid type for index.
* @exception Non-existing index.
* @exception Incorrect type of the element.
*/
PHP_METHOD(MapField, offsetSet) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
zval *key, *val;
upb_msgval upb_key, upb_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &key, &val) != SUCCESS ||
!Convert_PhpToUpb(key, &upb_key, intern->key_type, NULL, NULL) ||
!Convert_PhpToUpb(val, &upb_val, intern->val_type, intern->desc, arena)) {
return;
}
upb_map_set(intern->map, upb_key, upb_val, arena);
}
/**
* MapField::offsetUnset()
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* unset($map[$idx]);
*
* @param long The index of the element to be removed.
* @exception Invalid type for index.
* @exception The element to be removed is not at the end of the MapField.
*/
PHP_METHOD(MapField, offsetUnset) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
zval *key;
upb_msgval upb_key;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
!Convert_PhpToUpb(key, &upb_key, intern->key_type, NULL, NULL)) {
return;
}
upb_map_delete(intern->map, upb_key);
}
/**
* MapField::count()
*
* Implements the Countable interface. Invoked when PHP code calls:
*
* $len = count($map);
* Return the number of stored elements.
* This will also be called for: count($map)
* @return long The number of stored elements.
*/
PHP_METHOD(MapField, count) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(upb_map_size(intern->map));
}
/**
* MapField::getIterator()
*
* Implements the IteratorAggregate interface. Invoked when PHP code calls:
*
* foreach ($arr) {}
*
* @return object Beginning iterator.
*/
PHP_METHOD(MapField, getIterator) {
zval ret;
MapFieldIter_make(&ret, getThis());
RETURN_ZVAL(&ret, 0, 1);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()
static zend_function_entry MapField_methods[] = {
PHP_ME(MapField, __construct, NULL, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(MapField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// MapFieldIter
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval map_field;
size_t position;
} MapFieldIter;
zend_class_entry *MapFieldIter_class_entry;
static zend_object_handlers MapFieldIter_object_handlers;
/**
* MapFieldIter_create()
*
* PHP class entry function to allocate and initialize a new MapFieldIter
* object.
*/
zend_object* MapFieldIter_create(zend_class_entry *class_type) {
MapFieldIter *intern = emalloc(sizeof(MapFieldIter));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &MapFieldIter_object_handlers;
ZVAL_NULL(&intern->map_field);
intern->position = 0;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
/**
* MapFieldIter_dtor()
*
* Object handler to destroy a MapFieldIter. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void map_field_iter_dtor(zend_object* obj) {
MapFieldIter* intern = (MapFieldIter*)obj;
zval_ptr_dtor(&intern->map_field);
zend_object_std_dtor(&intern->std);
}
/**
* MapFieldIter_make()
*
* Function to create a MapFieldIter directly from C.
*/
static void MapFieldIter_make(zval *val, zval *map_field) {
MapFieldIter *iter;
ZVAL_OBJ(val,
MapFieldIter_class_entry->create_object(MapFieldIter_class_entry));
iter = (MapFieldIter*)Z_OBJ_P(val);
ZVAL_COPY(&iter->map_field, map_field);
}
// -----------------------------------------------------------------------------
// PHP MapFieldIter Methods
// -----------------------------------------------------------------------------
/*
* When a user writes:
*
* foreach($arr as $key => $val) {}
*
* PHP translates this into:
*
* $iter = $arr->getIterator();
* for ($iter->rewind(); $iter->valid(); $iter->next()) {
* $key = $iter->key();
* $val = $iter->current();
* }
*/
/**
* MapFieldIter::rewind()
*
* Implements the Iterator interface. Sets the iterator to the first element.
*/
PHP_METHOD(MapFieldIter, rewind) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *map_field = (MapField*)Z_OBJ_P(&intern->map_field);
intern->position = UPB_MAP_BEGIN;
upb_mapiter_next(map_field->map, &intern->position);
}
/**
* MapFieldIter::current()
*
* Implements the Iterator interface. Returns the current value.
*/
PHP_METHOD(MapFieldIter, current) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
upb_msgval upb_val = upb_mapiter_value(field->map, intern->position);
zval ret;
Convert_UpbToPhp(upb_val, &ret, field->val_type, field->desc, &field->arena);
RETURN_ZVAL(&ret, 0, 1);
}
/**
* MapFieldIter::key()
*
* Implements the Iterator interface. Returns the current key.
*/
PHP_METHOD(MapFieldIter, key) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
upb_msgval upb_key = upb_mapiter_key(field->map, intern->position);
zval ret;
Convert_UpbToPhp(upb_key, &ret, field->key_type, NULL, NULL);
RETURN_ZVAL(&ret, 0, 1);
}
/**
* MapFieldIter::next()
*
* Implements the Iterator interface. Advances to the next element.
*/
PHP_METHOD(MapFieldIter, next) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
upb_mapiter_next(field->map, &intern->position);
}
/**
* MapFieldIter::valid()
*
* Implements the Iterator interface. Returns true if this is a valid element.
*/
PHP_METHOD(MapFieldIter, valid) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
bool done = upb_mapiter_done(field->map, intern->position);
RETURN_BOOL(!done);
}
static zend_function_entry map_field_iter_methods[] = {
PHP_ME(MapFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
/**
* Map_ModuleInit()
*
* Called when the C extension is loaded to register all types.
*/
void Map_ModuleInit() {
zend_class_entry tmp_ce;
zend_object_handlers *h;
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\MapField",
MapField_methods);
MapField_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(MapField_class_entry, 3, spl_ce_ArrayAccess,
zend_ce_aggregate, spl_ce_Countable);
MapField_class_entry->ce_flags |= ZEND_ACC_FINAL;
MapField_class_entry->create_object = MapField_create;
h = &MapField_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = MapField_destructor;
h->get_properties = map_get_properties;
h->get_property_ptr_ptr = Map_GetPropertyPtrPtr;
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\MapFieldIter",
map_field_iter_methods);
MapFieldIter_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(MapFieldIter_class_entry, 1, zend_ce_iterator);
MapFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
MapFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
MapFieldIter_class_entry->create_object = MapFieldIter_create;
h = &MapFieldIter_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = map_field_iter_dtor;
}

@ -1,841 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2014 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.
#include "message.h"
#include <inttypes.h>
#include <php.h>
#include <stdlib.h>
// This is not self-contained: it must be after other Zend includes.
#include <Zend/zend_exceptions.h>
#include "arena.h"
#include "array.h"
#include "convert.h"
#include "def.h"
#include "map.h"
#include "php-upb.h"
#include "protobuf.h"
// -----------------------------------------------------------------------------
// Message
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval arena;
const Descriptor* desc;
upb_msg *msg;
} Message;
zend_class_entry *message_ce;
static zend_object_handlers message_object_handlers;
// PHP Object Handlers /////////////////////////////////////////////////////////
/**
* Message_create()
*
* PHP class entry function to allocate and initialize a new Message object.
*/
static zend_object* Message_create(zend_class_entry *class_type) {
Message *intern = emalloc(sizeof(Message));
// XXX(haberman): verify whether we actually want to take this route.
class_type->default_properties_count = 0;
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &message_object_handlers;
Arena_Init(&intern->arena);
return &intern->std;
}
/**
* Message_dtor()
*
* Object handler to destroy a Message. This releases all resources associated
* with the message. Note that it is possible to access a destroyed object from
* PHP in rare cases.
*/
static void Message_dtor(zend_object* obj) {
Message* intern = (Message*)obj;
ObjCache_Delete(intern->msg);
zval_dtor(&intern->arena);
zend_object_std_dtor(&intern->std);
}
/**
* get_field()
*
* Helper function to look up a field given a member name (as a string).
*/
static const upb_fielddef *get_field(Message *msg, zval *member) {
const upb_msgdef *m = msg->desc->msgdef;
const upb_fielddef *f =
upb_msgdef_ntof(m, Z_STRVAL_P(member), Z_STRLEN_P(member));
if (!f) {
zend_throw_exception_ex(NULL, 0, "No such property %s.",
ZSTR_VAL(msg->desc->class_entry->name));
}
return f;
}
/**
* Message_read_property()
*
* Object handler for reading a property in PHP. Called when PHP code does:
*
* $x = $message->foobar;
*
* Note that all properties of generated messages are private, so this should
* only be possible to invoke from generated code, which has accessors like:
*
* public function getOptionalInt32()
* {
* return $this->optional_int32;
* }
*
* We lookup the field and return the scalar, RepeatedField, or MapField for
* this field.
*/
static zval *Message_read_property(zval *obj, zval *member, int type,
void **cache_slot, zval *rv) {
Message* intern = (Message*)Z_OBJ_P(obj);
const upb_fielddef *f = get_field(intern, member);
upb_arena *arena = Arena_Get(&intern->arena);
if (!f) return NULL;
if (upb_fielddef_ismap(f)) {
upb_mutmsgval msgval = upb_msg_mutable(intern->msg, f, arena);
MapField_GetPhpWrapper(rv, msgval.map, f, &intern->arena);
} else if (upb_fielddef_isseq(f)) {
upb_mutmsgval msgval = upb_msg_mutable(intern->msg, f, arena);
RepeatedField_GetPhpWrapper(rv, msgval.array, f, &intern->arena);
} else {
upb_msgval msgval = upb_msg_get(intern->msg, f);
const Descriptor *subdesc = Descriptor_GetFromFieldDef(f);
Convert_UpbToPhp(msgval, rv, upb_fielddef_type(f), subdesc, &intern->arena);
}
return rv;
}
/**
* Message_write_property()
*
* Object handler for writing a property in PHP. Called when PHP code does:
*
* $message->foobar = $x;
*
* Note that all properties of generated messages are private, so this should
* only be possible to invoke from generated code, which has accessors like:
*
* public function setOptionalInt32($var)
* {
* GPBUtil::checkInt32($var);
* $this->optional_int32 = $var;
*
* return $this;
* }
*
* The C extension version of checkInt32() doesn't actually check anything, so
* we perform all checking and conversion in this function.
*/
static void Message_write_property(zval *obj, zval *member, zval *val,
void **cache_slot) {
Message* intern = (Message*)Z_OBJ_P(obj);
const upb_fielddef *f = get_field(intern, member);
upb_arena *arena = Arena_Get(&intern->arena);
upb_msgval msgval;
if (!f) return;
if (upb_fielddef_ismap(f)) {
msgval.map_val = MapField_GetUpbMap(val, f, arena);
if (!msgval.map_val) return;
} else if (upb_fielddef_isseq(f)) {
msgval.array_val = RepeatedField_GetUpbArray(val, f, arena);
if (!msgval.array_val) return;
} else {
upb_fieldtype_t type = upb_fielddef_type(f);
const Descriptor *subdesc = Descriptor_GetFromFieldDef(f);
bool ok = Convert_PhpToUpb(val, &msgval, type, subdesc, arena);
if (!ok) return;
}
upb_msg_set(intern->msg, f, msgval, arena);
}
/**
* Message_get_property_ptr_ptr()
*
* Object handler for the get_property_ptr_ptr event in PHP. This returns a
* reference to our internal properties. We don't support this, so we return
* NULL.
*/
static zval *Message_get_property_ptr_ptr(zval *object, zval *member, int type,
void **cache_slot) {
return NULL; // We do not have a properties table.
}
/**
* Message_get_properties()
*
* Object handler for the get_properties event in PHP. This returns a HashTable
* of our internal properties. We don't support this, so we return NULL.
*/
static HashTable* Message_get_properties(zval* object TSRMLS_DC) {
return NULL; // We don't offer direct references to our properties.
}
// C Functions from message.h. /////////////////////////////////////////////////
// These are documented in the header file.
void Message_GetPhpWrapper(zval *val, const Descriptor *desc, upb_msg *msg,
zval *arena) {
if (!msg) {
ZVAL_NULL(val);
return;
}
if (!ObjCache_Get(msg, val)) {
Message *intern = emalloc(sizeof(Message));
// XXX(haberman): verify whether we actually want to take this route.
desc->class_entry->default_properties_count = 0;
zend_object_std_init(&intern->std, desc->class_entry);
intern->std.handlers = &message_object_handlers;
ZVAL_COPY(&intern->arena, arena);
intern->desc = desc;
intern->msg = msg;
ZVAL_OBJ(val, &intern->std);
ObjCache_Add(intern->msg, &intern->std);
}
}
bool Message_GetUpbMessage(zval *val, const Descriptor *desc, upb_arena *arena,
upb_msg **msg) {
PBPHP_ASSERT(desc);
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
if (Z_TYPE_P(val) == IS_NULL) {
*msg = NULL;
return true;
}
if (Z_TYPE_P(val) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(val), desc->class_entry)) {
Message *intern = (Message*)Z_OBJ_P(val);
upb_arena_fuse(arena, Arena_Get(&intern->arena));
*msg = intern->msg;
return true;
} else {
zend_throw_exception_ex(NULL, 0, "Given value is not an instance of %s.",
ZSTR_VAL(desc->class_entry->name));
return false;
}
}
// Message PHP methods /////////////////////////////////////////////////////////
/**
* Message_InitFromPhp()
*
* Helper method to handle the initialization of a message from a PHP value, eg.
*
* $m = new TestMessage([
* 'optional_int32' => -42,
* 'optional_bool' => true,
* 'optional_string' => 'a',
* 'optional_enum' => TestEnum::ONE,
* 'optional_message' => new Sub([
* 'a' => 33
* ]),
* 'repeated_int32' => [-42, -52],
* 'repeated_enum' => [TestEnum::ZERO, TestEnum::ONE],
* 'repeated_message' => [new Sub(['a' => 34]),
* new Sub(['a' => 35])],
* 'map_int32_int32' => [-62 => -62],
* 'map_int32_enum' => [1 => TestEnum::ONE],
* 'map_int32_message' => [1 => new Sub(['a' => 36])],
* ]);
*
* The initializer must be an array.
*/
bool Message_InitFromPhp(upb_msg *msg, const upb_msgdef *m, zval *init,
upb_arena *arena) {
HashTable* table = HASH_OF(init);
HashPosition pos;
if (Z_ISREF_P(init)) {
ZVAL_DEREF(init);
}
if (Z_TYPE_P(init) != IS_ARRAY) {
zend_throw_exception_ex(NULL, 0,
"Initializer for a message %s must be an array.",
upb_msgdef_fullname(m));
return false;
}
zend_hash_internal_pointer_reset_ex(table, &pos);
while (true) { // Iterate over key/value pairs.
zval key;
zval *val;
const upb_fielddef *f;
upb_msgval msgval;
zend_hash_get_current_key_zval_ex(table, &key, &pos);
val = zend_hash_get_current_data_ex(table, &pos);
if (!val) return true; // Finished iteration.
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
f = upb_msgdef_ntof(m, Z_STRVAL_P(&key), Z_STRLEN_P(&key));
if (!f) {
zend_throw_exception_ex(NULL, 0,
"No such field %s", Z_STRVAL_P(&key));
return false;
}
if (upb_fielddef_ismap(f)) {
msgval.map_val = MapField_GetUpbMap(val, f, arena);
if (!msgval.map_val) return false;
} else if (upb_fielddef_isseq(f)) {
msgval.array_val = RepeatedField_GetUpbArray(val, f, arena);
if (!msgval.array_val) return false;
} else {
const Descriptor *desc = Descriptor_GetFromFieldDef(f);
upb_fieldtype_t type = upb_fielddef_type(f);
if (!Convert_PhpToUpbAutoWrap(val, &msgval, type, desc, arena)) {
return false;
}
}
upb_msg_set(msg, f, msgval, arena);
zend_hash_move_forward_ex(table, &pos);
zval_dtor(&key);
}
}
/**
* Message::__construct()
*
* Constructor for Message.
* @param array Map of initial values ['k' = val]
*/
PHP_METHOD(Message, __construct) {
Message* intern = (Message*)Z_OBJ_P(getThis());
const Descriptor* desc = Descriptor_GetFromClassEntry(Z_OBJCE_P(getThis()));
const upb_msgdef *msgdef = desc->msgdef;
upb_arena *arena = Arena_Get(&intern->arena);
zval *init_arr = NULL;
intern->desc = desc;
intern->msg = upb_msg_new(msgdef, arena);
ObjCache_Add(intern->msg, &intern->std);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!", &init_arr) == FAILURE) {
return;
}
if (init_arr) {
Message_InitFromPhp(intern->msg, desc->msgdef, init_arr, arena);
}
}
/**
* Message::discardUnknownFields()
*
* Discards any unknown fields for this message or any submessages.
*/
PHP_METHOD(Message, discardUnknownFields) {
Message* intern = (Message*)Z_OBJ_P(getThis());
upb_msg_discardunknown(intern->msg, intern->desc->msgdef, 64);
}
/**
* Message::clear()
*
* Clears all fields of this message.
*/
PHP_METHOD(Message, clear) {
Message* intern = (Message*)Z_OBJ_P(getThis());
upb_msg_clear(intern->msg, intern->desc->msgdef);
}
/**
* Message::mergeFrom()
*
* Merges from the given message, which must be of the same class as us.
* @param object Message to merge from.
*/
PHP_METHOD(Message, mergeFrom) {
Message* intern = (Message*)Z_OBJ_P(getThis());
Message* from;
upb_arena *arena = Arena_Get(&intern->arena);
const upb_msglayout *l = upb_msgdef_layout(intern->desc->msgdef);
zval* value;
char *pb;
size_t size;
bool ok;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &value,
intern->desc->class_entry) == FAILURE) {
return;
}
from = (Message*)Z_OBJ_P(value);
// Should be guaranteed since we passed the class type to
// zend_parse_parameters().
PBPHP_ASSERT(from->desc == intern->desc);
// TODO(haberman): use a temp arena for this once we can make upb_decode()
// copy strings.
pb = upb_encode(from->msg, l, arena, &size);
if (!pb) {
zend_throw_exception_ex(NULL, 0, "Max nesting exceeded");
return;
}
ok = upb_decode(pb, size, intern->msg, l, arena);
PBPHP_ASSERT(ok);
}
/**
* Message::mergeFromString()
*
* Merges from the given string.
* @param string Binary protobuf data to merge.
*/
PHP_METHOD(Message, mergeFromString) {
Message* intern = (Message*)Z_OBJ_P(getThis());
char *data = NULL;
char *data_copy = NULL;
zend_long data_len;
const upb_msglayout *l = upb_msgdef_layout(intern->desc->msgdef);
upb_arena *arena = Arena_Get(&intern->arena);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &data, &data_len) ==
FAILURE) {
return;
}
// TODO(haberman): avoid this copy when we can make the decoder copy.
data_copy = upb_arena_malloc(arena, data_len);
memcpy(data_copy, data, data_len);
if (!upb_decode(data_copy, data_len, intern->msg, l, arena)) {
zend_throw_exception_ex(NULL, 0, "Error occurred during parsing");
return;
}
}
/**
* Message::serializeToString()
*
* Serializes this message instance to protobuf data.
* @return string Serialized protobuf data.
*/
PHP_METHOD(Message, serializeToString) {
Message* intern = (Message*)Z_OBJ_P(getThis());
const upb_msglayout *l = upb_msgdef_layout(intern->desc->msgdef);
upb_arena *tmp_arena = upb_arena_new();
char *data;
size_t size;
data = upb_encode(intern->msg, l, tmp_arena, &size);
if (!data) {
zend_throw_exception_ex(NULL, 0, "Error occurred during serialization");
upb_arena_free(tmp_arena);
return;
}
RETVAL_STRINGL(data, size);
upb_arena_free(tmp_arena);
}
/**
* Message::mergeFromJsonString()
*
* Merges the JSON data parsed from the given string.
* @param string Serialized JSON data.
*/
PHP_METHOD(Message, mergeFromJsonString) {
Message* intern = (Message*)Z_OBJ_P(getThis());
char *data = NULL;
char *data_copy = NULL;
zend_long data_len;
upb_arena *arena = Arena_Get(&intern->arena);
upb_status status;
zend_bool ignore_json_unknown = false;
int options = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &data, &data_len,
&ignore_json_unknown) == FAILURE) {
return;
}
// TODO(haberman): avoid this copy when we can make the decoder copy.
data_copy = upb_arena_malloc(arena, data_len + 1);
memcpy(data_copy, data, data_len);
data_copy[data_len] = '\0';
if (ignore_json_unknown) {
options |= UPB_JSONDEC_IGNOREUNKNOWN;
}
upb_status_clear(&status);
if (!upb_json_decode(data_copy, data_len, intern->msg, intern->desc->msgdef,
DescriptorPool_GetSymbolTable(), options, arena,
&status)) {
zend_throw_exception_ex(NULL, 0, "Error occurred during parsing: %s",
upb_status_errmsg(&status));
return;
}
}
/**
* Message::serializeToJsonString()
*
* Serializes this object to JSON.
* @return string Serialized JSON data.
*/
PHP_METHOD(Message, serializeToJsonString) {
Message* intern = (Message*)Z_OBJ_P(getThis());
size_t size;
int options = 0;
char buf[1024];
zend_bool preserve_proto_fieldnames = false;
upb_status status;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b",
&preserve_proto_fieldnames) == FAILURE) {
return;
}
if (preserve_proto_fieldnames) {
options |= UPB_JSONENC_PROTONAMES;
}
upb_status_clear(&status);
size = upb_json_encode(intern->msg, intern->desc->msgdef,
DescriptorPool_GetSymbolTable(), options, buf,
sizeof(buf), &status);
if (!upb_ok(&status)) {
zend_throw_exception_ex(NULL, 0,
"Error occurred during JSON serialization: %s",
upb_status_errmsg(&status));
return;
}
if (size >= sizeof(buf)) {
char *buf2 = malloc(size + 1);
upb_json_encode(intern->msg, intern->desc->msgdef,
DescriptorPool_GetSymbolTable(), options, buf2, size + 1,
&status);
RETVAL_STRINGL(buf2, size);
free(buf2);
} else {
RETVAL_STRINGL(buf, size);
}
}
/**
* Message::readWrapperValue()
*
* Returns an unboxed value for the given field. This is called from generated
* methods for wrapper fields, eg.
*
* public function getDoubleValueUnwrapped()
* {
* return $this->readWrapperValue("double_value");
* }
*
* @return Unwrapped field value or null.
*/
PHP_METHOD(Message, readWrapperValue) {
Message* intern = (Message*)Z_OBJ_P(getThis());
char* member;
const upb_fielddef *f;
zend_long size;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &member, &size) == FAILURE) {
return;
}
f = upb_msgdef_ntof(intern->desc->msgdef, member, size);
if (!f || !upb_msgdef_iswrapper(upb_fielddef_msgsubdef(f))) {
zend_throw_exception_ex(NULL, 0, "Message %s has no field %s",
upb_msgdef_fullname(intern->desc->msgdef), member);
return;
}
if (upb_msg_has(intern->msg, f)) {
const upb_msg *wrapper = upb_msg_get(intern->msg, f).msg_val;
const upb_msgdef *m = upb_fielddef_msgsubdef(f);
const upb_fielddef *val_f = upb_msgdef_itof(m, 1);
const upb_fieldtype_t val_type = upb_fielddef_type(val_f);
upb_msgval msgval = upb_msg_get(wrapper, val_f);
zval ret;
Convert_UpbToPhp(msgval, &ret, val_type, NULL, &intern->arena);
RETURN_ZVAL(&ret, 1, 0);
} else {
RETURN_NULL();
}
}
/**
* Message::writeWrapperValue()
*
* Sets the given wrapper field to the given unboxed value. This is called from
* generated methods for wrapper fields, eg.
*
*
* public function setDoubleValueUnwrapped($var)
* {
* $this->writeWrapperValue("double_value", $var);
* return $this;
* }
*
* @param Unwrapped field value or null.
*/
PHP_METHOD(Message, writeWrapperValue) {
Message* intern = (Message*)Z_OBJ_P(getThis());
upb_arena *arena = Arena_Get(&intern->arena);
char* member;
const upb_fielddef *f;
upb_msgval msgval;
zend_long size;
zval* val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &member, &size, &val) ==
FAILURE) {
return;
}
f = upb_msgdef_ntof(intern->desc->msgdef, member, size);
if (!f || !upb_msgdef_iswrapper(upb_fielddef_msgsubdef(f))) {
zend_throw_exception_ex(NULL, 0, "Message %s has no field %s",
upb_msgdef_fullname(intern->desc->msgdef), member);
return;
}
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
if (Z_TYPE_P(val) == IS_NULL) {
upb_msg_clearfield(intern->msg, f);
} else {
const upb_msgdef *m = upb_fielddef_msgsubdef(f);
const upb_fielddef *val_f = upb_msgdef_itof(m, 1);
upb_fieldtype_t val_type = upb_fielddef_type(val_f);
upb_msg *wrapper;
if (!Convert_PhpToUpb(val, &msgval, val_type, NULL, arena)) {
return; // Error is already set.
}
wrapper = upb_msg_mutable(intern->msg, f, arena).msg;
upb_msg_set(wrapper, val_f, msgval, arena);
}
}
/**
* Message::whichOneof()
*
* Given a oneof name, returns the name of the field that is set for this oneof,
* or otherwise the empty string.
*
* @return string The field name in this oneof that is currently set.
*/
PHP_METHOD(Message, whichOneof) {
Message* intern = (Message*)Z_OBJ_P(getThis());
const upb_oneofdef* oneof;
const upb_fielddef* field;
char* name;
zend_long len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len) == FAILURE) {
return;
}
oneof = upb_msgdef_ntoo(intern->desc->msgdef, name, len);
if (!oneof) {
zend_throw_exception_ex(NULL, 0, "Message %s has no oneof %s",
upb_msgdef_fullname(intern->desc->msgdef), name);
return;
}
field = upb_msg_whichoneof(intern->msg, oneof);
RETURN_STRING(field ? upb_fielddef_name(field) : "");
}
/**
* Message::readOneof()
*
* Returns the contents of the given oneof field, given a field number. Called
* from generated code methods such as:
*
* public function getDoubleValueOneof()
* {
* return $this->readOneof(10);
* }
*
* @return object The oneof's field value.
*/
PHP_METHOD(Message, readOneof) {
Message* intern = (Message*)Z_OBJ_P(getThis());
zend_long field_num;
const upb_fielddef* f;
zval ret;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &field_num) == FAILURE) {
return;
}
f = upb_msgdef_itof(intern->desc->msgdef, field_num);
if (!f || !upb_fielddef_realcontainingoneof(f)) {
php_error_docref(NULL, E_USER_ERROR,
"Internal error, no such oneof field %d\n",
(int)field_num);
}
{
upb_msgval msgval = upb_msg_get(intern->msg, f);
const Descriptor *subdesc = Descriptor_GetFromFieldDef(f);
Convert_UpbToPhp(msgval, &ret, upb_fielddef_type(f), subdesc,
&intern->arena);
}
RETURN_ZVAL(&ret, 1, 0);
}
/**
* Message::writeOneof()
*
* Sets the contents of the given oneof field, given a field number. Called
* from generated code methods such as:
*
* public function setDoubleValueOneof($var)
* {
* GPBUtil::checkMessage($var, \Google\Protobuf\DoubleValue::class);
* $this->writeOneof(10, $var);
*
* return $this;
* }
*
* The C extension version of GPBUtil::check*() does nothing, so we perform
* all type checking and conversion here.
*
* @param integer The field number we are setting.
* @param object The field value we want to set.
*/
PHP_METHOD(Message, writeOneof) {
Message* intern = (Message*)Z_OBJ_P(getThis());
zend_long field_num;
const upb_fielddef* f;
upb_arena *arena = Arena_Get(&intern->arena);
upb_msgval msgval;
zval* val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &field_num, &val) ==
FAILURE) {
return;
}
f = upb_msgdef_itof(intern->desc->msgdef, field_num);
if (!Convert_PhpToUpb(val, &msgval, upb_fielddef_type(f),
Descriptor_GetFromFieldDef(f), arena)) {
return;
}
upb_msg_set(intern->msg, f, msgval, arena);
}
static zend_function_entry Message_methods[] = {
PHP_ME(Message, clear, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, discardUnknownFields, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, serializeToString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, mergeFromString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, serializeToJsonString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, mergeFromJsonString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, mergeFrom, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, readWrapperValue, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, writeWrapperValue, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, readOneof, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, writeOneof, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, whichOneof, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, __construct, NULL, ZEND_ACC_PROTECTED)
ZEND_FE_END
};
/**
* Message_ModuleInit()
*
* Called when the C extension is loaded to register all types.
*/
void Message_ModuleInit() {
zend_class_entry tmp_ce;
zend_object_handlers *h = &message_object_handlers;
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\Message",
Message_methods);
message_ce = zend_register_internal_class(&tmp_ce);
message_ce->create_object = Message_create;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = Message_dtor;
h->read_property = Message_read_property;
h->write_property = Message_write_property;
h->get_properties = Message_get_properties;
h->get_property_ptr_ptr = Message_get_property_ptr_ptr;
}

@ -1,349 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "protobuf.h"
#include <php.h>
#include <Zend/zend_interfaces.h>
#include "arena.h"
#include "array.h"
#include "bundled_php.h"
#include "convert.h"
#include "def.h"
#include "map.h"
#include "message.h"
#include "names.h"
// -----------------------------------------------------------------------------
// Module "globals"
// -----------------------------------------------------------------------------
// Despite the name, module "globals" are really thread-locals:
// * PROTOBUF_G(var) accesses the thread-local variable for 'var'. Either:
// * PROTOBUF_G(var) -> protobuf_globals.var (Non-ZTS / non-thread-safe)
// * PROTOBUF_G(var) -> <Zend magic> (ZTS / thread-safe builds)
#define PROTOBUF_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(protobuf, v)
ZEND_BEGIN_MODULE_GLOBALS(protobuf)
// Set by the user to make the descriptor pool persist between requests.
zend_bool keep_descriptor_pool_after_request;
// Currently we make the generated pool a "global", which means that if a user
// does explicitly create threads within their request, the other threads will
// get different results from DescriptorPool::getGeneratedPool(). We require
// that all descriptors are loaded from the main thread.
zval generated_pool;
// A upb_symtab that we are saving for the next request so that we don't have
// to rebuild it from scratch. When keep_descriptor_pool_after_request==true,
// we steal the upb_symtab from the global DescriptorPool object just before
// destroying it.
upb_symtab *saved_symtab;
// Object cache (see interface in protobuf.h).
HashTable object_cache;
// Name cache (see interface in protobuf.h).
HashTable name_msg_cache;
HashTable name_enum_cache;
ZEND_END_MODULE_GLOBALS(protobuf)
ZEND_DECLARE_MODULE_GLOBALS(protobuf)
const zval *get_generated_pool() {
return &PROTOBUF_G(generated_pool);
}
// This is a PHP extension (not a Zend extension). What follows is a summary of
// a PHP extension's lifetime and when various handlers are called.
//
// * PHP_GINIT_FUNCTION(protobuf) / PHP_GSHUTDOWN_FUNCTION(protobuf)
// are the constructor/destructor for the globals. The sequence over the
// course of a process lifetime is:
//
// # Process startup
// GINIT(<Main Thread Globals>)
// MINIT
//
// foreach request:
// RINIT
// # Request is processed here.
// RSHUTDOWN
//
// foreach thread:
// GINIT(<This Thread Globals>)
// # Code for the thread runs here.
// GSHUTDOWN(<This Thread Globals>)
//
// # Process Shutdown
// #
// # These should be running per the docs, but I have not been able to
// # actually get the process-wide shutdown functions to run.
// #
// # MSHUTDOWN
// # GSHUTDOWN(<Main Thread Globals>)
//
// * Threads can be created either explicitly by the user, inside a request,
// or implicitly by the runtime, to process multiple requests concurrently.
// If the latter is being used, then the "foreach thread" block above
// actually looks like this:
//
// foreach thread:
// GINIT(<This Thread Globals>)
// # A non-main thread will only receive requests when using a threaded
// # MPM with Apache
// foreach request:
// RINIT
// # Request is processed here.
// RSHUTDOWN
// GSHUTDOWN(<This Thread Globals>)
//
// That said, it appears that few people use threads with PHP:
// * The pthread package documented at
// https://www.php.net/manual/en/class.thread.php nas not been released
// since 2016, and the current release fails to compile against any PHP
// newer than 7.0.33.
// * The GitHub master branch supports 7.2+, but this has not been released
// to PECL.
// * Its owner has disavowed it as "broken by design" and "in an untenable
// position for the future": https://github.com/krakjoe/pthreads/issues/929
// * The only way to use PHP with requests in different threads is to use the
// Apache 2 mod_php with the "worker" MPM. But this is explicitly
// discouraged by the documentation: https://serverfault.com/a/231660
static PHP_GSHUTDOWN_FUNCTION(protobuf) {
if (protobuf_globals->saved_symtab) {
upb_symtab_free(protobuf_globals->saved_symtab);
}
}
static PHP_GINIT_FUNCTION(protobuf) {
ZVAL_NULL(&protobuf_globals->generated_pool);
protobuf_globals->saved_symtab = NULL;
}
/**
* PHP_RINIT_FUNCTION(protobuf)
*
* This function is run at the beginning of processing each request.
*/
static PHP_RINIT_FUNCTION(protobuf) {
// Create the global generated pool.
// Reuse the symtab (if any) left to us by the last request.
upb_symtab *symtab = PROTOBUF_G(saved_symtab);
DescriptorPool_CreateWithSymbolTable(&PROTOBUF_G(generated_pool), symtab);
// Set up autoloader for bundled sources.
zend_eval_string("spl_autoload_register('protobuf_internal_loadbundled');",
NULL, "autoload_register.php");
zend_hash_init(&PROTOBUF_G(object_cache), 64, NULL, NULL, 0);
zend_hash_init(&PROTOBUF_G(name_msg_cache), 64, NULL, NULL, 0);
zend_hash_init(&PROTOBUF_G(name_enum_cache), 64, NULL, NULL, 0);
return SUCCESS;
}
/**
* PHP_RSHUTDOWN_FUNCTION(protobuf)
*
* This function is run at the end of processing each request.
*/
static PHP_RSHUTDOWN_FUNCTION(protobuf) {
// Preserve the symtab if requested.
if (PROTOBUF_G(keep_descriptor_pool_after_request)) {
zval *zv = &PROTOBUF_G(generated_pool);
PROTOBUF_G(saved_symtab) = DescriptorPool_Steal(zv);
}
zval_dtor(&PROTOBUF_G(generated_pool));
zend_hash_destroy(&PROTOBUF_G(object_cache));
zend_hash_destroy(&PROTOBUF_G(name_msg_cache));
zend_hash_destroy(&PROTOBUF_G(name_enum_cache));
return SUCCESS;
}
// -----------------------------------------------------------------------------
// Bundled PHP sources
// -----------------------------------------------------------------------------
// We bundle PHP sources for well-known types into the C extension. There is no
// need to implement these in C.
static PHP_FUNCTION(protobuf_internal_loadbundled) {
char *name = NULL;
zend_long size;
BundledPhp_File *file;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &size) != SUCCESS) {
return;
}
for (file = bundled_files; file->filename; file++) {
if (strcmp(file->filename, name) == 0) {
zend_eval_string((char*)file->contents, NULL, (char*)file->filename);
return;
}
}
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_load_bundled_source, 0, 0, 1)
ZEND_ARG_INFO(0, class_name)
ZEND_END_ARG_INFO()
// -----------------------------------------------------------------------------
// Object Cache.
// -----------------------------------------------------------------------------
void ObjCache_Add(const void *upb_obj, zend_object *php_obj) {
zend_ulong k = (zend_ulong)upb_obj;
zend_hash_index_add_ptr(&PROTOBUF_G(object_cache), k, php_obj);
}
void ObjCache_Delete(const void *upb_obj) {
if (upb_obj) {
zend_ulong k = (zend_ulong)upb_obj;
int ret = zend_hash_index_del(&PROTOBUF_G(object_cache), k);
PBPHP_ASSERT(ret == SUCCESS);
}
}
bool ObjCache_Get(const void *upb_obj, zval *val) {
zend_ulong k = (zend_ulong)upb_obj;
zend_object *obj = zend_hash_index_find_ptr(&PROTOBUF_G(object_cache), k);
if (obj) {
GC_ADDREF(obj);
ZVAL_OBJ(val, obj);
return true;
} else {
ZVAL_NULL(val);
return false;
}
}
// -----------------------------------------------------------------------------
// Name Cache.
// -----------------------------------------------------------------------------
void NameMap_AddMessage(const upb_msgdef *m) {
char *k = GetPhpClassname(upb_msgdef_file(m), upb_msgdef_fullname(m));
zend_hash_str_add_ptr(&PROTOBUF_G(name_msg_cache), k, strlen(k), (void*)m);
free(k);
}
void NameMap_AddEnum(const upb_enumdef *e) {
char *k = GetPhpClassname(upb_enumdef_file(e), upb_enumdef_fullname(e));
zend_hash_str_add_ptr(&PROTOBUF_G(name_enum_cache), k, strlen(k), (void*)e);
free(k);
}
const upb_msgdef *NameMap_GetMessage(zend_class_entry *ce) {
const upb_msgdef *ret =
zend_hash_find_ptr(&PROTOBUF_G(name_msg_cache), ce->name);
if (!ret && ce->create_object) {
zval tmp;
zval zv;
ZVAL_OBJ(&tmp, ce->create_object(ce));
zend_call_method_with_0_params(&tmp, ce, NULL, "__construct", &zv);
zval_ptr_dtor(&tmp);
zval_ptr_dtor(&zv);
ret = zend_hash_find_ptr(&PROTOBUF_G(name_msg_cache), ce->name);
}
return ret;
}
const upb_enumdef *NameMap_GetEnum(zend_class_entry *ce) {
const upb_enumdef *ret =
zend_hash_find_ptr(&PROTOBUF_G(name_enum_cache), ce->name);
return ret;
}
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
zend_function_entry protobuf_functions[] = {
PHP_FE(protobuf_internal_loadbundled, arginfo_load_bundled_source)
ZEND_FE_END
};
static const zend_module_dep protobuf_deps[] = {
ZEND_MOD_OPTIONAL("date")
ZEND_MOD_END
};
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("protobuf.keep_descriptor_pool_after_request", "0",
PHP_INI_SYSTEM, OnUpdateBool,
keep_descriptor_pool_after_request, zend_protobuf_globals,
protobuf_globals)
PHP_INI_END()
static PHP_MINIT_FUNCTION(protobuf) {
REGISTER_INI_ENTRIES();
Arena_ModuleInit();
Array_ModuleInit();
Convert_ModuleInit();
Def_ModuleInit();
Map_ModuleInit();
Message_ModuleInit();
return SUCCESS;
}
static PHP_MSHUTDOWN_FUNCTION(protobuf) {
return SUCCESS;
}
zend_module_entry protobuf_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
protobuf_deps,
"protobuf", // extension name
protobuf_functions, // function list
PHP_MINIT(protobuf), // process startup
PHP_MSHUTDOWN(protobuf), // process shutdown
PHP_RINIT(protobuf), // request shutdown
PHP_RSHUTDOWN(protobuf), // request shutdown
NULL, // extension info
"3.13.0", // extension version
PHP_MODULE_GLOBALS(protobuf), // globals descriptor
PHP_GINIT(protobuf), // globals ctor
PHP_GSHUTDOWN(protobuf), // globals dtor
NULL, // post deactivate
STANDARD_MODULE_PROPERTIES_EX
};
ZEND_GET_MODULE(protobuf)

@ -1,89 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_H_
#define PHP_PROTOBUF_H_
#include <php.h>
#include <stdbool.h>
#include "php-upb.h"
const zval *get_generated_pool();
#if PHP_VERSION_ID < 70300
#define GC_ADDREF(h) ++GC_REFCOUNT(h)
#define GC_DELREF(h) --GC_REFCOUNT(h)
#endif
// ptr -> PHP object cache. This is a weak map that caches lazily-created
// wrapper objects around upb types:
// * upb_msg* -> Message
// * upb_array* -> RepeatedField
// * upb_map*, -> MapField
// * upb_msgdef* -> Descriptor
// * upb_enumdef* -> EnumDescriptor
// * zend_class_entry* -> Descriptor
//
// Each wrapped object should add itself to the map when it is constructed, and
// remove itself from the map when it is destroyed. This is how we ensure that
// the map only contains live objects. The map is weak so it does not actually
// take references to the cached objects.
void ObjCache_Add(const void *key, zend_object *php_obj);
void ObjCache_Delete(const void *key);
bool ObjCache_Get(const void *key, zval *val);
// PHP class name map. This is necessary because the pb_name->php_class_name
// transformation is non-reversible, so when we need to look up a msgdef or
// enumdef by PHP class, we can't turn the class name into a pb_name.
// * php_class_name -> upb_msgdef*
// * php_class_name -> upb_enumdef*
void NameMap_AddMessage(const upb_msgdef *m);
void NameMap_AddEnum(const upb_enumdef *m);
const upb_msgdef *NameMap_GetMessage(zend_class_entry *ce);
const upb_enumdef *NameMap_GetEnum(zend_class_entry *ce);
// We need our own assert() because PHP takes control of NDEBUG in its headers.
#ifdef PBPHP_ENABLE_ASSERTS
#define PBPHP_ASSERT(x) \
do { \
if (!(x)) { \
fprintf(stderr, "Assertion failure at %s:%d %s", __FILE__, __LINE__, \
#x); \
abort(); \
} \
} while (false)
#else
#define PBPHP_ASSERT(x) \
do { \
} while (false && (x))
#endif
#endif // PHP_PROTOBUF_H_

@ -185,8 +185,8 @@ class Descriptor
$containing,
$file_proto,
$message_name_without_package,
$legacy_classname,
$classname,
$legacy_classname,
$fullname);
$desc->setFullName($fullname);
$desc->setClass($classname);

@ -252,7 +252,7 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
*/
public function setLabel($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Label::class);
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto\Label::class);
$this->label = $var;
$this->has_label = true;
@ -286,7 +286,7 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
*/
public function setType($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Type::class);
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto\Type::class);
$this->type = $var;
$this->has_type = true;

@ -202,7 +202,7 @@ class FieldOptions extends \Google\Protobuf\Internal\Message
*/
public function setCtype($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_CType::class);
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions\CType::class);
$this->ctype = $var;
$this->has_ctype = true;
@ -292,7 +292,7 @@ class FieldOptions extends \Google\Protobuf\Internal\Message
*/
public function setJstype($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_JSType::class);
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions\JSType::class);
$this->jstype = $var;
$this->has_jstype = true;

@ -506,7 +506,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message
*/
public function setOptimizeFor($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FileOptions_OptimizeMode::class);
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FileOptions\OptimizeMode::class);
$this->optimize_for = $var;
$this->has_optimize_for = true;

@ -113,7 +113,7 @@ class MethodOptions extends \Google\Protobuf\Internal\Message
*/
public function setIdempotencyLevel($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class);
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\MethodOptions\IdempotencyLevel::class);
$this->idempotency_level = $var;
$this->has_idempotency_level = true;

@ -12,18 +12,9 @@ else
CFLAGS="-g -O0 -Wall"
fi
pushd ../ext/google/protobuf
phpize --clean
rm -f configure.in configure.ac
php make-preload.php
phpize && ./configure --with-php-config=$(which php-config) CFLAGS="$CFLAGS" && make
popd
if [ $(php -r "echo PHP_VERSION;" | cut -c1) != "5" ]; then
pushd ../ext/google/protobuf2
phpize --clean
rm -f configure.in configure.ac
php make-preload.php
phpize && ./configure --with-php-config=$(which php-config) CFLAGS="$CFLAGS" && make
popd
fi

@ -538,7 +538,7 @@ class ImplementationTest extends TestBase
/**
* @expectedException Exception
* @expectedExceptionMessage Expect Foo\TestMessage_Sub.
* @expectedExceptionMessage Expect Foo\TestMessage\Sub.
*/
public function testArraysForMessagesThrowsException()
{

@ -8,14 +8,9 @@ cd $(dirname $0)
./compile_extension.sh
PHP_VERSION=$(php -r "echo PHP_VERSION;")
TEST_NEW_EXTENSION=true
# Each version of PHPUnit supports a fairly narrow range of PHP versions.
case "$PHP_VERSION" in
5.*.*)
PHPUNIT=phpunit-5.6.8.phar
TEST_NEW_EXTENSION=false
;;
7.0.*|7.1.*|7.2.*)
# Oddly older than for 5.6. Not sure the reason.
PHPUNIT=phpunit-5.6.0.phar
@ -24,7 +19,7 @@ case "$PHP_VERSION" in
PHPUNIT=phpunit-8.phar
;;
*)
echo "ERROR: Unknown PHP version $PHP_VERSION"
echo "ERROR: Unsupported PHP version $PHP_VERSION"
exit 1
;;
esac
@ -39,9 +34,6 @@ do
echo "* $t"
echo "****************************"
php -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
if [ "$TEST_NEW_EXTENSION" = "true" ]; then
php -dextension=../ext/google/protobuf2/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
fi
echo ""
done
@ -51,9 +43,6 @@ do
echo "* $t persistent"
echo "****************************"
php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
if [ "$TEST_NEW_EXTENSION" = "true" ]; then
php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf2/modules/protobuf.so $PHPUNIT --bootstrap autoload.php $t
fi
echo ""
done
@ -64,10 +53,6 @@ export ZEND_DONT_UNLOAD_MODULES=1
export USE_ZEND_ALLOC=0
valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
valgrind --leak-check=yes php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
if [ "$TEST_NEW_EXTENSION" = "true" ]; then
valgrind --leak-check=yes php -dextension=../ext/google/protobuf2/modules/protobuf.so memory_leak_test.php
valgrind --leak-check=yes php -d protobuf.keep_descriptor_pool_after_request=1 -dextension=../ext/google/protobuf2/modules/protobuf.so memory_leak_test.php
fi
# TODO(teboring): Only for debug (phpunit has memory leak which blocks this beging used by
# regresssion test.)

@ -30,7 +30,7 @@
# Copyright 2007 Google Inc. All Rights Reserved.
__version__ = '3.12.2'
__version__ = '3.12.3'
if __name__ != '__main__':
try:

@ -18,7 +18,7 @@ else
PTHREAD_DEF =
endif
PROTOBUF_VERSION = 23:2:0
PROTOBUF_VERSION = 23:3:0
if GCC
# Turn on all warnings except for sign comparison (we ignore sign comparison

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -1274,13 +1274,17 @@ bool CommandLineInterface::MakeProtoProtoPathRelative(
"comes first."
<< std::endl;
return false;
case DiskSourceTree::CANNOT_OPEN:
case DiskSourceTree::CANNOT_OPEN: {
if (in_fallback_database) {
return true;
}
std::string error_str = source_tree->GetLastErrorMessage().empty()
? strerror(errno)
: source_tree->GetLastErrorMessage();
std::cerr << "Could not map to virtual file: " << *proto << ": "
<< strerror(errno) << std::endl;
<< error_str << std::endl;
return false;
}
case DiskSourceTree::NO_MAPPING: {
// Try to interpret the path as a virtual path.
std::string disk_file;

@ -490,6 +490,15 @@ io::ZeroCopyInputStream* DiskSourceTree::OpenVirtualFile(
io::ZeroCopyInputStream* DiskSourceTree::OpenDiskFile(
const std::string& filename) {
struct stat sb;
int ret = 0;
do {
ret = stat(filename.c_str(), &sb);
} while (ret != 0 && errno == EINTR);
if (sb.st_mode & S_IFDIR) {
last_error_message_ = "Input file is a directory.";
return NULL;
}
int file_descriptor;
do {
file_descriptor = open(filename.c_str(), O_RDONLY);

@ -467,6 +467,7 @@ bool IgnoreMessage(const Descriptor* d) { return d->options().map_entry(); }
// Does JSPB ignore this entire oneof? True only if all fields are ignored.
bool IgnoreOneof(const OneofDescriptor* oneof) {
if (oneof->is_synthetic()) return true;
for (int i = 0; i < oneof->field_count(); i++) {
if (!IgnoreField(oneof->field(i))) {
return false;
@ -576,6 +577,7 @@ std::string JSOneofIndex(const OneofDescriptor* oneof) {
int index = -1;
for (int i = 0; i < oneof->containing_type()->oneof_decl_count(); i++) {
const OneofDescriptor* o = oneof->containing_type()->oneof_decl(i);
if (o->is_synthetic()) continue;
// If at least one field in this oneof is not JSPB-ignored, count the oneof.
for (int j = 0; j < o->field_count(); j++) {
const FieldDescriptor* f = o->field(j);
@ -794,6 +796,11 @@ std::string DoubleToString(double value) {
return PostProcessFloat(result);
}
bool InRealOneof(const FieldDescriptor* field) {
return field->containing_oneof() &&
!field->containing_oneof()->is_synthetic();
}
// Return true if this is an integral field that should be represented as string
// in JS.
bool IsIntegralFieldWithStringJSType(const FieldDescriptor* field) {
@ -1173,7 +1180,7 @@ std::string RepeatedFieldsArrayName(const GeneratorOptions& options,
bool HasOneofFields(const Descriptor* desc) {
for (int i = 0; i < desc->field_count(); i++) {
if (desc->field(i)->containing_oneof()) {
if (InRealOneof(desc->field(i))) {
return true;
}
}
@ -1411,15 +1418,9 @@ std::string GetPivot(const Descriptor* desc) {
// generate extra methods (clearFoo() and hasFoo()) for this field.
bool HasFieldPresence(const GeneratorOptions& options,
const FieldDescriptor* field) {
if (field->is_repeated() || field->is_map()) {
// We say repeated fields and maps don't have presence, but we still do
// generate clearFoo() methods for them through a special case elsewhere.
return false;
}
return field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ||
field->containing_oneof() != NULL ||
field->file()->syntax() == FileDescriptor::SYNTAX_PROTO2;
// This returns false for repeated fields and maps, but we still do
// generate clearFoo() methods for these through a special case elsewhere.
return field->has_presence();
}
// We use this to implement the semantics that same file can be generated
@ -2676,7 +2677,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
/* singular_if_not_packed = */ false),
"class", GetMessagePath(options, field->containing_type()),
"settername", "set" + JSGetterName(options, field), "oneoftag",
(field->containing_oneof() ? "Oneof" : ""), "repeatedtag",
(InRealOneof(field) ? "Oneof" : ""), "repeatedtag",
(field->is_repeated() ? "Repeated" : ""));
printer->Annotate("settername", field);
@ -2686,8 +2687,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
"\n"
"\n",
"index", JSFieldIndex(field), "oneofgroup",
(field->containing_oneof() ? (", " + JSOneofArray(options, field))
: ""));
(InRealOneof(field) ? (", " + JSOneofArray(options, field)) : ""));
if (field->is_repeated()) {
GenerateRepeatedMessageHelperMethods(options, printer, field);
@ -2811,8 +2811,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
" return jspb.Message.set$oneoftag$Field(this, $index$",
"class", GetMessagePath(options, field->containing_type()),
"settername", "set" + JSGetterName(options, field), "oneoftag",
(field->containing_oneof() ? "Oneof" : ""), "index",
JSFieldIndex(field));
(InRealOneof(field) ? "Oneof" : ""), "index", JSFieldIndex(field));
printer->Annotate("settername", field);
printer->Print(
"$oneofgroup$, $type$value$rptvalueinit$$typeclose$);\n"
@ -2822,8 +2821,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
"type",
untyped ? "/** @type{string|number|boolean|Array|undefined} */(" : "",
"typeclose", untyped ? ")" : "", "oneofgroup",
(field->containing_oneof() ? (", " + JSOneofArray(options, field))
: ""),
(InRealOneof(field) ? (", " + JSOneofArray(options, field)) : ""),
"rptvalueinit", (field->is_repeated() ? " || []" : ""));
}
@ -2899,8 +2897,8 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
"$index$$maybeoneofgroup$, ",
"class", GetMessagePath(options, field->containing_type()),
"clearername", "clear" + JSGetterName(options, field),
"maybeoneof", (field->containing_oneof() ? "Oneof" : ""),
"maybeoneofgroup", (field->containing_oneof()
"maybeoneof", (InRealOneof(field) ? "Oneof" : ""),
"maybeoneofgroup", (InRealOneof(field)
? (", " + JSOneofArray(options, field))
: ""),
"index", JSFieldIndex(field));
@ -2965,7 +2963,7 @@ void Generator::GenerateRepeatedPrimitiveHelperMethods(
"\n",
"type", untyped ? "/** @type{string|number|boolean|!Uint8Array} */(" : "",
"typeclose", untyped ? ")" : "", "oneofgroup",
(field->containing_oneof() ? (", " + JSOneofArray(options, field)) : ""),
(InRealOneof(field) ? (", " + JSOneofArray(options, field)) : ""),
"rptvalueinit", "");
// clang-format on
}
@ -2994,8 +2992,8 @@ void Generator::GenerateRepeatedMessageHelperMethods(
"\n"
"\n",
"index", JSFieldIndex(field), "oneofgroup",
(field->containing_oneof() ? (", " + JSOneofArray(options, field)) : ""),
"ctor", GetMessagePath(options, field->message_type()));
(InRealOneof(field) ? (", " + JSOneofArray(options, field)) : ""), "ctor",
GetMessagePath(options, field->message_type()));
}
void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,

@ -142,18 +142,21 @@ class PROTOC_EXPORT Generator : public CodeGenerator {
Generator() {}
virtual ~Generator() {}
virtual bool Generate(const FileDescriptor* file,
const std::string& parameter, GeneratorContext* context,
std::string* error) const {
bool Generate(const FileDescriptor* file, const std::string& parameter,
GeneratorContext* context, std::string* error) const override {
*error = "Unimplemented Generate() method. Call GenerateAll() instead.";
return false;
}
virtual bool HasGenerateAll() const { return true; }
bool HasGenerateAll() const override { return true; }
virtual bool GenerateAll(const std::vector<const FileDescriptor*>& files,
const std::string& parameter,
GeneratorContext* context, std::string* error) const;
bool GenerateAll(const std::vector<const FileDescriptor*>& files,
const std::string& parameter, GeneratorContext* context,
std::string* error) const override;
uint64 GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
}
private:
void GenerateHeader(const GeneratorOptions& options,

@ -119,7 +119,7 @@ std::string ReservedNamePrefix(const string& classname,
bool is_reserved = false;
string lower = classname;
transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
for (int i = 0; i < kReservedNamesSize; i++) {
if (lower == kReservedNames[i]) {
@ -203,7 +203,7 @@ std::string LegacyGeneratedClassName(const DescriptorType* desc) {
std::string ClassNamePrefix(const string& classname) {
string lower = classname;
transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
for (int i = 0; i < kReservedNamesSize; i++) {
if (lower == kReservedNames[i]) {
@ -218,7 +218,7 @@ std::string ConstantNamePrefix(const string& classname) {
bool is_reserved = false;
string lower = classname;
transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
for (int i = 0; i < kReservedNamesSize; i++) {
if (lower == kReservedNames[i]) {
@ -744,11 +744,11 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
printer->Print(
"GPBUtil::checkMessage($var, \\^class_name^::class);\n",
"class_name", LegacyFullClassName(field->message_type(), is_descriptor));
"class_name", FullClassName(field->message_type(), is_descriptor));
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
printer->Print(
"GPBUtil::checkEnum($var, \\^class_name^::class);\n",
"class_name", LegacyFullClassName(field->enum_type(), is_descriptor));
"class_name", FullClassName(field->enum_type(), is_descriptor));
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) {
printer->Print(
"GPBUtil::checkString($var, ^utf8^);\n",
@ -1754,7 +1754,7 @@ void GenerateWrapperFieldSetterDocComment(io::Printer* printer, const FieldDescr
printer->Print("/**\n");
printer->Print(
" * Sets the field by wrapping a primitive type in a ^message_name^ object.\n\n",
"message_name", LegacyFullClassName(field->message_type(), false));
"message_name", FullClassName(field->message_type(), false));
GenerateDocCommentBody(printer, field);
printer->Print(
" * Generated from protobuf field <code>^def^</code>\n",

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -184,7 +184,7 @@ void PrintTopBoilerplate(io::Printer* printer, const FileDescriptor* file,
"# -*- coding: utf-8 -*-\n"
"# Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"# source: $filename$\n"
"\n",
"\"\"\"Generated protocol buffer code.\"\"\"\n",
"filename", file->name());
if (HasTopLevelEnums(file)) {
printer->Print(

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -2044,10 +2044,8 @@ void Reflection::SetBit(Message* message, const FieldDescriptor* field) const {
void Reflection::ClearBit(Message* message,
const FieldDescriptor* field) const {
GOOGLE_DCHECK(!field->options().weak());
if (!schema_.HasHasbits()) {
return;
}
const uint32 index = schema_.HasBitIndex(field);
if (index == -1) return;
MutableHasBits(message)[index / 32] &=
~(static_cast<uint32>(1) << (index % 32));
}

@ -65,7 +65,7 @@ void DestroyMessage(const void* message) {
static_cast<const MessageLite*>(message)->~MessageLite();
}
void DestroyString(const void* s) {
static_cast<const std::string*>(s)->~string();
static_cast<const std::string*>(s)->~basic_string();
}
ExplicitlyConstructed<std::string> fixed_address_empty_string;

@ -300,7 +300,7 @@
// Shared google3/opensource definitions. //////////////////////////////////////
#define PROTOBUF_VERSION 3012002
#define PROTOBUF_VERSION 3012003
#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3012000
#define PROTOBUF_MIN_PROTOC_VERSION 3012000
#define PROTOBUF_VERSION_SUFFIX ""
@ -356,8 +356,8 @@
#endif
#if defined(PROTOBUF_USE_DLLS)
#if defined(_MSC_VER)
#ifdef LIBPROTOBUF_EXPORTS
#if defined(_MSC_VER)
#ifdef LIBPROTOBUF_EXPORTS
#define PROTOBUF_EXPORT __declspec(dllexport)
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
@ -388,8 +388,8 @@
#endif
#endif
#else // defined(PROTOBUF_USE_DLLS)
#define PROTOBUF_EXPORT
#define PROTOC_EXPORT
#define PROTOBUF_EXPORT
#define PROTOC_EXPORT
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#endif

@ -293,6 +293,47 @@ TEST(Proto3OptionalTest, OptionalFieldReflection) {
EXPECT_TRUE(r->GetOneofFieldDescriptor(msg, o) == nullptr);
}
// It's a regression test for b/160665543.
TEST(Proto3OptionalTest, ClearNonOptionalMessageField) {
protobuf_unittest::TestProto3OptionalMessage msg;
msg.mutable_nested_message();
const google::protobuf::Descriptor* d = msg.GetDescriptor();
const google::protobuf::Reflection* r = msg.GetReflection();
const google::protobuf::FieldDescriptor* f = d->FindFieldByName("nested_message");
r->ClearField(&msg, f);
}
TEST(Proto3OptionalTest, ClearOptionalMessageField) {
protobuf_unittest::TestProto3OptionalMessage msg;
msg.mutable_optional_nested_message();
const google::protobuf::Descriptor* d = msg.GetDescriptor();
const google::protobuf::Reflection* r = msg.GetReflection();
const google::protobuf::FieldDescriptor* f =
d->FindFieldByName("optional_nested_message");
r->ClearField(&msg, f);
}
TEST(Proto3OptionalTest, SwapNonOptionalMessageField) {
protobuf_unittest::TestProto3OptionalMessage msg1;
protobuf_unittest::TestProto3OptionalMessage msg2;
msg1.mutable_nested_message();
const google::protobuf::Descriptor* d = msg1.GetDescriptor();
const google::protobuf::Reflection* r = msg1.GetReflection();
const google::protobuf::FieldDescriptor* f = d->FindFieldByName("nested_message");
r->SwapFields(&msg1, &msg2, {f});
}
TEST(Proto3OptionalTest, SwapOptionalMessageField) {
protobuf_unittest::TestProto3OptionalMessage msg1;
protobuf_unittest::TestProto3OptionalMessage msg2;
msg1.mutable_optional_nested_message();
const google::protobuf::Descriptor* d = msg1.GetDescriptor();
const google::protobuf::Reflection* r = msg1.GetReflection();
const google::protobuf::FieldDescriptor* f =
d->FindFieldByName("optional_nested_message");
r->SwapFields(&msg1, &msg2, {f});
}
void SetAllFieldsZero(protobuf_unittest::TestProto3Optional* msg) {
msg->set_optional_int32(0);
msg->set_optional_int64(0);

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -82,7 +82,7 @@ namespace internal {
// The current version, represented as a single integer to make comparison
// easier: major * 10^6 + minor * 10^3 + micro
#define GOOGLE_PROTOBUF_VERSION 3012002
#define GOOGLE_PROTOBUF_VERSION 3012003
// A suffix string for alpha, beta or rc releases. Empty for stable releases.
#define GOOGLE_PROTOBUF_VERSION_SUFFIX ""

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

@ -77,3 +77,12 @@ message TestProto3Optional {
int32 singular_int32 = 22;
int64 singular_int64 = 23;
}
message TestProto3OptionalMessage {
message NestedMessage {
string s = 1;
}
NestedMessage nested_message = 1;
optional NestedMessage optional_nested_message = 2;
}

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3012002 < PROTOBUF_MIN_PROTOC_VERSION
#if 3012003 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.

Loading…
Cancel
Save