diff --git a/.github/mergeable.yml b/.github/mergeable.yml deleted file mode 100644 index 17688527de..0000000000 --- a/.github/mergeable.yml +++ /dev/null @@ -1,18 +0,0 @@ -mergeable: - pull_requests: - label: - and: - - must_exclude: - regex: '^disposition/DO NOT MERGE' - message: 'Pull request marked not mergeable' - - or: - - and: - - must_include: - regex: 'release notes: yes' - message: 'Include release notes: yes' - - must_include: - regex: '^(autotools|bazel|c#|c\+\+|cleanup|cmake|conformance tests|integration|go|java|javascript|objective-c|php|protoc|python|ruby|kotlin)' - message: 'at least a language label (e.g., c++, java, python). Or apply one of the following labels: autotools, bazel, cmake, cleanup, conformance tests, integration, protoc.' - - must_include: - regex: 'release notes: no' - message: 'Include release notes: no' diff --git a/.github/workflows/generated_cmake.yml b/.github/workflows/generate_files.yml similarity index 76% rename from .github/workflows/generated_cmake.yml rename to .github/workflows/generate_files.yml index 640bd137ec..c1562b3918 100644 --- a/.github/workflows/generated_cmake.yml +++ b/.github/workflows/generate_files.yml @@ -1,12 +1,12 @@ -name: Generate CMake File Lists +name: Auto-generate checked-in files on: push: branches: - main - '[0-9]+.x' - # The 21.x branch predates support for auto-generation of the CMake file - # lists, so we make sure to exclude it. + # The 21.x branch predates support for auto-generation, so we make sure + # to exclude it. - '!21.x' jobs: @@ -26,4 +26,4 @@ jobs: - name: Configure name and email address in Git run: cd ${{ github.workspace }} && git config user.name "Protobuf Team Bot" && git config user.email "protobuf-team-bot@google.com" - name: Commit and push update - run: cd ${{ github.workspace }} && ./cmake/push_auto_update.sh + run: cd ${{ github.workspace }} && ./push_auto_update.sh diff --git a/.github/workflows/php-ext.yml b/.github/workflows/php-ext.yml index f24f6bf62b..17b6adf9d5 100644 --- a/.github/workflows/php-ext.yml +++ b/.github/workflows/php-ext.yml @@ -15,28 +15,32 @@ jobs: - php:7.4-cli - php:8.1-cli steps: - - name: Install git + - name: Install python3 run: | apt-get update -q + apt-get install -qy python3 + - name: Install bazel + run: | + apt-get install -qy wget + mkdir $HOME/bin + wget -O $HOME/bin/bazel https://github.com/bazelbuild/bazel/releases/download/5.3.2/bazel-5.3.2-linux-x86_64 + chmod a+x $HOME/bin/bazel + - name: Install git + run: | apt-get install -qy --no-install-recommends git - name: Checkout uses: actions/checkout@v3 with: submodules: recursive - - name: Prepare source code - run: | - rm -rf "$GITHUB_WORKSPACE/php/ext/google/protobuf/third_party" - cp -r "$GITHUB_WORKSPACE/third_party" "$GITHUB_WORKSPACE/php/ext/google/protobuf" - cp "$GITHUB_WORKSPACE/LICENSE" "$GITHUB_WORKSPACE/php/ext/google/protobuf" - name: Create package run: | - cd /tmp - rm -rf protobuf-*.tgz - pecl package "$GITHUB_WORKSPACE/php/ext/google/protobuf/package.xml" + cd $GITHUB_WORKSPACE + rm -rf bazel-bin/php/protobuf-*.tgz + $HOME/bin/bazel build php:release - name: Compile extension run: | cd /tmp - MAKE="make -j$(nproc)" pecl install protobuf-*.tgz + MAKE="make -j$(nproc)" pecl install $GITHUB_WORKSPACE/bazel-bin/php/protobuf-*.tgz - name: Enable extension run: docker-php-ext-enable protobuf - name: Inspect extension diff --git a/BUILD.bazel b/BUILD.bazel index b980d990e8..c9b247255d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -551,7 +551,6 @@ pkg_files( "WORKSPACE", "cmake/CMakeLists.txt", "cmake/README.md", - "cmake/update_file_lists.sh", "generate_descriptor_proto.sh", "maven_install.json", "//third_party:BUILD.bazel", diff --git a/CMakeLists.txt b/CMakeLists.txt index d490527747..cab1ff68e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,11 +61,6 @@ else() set(CMAKE_CXX_EXTENSIONS OFF) endif() -# For -fvisibility=hidden and -fvisibility-inlines-hidden -set(CMAKE_C_VISIBILITY_PRESET hidden) -set(CMAKE_CXX_VISIBILITY_PRESET hidden) -set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) - # The Intel compiler isn't able to deal with noinline member functions of # template classes defined in headers. As such it spams the output with # warning #2196: routine is both "inline" and "noinline" @@ -107,6 +102,20 @@ include(${protobuf_SOURCE_DIR}/cmake/protobuf-options.cmake) if (protobuf_BUILD_SHARED_LIBS) # This is necessary for linking in Abseil. set(CMAKE_POSITION_INDEPENDENT_CODE ON) + + # Build Abseil as shared libraries to avoid ODR violations. + set(BUILD_SHARED_LIBS ON) + + # Output directory is correct by default for most build setups. However, when + # building Protobuf as a DLL, it is important to have the DLL in the same + # directory as the executable using it. Thus, we put all binaries in a single + # /bin directory. + if (MSVC) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + endif () endif () # Version metadata diff --git a/cmake/abseil-cpp.cmake b/cmake/abseil-cpp.cmake index c1c4c16279..523517cdc4 100644 --- a/cmake/abseil-cpp.cmake +++ b/cmake/abseil-cpp.cmake @@ -29,30 +29,42 @@ elseif(protobuf_ABSL_PROVIDER STREQUAL "package") endif() set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n find_package(absl CONFIG)\nendif()") -set(protobuf_ABSL_USED_TARGETS - absl::algorithm - absl::base - absl::bind_front - absl::bits - absl::cleanup - absl::cord - absl::core_headers - absl::debugging - absl::dynamic_annotations - absl::flags - absl::flat_hash_map - absl::flat_hash_set - absl::function_ref - absl::hash - absl::layout - absl::memory - absl::optional - absl::span - absl::status - absl::statusor - absl::strings - absl::synchronization - absl::time - absl::utility - absl::variant -) +if (BUILD_SHARED_LIBS AND MSVC) + # On MSVC Abseil is bundled into a single DLL. + set(protobuf_ABSL_USED_TARGETS abseil_dll) + + # As a workaround for https://github.com/abseil/abseil-cpp/issues/1118, + # make sure ABSL_CONSUME_DLL gets set for all subsequent builds. + add_definitions(-DABSL_CONSUME_DLL) +else() + set(protobuf_ABSL_USED_TARGETS + absl::algorithm + absl::base + absl::bind_front + absl::bits + absl::btree + absl::cleanup + absl::cord + absl::core_headers + absl::debugging + absl::dynamic_annotations + absl::flags + absl::flat_hash_map + absl::flat_hash_set + absl::function_ref + absl::hash + absl::layout + absl::memory + absl::node_hash_map + absl::node_hash_set + absl::optional + absl::span + absl::status + absl::statusor + absl::strings + absl::synchronization + absl::time + absl::utility + absl::variant + ) +endif () \ No newline at end of file diff --git a/cmake/conformance.cmake b/cmake/conformance.cmake index 801d7228ff..61ac25a0de 100644 --- a/cmake/conformance.cmake +++ b/cmake/conformance.cmake @@ -76,7 +76,7 @@ target_link_libraries(conformance_cpp ${protobuf_LIB_PROTOBUF}) target_link_libraries(conformance_cpp ${protobuf_ABSL_USED_TARGETS}) add_test(NAME conformance_cpp_test - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/conformance_test_runner + COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/conformance_test_runner --failure_list ${protobuf_SOURCE_DIR}/conformance/failure_list_cpp.txt --text_format_failure_list ${protobuf_SOURCE_DIR}/conformance/text_format_failure_list_cpp.txt --output_dir ${protobuf_TEST_XML_OUTDIR} diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index c0c331a191..9a82d92799 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -32,7 +32,12 @@ endif() set_target_properties(libprotobuf-lite PROPERTIES VERSION ${protobuf_VERSION} OUTPUT_NAME ${LIB_PREFIX}protobuf-lite - DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") + DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}" + # For -fvisibility=hidden and -fvisibility-inlines-hidden + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON +) add_library(protobuf::libprotobuf-lite ALIAS libprotobuf-lite) target_include_directories(libprotobuf-lite PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/utf8_range) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 3f21de5ea7..23528427b9 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -35,7 +35,12 @@ endif() set_target_properties(libprotobuf PROPERTIES VERSION ${protobuf_VERSION} OUTPUT_NAME ${LIB_PREFIX}protobuf - DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") + DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}" + # For -fvisibility=hidden and -fvisibility-inlines-hidden + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON +) add_library(protobuf::libprotobuf ALIAS libprotobuf) target_include_directories(libprotobuf PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/utf8_range) diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 3be0df379e..02667c56f5 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -26,5 +26,10 @@ set_target_properties(libprotoc PROPERTIES COMPILE_DEFINITIONS LIBPROTOC_EXPORTS VERSION ${protobuf_VERSION} OUTPUT_NAME ${LIB_PREFIX}protoc - DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") + DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}" + # For -fvisibility=hidden and -fvisibility-inlines-hidden + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON +) add_library(protobuf::libprotoc ALIAS libprotoc) diff --git a/cmake/push_auto_update.sh b/cmake/push_auto_update.sh deleted file mode 100755 index abae4f4c0c..0000000000 --- a/cmake/push_auto_update.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -# This script updates the CMake file lists (i.e. src/file_lists.cmake), commits -# the resulting change, and pushes it. This does not do anything useful when -# run manually, but should be run by our GitHub action instead. - -set -ex - -# Exit early if the previous commit was made by the bot. This reduces the risk -# of a bug causing an infinite loop of auto-generated commits. -if (git log -1 --pretty=format:'%an' | grep -q "Protobuf Team Bot"); then - echo "Previous commit was authored by bot" - exit 0 -fi - -$(dirname -- "$0")/update_file_lists.sh - -# Try to determine the most recent pull request number. -title=$(git log -1 --pretty='%s') -pr_from_merge=$(echo "$title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p') -pr_from_squash=$(echo "$title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p') - -pr="" -if [ ! -z "$pr_from_merge" ]; then - pr="$pr_from_merge" -elif [ ! -z "$pr_from_squash" ]; then - pr="$pr_from_squash" -fi - -if [ ! -z "$pr" ]; then - commit_message="Auto-generate CMake file lists after PR #$pr" -else - # If we are unable to determine the pull request number, we fall back on this - # default commit message. Typically this should not occur, but could happen - # if a pull request was merged via a rebase. - commit_message="Auto-generate CMake file lists" -fi - -git add -A -git diff --staged --quiet || git commit -am "$commit_message" -git push diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 530a66ba8b..d3a0517927 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -50,6 +50,7 @@ set(tests_protos ${protobuf_test_protos_files} ${compiler_test_protos_files} ${util_test_protos_files} + ${lite_test_protos} ) macro(compile_proto_file filename) @@ -77,25 +78,14 @@ foreach(proto_file ${tests_protos}) set(tests_proto_files ${tests_proto_files} ${pb_src} ${pb_hdr}) endforeach(proto_file) -add_library(protobuf-lite-test-common STATIC - ${lite_test_util_srcs} ${lite_test_proto_files}) -target_include_directories(protobuf-lite-test-common PRIVATE ${ABSL_ROOT_DIR}) -target_link_libraries(protobuf-lite-test-common - ${protobuf_LIB_PROTOBUF_LITE} ${protobuf_ABSL_USED_TARGETS} GTest::gmock) - set(common_test_files ${test_util_hdrs} + ${lite_test_util_srcs} ${test_util_srcs} ${common_test_hdrs} ${common_test_srcs} ) -add_library(protobuf-test-common STATIC - ${common_test_files} ${tests_proto_files}) -target_include_directories(protobuf-test-common PRIVATE ${ABSL_ROOT_DIR}) -target_link_libraries(protobuf-test-common - ${protobuf_LIB_PROTOBUF} ${protobuf_ABSL_USED_TARGETS} GTest::gmock) - set(tests_files ${protobuf_test_files} ${compiler_test_files} @@ -129,13 +119,22 @@ else() set(protobuf_GTEST_ARGS) endif() -add_executable(tests ${tests_files}) +add_executable(tests + ${tests_files} + ${common_test_files} + ${tests_proto_files} +) if (MSVC) target_compile_options(tests PRIVATE /wd4146 # unary minus operator applied to unsigned type, result still unsigned ) endif() -target_link_libraries(tests protobuf-lite-test-common protobuf-test-common ${protobuf_LIB_PROTOC} ${protobuf_LIB_PROTOBUF} GTest::gmock_main) +target_link_libraries(tests + ${protobuf_LIB_PROTOC} + ${protobuf_LIB_PROTOBUF} + ${protobuf_ABSL_USED_TARGETS} + GTest::gmock_main +) set(test_plugin_files ${test_plugin_files} @@ -152,8 +151,16 @@ target_link_libraries(test_plugin GTest::gmock ) -add_executable(lite-test ${protobuf_lite_test_files}) -target_link_libraries(lite-test protobuf-lite-test-common ${protobuf_LIB_PROTOBUF_LITE} GTest::gmock_main) +add_executable(lite-test + ${protobuf_lite_test_files} + ${lite_test_util_srcs} + ${lite_test_proto_files} +) +target_link_libraries(lite-test + ${protobuf_LIB_PROTOBUF_LITE} + ${protobuf_ABSL_USED_TARGETS} + GTest::gmock_main +) add_test(NAME lite-test COMMAND lite-test ${protobuf_GTEST_ARGS}) diff --git a/cmake/update_file_lists.sh b/cmake/update_file_lists.sh deleted file mode 100755 index a08bdf3138..0000000000 --- a/cmake/update_file_lists.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -u - -# This script generates file lists from Bazel for CMake. - -set -e - -bazel build //pkg:gen_src_file_lists -cp -v bazel-bin/pkg/src_file_lists.cmake src/file_lists.cmake diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 7c30b83b76..6951cca0a8 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -31,7 +31,6 @@ #include "binary_json_conformance_suite.h" #include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format_lite.h" #include "google/protobuf/util/json_util.h" #include "google/protobuf/util/type_resolver_util.h" #include "absl/status/status.h" @@ -41,6 +40,7 @@ #include "conformance_test.h" #include "google/protobuf/test_messages_proto2.pb.h" #include "google/protobuf/test_messages_proto3.pb.h" +#include "google/protobuf/wire_format_lite.h" namespace proto2_messages = protobuf_test_messages::proto2; diff --git a/conformance/conformance_python.py b/conformance/conformance_python.py index cffadc9478..6576621b9e 100755 --- a/conformance/conformance_python.py +++ b/conformance/conformance_python.py @@ -178,9 +178,6 @@ def do_test_io(): elif len(length_bytes) != 4: raise IOError("I/O error") - # "I" is "unsigned int", so this depends on running on a platform with - # 32-bit "unsigned int" type. The Python struct module unfortunately - # has no format specifier for uint32_t. length = struct.unpack(" #include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format_lite.h" #include "google/protobuf/util/type_resolver.h" #include "conformance/conformance.pb.h" +#include "google/protobuf/wire_format_lite.h" namespace conformance { class ConformanceRequest; diff --git a/csharp/Google.Protobuf.Tools.targets b/csharp/Google.Protobuf.Tools.targets index 682e11b024..4dcb8f95cb 100644 --- a/csharp/Google.Protobuf.Tools.targets +++ b/csharp/Google.Protobuf.Tools.targets @@ -1,11 +1,11 @@ - - - $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)/../tools/')) - $([System.IO.Path]::GetFullPath('$(protoc_tools)/linux_x64/protoc')) - $([System.IO.Path]::GetFullPath('$(protoc_tools)/linux_x86/protoc')) - $([System.IO.Path]::GetFullPath('$(protoc_tools)/macosx_x64/protoc')) - $([System.IO.Path]::GetFullPath('$(protoc_tools)/macosx_x86/protoc')) - $([System.IO.Path]::GetFullPath('$(protoc_tools)/windows_x64/protoc.exe')) - $([System.IO.Path]::GetFullPath('$(protoc_tools)/windows_x86/protoc.exe')) - - + + + $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)/../tools/')) + $([System.IO.Path]::GetFullPath('$(protoc_tools)/linux_x64/protoc')) + $([System.IO.Path]::GetFullPath('$(protoc_tools)/linux_x86/protoc')) + $([System.IO.Path]::GetFullPath('$(protoc_tools)/macosx_x64/protoc')) + $([System.IO.Path]::GetFullPath('$(protoc_tools)/macosx_x86/protoc')) + $([System.IO.Path]::GetFullPath('$(protoc_tools)/windows_x64/protoc.exe')) + $([System.IO.Path]::GetFullPath('$(protoc_tools)/windows_x86/protoc.exe')) + + diff --git a/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto b/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto index b6178bf1af..554a48ff89 100644 --- a/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto +++ b/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto @@ -1,3 +1,33 @@ +// 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. + syntax = "proto3"; // These proto descriptors have at one time been reported as an issue or defect. diff --git a/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_well_known_types.proto b/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_well_known_types.proto index c90752440b..f03070022a 100644 --- a/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_well_known_types.proto +++ b/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_well_known_types.proto @@ -1,3 +1,33 @@ +// 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. + syntax = "proto3"; package protobuf_unittest; diff --git a/csharp/protos/unittest_issue6936_a.proto b/csharp/protos/unittest_issue6936_a.proto index 097d083a98..45214c7eb6 100644 --- a/csharp/protos/unittest_issue6936_a.proto +++ b/csharp/protos/unittest_issue6936_a.proto @@ -1,3 +1,33 @@ +// 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. + syntax = "proto3"; package unittest_issues; @@ -12,4 +42,4 @@ import "google/protobuf/descriptor.proto"; extend google.protobuf.MessageOptions { string opt = 50000; -} \ No newline at end of file +} diff --git a/csharp/protos/unittest_issue6936_b.proto b/csharp/protos/unittest_issue6936_b.proto index 8f71683ba6..1d6d945b84 100644 --- a/csharp/protos/unittest_issue6936_b.proto +++ b/csharp/protos/unittest_issue6936_b.proto @@ -1,3 +1,33 @@ +// 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. + syntax = "proto3"; import "unittest_issue6936_a.proto"; @@ -11,4 +41,4 @@ option csharp_namespace = "UnitTest.Issues.TestProtos"; message Foo { option (opt) = "foo"; -} \ No newline at end of file +} diff --git a/csharp/protos/unittest_issue6936_c.proto b/csharp/protos/unittest_issue6936_c.proto index 40004ecaae..2bc3115494 100644 --- a/csharp/protos/unittest_issue6936_c.proto +++ b/csharp/protos/unittest_issue6936_c.proto @@ -1,3 +1,33 @@ +// 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. + syntax = "proto3"; import "unittest_issue6936_a.proto"; @@ -13,4 +43,4 @@ option csharp_namespace = "UnitTest.Issues.TestProtos"; message Bar { option (opt) = "bar"; Foo foo = 1; -} \ No newline at end of file +} diff --git a/csharp/protos/unittest_issues.proto b/csharp/protos/unittest_issues.proto index d5907bb642..1b5562f5c8 100644 --- a/csharp/protos/unittest_issues.proto +++ b/csharp/protos/unittest_issues.proto @@ -1,3 +1,33 @@ +// 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. + syntax = "proto3"; // These proto descriptors have at one time been reported as an issue or defect. diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 79977a0ca8..77fd9c9bba 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -64,7 +64,7 @@ namespace Conformance { [pbr::OriginalName("PROTOBUF")] Protobuf = 1, [pbr::OriginalName("JSON")] Json = 2, /// - /// Google internal only. Opensource testees just skip it. + /// Only used inside Google. Opensource testees just skip it. /// [pbr::OriginalName("JSPB")] Jspb = 3, [pbr::OriginalName("TEXT_FORMAT")] TextFormat = 4, @@ -89,7 +89,7 @@ namespace Conformance { /// [pbr::OriginalName("JSON_IGNORE_UNKNOWN_PARSING_TEST")] JsonIgnoreUnknownParsingTest = 3, /// - /// Test jspb wire format. Google internal only. Opensource testees just skip it. + /// Test jspb wire format. Only used inside Google. Opensource testees just skip it. /// [pbr::OriginalName("JSPB_TEST")] JspbTest = 4, /// @@ -382,7 +382,7 @@ namespace Conformance { /// Field number for the "jspb_payload" field. public const int JspbPayloadFieldNumber = 7; /// - /// Google internal only. Opensource testees just skip it. + /// Only used inside google. Opensource testees just skip it. /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -1026,8 +1026,8 @@ namespace Conformance { public const int JspbPayloadFieldNumber = 7; /// /// If the input was successfully parsed and the requested output was JSPB, - /// serialize to JSPB and set it in this field. JSPB is google internal only - /// format. Opensource testees can just skip it. + /// serialize to JSPB and set it in this field. JSPB is only used inside + /// Google. Opensource testees can just skip it. /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] diff --git a/csharp/src/Google.Protobuf.sln b/csharp/src/Google.Protobuf.sln index b0bebec9f2..e5f38a64e7 100644 --- a/csharp/src/Google.Protobuf.sln +++ b/csharp/src/Google.Protobuf.sln @@ -1,54 +1,54 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26114.2 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AddressBook", "AddressBook\AddressBook.csproj", "{AFB63919-1E05-43B4-802A-8FB8C9B2F463}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf", "Google.Protobuf\Google.Protobuf.csproj", "{9B576380-726D-4142-8238-60A43AB0E35A}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf.Test", "Google.Protobuf.Test\Google.Protobuf.Test.csproj", "{580EB013-D3C7-4578-B845-015F4A3B0591}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf.Conformance", "Google.Protobuf.Conformance\Google.Protobuf.Conformance.csproj", "{DDDC055B-E185-4181-BAB0-072F0F984569}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.csproj", "{9695E08F-9829-497D-B95C-B38F28D48690}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Test.TestProtos", "Google.Protobuf.Test.TestProtos\Google.Protobuf.Test.TestProtos.csproj", "{ADF24BEB-A318-4530-8448-356B72B820EA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Release|Any CPU.Build.0 = Release|Any CPU - {9B576380-726D-4142-8238-60A43AB0E35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9B576380-726D-4142-8238-60A43AB0E35A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9B576380-726D-4142-8238-60A43AB0E35A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9B576380-726D-4142-8238-60A43AB0E35A}.Release|Any CPU.Build.0 = Release|Any CPU - {580EB013-D3C7-4578-B845-015F4A3B0591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {580EB013-D3C7-4578-B845-015F4A3B0591}.Debug|Any CPU.Build.0 = Debug|Any CPU - {580EB013-D3C7-4578-B845-015F4A3B0591}.Release|Any CPU.ActiveCfg = Release|Any CPU - {580EB013-D3C7-4578-B845-015F4A3B0591}.Release|Any CPU.Build.0 = Release|Any CPU - {DDDC055B-E185-4181-BAB0-072F0F984569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DDDC055B-E185-4181-BAB0-072F0F984569}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DDDC055B-E185-4181-BAB0-072F0F984569}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DDDC055B-E185-4181-BAB0-072F0F984569}.Release|Any CPU.Build.0 = Release|Any CPU - {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.Build.0 = Release|Any CPU - {ADF24BEB-A318-4530-8448-356B72B820EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ADF24BEB-A318-4530-8448-356B72B820EA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ADF24BEB-A318-4530-8448-356B72B820EA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ADF24BEB-A318-4530-8448-356B72B820EA}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7B06C87B-83E1-4F5F-A0DD-6E9AFAC03DAC} - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26114.2 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AddressBook", "AddressBook\AddressBook.csproj", "{AFB63919-1E05-43B4-802A-8FB8C9B2F463}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf", "Google.Protobuf\Google.Protobuf.csproj", "{9B576380-726D-4142-8238-60A43AB0E35A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf.Test", "Google.Protobuf.Test\Google.Protobuf.Test.csproj", "{580EB013-D3C7-4578-B845-015F4A3B0591}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf.Conformance", "Google.Protobuf.Conformance\Google.Protobuf.Conformance.csproj", "{DDDC055B-E185-4181-BAB0-072F0F984569}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.csproj", "{9695E08F-9829-497D-B95C-B38F28D48690}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Test.TestProtos", "Google.Protobuf.Test.TestProtos\Google.Protobuf.Test.TestProtos.csproj", "{ADF24BEB-A318-4530-8448-356B72B820EA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Release|Any CPU.Build.0 = Release|Any CPU + {9B576380-726D-4142-8238-60A43AB0E35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B576380-726D-4142-8238-60A43AB0E35A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B576380-726D-4142-8238-60A43AB0E35A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B576380-726D-4142-8238-60A43AB0E35A}.Release|Any CPU.Build.0 = Release|Any CPU + {580EB013-D3C7-4578-B845-015F4A3B0591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {580EB013-D3C7-4578-B845-015F4A3B0591}.Debug|Any CPU.Build.0 = Debug|Any CPU + {580EB013-D3C7-4578-B845-015F4A3B0591}.Release|Any CPU.ActiveCfg = Release|Any CPU + {580EB013-D3C7-4578-B845-015F4A3B0591}.Release|Any CPU.Build.0 = Release|Any CPU + {DDDC055B-E185-4181-BAB0-072F0F984569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DDDC055B-E185-4181-BAB0-072F0F984569}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DDDC055B-E185-4181-BAB0-072F0F984569}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DDDC055B-E185-4181-BAB0-072F0F984569}.Release|Any CPU.Build.0 = Release|Any CPU + {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.Build.0 = Release|Any CPU + {ADF24BEB-A318-4530-8448-356B72B820EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADF24BEB-A318-4530-8448-356B72B820EA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADF24BEB-A318-4530-8448-356B72B820EA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADF24BEB-A318-4530-8448-356B72B820EA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7B06C87B-83E1-4F5F-A0DD-6E9AFAC03DAC} + EndGlobalSection +EndGlobal diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index c1079367d1..5389868865 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -136,8 +136,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri protected void mergeFromAndMakeImmutableInternal( CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { - Schema schema = - (Schema) Protobuf.getInstance().schemaFor(this); + Schema schema = Protobuf.getInstance().schemaFor(this); try { schema.mergeFrom(this, CodedInputStreamReader.forCodedInput(input), extensionRegistry); } catch (InvalidProtocolBufferException e) { @@ -156,7 +155,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri * @param getBytesForString whether to generate ByteString for string fields */ private Map getAllFieldsMutable(boolean getBytesForString) { - final TreeMap result = new TreeMap(); + final TreeMap result = new TreeMap<>(); final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; final List fields = descriptor.getFields(); @@ -520,8 +519,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Builder class for {@link GeneratedMessageV3}. */ @SuppressWarnings("unchecked") - public abstract static class Builder> - extends AbstractMessage.Builder { + public abstract static class Builder> + extends AbstractMessage.Builder { private BuilderParent builderParent; @@ -583,8 +582,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public BuilderType clone() { - BuilderType builder = (BuilderType) getDefaultInstanceForType().newBuilderForType(); + public BuilderT clone() { + BuilderT builder = (BuilderT) getDefaultInstanceForType().newBuilderForType(); builder.mergeFrom(buildPartial()); return builder; } @@ -594,10 +593,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri * builtin fields back to the initial values. */ @Override - public BuilderType clear() { + public BuilderT clear() { unknownFieldsOrBuilder = UnknownFieldSet.getDefaultInstance(); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } /** @@ -618,7 +617,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Internal helper which returns a mutable map. */ private Map getAllFieldsMutable() { - final TreeMap result = new TreeMap(); + final TreeMap result = new TreeMap<>(); final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; final List fields = descriptor.getFields(); @@ -701,21 +700,21 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public BuilderType setField(final FieldDescriptor field, final Object value) { + public BuilderT setField(final FieldDescriptor field, final Object value) { internalGetFieldAccessorTable().getField(field).set(this, value); - return (BuilderType) this; + return (BuilderT) this; } @Override - public BuilderType clearField(final FieldDescriptor field) { + public BuilderT clearField(final FieldDescriptor field) { internalGetFieldAccessorTable().getField(field).clear(this); - return (BuilderType) this; + return (BuilderT) this; } @Override - public BuilderType clearOneof(final OneofDescriptor oneof) { + public BuilderT clearOneof(final OneofDescriptor oneof) { internalGetFieldAccessorTable().getOneof(oneof).clear(this); - return (BuilderType) this; + return (BuilderT) this; } @Override @@ -729,51 +728,51 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public BuilderType setRepeatedField( + public BuilderT setRepeatedField( final FieldDescriptor field, final int index, final Object value) { internalGetFieldAccessorTable().getField(field).setRepeated(this, index, value); - return (BuilderType) this; + return (BuilderT) this; } @Override - public BuilderType addRepeatedField(final FieldDescriptor field, final Object value) { + public BuilderT addRepeatedField(final FieldDescriptor field, final Object value) { internalGetFieldAccessorTable().getField(field).addRepeated(this, value); - return (BuilderType) this; + return (BuilderT) this; } - private BuilderType setUnknownFieldsInternal(final UnknownFieldSet unknownFields) { + private BuilderT setUnknownFieldsInternal(final UnknownFieldSet unknownFields) { unknownFieldsOrBuilder = unknownFields; onChanged(); - return (BuilderType) this; + return (BuilderT) this; } @Override - public BuilderType setUnknownFields(final UnknownFieldSet unknownFields) { + public BuilderT setUnknownFields(final UnknownFieldSet unknownFields) { return setUnknownFieldsInternal(unknownFields); } /** * This method is obsolete, but we must retain it for compatibility with older generated code. */ - protected BuilderType setUnknownFieldsProto3(final UnknownFieldSet unknownFields) { + protected BuilderT setUnknownFieldsProto3(final UnknownFieldSet unknownFields) { return setUnknownFieldsInternal(unknownFields); } @Override - public BuilderType mergeUnknownFields(final UnknownFieldSet unknownFields) { + public BuilderT mergeUnknownFields(final UnknownFieldSet unknownFields) { if (UnknownFieldSet.getDefaultInstance().equals(unknownFields)) { - return (BuilderType) this; + return (BuilderT) this; } if (UnknownFieldSet.getDefaultInstance().equals(unknownFieldsOrBuilder)) { unknownFieldsOrBuilder = unknownFields; onChanged(); - return (BuilderType) this; + return (BuilderT) this; } getUnknownFieldSetBuilder().mergeFrom(unknownFields); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } @Override @@ -919,49 +918,49 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri // Extensions-related stuff /** Extends {@link MessageOrBuilder} with extension-related functions. */ - public interface ExtendableMessageOrBuilder + public interface ExtendableMessageOrBuilder extends MessageOrBuilder { // Re-define for return type covariance. @Override Message getDefaultInstanceForType(); /** Check if a singular extension is present. */ - boolean hasExtension(ExtensionLite extension); + boolean hasExtension(ExtensionLite extension); /** Get the number of elements in a repeated extension. */ - int getExtensionCount(ExtensionLite> extension); + int getExtensionCount(ExtensionLite> extension); /** Get the value of an extension. */ - Type getExtension(ExtensionLite extension); + T getExtension(ExtensionLite extension); /** Get one element of a repeated extension. */ - Type getExtension(ExtensionLite> extension, int index); + T getExtension(ExtensionLite> extension, int index); /** Check if a singular extension is present. */ - boolean hasExtension( - Extension extension); + boolean hasExtension( + Extension extension); /** Check if a singular extension is present. */ - boolean hasExtension( - GeneratedExtension extension); + boolean hasExtension( + GeneratedExtension extension); /** Get the number of elements in a repeated extension. */ - int getExtensionCount( - Extension> extension); + int getExtensionCount( + Extension> extension); /** Get the number of elements in a repeated extension. */ - int getExtensionCount( - GeneratedExtension> extension); + int getExtensionCount( + GeneratedExtension> extension); /** Get the value of an extension. */ - Type getExtension( - Extension extension); + T getExtension( + Extension extension); /** Get the value of an extension. */ - Type getExtension( - GeneratedExtension extension); + T getExtension( + GeneratedExtension extension); /** Get one element of a repeated extension. */ - Type getExtension( - Extension> extension, + T getExtension( + Extension> extension, int index); /** Get one element of a repeated extension. */ - Type getExtension( - GeneratedExtension> extension, + T getExtension( + GeneratedExtension> extension, int index); } @@ -997,8 +996,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri * *

See also {@link ExtendableBuilder}. */ - public abstract static class ExtendableMessage - extends GeneratedMessageV3 implements ExtendableMessageOrBuilder { + public abstract static class ExtendableMessage + extends GeneratedMessageV3 implements ExtendableMessageOrBuilder { private static final long serialVersionUID = 1L; @@ -1008,12 +1007,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri this.extensions = FieldSet.newFieldSet(); } - protected ExtendableMessage(ExtendableBuilder builder) { + protected ExtendableMessage(ExtendableBuilder builder) { super(builder); this.extensions = builder.buildExtensions(); } - private void verifyExtensionContainingType(final Extension extension) { + private void verifyExtensionContainingType(final Extension extension) { if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { // This can only happen if someone uses unchecked operations. throw new IllegalArgumentException( @@ -1028,8 +1027,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Check if a singular extension is present. */ @Override @SuppressWarnings("unchecked") - public final boolean hasExtension(final ExtensionLite extensionLite) { - Extension extension = checkNotLite(extensionLite); + public final boolean hasExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); return extensions.hasField(extension.getDescriptor()); @@ -1038,9 +1037,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Get the number of elements in a repeated extension. */ @Override @SuppressWarnings("unchecked") - public final int getExtensionCount( - final ExtensionLite> extensionLite) { - Extension> extension = checkNotLite(extensionLite); + public final int getExtensionCount(final ExtensionLite> extensionLite) { + Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); final FieldDescriptor descriptor = extension.getDescriptor(); @@ -1050,83 +1048,83 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Get the value of an extension. */ @Override @SuppressWarnings("unchecked") - public final Type getExtension(final ExtensionLite extensionLite) { - Extension extension = checkNotLite(extensionLite); + public final T getExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); FieldDescriptor descriptor = extension.getDescriptor(); final Object value = extensions.getField(descriptor); if (value == null) { if (descriptor.isRepeated()) { - return (Type) Collections.emptyList(); + return (T) Collections.emptyList(); } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { - return (Type) extension.getMessageDefaultInstance(); + return (T) extension.getMessageDefaultInstance(); } else { - return (Type) extension.fromReflectionType(descriptor.getDefaultValue()); + return (T) extension.fromReflectionType(descriptor.getDefaultValue()); } } else { - return (Type) extension.fromReflectionType(value); + return (T) extension.fromReflectionType(value); } } /** Get one element of a repeated extension. */ @Override @SuppressWarnings("unchecked") - public final Type getExtension( - final ExtensionLite> extensionLite, final int index) { - Extension> extension = checkNotLite(extensionLite); + public final T getExtension( + final ExtensionLite> extensionLite, final int index) { + Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); FieldDescriptor descriptor = extension.getDescriptor(); - return (Type) + return (T) extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); } /** Check if a singular extension is present. */ @Override - public final boolean hasExtension(final Extension extension) { - return hasExtension((ExtensionLite) extension); + public final boolean hasExtension(final Extension extension) { + return hasExtension((ExtensionLite) extension); } /** Check if a singular extension is present. */ @Override - public final boolean hasExtension( - final GeneratedExtension extension) { - return hasExtension((ExtensionLite) extension); + public final boolean hasExtension( + final GeneratedExtension extension) { + return hasExtension((ExtensionLite) extension); } /** Get the number of elements in a repeated extension. */ @Override - public final int getExtensionCount( - final Extension> extension) { - return getExtensionCount((ExtensionLite>) extension); + public final int getExtensionCount( + final Extension> extension) { + return getExtensionCount((ExtensionLite>) extension); } /** Get the number of elements in a repeated extension. */ @Override - public final int getExtensionCount( - final GeneratedExtension> extension) { - return getExtensionCount((ExtensionLite>) extension); + public final int getExtensionCount( + final GeneratedExtension> extension) { + return getExtensionCount((ExtensionLite>) extension); } /** Get the value of an extension. */ @Override - public final Type getExtension(final Extension extension) { - return getExtension((ExtensionLite) extension); + public final T getExtension(final Extension extension) { + return getExtension((ExtensionLite) extension); } /** Get the value of an extension. */ @Override - public final Type getExtension( - final GeneratedExtension extension) { - return getExtension((ExtensionLite) extension); + public final T getExtension( + final GeneratedExtension extension) { + return getExtension((ExtensionLite) extension); } /** Get one element of a repeated extension. */ @Override - public final Type getExtension( - final Extension> extension, final int index) { - return getExtension((ExtensionLite>) extension, index); + public final T getExtension( + final Extension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); } /** Get one element of a repeated extension. */ @Override - public final Type getExtension( - final GeneratedExtension> extension, final int index) { - return getExtension((ExtensionLite>) extension, index); + public final T getExtension( + final GeneratedExtension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); } /** Called by subclasses to check if all extensions are initialized. */ @@ -1363,9 +1361,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri */ @SuppressWarnings("unchecked") public abstract static class ExtendableBuilder< - MessageType extends ExtendableMessage, - BuilderType extends ExtendableBuilder> - extends Builder implements ExtendableMessageOrBuilder { + MessageT extends ExtendableMessage, + BuilderT extends ExtendableBuilder> + extends Builder implements ExtendableMessageOrBuilder { private FieldSet.Builder extensions; @@ -1381,7 +1379,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public BuilderType clear() { + public BuilderT clear() { extensions = null; return super.clear(); } @@ -1392,7 +1390,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - private void verifyExtensionContainingType(final Extension extension) { + private void verifyExtensionContainingType(final Extension extension) { if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { // This can only happen if someone uses unchecked operations. throw new IllegalArgumentException( @@ -1406,18 +1404,17 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Check if a singular extension is present. */ @Override - public final boolean hasExtension(final ExtensionLite extensionLite) { - Extension extension = checkNotLite(extensionLite); + public final boolean hasExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); - return extensions == null ? false : extensions.hasField(extension.getDescriptor()); + return extensions != null && extensions.hasField(extension.getDescriptor()); } /** Get the number of elements in a repeated extension. */ @Override - public final int getExtensionCount( - final ExtensionLite> extensionLite) { - Extension> extension = checkNotLite(extensionLite); + public final int getExtensionCount(final ExtensionLite> extensionLite) { + Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); final FieldDescriptor descriptor = extension.getDescriptor(); @@ -1426,184 +1423,182 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Get the value of an extension. */ @Override - public final Type getExtension(final ExtensionLite extensionLite) { - Extension extension = checkNotLite(extensionLite); + public final T getExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); FieldDescriptor descriptor = extension.getDescriptor(); final Object value = extensions == null ? null : extensions.getField(descriptor); if (value == null) { if (descriptor.isRepeated()) { - return (Type) Collections.emptyList(); + return (T) Collections.emptyList(); } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { - return (Type) extension.getMessageDefaultInstance(); + return (T) extension.getMessageDefaultInstance(); } else { - return (Type) extension.fromReflectionType(descriptor.getDefaultValue()); + return (T) extension.fromReflectionType(descriptor.getDefaultValue()); } } else { - return (Type) extension.fromReflectionType(value); + return (T) extension.fromReflectionType(value); } } /** Get one element of a repeated extension. */ @Override - public final Type getExtension( - final ExtensionLite> extensionLite, final int index) { - Extension> extension = checkNotLite(extensionLite); + public final T getExtension( + final ExtensionLite> extensionLite, final int index) { + Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); FieldDescriptor descriptor = extension.getDescriptor(); if (extensions == null) { throw new IndexOutOfBoundsException(); } - return (Type) + return (T) extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); } /** Set the value of an extension. */ - public final BuilderType setExtension( - final ExtensionLite extensionLite, final Type value) { - Extension extension = checkNotLite(extensionLite); + public final BuilderT setExtension( + final ExtensionLite extensionLite, final T value) { + Extension extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); ensureExtensionsIsMutable(); final FieldDescriptor descriptor = extension.getDescriptor(); extensions.setField(descriptor, extension.toReflectionType(value)); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } /** Set the value of one element of a repeated extension. */ - public final BuilderType setExtension( - final ExtensionLite> extensionLite, - final int index, - final Type value) { - Extension> extension = checkNotLite(extensionLite); + public final BuilderT setExtension( + final ExtensionLite> extensionLite, final int index, final T value) { + Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); ensureExtensionsIsMutable(); final FieldDescriptor descriptor = extension.getDescriptor(); extensions.setRepeatedField(descriptor, index, extension.singularToReflectionType(value)); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } /** Append a value to a repeated extension. */ - public final BuilderType addExtension( - final ExtensionLite> extensionLite, final Type value) { - Extension> extension = checkNotLite(extensionLite); + public final BuilderT addExtension( + final ExtensionLite> extensionLite, final T value) { + Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); ensureExtensionsIsMutable(); final FieldDescriptor descriptor = extension.getDescriptor(); extensions.addRepeatedField(descriptor, extension.singularToReflectionType(value)); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } /** Clear an extension. */ - public final BuilderType clearExtension(final ExtensionLite extensionLite) { - Extension extension = checkNotLite(extensionLite); + public final BuilderT clearExtension(final ExtensionLite extensionLite) { + Extension extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); ensureExtensionsIsMutable(); extensions.clearField(extension.getDescriptor()); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } /** Check if a singular extension is present. */ @Override - public final boolean hasExtension(final Extension extension) { - return hasExtension((ExtensionLite) extension); + public final boolean hasExtension(final Extension extension) { + return hasExtension((ExtensionLite) extension); } /** Check if a singular extension is present. */ @Override - public final boolean hasExtension( - final GeneratedExtension extension) { - return hasExtension((ExtensionLite) extension); + public final boolean hasExtension( + final GeneratedExtension extension) { + return hasExtension((ExtensionLite) extension); } /** Get the number of elements in a repeated extension. */ @Override - public final int getExtensionCount( - final Extension> extension) { - return getExtensionCount((ExtensionLite>) extension); + public final int getExtensionCount( + final Extension> extension) { + return getExtensionCount((ExtensionLite>) extension); } /** Get the number of elements in a repeated extension. */ @Override - public final int getExtensionCount( - final GeneratedExtension> extension) { - return getExtensionCount((ExtensionLite>) extension); + public final int getExtensionCount( + final GeneratedExtension> extension) { + return getExtensionCount((ExtensionLite>) extension); } /** Get the value of an extension. */ @Override - public final Type getExtension(final Extension extension) { - return getExtension((ExtensionLite) extension); + public final T getExtension(final Extension extension) { + return getExtension((ExtensionLite) extension); } /** Get the value of an extension. */ @Override - public final Type getExtension( - final GeneratedExtension extension) { - return getExtension((ExtensionLite) extension); + public final T getExtension( + final GeneratedExtension extension) { + return getExtension((ExtensionLite) extension); } /** Get the value of an extension. */ @Override - public final Type getExtension( - final Extension> extension, final int index) { - return getExtension((ExtensionLite>) extension, index); + public final T getExtension( + final Extension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); } /** Get the value of an extension. */ @Override - public final Type getExtension( - final GeneratedExtension> extension, final int index) { - return getExtension((ExtensionLite>) extension, index); + public final T getExtension( + final GeneratedExtension> extension, final int index) { + return getExtension((ExtensionLite>) extension, index); } /** Set the value of an extension. */ - public final BuilderType setExtension( - final Extension extension, final Type value) { - return setExtension((ExtensionLite) extension, value); + public final BuilderT setExtension( + final Extension extension, final T value) { + return setExtension((ExtensionLite) extension, value); } /** Set the value of an extension. */ - public BuilderType setExtension( - final GeneratedExtension extension, final Type value) { - return setExtension((ExtensionLite) extension, value); + public BuilderT setExtension( + final GeneratedExtension extension, final T value) { + return setExtension((ExtensionLite) extension, value); } /** Set the value of one element of a repeated extension. */ - public final BuilderType setExtension( - final Extension> extension, - final int index, final Type value) { - return setExtension((ExtensionLite>) extension, index, value); + public final BuilderT setExtension( + final Extension> extension, + final int index, final T value) { + return setExtension((ExtensionLite>) extension, index, value); } /** Set the value of one element of a repeated extension. */ - public BuilderType setExtension( - final GeneratedExtension> extension, - final int index, final Type value) { - return setExtension((ExtensionLite>) extension, index, value); + public BuilderT setExtension( + final GeneratedExtension> extension, + final int index, final T value) { + return setExtension((ExtensionLite>) extension, index, value); } /** Append a value to a repeated extension. */ - public final BuilderType addExtension( - final Extension> extension, final Type value) { - return addExtension((ExtensionLite>) extension, value); + public final BuilderT addExtension( + final Extension> extension, final T value) { + return addExtension((ExtensionLite>) extension, value); } /** Append a value to a repeated extension. */ - public BuilderType addExtension( - final GeneratedExtension> extension, final Type value) { - return addExtension((ExtensionLite>) extension, value); + public BuilderT addExtension( + final GeneratedExtension> extension, final T value) { + return addExtension((ExtensionLite>) extension, value); } /** Clear an extension. */ - public final BuilderType clearExtension( - final Extension extension) { - return clearExtension((ExtensionLite) extension); + public final BuilderT clearExtension( + final Extension extension) { + return clearExtension((ExtensionLite) extension); } /** Clear an extension. */ - public BuilderType clearExtension( - final GeneratedExtension extension) { - return clearExtension((ExtensionLite) extension); + public BuilderT clearExtension( + final GeneratedExtension extension) { + return clearExtension((ExtensionLite) extension); } /** Called by subclasses to check if all extensions are initialized. */ protected boolean extensionsAreInitialized() { - return extensions == null ? true : extensions.isInitialized(); + return extensions == null || extensions.isInitialized(); } /** @@ -1739,60 +1734,60 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri public boolean hasField(final FieldDescriptor field) { if (field.isExtension()) { verifyContainingType(field); - return extensions == null ? false : extensions.hasField(field); + return extensions != null && extensions.hasField(field); } else { return super.hasField(field); } } @Override - public BuilderType setField(final FieldDescriptor field, final Object value) { + public BuilderT setField(final FieldDescriptor field, final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); extensions.setField(field, value); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } else { return super.setField(field, value); } } @Override - public BuilderType clearField(final FieldDescriptor field) { + public BuilderT clearField(final FieldDescriptor field) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); extensions.clearField(field); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } else { return super.clearField(field); } } @Override - public BuilderType setRepeatedField( + public BuilderT setRepeatedField( final FieldDescriptor field, final int index, final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); extensions.setRepeatedField(field, index, value); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } else { return super.setRepeatedField(field, index, value); } } @Override - public BuilderType addRepeatedField(final FieldDescriptor field, final Object value) { + public BuilderT addRepeatedField(final FieldDescriptor field, final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); extensions.addRepeatedField(field, value); onChanged(); - return (BuilderType) this; + return (BuilderT) this; } else { return super.addRepeatedField(field, value); } @@ -1963,8 +1958,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri if (field.isRepeated()) { if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (field.isMapField()) { - fields[i] = - new MapFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new MapFieldAccessor(field, messageClass); } else { fields[i] = new RepeatedMessageFieldAccessor( @@ -2092,9 +2086,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri Message.Builder newBuilder(); - Message.Builder getBuilder(GeneratedMessageV3.Builder builder); + Message.Builder getBuilder(GeneratedMessageV3.Builder builder); - Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index); + Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index); } /** OneofAccessor provides access to a single oneof. */ @@ -2129,22 +2123,16 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri if (fieldDescriptor != null) { return message.hasField(fieldDescriptor); } else { - if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) { - return false; - } + return ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() != 0; } - return true; } public boolean has(GeneratedMessageV3.Builder builder) { if (fieldDescriptor != null) { return builder.hasField(fieldDescriptor); } else { - if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) { - return false; - } + return ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() != 0; } - return true; } public FieldDescriptor get(final GeneratedMessageV3 message) { @@ -2421,12 +2409,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { + public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); } @Override - public Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index) { + public Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index) { throw new UnsupportedOperationException( "getRepeatedFieldBuilder() called on a non-Message type."); } @@ -2434,9 +2422,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri private static class RepeatedFieldAccessor implements FieldAccessor { interface MethodInvoker { - public Object get(final GeneratedMessageV3 message); + Object get(final GeneratedMessageV3 message); - public Object get(GeneratedMessageV3.Builder builder); + Object get(GeneratedMessageV3.Builder builder); Object getRepeated(final GeneratedMessageV3 message, final int index); @@ -2455,15 +2443,15 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } private static final class ReflectionInvoker implements MethodInvoker { - protected final Method getMethod; - protected final Method getMethodBuilder; - protected final Method getRepeatedMethod; - protected final Method getRepeatedMethodBuilder; - protected final Method setRepeatedMethod; - protected final Method addRepeatedMethod; - protected final Method getCountMethod; - protected final Method getCountMethodBuilder; - protected final Method clearMethod; + private final Method getMethod; + private final Method getMethodBuilder; + private final Method getRepeatedMethod; + private final Method getRepeatedMethodBuilder; + private final Method setRepeatedMethod; + private final Method addRepeatedMethod; + private final Method getCountMethod; + private final Method getCountMethodBuilder; + private final Method clearMethod; ReflectionInvoker( final FieldDescriptor descriptor, @@ -2646,12 +2634,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { + public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); } @Override - public Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index) { + public Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index) { throw new UnsupportedOperationException( "getRepeatedFieldBuilder() called on a non-Message type."); } @@ -2659,13 +2647,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri private static class MapFieldAccessor implements FieldAccessor { MapFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, - final Class messageClass, - final Class builderClass) { + final FieldDescriptor descriptor, final Class messageClass) { field = descriptor; Method getDefaultInstanceMethod = getMethodOrDie(messageClass, "getDefaultInstance"); - MapField defaultMapField = + MapField defaultMapField = getMapField((GeneratedMessageV3) invokeOrDie(getDefaultInstanceMethod, null)); mapEntryMessageDefaultInstance = defaultMapField.getMapEntryMessageDefaultInstance(); } @@ -2793,17 +2778,17 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public com.google.protobuf.Message.Builder newBuilder() { + public Message.Builder newBuilder() { return mapEntryMessageDefaultInstance.newBuilderForType(); } @Override - public com.google.protobuf.Message.Builder getBuilder(Builder builder) { + public Message.Builder getBuilder(Builder builder) { throw new UnsupportedOperationException("Nested builder not supported for map fields."); } @Override - public com.google.protobuf.Message.Builder getRepeatedBuilder(Builder builder, int index) { + public Message.Builder getRepeatedBuilder(Builder builder, int index) { throw new UnsupportedOperationException("Map fields cannot be repeated"); } } @@ -2832,12 +2817,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - private EnumDescriptor enumDescriptor; + private final EnumDescriptor enumDescriptor; - private Method valueOfMethod; - private Method getValueDescriptorMethod; + private final Method valueOfMethod; + private final Method getValueDescriptorMethod; - private boolean supportUnknownEnumValue; + private final boolean supportUnknownEnumValue; private Method getValueMethod; private Method getValueMethodBuilder; private Method setValueMethod; @@ -2898,21 +2883,21 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - private EnumDescriptor enumDescriptor; + private final EnumDescriptor enumDescriptor; private final Method valueOfMethod; private final Method getValueDescriptorMethod; - private boolean supportUnknownEnumValue; + private final boolean supportUnknownEnumValue; + private Method getRepeatedValueMethod; private Method getRepeatedValueMethodBuilder; private Method setRepeatedValueMethod; private Method addRepeatedValueMethod; @Override - @SuppressWarnings("unchecked") public Object get(final GeneratedMessageV3 message) { - final List newList = new ArrayList<>(); + final List newList = new ArrayList<>(); final int size = getRepeatedCount(message); for (int i = 0; i < size; i++) { newList.add(getRepeated(message, i)); @@ -2921,9 +2906,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - @SuppressWarnings("unchecked") public Object get(final GeneratedMessageV3.Builder builder) { - final List newList = new ArrayList<>(); + final List newList = new ArrayList<>(); final int size = getRepeatedCount(builder); for (int i = 0; i < size; i++) { newList.add(getRepeated(builder, i)); @@ -3071,7 +3055,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { + public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder); } } @@ -3123,7 +3107,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public Message.Builder getRepeatedBuilder( - final GeneratedMessageV3.Builder builder, final int index) { + final GeneratedMessageV3.Builder builder, final int index) { return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder, index); } } @@ -3143,13 +3127,13 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** * Checks that the {@link Extension} is non-Lite and returns it as a {@link GeneratedExtension}. */ - private static , T> - Extension checkNotLite(ExtensionLite extension) { + private static , T> + Extension checkNotLite(ExtensionLite extension) { if (extension.isLite()) { throw new IllegalArgumentException("Expected non-lite extension."); } - return (Extension) extension; + return (Extension) extension; } protected static boolean isStringEmpty(final Object value) { diff --git a/java/core/src/test/java/com/google/protobuf/AnyTest.java b/java/core/src/test/java/com/google/protobuf/AnyTest.java index ac047a9cf9..11b214b4b7 100644 --- a/java/core/src/test/java/com/google/protobuf/AnyTest.java +++ b/java/core/src/test/java/com/google/protobuf/AnyTest.java @@ -43,7 +43,6 @@ import org.junit.runners.JUnit4; /** Unit tests for Any message. */ @RunWith(JUnit4.class) public class AnyTest { - @Test public void testAnyGeneratedApi() throws Exception { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); @@ -78,6 +77,40 @@ public class AnyTest { } } + @Test + public void testAnyGeneratedExemplarApi() throws Exception { + TestAllTypes.Builder builder = TestAllTypes.newBuilder(); + TestUtil.setAllFields(builder); + TestAllTypes message = builder.build(); + + TestAny container = TestAny.newBuilder().setValue(Any.pack(message)).build(); + + assertThat(container.getValue().isSameTypeAs(TestAllTypes.getDefaultInstance())).isTrue(); + assertThat(container.getValue().isSameTypeAs(TestAny.getDefaultInstance())).isFalse(); + + TestAllTypes result = container.getValue().unpackSameTypeAs(TestAllTypes.getDefaultInstance()); + TestUtil.assertAllFieldsSet(result); + + // Unpacking to a wrong exemplar will throw an exception. + try { + container.getValue().unpackSameTypeAs(TestAny.getDefaultInstance()); + assertWithMessage("Exception is expected.").fail(); + } catch (InvalidProtocolBufferException e) { + // expected. + } + + // Test that unpacking throws an exception if parsing fails. + TestAny.Builder containerBuilder = container.toBuilder(); + containerBuilder.getValueBuilder().setValue(ByteString.copyFrom(new byte[] {0x11})); + container = containerBuilder.build(); + try { + container.getValue().unpackSameTypeAs(TestAllTypes.getDefaultInstance()); + assertWithMessage("Exception is expected.").fail(); + } catch (InvalidProtocolBufferException e) { + // expected. + } + } + @Test public void testCustomTypeUrls() throws Exception { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); @@ -90,7 +123,9 @@ public class AnyTest { .isEqualTo("xxx.com/" + TestAllTypes.getDescriptor().getFullName()); assertThat(container.getValue().is(TestAllTypes.class)).isTrue(); + assertThat(container.getValue().isSameTypeAs(TestAllTypes.getDefaultInstance())).isTrue(); assertThat(container.getValue().is(TestAny.class)).isFalse(); + assertThat(container.getValue().isSameTypeAs(TestAny.getDefaultInstance())).isFalse(); TestAllTypes result = container.getValue().unpack(TestAllTypes.class); TestUtil.assertAllFieldsSet(result); @@ -101,7 +136,9 @@ public class AnyTest { .isEqualTo("yyy.com/" + TestAllTypes.getDescriptor().getFullName()); assertThat(container.getValue().is(TestAllTypes.class)).isTrue(); + assertThat(container.getValue().isSameTypeAs(TestAllTypes.getDefaultInstance())).isTrue(); assertThat(container.getValue().is(TestAny.class)).isFalse(); + assertThat(container.getValue().isSameTypeAs(TestAny.getDefaultInstance())).isFalse(); result = container.getValue().unpack(TestAllTypes.class); TestUtil.assertAllFieldsSet(result); @@ -112,12 +149,54 @@ public class AnyTest { .isEqualTo("/" + TestAllTypes.getDescriptor().getFullName()); assertThat(container.getValue().is(TestAllTypes.class)).isTrue(); + assertThat(container.getValue().isSameTypeAs(TestAllTypes.getDefaultInstance())).isTrue(); assertThat(container.getValue().is(TestAny.class)).isFalse(); + assertThat(container.getValue().isSameTypeAs(TestAny.getDefaultInstance())).isFalse(); result = container.getValue().unpack(TestAllTypes.class); TestUtil.assertAllFieldsSet(result); } + @Test + public void testCustomTypeUrlsWithExemplars() throws Exception { + TestAllTypes.Builder builder = TestAllTypes.newBuilder(); + TestUtil.setAllFields(builder); + TestAllTypes message = builder.build(); + + TestAny container = TestAny.newBuilder().setValue(Any.pack(message, "xxx.com")).build(); + + assertThat(container.getValue().getTypeUrl()) + .isEqualTo("xxx.com/" + TestAllTypes.getDescriptor().getFullName()); + + assertThat(container.getValue().isSameTypeAs(TestAllTypes.getDefaultInstance())).isTrue(); + assertThat(container.getValue().isSameTypeAs(TestAny.getDefaultInstance())).isFalse(); + + TestAllTypes result = container.getValue().unpackSameTypeAs(TestAllTypes.getDefaultInstance()); + TestUtil.assertAllFieldsSet(result); + + container = TestAny.newBuilder().setValue(Any.pack(message, "yyy.com/")).build(); + + assertThat(container.getValue().getTypeUrl()) + .isEqualTo("yyy.com/" + TestAllTypes.getDescriptor().getFullName()); + + assertThat(container.getValue().isSameTypeAs(TestAllTypes.getDefaultInstance())).isTrue(); + assertThat(container.getValue().isSameTypeAs(TestAny.getDefaultInstance())).isFalse(); + + result = container.getValue().unpackSameTypeAs(TestAllTypes.getDefaultInstance()); + TestUtil.assertAllFieldsSet(result); + + container = TestAny.newBuilder().setValue(Any.pack(message, "")).build(); + + assertThat(container.getValue().getTypeUrl()) + .isEqualTo("/" + TestAllTypes.getDescriptor().getFullName()); + + assertThat(container.getValue().isSameTypeAs(TestAllTypes.getDefaultInstance())).isTrue(); + assertThat(container.getValue().isSameTypeAs(TestAny.getDefaultInstance())).isFalse(); + + result = container.getValue().unpackSameTypeAs(TestAllTypes.getDefaultInstance()); + TestUtil.assertAllFieldsSet(result); + } + @Test public void testCachedUnpackResult() throws Exception { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); @@ -132,4 +211,19 @@ public class AnyTest { TestAllTypes result2 = container.getValue().unpack(TestAllTypes.class); assertThat(Objects.equals(result1, result2)).isTrue(); } + + @Test + public void testCachedUnpackExemplarResult() throws Exception { + TestAllTypes.Builder builder = TestAllTypes.newBuilder(); + TestUtil.setAllFields(builder); + TestAllTypes message = builder.build(); + + TestAny container = TestAny.newBuilder().setValue(Any.pack(message)).build(); + + assertThat(container.getValue().isSameTypeAs(TestAllTypes.getDefaultInstance())).isTrue(); + + TestAllTypes result1 = container.getValue().unpackSameTypeAs(TestAllTypes.getDefaultInstance()); + TestAllTypes result2 = container.getValue().unpackSameTypeAs(TestAllTypes.getDefaultInstance()); + assertThat(Objects.equals(result1, result2)).isTrue(); + } } diff --git a/objectivec/DevTools/full_mac_build.sh b/objectivec/DevTools/full_mac_build.sh index afff93d3d8..4fed4f5cdb 100755 --- a/objectivec/DevTools/full_mac_build.sh +++ b/objectivec/DevTools/full_mac_build.sh @@ -187,8 +187,6 @@ else # Can't issue these together, when fully parallel, something sometimes chokes # at random. "${BazelBin}" test //src/... $BazelFlags - # Fire off the conformance tests also. - "${BazelBin}" test //objectivec:conformance_test $BazelFlags fi # Ensure the WKT sources checked in are current. diff --git a/objectivec/GPBAny.pbobjc.h b/objectivec/GPBAny.pbobjc.h index 3edf349865..4720bfdd7f 100644 --- a/objectivec/GPBAny.pbobjc.h +++ b/objectivec/GPBAny.pbobjc.h @@ -69,6 +69,10 @@ typedef GPB_ENUM(GPBAny_FieldNumber) { * if (any.is(Foo.class)) { * foo = any.unpack(Foo.class); * } + * // or ... + * if (any.isSameTypeAs(Foo.getDefaultInstance())) { + * foo = any.unpack(Foo.getDefaultInstance()); + * } * * Example 3: Pack and unpack a message in Python. * diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index 1d26392ed8..5a9c53eb78 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -89,7 +89,7 @@ static NSString *const kGPBDataCoderKey = @"GPBData"; // http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/ // https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html // It was changed to a dispatch_semaphore_t, but that has potential for priority inversion issues. - // The minOS versions are now high enough that os_unfair_lock can be used, and should provide + // The minOS versions are now high enough that os_unfair_lock can be used, and should provide // all the support we need. For more information in the concurrency/locking space see: // https://gist.github.com/tclementdev/6af616354912b0347cdf6db159c37057 // https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html diff --git a/objectivec/GPBRootObject.m b/objectivec/GPBRootObject.m index b546959c1c..d013b2d41a 100644 --- a/objectivec/GPBRootObject.m +++ b/objectivec/GPBRootObject.m @@ -102,7 +102,7 @@ static CFHashCode GPBRootExtensionKeyHash(const void *value) { // http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/ // https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html // It was changed to a dispatch_semaphore_t, but that has potential for priority inversion issues. -// The minOS versions are now high enough that os_unfair_lock can be used, and should provide +// The minOS versions are now high enough that os_unfair_lock can be used, and should provide // all the support we need. For more information in the concurrency/locking space see: // https://gist.github.com/tclementdev/6af616354912b0347cdf6db159c37057 // https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html diff --git a/objectivec/Tests/UnitTests-Bridging-Header.h b/objectivec/Tests/UnitTests-Bridging-Header.h index 6d3d9ec5f3..c5b651c073 100644 --- a/objectivec/Tests/UnitTests-Bridging-Header.h +++ b/objectivec/Tests/UnitTests-Bridging-Header.h @@ -1,3 +1,33 @@ +// 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. + // // Use this file to import your target's public headers that you would like to // expose to Swift. diff --git a/objectivec/Tests/unittest_cycle.proto b/objectivec/Tests/unittest_cycle.proto index 91e33ce9f0..850fdbad11 100644 --- a/objectivec/Tests/unittest_cycle.proto +++ b/objectivec/Tests/unittest_cycle.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_deprecated.proto b/objectivec/Tests/unittest_deprecated.proto index aa06a06a8c..9d09a9aefd 100644 --- a/objectivec/Tests/unittest_deprecated.proto +++ b/objectivec/Tests/unittest_deprecated.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_deprecated_file.proto b/objectivec/Tests/unittest_deprecated_file.proto index b32b4b4c5d..5481032d82 100644 --- a/objectivec/Tests/unittest_deprecated_file.proto +++ b/objectivec/Tests/unittest_deprecated_file.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_extension_chain_a.proto b/objectivec/Tests/unittest_extension_chain_a.proto index 2e09a4094d..aceeed3193 100644 --- a/objectivec/Tests/unittest_extension_chain_a.proto +++ b/objectivec/Tests/unittest_extension_chain_a.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_extension_chain_b.proto b/objectivec/Tests/unittest_extension_chain_b.proto index 5cf7ea31f7..a9f3947760 100644 --- a/objectivec/Tests/unittest_extension_chain_b.proto +++ b/objectivec/Tests/unittest_extension_chain_b.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_extension_chain_c.proto b/objectivec/Tests/unittest_extension_chain_c.proto index b07b2880b5..a8d4862d5d 100644 --- a/objectivec/Tests/unittest_extension_chain_c.proto +++ b/objectivec/Tests/unittest_extension_chain_c.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_extension_chain_d.proto b/objectivec/Tests/unittest_extension_chain_d.proto index 44d9ee88ff..5c91a1bc18 100644 --- a/objectivec/Tests/unittest_extension_chain_d.proto +++ b/objectivec/Tests/unittest_extension_chain_d.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_extension_chain_e.proto b/objectivec/Tests/unittest_extension_chain_e.proto index 9c7cea8f51..bf63e8a7c8 100644 --- a/objectivec/Tests/unittest_extension_chain_e.proto +++ b/objectivec/Tests/unittest_extension_chain_e.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_extension_chain_f.proto b/objectivec/Tests/unittest_extension_chain_f.proto index 33fcaf9a60..5f9196bd16 100644 --- a/objectivec/Tests/unittest_extension_chain_f.proto +++ b/objectivec/Tests/unittest_extension_chain_f.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_extension_chain_g.proto b/objectivec/Tests/unittest_extension_chain_g.proto index 9044e46103..7b228aeae1 100644 --- a/objectivec/Tests/unittest_extension_chain_g.proto +++ b/objectivec/Tests/unittest_extension_chain_g.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2016 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_objc.proto b/objectivec/Tests/unittest_objc.proto index c7e403410d..48db8568a4 100644 --- a/objectivec/Tests/unittest_objc.proto +++ b/objectivec/Tests/unittest_objc.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2011 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 diff --git a/objectivec/Tests/unittest_runtime_proto2.proto b/objectivec/Tests/unittest_runtime_proto2.proto index 12c2b1c418..b2f0ceb75f 100644 --- a/objectivec/Tests/unittest_runtime_proto2.proto +++ b/objectivec/Tests/unittest_runtime_proto2.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/Tests/unittest_runtime_proto3.proto b/objectivec/Tests/unittest_runtime_proto3.proto index d6d4380eee..2a2fb66999 100644 --- a/objectivec/Tests/unittest_runtime_proto3.proto +++ b/objectivec/Tests/unittest_runtime_proto3.proto @@ -1,5 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/objectivec/generate_well_known_types.sh b/objectivec/generate_well_known_types.sh index 0fb9f4cafc..83a341e3e7 100755 --- a/objectivec/generate_well_known_types.sh +++ b/objectivec/generate_well_known_types.sh @@ -30,7 +30,7 @@ __EOF__ fi # Make sure the compiler is current. -"${BazelBin}" build $@ //:protoc +"${BazelBin}" build //:protoc $@ cd src declare -a RUNTIME_PROTO_FILES=( \ diff --git a/php/BUILD.bazel b/php/BUILD.bazel index ac33702ab7..e3be2225ed 100644 --- a/php/BUILD.bazel +++ b/php/BUILD.bazel @@ -2,10 +2,12 @@ # # See also code generation logic under /src/google/protobuf/compiler/php. -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") +load("@rules_pkg//:mappings.bzl", "pkg_files", "pkg_filegroup", "strip_prefix") +load("@rules_pkg//:pkg.bzl", "pkg_tar") load("@upb//cmake:build_defs.bzl", "staleness_test") load("//build_defs:internal_shell.bzl", "inline_sh_binary") load("//conformance:defs.bzl", "conformance_test") +load("//:protobuf_version.bzl", "PROTOBUF_PHP_VERSION", "PROTOC_VERSION") filegroup( name = "source_files", @@ -14,15 +16,11 @@ filegroup( "//php:__pkg__", ], srcs = glob([ - "ext/google/protobuf/*.h", - "ext/google/protobuf/*.c", "src/GPBMetadata/Google/Protobuf/**/*.php", "src/Google/Protobuf/**/*.php", ]) + [ "composer.json", - "ext/google/protobuf/wkt.inc", - "ext/google/protobuf/config.m4", - "ext/google/protobuf/package.xml", + ":php_ext_source_files", ], ) @@ -137,3 +135,76 @@ pkg_files( strip_prefix = strip_prefix.from_pkg(""), visibility = ["//pkg:__pkg__"], ) + +################################################################################ +# PECL .tgz Release +################################################################################ + +pkg_files( + name = "php_ext_source_files", + srcs = glob([ + "ext/google/protobuf/*.h", + "ext/google/protobuf/*.c", + ]) + [ + "//:LICENSE", + "ext/google/protobuf/config.m4", + "ext/google/protobuf/wkt.inc", + ], +) + +pkg_files( + name = "utf8_range_files", + srcs = [ + "@utf8_range//:utf8_range_srcs", + "@utf8_range//:LICENSE", + ], + prefix = "third_party/utf8_range", +) + +pkg_filegroup( + name = "pecl_release_files", + srcs = [ + ":php_ext_source_files", + ":utf8_range_files", + ], + prefix = "protobuf-%s" % PROTOBUF_PHP_VERSION, +) + +# PECL .tgz without package.xml +pkg_tar( + name = "release_without_package", + extension = "tgz", + srcs = [ + ":pecl_release_files", + ], + out = "release_without_package.tgz", +) + +# Generate PECL package.xml +genrule( + name = "generate_package_xml", + srcs = [ + ":release_without_package", + "ext/google/protobuf/template_package.xml", + ], + outs = ["package.xml"], + cmd = " ".join([ + "$(location ext/google/protobuf/generate_package_xml.sh)", + "$(location ext/google/protobuf/template_package.xml)", + PROTOBUF_PHP_VERSION, + PROTOC_VERSION, + "$$(tar -tf $(location :release_without_package) | sed -z -e 's;\\n;,;g')", + "$(location package.xml)" + ]), + tools = ["ext/google/protobuf/generate_package_xml.sh"], +) + +pkg_tar( + name = "release", + extension = "tgz", + srcs = [ + ":pecl_release_files", + ":generate_package_xml", + ], + out = "protobuf-%s.tgz" % PROTOBUF_PHP_VERSION, +) diff --git a/php/ext/google/protobuf/generate_package_xml.sh b/php/ext/google/protobuf/generate_package_xml.sh new file mode 100755 index 0000000000..7d4aa94a91 --- /dev/null +++ b/php/ext/google/protobuf/generate_package_xml.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +template_package_xml=$1 +release_version=$2 +protoc_version=$3 +release_files=$4 +out=$5 + +date=$(date +%Y-%m-%d) +time=$(date +%H:%M:%S) + +php_version_array=(${release_version//RC/ }) +api_version=${php_version_array[0]} +if [ ${#php_version_array[@]} -eq 2 ]; then + rc=${php_version_array[1]} + stability='beta' +else + stability='stable' +fi + +files="\\n" +for file in ${release_files//,/ }; do + name=$(echo $file | grep .*[^/]\$ | sed -e "s;protobuf-${release_version}/;;") + if [ ! -z $name ]; then + if [[ $name =~ LICENSE$ ]]; then + role='doc' + else + role='src' + fi + files+=" \\n" + fi +done + +cat $template_package_xml | +sed -e "s;TEMPLATE_DATE;${date};" | +sed -e "s;TEMPLATE_TIME;${time};" | +sed -e "s;TEMPLATE_PHP_RELEASE;${release_version};" | +sed -e "s;TEMPLATE_PHP_API;${api_version};" | +sed -e "s;TEMPLATE_PHP_STABILITY;${stability};g" | +sed -e "s;TEMPLATE_PROTOC_VERSION;${protoc_version};" | +sed -e "s;TEMPLATE_FILES;${files};" > $out diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml deleted file mode 100644 index ecffa138f1..0000000000 --- a/php/ext/google/protobuf/package.xml +++ /dev/null @@ -1,1468 +0,0 @@ - - - protobuf - pecl.php.net - Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. - https://developers.google.com/protocol-buffers/ - - Protobuf Team - protobufpackages - protobuf-packages@google.com - yes - - 2022-10-26 - - - 3.21.9 - 3.21.9 - - - stable - stable - - BSD-3-Clause - - * See github.com/protocolbuffers/protobuf/releases for release notes. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 7.0.0 - - - 1.4.0 - - - - protobuf - - - - - 3.1.0a1 - 3.1.0a1 - - - alpha - alpha - - 2016-09-23 - - BSD-3-Clause - -First alpha release - - - - - 3.2.0a1 - 3.2.0a1 - - - alpha - alpha - - 2017-01-13 - - BSD-3-Clause - -Second alpha release. - - - - - 3.3.0 - 3.3.0 - - - stable - stable - - 2017-04-28 - - BSD-3-Clause - -GA release. - - - - - 3.3.1 - 3.3.0 - - - stable - stable - - 2017-05-08 - - BSD-3-Clause - -GA release. - - - - - 3.3.2 - 3.3.0 - - - stable - stable - - 2017-06-21 - - BSD-3-Clause - -GA release. - - - - - 3.4.0 - 3.4.0 - - - stable - stable - - 2017-08-16 - - BSD-3-Clause - -GA release. - - - - - 3.4.1 - 3.4.1 - - - stable - stable - - 2017-09-14 - - BSD-3-Clause - -GA release. - - - - - 3.5.0 - 3.5.0 - - - stable - stable - - 2017-11-15 - - BSD-3-Clause - -GA release. - - - - - 3.5.0.1 - 3.5.0.1 - - - stable - stable - - 2017-12-06 - - BSD-3-Clause - -GA release. - - - - - 3.5.1 - 3.5.1 - - - stable - stable - - 2017-12-11 - - BSD-3-Clause - -GA release. - - - - - 3.5.2 - 3.5.2 - - - stable - stable - - 2018-03-06 - - BSD-3-Clause - -G A release. - - - - - 3.6.0 - 3.6.0 - - - stable - stable - - 2018-06-06 - - BSD-3-Clause - -G A release. - - - - - 3.6.1 - 3.6.1 - - - stable - stable - - 2018-08-03 - - BSD-3-Clause - -G A release. - - - - - 3.7.0RC2 - 3.7.0 - - - stable - stable - - 2019-02-1 - - BSD-3-Clause - GA release. - - - - 3.7.0RC3 - 3.7.0 - - - beta - beta - - 2019-02-22 - - BSD-3-Clause - GA release. - - - - 3.7.0 - 3.7.0 - - - stable - stable - - 2019-02-28 - - BSD-3-Clause - GA release. - - - - 3.7.1 - 3.7.1 - - - stable - stable - - 2019-03-25 - - BSD-3-Clause - GA release. - - - - 3.8.0RC1 - 3.8.0 - - - beta - beta - - 2019-04-23 - - BSD-3-Clause - GA release. - - - - 3.8.0 - 3.8.0 - - - stable - stable - - 2019-05-21 - - BSD-3-Clause - GA release. - - - - 3.9.0RC1 - 3.9.0 - - - beta - beta - - 2019-06-17 - - BSD-3-Clause - GA release. - - - - 3.9.0 - 3.9.0 - - - stable - stable - - 2019-07-10 - - BSD-3-Clause - GA release. - - - - 3.9.1 - 3.9.1 - - - stable - stable - - 2019-08-02 - - BSD-3-Clause - GA release. - - - - 3.10.0RC1 - 3.10.0 - - - beta - beta - - 2019-09-04 - - BSD-3-Clause - GA release. - - - - 3.10.0RC1 - 3.10.0 - - - beta - beta - - 2019-09-05 - - BSD-3-Clause - GA release. - - - - 3.10.0 - 3.10.0 - - - stable - stable - - 2019-09-12 - - BSD-3-Clause - GA release. - - - - 3.11.0RC1 - 3.11.0 - - - beta - beta - - 2019-11-15 - - BSD-3-Clause - GA release. - - - - 3.11.0RC2 - 3.11.0 - - - beta - beta - - 2019-11-21 - - BSD-3-Clause - GA release. - - - - 3.11.0 - 3.11.0 - - - stable - stable - - 2019-11-25 - - BSD-3-Clause - GA release. - - - - 3.11.1 - 3.11.1 - - - stable - stable - - 2019-12-02 - - BSD-3-Clause - GA release. - - - - 3.11.2 - 3.11.2 - - - stable - stable - - 2019-12-10 - - BSD-3-Clause - GA release. - - - - 3.11.3 - 3.11.3 - - - stable - stable - - 2020-01-28 - - BSD-3-Clause - GA release. - - - - 3.11.4 - 3.11.4 - - - stable - stable - - 2020-02-12 - - BSD-3-Clause - GA release. - - - - 3.12.0RC1 - 3.12.0 - - - beta - beta - - 2020-04-30 - - BSD-3-Clause - GA release. - - - - 3.12.0RC2 - 3.12.0 - - - beta - beta - - 2020-05-12 - - BSD-3-Clause - GA release. - - - - 3.12.0 - 3.12.0 - - - stable - stable - - 2020-05-15 - - BSD-3-Clause - GA release. - - - - 3.12.1 - 3.12.1 - - - stable - stable - - 2020-05-20 - - BSD-3-Clause - GA release. - - - - 3.12.2 - 3.12.2 - - - stable - stable - - 2020-05-26 - - BSD-3-Clause - GA release. - - - - 3.12.3 - 3.12.3 - - - stable - stable - - 2020-06-01 - - BSD-3-Clause - GA release. - - - - 3.13.0RC1 - 3.13.0 - - - beta - beta - - 2020-08-05 - - BSD-3-Clause - GA release. - - - - 3.13.0RC2 - 3.13.0 - - - beta - beta - - 2020-08-05 - - BSD-3-Clause - GA release. - - - - 3.13.0RC3 - 3.13.0 - - - beta - beta - - 2020-08-12 - - BSD-3-Clause - GA release. - - - - 3.13.0 - 3.13.0 - - - stable - stable - - 2020-08-14 - - BSD-3-Clause - GA release. - - - - 3.13.0.1 - 3.13.0.1 - - - stable - stable - - 2020-10-08 - - BSD-3-Clause - GA release. - - - - 3.14.0RC1 - 3.14.0 - - - beta - beta - - 2020-11-05 - - BSD-3-Clause - - - - - - 3.14.0RC2 - 3.14.0 - - - beta - beta - - 2020-11-10 - - BSD-3-Clause - - - - - - 3.14.0RC3 - 3.14.0 - - - beta - beta - - 2020-11-11 - - BSD-3-Clause - - - - - - 3.14.0 - 3.14.0 - - - stable - stable - - 2020-11-12 - - BSD-3-Clause - - - - - - 3.15.0RC1 - 3.15.0 - - - beta - beta - - 2021-02-05 - - BSD-3-Clause - - - - - - 3.15.0RC2 - 3.15.0 - - - beta - beta - - 2021-02-17 - - BSD-3-Clause - - - - - - 3.15.0 - 3.15.0 - - - stable - stable - - 2021-02-18 - - BSD-3-Clause - - - - - - 3.15.1 - 3.15.1 - - - stable - stable - - 2021-02-19 - - BSD-3-Clause - - - - - - 3.15.2 - 3.15.2 - - - stable - stable - - 2021-02-23 - - BSD-3-Clause - - - - - - 3.15.3 - 3.15.3 - - - stable - stable - - 2021-02-24 - - BSD-3-Clause - - - - - - 3.15.4 - 3.15.4 - - - stable - stable - - 2021-03-02 - - BSD-3-Clause - - - - - - 3.15.5 - 3.15.5 - - - stable - stable - - 2021-03-04 - - BSD-3-Clause - - - - - - 3.15.6 - 3.15.6 - - - stable - stable - - 2021-03-10 - - BSD-3-Clause - - - - - - 3.15.7 - 3.15.7 - - - stable - stable - - 2021-04-02 - - BSD-3-Clause - - - - - - 3.16.0RC1 - 3.16.0 - - - beta - beta - - 2021-04-02 - - BSD-3-Clause - - - - - - 3.16.0RC2 - 3.16.0 - - - beta - beta - - 2021-05-03 - - BSD-3-Clause - - - - - - 3.16.0 - 3.16.0 - - - stable - stable - - 2021-05-05 - - BSD-3-Clause - - - - - - 3.17.0RC1 - 3.17.0 - - - beta - beta - - 2021-05-06 - - BSD-3-Clause - - - - - - 3.17.0RC2 - 3.17.0 - - - beta - beta - - 2021-05-07 - - BSD-3-Clause - - - - - - 3.17.0 - 3.17.0 - - - stable - stable - - 2021-05-11 - - BSD-3-Clause - - - - - - 3.17.1 - 3.17.1 - - - stable - stable - - 2021-05-19 - - BSD-3-Clause - - * Fixed PHP memory leaks and arginfo errors. (#8614) - * Fixed JSON parser to allow multiple values from the same oneof as long as - all but one are null. - - - - - 3.17.2 - 3.17.2 - - - stable - stable - - 2021-05-25 - - BSD-3-Clause - - - - - - 3.17.3 - 3.17.3 - - - stable - stable - - 2021-06-04 - - BSD-3-Clause - - - - - - 3.18.0RC1 - 3.18.0 - - - beta - beta - - 2021-08-18 - - BSD-3-Clause - - - - - - 3.18.0RC2 - 3.18.0 - - - beta - beta - - 2021-08-27 - - BSD-3-Clause - - - - - - 3.18.0 - 3.18.0 - - - stable - stable - - 2021-09-13 - - BSD-3-Clause - - - - - - 3.18.1 - 3.18.1 - - - stable - stable - - 2021-10-04 - - BSD-3-Clause - - - - - - 3.19.0RC1 - 3.19.0 - - - beta - beta - - 2021-10-15 - - BSD-3-Clause - - - - - - 3.19.0RC2 - 3.19.0 - - - beta - beta - - 2021-10-18 - - BSD-3-Clause - - - - - - 3.19.0 - 3.19.0 - - - stable - stable - - 2021-10-19 - - BSD-3-Clause - - - - - - 3.19.1 - 3.19.1 - - - stable - stable - - 2021-10-28 - - BSD-3-Clause - - - - - - 3.19.2 - 3.19.2 - - - stable - stable - - 2022-01-05 - - BSD-3-Clause - - - - - - 3.19.3 - 3.19.3 - - - stable - stable - - 2022-01-11 - - BSD-3-Clause - - - - - - 3.19.4 - 3.19.4 - - - stable - stable - - 2022-01-28 - - 3-Clause BSD License - - - - - - 3.20.0RC1 - 3.20.0 - - - beta - beta - - 2022-03-04 - - BSD-3-Clause - - - - - - 3.20.0RC2 - 3.20.0 - - - beta - beta - - 2022-03-15 - - BSD-3-Clause - - - - - - 3.20.0 - 3.20.0 - - - stable - stable - - 2022-03-25 - - BSD-3-Clause - - - - - - 3.20.1RC1 - 3.20.1 - - - beta - beta - - 2022-04-05 - - BSD-3-Clause - - - - - - 3.20.1 - 3.20.1 - - - stable - stable - - 2022-04-20 - - BSD-3-Clause - - - - - - 3.21.0RC1 - 3.21.0 - - - beta - beta - - 2022-05-10 - - BSD-3-Clause - - - - - - 3.21.0RC2 - 3.21.0 - - - beta - beta - - 2022-05-19 - - BSD-3-Clause - - - - - - 3.21.0 - 3.21.0 - - - stable - stable - - 2022-05-25 - - BSD-3-Clause - - - - - - 3.21.1 - 3.21.1 - - - stable - stable - - 2022-05-27 - - BSD-3-Clause - - - - - - 3.21.2 - 3.21.2 - - - stable - stable - - 2022-06-23 - - BSD-3-Clause - - - - - - 3.21.3 - 3.21.3 - - - stable - stable - - 2022-07-21 - - BSD-3-Clause - - - - - - 3.21.4 - 3.21.4 - - - stable - stable - - 2022-07-25 - - BSD-3-Clause - - - - - - 3.21.5 - 3.21.5 - - - stable - stable - - 2022-08-09 - - BSD-3-Clause - - - - - - 3.21.6 - 3.21.6 - - - stable - stable - - 2022-09-13 - - BSD-3-Clause - - - - - - 3.21.7 - 3.21.7 - - - stable - stable - - 2022-09-29 - - BSD-3-Clause - - - - - - 3.21.8 - 3.21.8 - - - stable - stable - - 2022-10-13 - - BSD-3-Clause - - - - - - 3.21.9 - 3.21.9 - - - stable - stable - - 2022-10-26 - - BSD-3-Clause - - - - - diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 0116c2737f..e097674e21 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -25,9 +25,9 @@ */ #if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ - (defined(__cplusplus) && __cplusplus >= 201103L) || \ + (defined(__cplusplus) && __cplusplus >= 201402L) || \ (defined(_MSC_VER) && _MSC_VER >= 1900)) -#error upb requires C99 or C++11 or MSVC >= 2015. +#error upb requires C99 or C++14 or MSVC >= 2015. #endif // Portable check for GCC minimum version: @@ -269,10 +269,132 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #endif +// Must be last. + +const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { + uint64_t u64 = 0; + while (ptr < end) { + unsigned ch = *ptr - '0'; + if (ch >= 10) break; + if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { + return NULL; // integer overflow + } + u64 *= 10; + u64 += ch; + ptr++; + } + + *val = u64; + return ptr; +} + +const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, + bool* is_neg) { + bool neg = false; + uint64_t u64; + + if (ptr != end && *ptr == '-') { + ptr++; + neg = true; + } + + ptr = upb_BufToUint64(ptr, end, &u64); + if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { + return NULL; // integer overflow + } + + *val = neg ? -u64 : u64; + if (is_neg) *is_neg = neg; + return ptr; +} + #include + // Must be last. +static const char _upb_CTypeo_sizelg2[12] = { + 0, + 0, /* kUpb_CType_Bool */ + 2, /* kUpb_CType_Float */ + 2, /* kUpb_CType_Int32 */ + 2, /* kUpb_CType_UInt32 */ + 2, /* kUpb_CType_Enum */ + UPB_SIZE(2, 3), /* kUpb_CType_Message */ + 3, /* kUpb_CType_Double */ + 3, /* kUpb_CType_Int64 */ + 3, /* kUpb_CType_UInt64 */ + UPB_SIZE(3, 4), /* kUpb_CType_String */ + UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ +}; + +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); +} + +size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } + +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; + const char* data = _upb_array_constptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->size); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->size); + memcpy(data + (i << lg2), &val, 1 << lg2); +} + +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + if (!upb_Array_Resize(arr, arr->size + 1, arena)) { + return false; + } + upb_Array_Set(arr, arr->size - 1, val); + return true; +} + +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +} + +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(i <= arr->size); + UPB_ASSERT(count + arr->size >= count); + size_t oldsize = arr->size; + if (!upb_Array_Resize(arr, arr->size + count, arena)) { + return false; + } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; +} + +/* + * i end arr->size + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->size); + upb_Array_Move(arr, i, end, arr->size - end); + arr->size -= count; +} + +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + return _upb_Array_Resize(arr, size, arena); +} + +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// + bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) { size_t new_capacity = UPB_MAX(arr->capacity, 4); int elem_size_lg2 = arr->data & 7; @@ -280,7 +402,7 @@ bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) { size_t new_bytes; void* ptr = _upb_array_ptr(arr); - /* Log2 ceiling of size. */ + // Log2 ceiling of size. while (new_capacity < min_capacity) new_capacity *= 2; new_bytes = new_capacity << elem_size_lg2; @@ -330,46 +452,6 @@ bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, } -// Must be last. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { - uint64_t u64 = 0; - while (ptr < end) { - unsigned ch = *ptr - '0'; - if (ch >= 10) break; - if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { - return NULL; // integer overflow - } - u64 *= 10; - u64 += ch; - ptr++; - } - - *val = u64; - return ptr; -} - -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg) { - bool neg = false; - uint64_t u64; - - if (ptr != end && *ptr == '-') { - ptr++; - neg = true; - } - - ptr = upb_BufToUint64(ptr, end, &u64); - if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { - return NULL; // integer overflow - } - - *val = neg ? -u64 : u64; - if (is_neg) *is_neg = neg; - return ptr; -} - - #include @@ -448,89 +530,197 @@ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { /* void upb_MapIterator_SetValue(upb_Map *map, size_t iter, upb_MessageValue * value); */ -/* This file was generated by upbc (the upb compiler) from the input - * file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. */ -#include +// Must be last. -static const upb_MiniTable_Sub google_protobuf_FileDescriptorSet_submsgs[1] = { - {.submsg = &google_protobuf_FileDescriptorProto_msg_init}, -}; +static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, + void* b_key, size_t size) { + const upb_tabent* const* a = _a; + const upb_tabent* const* b = _b; + upb_StringView a_tabkey = upb_tabstrview((*a)->key); + upb_StringView b_tabkey = upb_tabstrview((*b)->key); + _upb_map_fromkey(a_tabkey, a_key, size); + _upb_map_fromkey(b_tabkey, b_key, size); +} -static const upb_MiniTable_Field google_protobuf_FileDescriptorSet__fields[1] = { - {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, -}; +static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { + int64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return a < b ? -1 : a > b; +} -const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init = { - &google_protobuf_FileDescriptorSet_submsgs[0], - &google_protobuf_FileDescriptorSet__fields[0], - UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, -}; +static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { + uint64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return a < b ? -1 : a > b; +} -static const upb_MiniTable_Sub google_protobuf_FileDescriptorProto_submsgs[6] = { - {.submsg = &google_protobuf_DescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, - {.submsg = &google_protobuf_ServiceDescriptorProto_msg_init}, - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_FileOptions_msg_init}, - {.submsg = &google_protobuf_SourceCodeInfo_msg_init}, -}; +static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { + int32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return a < b ? -1 : a > b; +} -static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[13] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(20, 40), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(24, 48), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(28, 56), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(32, 64), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(36, 72), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(40, 80), UPB_SIZE(3, 3), 4, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(44, 88), UPB_SIZE(4, 4), 5, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(48, 96), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(52, 104), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {12, UPB_SIZE(56, 112), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {13, UPB_SIZE(64, 128), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, -}; +static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { + uint32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return a < b ? -1 : a > b; +} -const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init = { - &google_protobuf_FileDescriptorProto_submsgs[0], - &google_protobuf_FileDescriptorProto__fields[0], - UPB_SIZE(72, 144), 13, kUpb_ExtMode_NonExtendable, 13, 255, 0, -}; +static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { + bool a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); + return a < b ? -1 : a > b; +} -static const upb_MiniTable_Sub google_protobuf_DescriptorProto_submsgs[8] = { - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msg_init}, - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_MessageOptions_msg_init}, - {.submsg = &google_protobuf_OneofDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msg_init}, -}; +static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { + upb_StringView a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); + size_t common_size = UPB_MIN(a.size, b.size); + int cmp = memcmp(a.data, b.data, common_size); + if (cmp) return -cmp; + return a.size < b.size ? -1 : a.size > b.size; +} -static const upb_MiniTable_Field google_protobuf_DescriptorProto__fields[10] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 32), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(20, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(24, 48), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(28, 56), UPB_SIZE(0, 0), 4, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(32, 64), UPB_SIZE(2, 2), 5, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(36, 72), UPB_SIZE(0, 0), 6, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(40, 80), UPB_SIZE(0, 0), 7, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(44, 88), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, -}; +static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { + [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, + [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, + [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, -const upb_MiniTable google_protobuf_DescriptorProto_msg_init = { - &google_protobuf_DescriptorProto_submsgs[0], - &google_protobuf_DescriptorProto__fields[0], + [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, + [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, + + [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, + + [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, + [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, + + [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, + + [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, + [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, +}; + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted) { + int map_size = _upb_Map_Size(map); + sorted->start = s->size; + sorted->pos = sorted->start; + sorted->end = sorted->start + map_size; + + // Grow s->entries if necessary. + if (sorted->end > s->cap) { + s->cap = _upb_Log2CeilingSize(sorted->end); + s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); + if (!s->entries) return false; + } + + s->size = sorted->end; + + // Copy non-empty entries from the table to s->entries. + upb_tabent const** dst = &s->entries[sorted->start]; + const upb_tabent* src = map->table.t.entries; + const upb_tabent* end = src + upb_table_size(&map->table.t); + for (; src < end; src++) { + if (!upb_tabent_isempty(src)) { + *dst = src; + dst++; + } + } + UPB_ASSERT(dst == &s->entries[sorted->end]); + + // Sort entries according to the key type. + qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), + compar[key_type]); + return true; +} +/* This file was generated by upbc (the upb compiler) from the input + * file: + * + * google/protobuf/descriptor.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#include + + +static const upb_MiniTable_Sub google_protobuf_FileDescriptorSet_submsgs[1] = { + {.submsg = &google_protobuf_FileDescriptorProto_msg_init}, +}; + +static const upb_MiniTable_Field google_protobuf_FileDescriptorSet__fields[1] = { + {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init = { + &google_protobuf_FileDescriptorSet_submsgs[0], + &google_protobuf_FileDescriptorSet__fields[0], + UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, +}; + +static const upb_MiniTable_Sub google_protobuf_FileDescriptorProto_submsgs[6] = { + {.submsg = &google_protobuf_DescriptorProto_msg_init}, + {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, + {.submsg = &google_protobuf_ServiceDescriptorProto_msg_init}, + {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, + {.submsg = &google_protobuf_FileOptions_msg_init}, + {.submsg = &google_protobuf_SourceCodeInfo_msg_init}, +}; + +static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[13] = { + {1, UPB_SIZE(40, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(48, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(4, 40), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(8, 48), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(12, 56), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(16, 64), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(20, 72), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(24, 80), UPB_SIZE(3, 3), 4, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {9, UPB_SIZE(28, 88), UPB_SIZE(4, 4), 5, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {10, UPB_SIZE(32, 96), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {11, UPB_SIZE(36, 104), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {12, UPB_SIZE(56, 112), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {13, UPB_SIZE(64, 128), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init = { + &google_protobuf_FileDescriptorProto_submsgs[0], + &google_protobuf_FileDescriptorProto__fields[0], + UPB_SIZE(72, 144), 13, kUpb_ExtMode_NonExtendable, 13, 255, 0, +}; + +static const upb_MiniTable_Sub google_protobuf_DescriptorProto_submsgs[8] = { + {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, + {.submsg = &google_protobuf_DescriptorProto_msg_init}, + {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, + {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msg_init}, + {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, + {.submsg = &google_protobuf_MessageOptions_msg_init}, + {.submsg = &google_protobuf_OneofDescriptorProto_msg_init}, + {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msg_init}, +}; + +static const upb_MiniTable_Field google_protobuf_DescriptorProto__fields[10] = { + {1, UPB_SIZE(40, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(4, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(8, 32), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(12, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(16, 48), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(20, 56), UPB_SIZE(0, 0), 4, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(24, 64), UPB_SIZE(2, 2), 5, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(28, 72), UPB_SIZE(0, 0), 6, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {9, UPB_SIZE(32, 80), UPB_SIZE(0, 0), 7, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {10, UPB_SIZE(36, 88), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable google_protobuf_DescriptorProto_msg_init = { + &google_protobuf_DescriptorProto_submsgs[0], + &google_protobuf_DescriptorProto__fields[0], UPB_SIZE(48, 96), 10, kUpb_ExtMode_NonExtendable, 10, 255, 0, }; @@ -541,7 +731,7 @@ static const upb_MiniTable_Sub google_protobuf_DescriptorProto_ExtensionRange_su static const upb_MiniTable_Field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { {1, UPB_SIZE(4, 4), UPB_SIZE(1, 1), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {2, UPB_SIZE(8, 8), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(12, 16), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(12, 16), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msg_init = { @@ -566,7 +756,7 @@ static const upb_MiniTable_Sub google_protobuf_ExtensionRangeOptions_submsgs[1] }; static const upb_MiniTable_Field google_protobuf_ExtensionRangeOptions__fields[1] = { - {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_ExtensionRangeOptions_msg_init = { @@ -582,17 +772,17 @@ static const upb_MiniTable_Sub google_protobuf_FieldDescriptorProto_submsgs[3] = }; static const upb_MiniTable_Field google_protobuf_FieldDescriptorProto__fields[11] = { - {1, UPB_SIZE(24, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(32, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(28, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(36, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(4, 4), UPB_SIZE(3, 3), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {4, UPB_SIZE(8, 8), UPB_SIZE(4, 4), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {5, UPB_SIZE(12, 12), UPB_SIZE(5, 5), 1, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(40, 56), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(48, 72), UPB_SIZE(7, 7), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(56, 88), UPB_SIZE(8, 8), 2, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(16, 16), UPB_SIZE(9, 9), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(60, 96), UPB_SIZE(10, 10), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {17, UPB_SIZE(20, 20), UPB_SIZE(11, 11), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(44, 56), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(52, 72), UPB_SIZE(7, 7), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(16, 88), UPB_SIZE(8, 8), 2, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {9, UPB_SIZE(20, 16), UPB_SIZE(9, 9), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {10, UPB_SIZE(60, 96), UPB_SIZE(10, 10), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {17, UPB_SIZE(24, 20), UPB_SIZE(11, 11), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_FieldDescriptorProto_msg_init = { @@ -606,8 +796,8 @@ static const upb_MiniTable_Sub google_protobuf_OneofDescriptorProto_submsgs[1] = }; static const upb_MiniTable_Field google_protobuf_OneofDescriptorProto__fields[2] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 24), UPB_SIZE(2, 2), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(8, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(4, 24), UPB_SIZE(2, 2), 0, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_OneofDescriptorProto_msg_init = { @@ -623,11 +813,11 @@ static const upb_MiniTable_Sub google_protobuf_EnumDescriptorProto_submsgs[3] = }; static const upb_MiniTable_Field google_protobuf_EnumDescriptorProto__fields[5] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(20, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(24, 48), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(20, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(4, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(8, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(12, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(16, 48), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_EnumDescriptorProto_msg_init = { @@ -652,9 +842,9 @@ static const upb_MiniTable_Sub google_protobuf_EnumValueDescriptorProto_submsgs[ }; static const upb_MiniTable_Field google_protobuf_EnumValueDescriptorProto__fields[3] = { - {1, UPB_SIZE(8, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(12, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {2, UPB_SIZE(4, 4), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 24), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(8, 24), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msg_init = { @@ -669,9 +859,9 @@ static const upb_MiniTable_Sub google_protobuf_ServiceDescriptorProto_submsgs[2] }; static const upb_MiniTable_Field google_protobuf_ServiceDescriptorProto__fields[3] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(12, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(4, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(8, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_ServiceDescriptorProto_msg_init = { @@ -685,18 +875,18 @@ static const upb_MiniTable_Sub google_protobuf_MethodDescriptorProto_submsgs[1] }; static const upb_MiniTable_Field google_protobuf_MethodDescriptorProto__fields[6] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(12, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(20, 40), UPB_SIZE(3, 3), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(28, 56), UPB_SIZE(4, 4), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(1, 1), UPB_SIZE(5, 5), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(2, 2), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(12, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(20, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(28, 40), UPB_SIZE(3, 3), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(4, 56), UPB_SIZE(4, 4), 0, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(8, 1), UPB_SIZE(5, 5), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(9, 2), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_MethodDescriptorProto_msg_init = { &google_protobuf_MethodDescriptorProto_submsgs[0], &google_protobuf_MethodDescriptorProto__fields[0], - UPB_SIZE(32, 64), 6, kUpb_ExtMode_NonExtendable, 6, 255, 0, + UPB_SIZE(40, 64), 6, kUpb_ExtMode_NonExtendable, 6, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FileOptions_submsgs[2] = { @@ -705,11 +895,11 @@ static const upb_MiniTable_Sub google_protobuf_FileOptions_submsgs[2] = { }; static const upb_MiniTable_Field google_protobuf_FileOptions__fields[21] = { - {1, UPB_SIZE(20, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(28, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(24, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(32, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {9, UPB_SIZE(4, 4), UPB_SIZE(3, 3), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {10, UPB_SIZE(8, 8), UPB_SIZE(4, 4), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(36, 56), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {11, UPB_SIZE(40, 56), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {16, UPB_SIZE(9, 9), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {17, UPB_SIZE(10, 10), UPB_SIZE(7, 7), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {18, UPB_SIZE(11, 11), UPB_SIZE(8, 8), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, @@ -717,15 +907,15 @@ static const upb_MiniTable_Field google_protobuf_FileOptions__fields[21] = { {23, UPB_SIZE(13, 13), UPB_SIZE(10, 10), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {27, UPB_SIZE(14, 14), UPB_SIZE(11, 11), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {31, UPB_SIZE(15, 15), UPB_SIZE(12, 12), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {36, UPB_SIZE(44, 72), UPB_SIZE(13, 13), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {37, UPB_SIZE(52, 88), UPB_SIZE(14, 14), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {39, UPB_SIZE(60, 104), UPB_SIZE(15, 15), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {40, UPB_SIZE(68, 120), UPB_SIZE(16, 16), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {41, UPB_SIZE(76, 136), UPB_SIZE(17, 17), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {36, UPB_SIZE(48, 72), UPB_SIZE(13, 13), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {37, UPB_SIZE(56, 88), UPB_SIZE(14, 14), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {39, UPB_SIZE(64, 104), UPB_SIZE(15, 15), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {40, UPB_SIZE(72, 120), UPB_SIZE(16, 16), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {41, UPB_SIZE(80, 136), UPB_SIZE(17, 17), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {42, UPB_SIZE(16, 16), UPB_SIZE(18, 18), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {44, UPB_SIZE(84, 152), UPB_SIZE(19, 19), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {45, UPB_SIZE(92, 168), UPB_SIZE(20, 20), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(100, 184), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {44, UPB_SIZE(88, 152), UPB_SIZE(19, 19), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {45, UPB_SIZE(96, 168), UPB_SIZE(20, 20), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(20, 184), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_FileOptions_msg_init = { @@ -743,7 +933,7 @@ static const upb_MiniTable_Field google_protobuf_MessageOptions__fields[5] = { {2, UPB_SIZE(2, 2), UPB_SIZE(2, 2), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(3, 3), UPB_SIZE(3, 3), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {7, UPB_SIZE(4, 4), UPB_SIZE(4, 4), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_MessageOptions_msg_init = { @@ -766,7 +956,7 @@ static const upb_MiniTable_Field google_protobuf_FieldOptions__fields[8] = { {6, UPB_SIZE(12, 12), UPB_SIZE(5, 5), 1, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {10, UPB_SIZE(16, 16), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {15, UPB_SIZE(17, 17), UPB_SIZE(7, 7), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(20, 24), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(20, 24), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_FieldOptions_msg_init = { @@ -780,7 +970,7 @@ static const upb_MiniTable_Sub google_protobuf_OneofOptions_submsgs[1] = { }; static const upb_MiniTable_Field google_protobuf_OneofOptions__fields[1] = { - {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_OneofOptions_msg_init = { @@ -796,7 +986,7 @@ static const upb_MiniTable_Sub google_protobuf_EnumOptions_submsgs[1] = { static const upb_MiniTable_Field google_protobuf_EnumOptions__fields[3] = { {2, UPB_SIZE(1, 1), UPB_SIZE(1, 1), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(2, 2), UPB_SIZE(2, 2), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_EnumOptions_msg_init = { @@ -811,7 +1001,7 @@ static const upb_MiniTable_Sub google_protobuf_EnumValueOptions_submsgs[1] = { static const upb_MiniTable_Field google_protobuf_EnumValueOptions__fields[2] = { {1, UPB_SIZE(1, 1), UPB_SIZE(1, 1), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_EnumValueOptions_msg_init = { @@ -826,7 +1016,7 @@ static const upb_MiniTable_Sub google_protobuf_ServiceOptions_submsgs[1] = { static const upb_MiniTable_Field google_protobuf_ServiceOptions__fields[2] = { {33, UPB_SIZE(1, 1), UPB_SIZE(1, 1), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_ServiceOptions_msg_init = { @@ -843,7 +1033,7 @@ static const upb_MiniTable_Sub google_protobuf_MethodOptions_submsgs[2] = { static const upb_MiniTable_Field google_protobuf_MethodOptions__fields[3] = { {33, UPB_SIZE(1, 1), UPB_SIZE(1, 1), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {34, UPB_SIZE(4, 4), UPB_SIZE(2, 2), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_MethodOptions_msg_init = { @@ -857,13 +1047,13 @@ static const upb_MiniTable_Sub google_protobuf_UninterpretedOption_submsgs[1] = }; static const upb_MiniTable_Field google_protobuf_UninterpretedOption__fields[7] = { - {2, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(8, 16), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(32, 64), UPB_SIZE(2, 2), kUpb_NoSub, 4, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(40, 72), UPB_SIZE(3, 3), kUpb_NoSub, 3, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(48, 80), UPB_SIZE(4, 4), kUpb_NoSub, 1, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(16, 32), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(24, 48), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(8, 16), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(16, 32), UPB_SIZE(2, 2), kUpb_NoSub, 4, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(24, 40), UPB_SIZE(3, 3), kUpb_NoSub, 3, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(32, 48), UPB_SIZE(4, 4), kUpb_NoSub, 1, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(40, 56), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(48, 72), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_UninterpretedOption_msg_init = { @@ -873,7 +1063,7 @@ const upb_MiniTable google_protobuf_UninterpretedOption_msg_init = { }; static const upb_MiniTable_Field google_protobuf_UninterpretedOption_NamePart__fields[2] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {2, UPB_SIZE(1, 1), UPB_SIZE(2, 2), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; @@ -888,7 +1078,7 @@ static const upb_MiniTable_Sub google_protobuf_SourceCodeInfo_submsgs[1] = { }; static const upb_MiniTable_Field google_protobuf_SourceCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_SourceCodeInfo_msg_init = { @@ -898,11 +1088,11 @@ const upb_MiniTable google_protobuf_SourceCodeInfo_msg_init = { }; static const upb_MiniTable_Field google_protobuf_SourceCodeInfo_Location__fields[5] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(8, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(12, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(20, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(28, 56), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(8, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(16, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(24, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(12, 56), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msg_init = { @@ -916,7 +1106,7 @@ static const upb_MiniTable_Sub google_protobuf_GeneratedCodeInfo_submsgs[1] = { }; static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_GeneratedCodeInfo_msg_init = { @@ -930,11 +1120,11 @@ static const upb_MiniTable_Sub google_protobuf_GeneratedCodeInfo_Annotation_subm }; static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo_Annotation__fields[5] = { - {1, UPB_SIZE(16, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(20, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(4, 4), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(8, 8), UPB_SIZE(3, 3), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(12, 12), UPB_SIZE(4, 4), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(20, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(8, 4), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(12, 8), UPB_SIZE(3, 3), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(16, 12), UPB_SIZE(4, 4), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msg_init = { @@ -1065,319 +1255,319 @@ const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout = { * regenerated. */ -static const char descriptor[7820] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', -'t', 'o', 'r', '.', 'p', 'r', 'o', 't', 'o', '\022', '\017', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', -'f', '\"', 'M', '\n', '\021', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'S', 'e', 't', '\022', '8', '\n', -'\004', 'f', 'i', 'l', 'e', '\030', '\001', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', -'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', -'\004', 'f', 'i', 'l', 'e', '\"', '\376', '\004', '\n', '\023', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', -'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', -'\030', '\n', '\007', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\007', 'p', 'a', 'c', 'k', 'a', 'g', 'e', -'\022', '\036', '\n', '\n', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\030', '\003', ' ', '\003', '(', '\t', 'R', '\n', 'd', 'e', 'p', -'e', 'n', 'd', 'e', 'n', 'c', 'y', '\022', '+', '\n', '\021', 'p', 'u', 'b', 'l', 'i', 'c', '_', 'd', 'e', 'p', 'e', 'n', 'd', 'e', -'n', 'c', 'y', '\030', '\n', ' ', '\003', '(', '\005', 'R', '\020', 'p', 'u', 'b', 'l', 'i', 'c', 'D', 'e', 'p', 'e', 'n', 'd', 'e', 'n', -'c', 'y', '\022', '\'', '\n', '\017', 'w', 'e', 'a', 'k', '_', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\030', '\013', ' ', '\003', -'(', '\005', 'R', '\016', 'w', 'e', 'a', 'k', 'D', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\022', 'C', '\n', '\014', 'm', 'e', 's', -'s', 'a', 'g', 'e', '_', 't', 'y', 'p', 'e', '\030', '\004', ' ', '\003', '(', '\013', '2', ' ', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', -'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', -'\013', 'm', 'e', 's', 's', 'a', 'g', 'e', 'T', 'y', 'p', 'e', '\022', 'A', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', 'y', 'p', 'e', -'\030', '\005', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', -'E', 'n', 'u', 'm', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\010', 'e', 'n', 'u', 'm', -'T', 'y', 'p', 'e', '\022', 'A', '\n', '\007', 's', 'e', 'r', 'v', 'i', 'c', 'e', '\030', '\006', ' ', '\003', '(', '\013', '2', '\'', '.', 'g', -'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'D', 'e', 's', -'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\007', 's', 'e', 'r', 'v', 'i', 'c', 'e', '\022', 'C', '\n', '\t', -'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\007', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', -'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', -'r', 'o', 't', 'o', 'R', '\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\022', '6', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', -'s', '\030', '\010', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', -'.', 'F', 'i', 'l', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', 'I', '\n', '\020', -'s', 'o', 'u', 'r', 'c', 'e', '_', 'c', 'o', 'd', 'e', '_', 'i', 'n', 'f', 'o', '\030', '\t', ' ', '\001', '(', '\013', '2', '\037', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', -'e', 'I', 'n', 'f', 'o', 'R', '\016', 's', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', '\026', '\n', '\006', -'s', 'y', 'n', 't', 'a', 'x', '\030', '\014', ' ', '\001', '(', '\t', 'R', '\006', 's', 'y', 'n', 't', 'a', 'x', '\022', '\030', '\n', '\007', 'e', -'d', 'i', 't', 'i', 'o', 'n', '\030', '\r', ' ', '\001', '(', '\t', 'R', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\"', '\271', '\006', '\n', -'\017', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', -'\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ';', '\n', '\005', 'f', 'i', 'e', 'l', 'd', '\030', '\002', ' ', '\003', '(', -'\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', -'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'f', 'i', 'e', 'l', 'd', '\022', 'C', '\n', -'\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\006', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', -'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', -'P', 'r', 'o', 't', 'o', 'R', '\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\022', 'A', '\n', '\013', 'n', 'e', 's', 't', 'e', -'d', '_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\003', '(', '\013', '2', ' ', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', -'t', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\n', 'n', 'e', -'s', 't', 'e', 'd', 'T', 'y', 'p', 'e', '\022', 'A', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', 'y', 'p', 'e', '\030', '\004', ' ', '\003', -'(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', -'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\010', 'e', 'n', 'u', 'm', 'T', 'y', 'p', 'e', -'\022', 'X', '\n', '\017', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\005', ' ', '\003', '(', '\013', -'2', '/', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', -'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'R', -'\016', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', 'D', '\n', '\n', 'o', 'n', 'e', 'o', 'f', '_', -'d', 'e', 'c', 'l', '\030', '\010', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', -'b', 'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', -'\t', 'o', 'n', 'e', 'o', 'f', 'D', 'e', 'c', 'l', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\007', ' ', '\001', -'(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 's', 's', -'a', 'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', 'U', '\n', '\016', 'r', 'e', -'s', 'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\t', ' ', '\003', '(', '\013', '2', '.', '.', 'g', 'o', 'o', 'g', -'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', -'t', 'o', '.', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', -'d', 'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\n', -' ', '\003', '(', '\t', 'R', '\014', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', 'z', '\n', '\016', 'E', 'x', 't', -'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', -'\005', 'R', '\005', 's', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', -'d', '\022', '@', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', -'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', -'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\032', '7', '\n', '\r', 'R', 'e', 's', 'e', -'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', -'\005', 's', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', -'|', '\n', '\025', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', -'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', -'\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', -'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', -'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', -'\"', '\301', '\006', '\n', '\024', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', -'\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', -'u', 'm', 'b', 'e', 'r', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', 'A', '\n', '\005', 'l', 'a', -'b', 'e', 'l', '\030', '\004', ' ', '\001', '(', '\016', '2', '+', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', -'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'L', -'a', 'b', 'e', 'l', 'R', '\005', 'l', 'a', 'b', 'e', 'l', '\022', '>', '\n', '\004', 't', 'y', 'p', 'e', '\030', '\005', ' ', '\001', '(', '\016', -'2', '*', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', -'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'T', 'y', 'p', 'e', 'R', '\004', 't', 'y', 'p', 'e', -'\022', '\033', '\n', '\t', 't', 'y', 'p', 'e', '_', 'n', 'a', 'm', 'e', '\030', '\006', ' ', '\001', '(', '\t', 'R', '\010', 't', 'y', 'p', 'e', -'N', 'a', 'm', 'e', '\022', '\032', '\n', '\010', 'e', 'x', 't', 'e', 'n', 'd', 'e', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\010', 'e', -'x', 't', 'e', 'n', 'd', 'e', 'e', '\022', '#', '\n', '\r', 'd', 'e', 'f', 'a', 'u', 'l', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', -'\007', ' ', '\001', '(', '\t', 'R', '\014', 'd', 'e', 'f', 'a', 'u', 'l', 't', 'V', 'a', 'l', 'u', 'e', '\022', '\037', '\n', '\013', 'o', 'n', -'e', 'o', 'f', '_', 'i', 'n', 'd', 'e', 'x', '\030', '\t', ' ', '\001', '(', '\005', 'R', '\n', 'o', 'n', 'e', 'o', 'f', 'I', 'n', 'd', -'e', 'x', '\022', '\033', '\n', '\t', 'j', 's', 'o', 'n', '_', 'n', 'a', 'm', 'e', '\030', '\n', ' ', '\001', '(', '\t', 'R', '\010', 'j', 's', -'o', 'n', 'N', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\010', ' ', '\001', '(', '\013', '2', '\035', -'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', -'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '\'', '\n', '\017', 'p', 'r', 'o', 't', 'o', '3', '_', 'o', -'p', 't', 'i', 'o', 'n', 'a', 'l', '\030', '\021', ' ', '\001', '(', '\010', 'R', '\016', 'p', 'r', 'o', 't', 'o', '3', 'O', 'p', 't', 'i', -'o', 'n', 'a', 'l', '\"', '\266', '\002', '\n', '\004', 'T', 'y', 'p', 'e', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'D', 'O', 'U', -'B', 'L', 'E', '\020', '\001', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'F', 'L', 'O', 'A', 'T', '\020', '\002', '\022', '\016', '\n', '\n', -'T', 'Y', 'P', 'E', '_', 'I', 'N', 'T', '6', '4', '\020', '\003', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', 'T', -'6', '4', '\020', '\004', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'I', 'N', 'T', '3', '2', '\020', '\005', '\022', '\020', '\n', '\014', 'T', -'Y', 'P', 'E', '_', 'F', 'I', 'X', 'E', 'D', '6', '4', '\020', '\006', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'X', -'E', 'D', '3', '2', '\020', '\007', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'B', 'O', 'O', 'L', '\020', '\010', '\022', '\017', '\n', '\013', -'T', 'Y', 'P', 'E', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\t', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'G', 'R', 'O', -'U', 'P', '\020', '\n', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'S', 'S', 'A', 'G', 'E', '\020', '\013', '\022', '\016', '\n', -'\n', 'T', 'Y', 'P', 'E', '_', 'B', 'Y', 'T', 'E', 'S', '\020', '\014', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', -'T', '3', '2', '\020', '\r', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '\020', '\016', '\022', '\021', '\n', '\r', 'T', -'Y', 'P', 'E', '_', 'S', 'F', 'I', 'X', 'E', 'D', '3', '2', '\020', '\017', '\022', '\021', '\n', '\r', 'T', 'Y', 'P', 'E', '_', 'S', 'F', -'I', 'X', 'E', 'D', '6', '4', '\020', '\020', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '3', '2', '\020', '\021', -'\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '6', '4', '\020', '\022', '\"', 'C', '\n', '\005', 'L', 'a', 'b', 'e', -'l', '\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', '_', 'O', 'P', 'T', 'I', 'O', 'N', 'A', 'L', '\020', '\001', '\022', '\022', '\n', '\016', -'L', 'A', 'B', 'E', 'L', '_', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D', '\020', '\002', '\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', -'_', 'R', 'E', 'P', 'E', 'A', 'T', 'E', 'D', '\020', '\003', '\"', 'c', '\n', '\024', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', -'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', -'\004', 'n', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\035', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', -'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', '\343', '\002', '\n', '\023', 'E', 'n', 'u', 'm', 'D', 'e', 's', 'c', -'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', -'R', '\004', 'n', 'a', 'm', 'e', '\022', '?', '\n', '\005', 'v', 'a', 'l', 'u', 'e', '\030', '\002', ' ', '\003', '(', '\013', '2', ')', '.', 'g', -'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', -'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'v', 'a', 'l', 'u', 'e', '\022', '6', '\n', '\007', -'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', -'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', -'n', 's', '\022', ']', '\n', '\016', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\004', ' ', '\003', '(', -'\013', '2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'D', -'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', -'e', 'd', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', -'\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\005', ' ', '\003', '(', '\t', 'R', '\014', 'r', 'e', 's', -'e', 'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', ';', '\n', '\021', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', -'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', '\005', 's', 't', 'a', -'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', '\203', '\001', '\n', '\030', -'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', -'\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', 'u', -'m', 'b', 'e', 'r', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', ';', '\n', '\007', 'o', 'p', 't', -'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '!', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', -'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', -'i', 'o', 'n', 's', '\"', '\247', '\001', '\n', '\026', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', -'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', -'e', '\022', '>', '\n', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\030', '\002', ' ', '\003', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', 'l', -'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', -'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', -'s', '\030', '\003', ' ', '\001', '(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', -'.', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', -'\211', '\002', '\n', '\025', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', -'\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\035', '\n', '\n', 'i', -'n', 'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\t', 'i', 'n', 'p', 'u', 't', 'T', 'y', 'p', -'e', '\022', '\037', '\n', '\013', 'o', 'u', 't', 'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\n', 'o', -'u', 't', 'p', 'u', 't', 'T', 'y', 'p', 'e', '\022', '8', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\004', ' ', '\001', '(', -'\013', '2', '\036', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', -'d', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '0', '\n', '\020', 'c', 'l', 'i', 'e', -'n', 't', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', -'R', '\017', 'c', 'l', 'i', 'e', 'n', 't', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\022', '0', '\n', '\020', 's', 'e', 'r', 'v', -'e', 'r', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\006', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', -'R', '\017', 's', 'e', 'r', 'v', 'e', 'r', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\"', '\221', '\t', '\n', '\013', 'F', 'i', 'l', -'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '!', '\n', '\014', 'j', 'a', 'v', 'a', '_', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', -'\001', ' ', '\001', '(', '\t', 'R', '\013', 'j', 'a', 'v', 'a', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '0', '\n', '\024', 'j', 'a', 'v', -'a', '_', 'o', 'u', 't', 'e', 'r', '_', 'c', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\022', -'j', 'a', 'v', 'a', 'O', 'u', 't', 'e', 'r', 'C', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\022', '5', '\n', '\023', 'j', 'a', 'v', -'a', '_', 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', '_', 'f', 'i', 'l', 'e', 's', '\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', -'a', 'l', 's', 'e', 'R', '\021', 'j', 'a', 'v', 'a', 'M', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'F', 'i', 'l', 'e', 's', '\022', 'D', -'\n', '\035', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'a', 't', 'e', '_', 'e', 'q', 'u', 'a', 'l', 's', '_', 'a', 'n', -'d', '_', 'h', 'a', 's', 'h', '\030', '\024', ' ', '\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\031', 'j', 'a', 'v', 'a', 'G', 'e', 'n', -'e', 'r', 'a', 't', 'e', 'E', 'q', 'u', 'a', 'l', 's', 'A', 'n', 'd', 'H', 'a', 's', 'h', '\022', ':', '\n', '\026', 'j', 'a', 'v', -'a', '_', 's', 't', 'r', 'i', 'n', 'g', '_', 'c', 'h', 'e', 'c', 'k', '_', 'u', 't', 'f', '8', '\030', '\033', ' ', '\001', '(', '\010', -':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'S', 't', 'r', 'i', 'n', 'g', 'C', 'h', 'e', 'c', 'k', 'U', -'t', 'f', '8', '\022', 'S', '\n', '\014', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', '_', 'f', 'o', 'r', '\030', '\t', ' ', '\001', '(', '\016', -'2', ')', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'O', 'p', -'t', 'i', 'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o', 'd', 'e', ':', '\005', 'S', 'P', 'E', 'E', 'D', -'R', '\013', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'F', 'o', 'r', '\022', '\035', '\n', '\n', 'g', 'o', '_', 'p', 'a', 'c', 'k', 'a', -'g', 'e', '\030', '\013', ' ', '\001', '(', '\t', 'R', '\t', 'g', 'o', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '5', '\n', '\023', 'c', 'c', -'_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '\020', ' ', '\001', '(', '\010', ':', '\005', -'f', 'a', 'l', 's', 'e', 'R', '\021', 'c', 'c', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', -'9', '\n', '\025', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', -'\021', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'G', 'e', 'n', 'e', 'r', 'i', 'c', -'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '5', '\n', '\023', 'p', 'y', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', -'r', 'v', 'i', 'c', 'e', 's', '\030', '\022', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\021', 'p', 'y', 'G', 'e', -'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '7', '\n', '\024', 'p', 'h', 'p', '_', 'g', 'e', 'n', 'e', -'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '*', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', -'R', '\022', 'p', 'h', 'p', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '%', '\n', '\n', 'd', -'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\027', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', -'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '.', '\n', '\020', 'c', 'c', '_', 'e', 'n', 'a', 'b', 'l', 'e', '_', 'a', 'r', -'e', 'n', 'a', 's', '\030', '\037', ' ', '\001', '(', '\010', ':', '\004', 't', 'r', 'u', 'e', 'R', '\016', 'c', 'c', 'E', 'n', 'a', 'b', 'l', -'e', 'A', 'r', 'e', 'n', 'a', 's', '\022', '*', '\n', '\021', 'o', 'b', 'j', 'c', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', -'f', 'i', 'x', '\030', '$', ' ', '\001', '(', '\t', 'R', '\017', 'o', 'b', 'j', 'c', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', -'x', '\022', ')', '\n', '\020', 'c', 's', 'h', 'a', 'r', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', '%', ' ', '\001', -'(', '\t', 'R', '\017', 'c', 's', 'h', 'a', 'r', 'p', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 's', 'w', -'i', 'f', 't', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '\'', ' ', '\001', '(', '\t', 'R', '\013', 's', 'w', 'i', 'f', 't', 'P', 'r', -'e', 'f', 'i', 'x', '\022', '(', '\n', '\020', 'p', 'h', 'p', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', -'(', ' ', '\001', '(', '\t', 'R', '\016', 'p', 'h', 'p', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', '\022', '#', '\n', '\r', -'p', 'h', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ')', ' ', '\001', '(', '\t', 'R', '\014', 'p', 'h', 'p', 'N', -'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '4', '\n', '\026', 'p', 'h', 'p', '_', 'm', 'e', 't', 'a', 'd', 'a', 't', 'a', '_', -'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ',', ' ', '\001', '(', '\t', 'R', '\024', 'p', 'h', 'p', 'M', 'e', 't', 'a', 'd', -'a', 't', 'a', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 'r', 'u', 'b', 'y', '_', 'p', 'a', 'c', 'k', -'a', 'g', 'e', '\030', '-', ' ', '\001', '(', '\t', 'R', '\013', 'r', 'u', 'b', 'y', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', 'X', '\n', -'\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', -'\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', -'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', -'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', ':', '\n', '\014', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', -'o', 'd', 'e', '\022', '\t', '\n', '\005', 'S', 'P', 'E', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'C', 'O', 'D', 'E', '_', 'S', 'I', -'Z', 'E', '\020', '\002', '\022', '\020', '\n', '\014', 'L', 'I', 'T', 'E', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', '\020', '\003', '*', '\t', '\010', -'\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '&', '\020', '\'', '\"', '\343', '\002', '\n', '\016', 'M', 'e', 's', 's', 'a', 'g', -'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '<', '\n', '\027', 'm', 'e', 's', 's', 'a', 'g', 'e', '_', 's', 'e', 't', '_', 'w', -'i', 'r', 'e', '_', 'f', 'o', 'r', 'm', 'a', 't', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\024', -'m', 'e', 's', 's', 'a', 'g', 'e', 'S', 'e', 't', 'W', 'i', 'r', 'e', 'F', 'o', 'r', 'm', 'a', 't', '\022', 'L', '\n', '\037', 'n', -'o', '_', 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', '_', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '_', 'a', 'c', 'c', -'e', 's', 's', 'o', 'r', '\030', '\002', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\034', 'n', 'o', 'S', 't', 'a', -'n', 'd', 'a', 'r', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'A', 'c', 'c', 'e', 's', 's', 'o', 'r', '\022', '%', -'\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', -'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\033', '\n', '\t', 'm', 'a', 'p', '_', 'e', 'n', 't', 'r', 'y', -'\030', '\007', ' ', '\001', '(', '\010', 'R', '\010', 'm', 'a', 'p', 'E', 'n', 't', 'r', 'y', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', -'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', -'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', -'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', 'J', '\004', -'\010', '\005', '\020', '\006', 'J', '\004', '\010', '\006', '\020', '\007', 'J', '\004', '\010', '\010', '\020', '\t', 'J', '\004', '\010', '\t', '\020', '\n', '\"', '\222', '\004', -'\n', '\014', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'A', '\n', '\005', 'c', 't', 'y', 'p', 'e', '\030', '\001', -' ', '\001', '(', '\016', '2', '#', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', -'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'C', 'T', 'y', 'p', 'e', ':', '\006', 'S', 'T', 'R', 'I', 'N', 'G', 'R', -'\005', 'c', 't', 'y', 'p', 'e', '\022', '\026', '\n', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\006', 'p', -'a', 'c', 'k', 'e', 'd', '\022', 'G', '\n', '\006', 'j', 's', 't', 'y', 'p', 'e', '\030', '\006', ' ', '\001', '(', '\016', '2', '$', '.', 'g', -'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', -'n', 's', '.', 'J', 'S', 'T', 'y', 'p', 'e', ':', '\t', 'J', 'S', '_', 'N', 'O', 'R', 'M', 'A', 'L', 'R', '\006', 'j', 's', 't', -'y', 'p', 'e', '\022', '\031', '\n', '\004', 'l', 'a', 'z', 'y', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', -'\004', 'l', 'a', 'z', 'y', '\022', '.', '\n', '\017', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', '_', 'l', 'a', 'z', 'y', '\030', -'\017', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\016', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'L', -'a', 'z', 'y', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', -'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\031', '\n', '\004', 'w', 'e', 'a', 'k', -'\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', 'w', 'e', 'a', 'k', '\022', 'X', '\n', '\024', 'u', 'n', -'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', -'2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', -'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', -'t', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', '/', '\n', '\005', 'C', 'T', 'y', 'p', 'e', '\022', '\n', '\n', '\006', 'S', 'T', 'R', -'I', 'N', 'G', '\020', '\000', '\022', '\010', '\n', '\004', 'C', 'O', 'R', 'D', '\020', '\001', '\022', '\020', '\n', '\014', 'S', 'T', 'R', 'I', 'N', 'G', -'_', 'P', 'I', 'E', 'C', 'E', '\020', '\002', '\"', '5', '\n', '\006', 'J', 'S', 'T', 'y', 'p', 'e', '\022', '\r', '\n', '\t', 'J', 'S', '_', -'N', 'O', 'R', 'M', 'A', 'L', '\020', '\000', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\001', '\022', '\r', -'\n', '\t', 'J', 'S', '_', 'N', 'U', 'M', 'B', 'E', 'R', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', -'\004', '\010', '\004', '\020', '\005', '\"', 's', '\n', '\014', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'X', '\n', '\024', -'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', -'(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', -'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', -'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\300', '\001', -'\n', '\013', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '\037', '\n', '\013', 'a', 'l', 'l', 'o', 'w', '_', 'a', 'l', -'i', 'a', 's', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\n', 'a', 'l', 'l', 'o', 'w', 'A', 'l', 'i', 'a', 's', '\022', '%', '\n', '\n', -'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', -'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', -'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', -'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', -'t', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', -'*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\005', '\020', '\006', '\"', '\236', '\001', '\n', '\020', 'E', 'n', 'u', -'m', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', -'e', 'd', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', -'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', -'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', -'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', -'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', -'\200', '\200', '\002', '\"', '\234', '\001', '\n', '\016', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', -'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', -'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', -'t', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', -'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', -'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', -'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\340', '\002', '\n', '\r', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', -'t', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', -':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'q', '\n', '\021', 'i', 'd', -'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', '_', 'l', 'e', 'v', 'e', 'l', '\030', '\"', ' ', '\001', '(', '\016', '2', '/', '.', 'g', -'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', -'o', 'n', 's', '.', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', ':', '\023', 'I', 'D', 'E', -'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', 'R', '\020', 'i', 'd', 'e', 'm', 'p', 'o', 't', -'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', -'d', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', -'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', -'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', -'P', '\n', '\020', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', '\027', '\n', '\023', 'I', 'D', -'E', 'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\017', 'N', 'O', -'_', 'S', 'I', 'D', 'E', '_', 'E', 'F', 'F', 'E', 'C', 'T', 'S', '\020', '\001', '\022', '\016', '\n', '\n', 'I', 'D', 'E', 'M', 'P', 'O', -'T', 'E', 'N', 'T', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\232', '\003', '\n', '\023', 'U', 'n', 'i', -'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\022', 'A', '\n', '\004', 'n', 'a', 'm', 'e', '\030', -'\002', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', -'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '.', 'N', 'a', 'm', 'e', 'P', 'a', -'r', 't', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ')', '\n', '\020', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', '_', 'v', 'a', -'l', 'u', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', 'V', 'a', 'l', 'u', -'e', '\022', ',', '\n', '\022', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\004', -' ', '\001', '(', '\004', 'R', '\020', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', ',', '\n', -'\022', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\005', ' ', '\001', '(', '\003', -'R', '\020', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', '\014', 'd', 'o', 'u', -'b', 'l', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\006', ' ', '\001', '(', '\001', 'R', '\013', 'd', 'o', 'u', 'b', 'l', 'e', 'V', 'a', -'l', 'u', 'e', '\022', '!', '\n', '\014', 's', 't', 'r', 'i', 'n', 'g', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\007', ' ', '\001', '(', '\014', -'R', '\013', 's', 't', 'r', 'i', 'n', 'g', 'V', 'a', 'l', 'u', 'e', '\022', '\'', '\n', '\017', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', -'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\016', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', 'e', 'V', -'a', 'l', 'u', 'e', '\032', 'J', '\n', '\010', 'N', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '\033', '\n', '\t', 'n', 'a', 'm', 'e', '_', -'p', 'a', 'r', 't', '\030', '\001', ' ', '\002', '(', '\t', 'R', '\010', 'n', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '!', '\n', '\014', 'i', -'s', '_', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\002', ' ', '\002', '(', '\010', 'R', '\013', 'i', 's', 'E', 'x', 't', 'e', -'n', 's', 'i', 'o', 'n', '\"', '\247', '\002', '\n', '\016', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', -'D', '\n', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '(', '.', 'g', 'o', 'o', 'g', 'l', -'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', -'.', 'L', 'o', 'c', 'a', 't', 'i', 'o', 'n', 'R', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\032', '\316', '\001', '\n', '\010', 'L', -'o', 'c', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', -'R', '\004', 'p', 'a', 't', 'h', '\022', '\026', '\n', '\004', 's', 'p', 'a', 'n', '\030', '\002', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', -'\004', 's', 'p', 'a', 'n', '\022', ')', '\n', '\020', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', -'\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', '+', -'\n', '\021', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\004', ' ', '\001', '(', '\t', -'R', '\020', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', ':', '\n', '\031', 'l', 'e', 'a', -'d', 'i', 'n', 'g', '_', 'd', 'e', 't', 'a', 'c', 'h', 'e', 'd', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\006', ' ', -'\003', '(', '\t', 'R', '\027', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'D', 'e', 't', 'a', 'c', 'h', 'e', 'd', 'C', 'o', 'm', 'm', 'e', -'n', 't', 's', '\"', '\320', '\002', '\n', '\021', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', -'\022', 'M', '\n', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', -'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', -'d', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 'R', '\n', 'a', 'n', 'n', 'o', 't', 'a', -'t', 'i', 'o', 'n', '\032', '\353', '\001', '\n', '\n', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', -'t', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', '\037', '\n', '\013', 's', 'o', 'u', -'r', 'c', 'e', '_', 'f', 'i', 'l', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\n', 's', 'o', 'u', 'r', 'c', 'e', 'F', 'i', 'l', -'e', '\022', '\024', '\n', '\005', 'b', 'e', 'g', 'i', 'n', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\005', 'b', 'e', 'g', 'i', 'n', '\022', '\020', -'\n', '\003', 'e', 'n', 'd', '\030', '\004', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\022', 'R', '\n', '\010', 's', 'e', 'm', 'a', 'n', -'t', 'i', 'c', '\030', '\005', ' ', '\001', '(', '\016', '2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', -'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', -'t', 'a', 't', 'i', 'o', 'n', '.', 'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', 'R', '\010', 's', 'e', 'm', 'a', 'n', 't', 'i', 'c', -'\"', '(', '\n', '\010', 'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\022', '\010', '\n', '\004', 'N', 'O', 'N', 'E', '\020', '\000', '\022', '\007', '\n', -'\003', 'S', 'E', 'T', '\020', '\001', '\022', '\t', '\n', '\005', 'A', 'L', 'I', 'A', 'S', '\020', '\002', 'B', '~', '\n', '\023', 'c', 'o', 'm', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', -'o', 'r', 'P', 'r', 'o', 't', 'o', 's', 'H', '\001', 'Z', '-', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a', 'n', 'g', -'.', 'o', 'r', 'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'd', 'e', 's', 'c', 'r', -'i', 'p', 't', 'o', 'r', 'p', 'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', 'e', -'.', 'P', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n', +static const char descriptor[7820] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', +'t', 'o', 'r', '.', 'p', 'r', 'o', 't', 'o', '\022', '\017', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', +'f', '\"', 'M', '\n', '\021', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'S', 'e', 't', '\022', '8', '\n', +'\004', 'f', 'i', 'l', 'e', '\030', '\001', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', +'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', +'\004', 'f', 'i', 'l', 'e', '\"', '\376', '\004', '\n', '\023', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', +'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', +'\030', '\n', '\007', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\007', 'p', 'a', 'c', 'k', 'a', 'g', 'e', +'\022', '\036', '\n', '\n', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\030', '\003', ' ', '\003', '(', '\t', 'R', '\n', 'd', 'e', 'p', +'e', 'n', 'd', 'e', 'n', 'c', 'y', '\022', '+', '\n', '\021', 'p', 'u', 'b', 'l', 'i', 'c', '_', 'd', 'e', 'p', 'e', 'n', 'd', 'e', +'n', 'c', 'y', '\030', '\n', ' ', '\003', '(', '\005', 'R', '\020', 'p', 'u', 'b', 'l', 'i', 'c', 'D', 'e', 'p', 'e', 'n', 'd', 'e', 'n', +'c', 'y', '\022', '\'', '\n', '\017', 'w', 'e', 'a', 'k', '_', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\030', '\013', ' ', '\003', +'(', '\005', 'R', '\016', 'w', 'e', 'a', 'k', 'D', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\022', 'C', '\n', '\014', 'm', 'e', 's', +'s', 'a', 'g', 'e', '_', 't', 'y', 'p', 'e', '\030', '\004', ' ', '\003', '(', '\013', '2', ' ', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', +'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', +'\013', 'm', 'e', 's', 's', 'a', 'g', 'e', 'T', 'y', 'p', 'e', '\022', 'A', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', 'y', 'p', 'e', +'\030', '\005', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', +'E', 'n', 'u', 'm', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\010', 'e', 'n', 'u', 'm', +'T', 'y', 'p', 'e', '\022', 'A', '\n', '\007', 's', 'e', 'r', 'v', 'i', 'c', 'e', '\030', '\006', ' ', '\003', '(', '\013', '2', '\'', '.', 'g', +'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'D', 'e', 's', +'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\007', 's', 'e', 'r', 'v', 'i', 'c', 'e', '\022', 'C', '\n', '\t', +'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\007', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', +'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', +'r', 'o', 't', 'o', 'R', '\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\022', '6', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', +'s', '\030', '\010', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', +'.', 'F', 'i', 'l', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', 'I', '\n', '\020', +'s', 'o', 'u', 'r', 'c', 'e', '_', 'c', 'o', 'd', 'e', '_', 'i', 'n', 'f', 'o', '\030', '\t', ' ', '\001', '(', '\013', '2', '\037', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', +'e', 'I', 'n', 'f', 'o', 'R', '\016', 's', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', '\026', '\n', '\006', +'s', 'y', 'n', 't', 'a', 'x', '\030', '\014', ' ', '\001', '(', '\t', 'R', '\006', 's', 'y', 'n', 't', 'a', 'x', '\022', '\030', '\n', '\007', 'e', +'d', 'i', 't', 'i', 'o', 'n', '\030', '\r', ' ', '\001', '(', '\t', 'R', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\"', '\271', '\006', '\n', +'\017', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', +'\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ';', '\n', '\005', 'f', 'i', 'e', 'l', 'd', '\030', '\002', ' ', '\003', '(', +'\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', +'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'f', 'i', 'e', 'l', 'd', '\022', 'C', '\n', +'\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\006', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', +'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', +'P', 'r', 'o', 't', 'o', 'R', '\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\022', 'A', '\n', '\013', 'n', 'e', 's', 't', 'e', +'d', '_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\003', '(', '\013', '2', ' ', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', +'t', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\n', 'n', 'e', +'s', 't', 'e', 'd', 'T', 'y', 'p', 'e', '\022', 'A', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', 'y', 'p', 'e', '\030', '\004', ' ', '\003', +'(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', +'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\010', 'e', 'n', 'u', 'm', 'T', 'y', 'p', 'e', +'\022', 'X', '\n', '\017', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\005', ' ', '\003', '(', '\013', +'2', '/', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', +'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'R', +'\016', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', 'D', '\n', '\n', 'o', 'n', 'e', 'o', 'f', '_', +'d', 'e', 'c', 'l', '\030', '\010', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', +'b', 'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', +'\t', 'o', 'n', 'e', 'o', 'f', 'D', 'e', 'c', 'l', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\007', ' ', '\001', +'(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 's', 's', +'a', 'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', 'U', '\n', '\016', 'r', 'e', +'s', 'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\t', ' ', '\003', '(', '\013', '2', '.', '.', 'g', 'o', 'o', 'g', +'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', +'t', 'o', '.', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', +'d', 'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\n', +' ', '\003', '(', '\t', 'R', '\014', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', 'z', '\n', '\016', 'E', 'x', 't', +'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', +'\005', 'R', '\005', 's', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', +'d', '\022', '@', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', +'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', +'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\032', '7', '\n', '\r', 'R', 'e', 's', 'e', +'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', +'\005', 's', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', +'|', '\n', '\025', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', +'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', +'\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', +'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', +'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', +'\"', '\301', '\006', '\n', '\024', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', +'\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', +'u', 'm', 'b', 'e', 'r', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', 'A', '\n', '\005', 'l', 'a', +'b', 'e', 'l', '\030', '\004', ' ', '\001', '(', '\016', '2', '+', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', +'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'L', +'a', 'b', 'e', 'l', 'R', '\005', 'l', 'a', 'b', 'e', 'l', '\022', '>', '\n', '\004', 't', 'y', 'p', 'e', '\030', '\005', ' ', '\001', '(', '\016', +'2', '*', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', +'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'T', 'y', 'p', 'e', 'R', '\004', 't', 'y', 'p', 'e', +'\022', '\033', '\n', '\t', 't', 'y', 'p', 'e', '_', 'n', 'a', 'm', 'e', '\030', '\006', ' ', '\001', '(', '\t', 'R', '\010', 't', 'y', 'p', 'e', +'N', 'a', 'm', 'e', '\022', '\032', '\n', '\010', 'e', 'x', 't', 'e', 'n', 'd', 'e', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\010', 'e', +'x', 't', 'e', 'n', 'd', 'e', 'e', '\022', '#', '\n', '\r', 'd', 'e', 'f', 'a', 'u', 'l', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', +'\007', ' ', '\001', '(', '\t', 'R', '\014', 'd', 'e', 'f', 'a', 'u', 'l', 't', 'V', 'a', 'l', 'u', 'e', '\022', '\037', '\n', '\013', 'o', 'n', +'e', 'o', 'f', '_', 'i', 'n', 'd', 'e', 'x', '\030', '\t', ' ', '\001', '(', '\005', 'R', '\n', 'o', 'n', 'e', 'o', 'f', 'I', 'n', 'd', +'e', 'x', '\022', '\033', '\n', '\t', 'j', 's', 'o', 'n', '_', 'n', 'a', 'm', 'e', '\030', '\n', ' ', '\001', '(', '\t', 'R', '\010', 'j', 's', +'o', 'n', 'N', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\010', ' ', '\001', '(', '\013', '2', '\035', +'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', +'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '\'', '\n', '\017', 'p', 'r', 'o', 't', 'o', '3', '_', 'o', +'p', 't', 'i', 'o', 'n', 'a', 'l', '\030', '\021', ' ', '\001', '(', '\010', 'R', '\016', 'p', 'r', 'o', 't', 'o', '3', 'O', 'p', 't', 'i', +'o', 'n', 'a', 'l', '\"', '\266', '\002', '\n', '\004', 'T', 'y', 'p', 'e', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'D', 'O', 'U', +'B', 'L', 'E', '\020', '\001', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'F', 'L', 'O', 'A', 'T', '\020', '\002', '\022', '\016', '\n', '\n', +'T', 'Y', 'P', 'E', '_', 'I', 'N', 'T', '6', '4', '\020', '\003', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', 'T', +'6', '4', '\020', '\004', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'I', 'N', 'T', '3', '2', '\020', '\005', '\022', '\020', '\n', '\014', 'T', +'Y', 'P', 'E', '_', 'F', 'I', 'X', 'E', 'D', '6', '4', '\020', '\006', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'X', +'E', 'D', '3', '2', '\020', '\007', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'B', 'O', 'O', 'L', '\020', '\010', '\022', '\017', '\n', '\013', +'T', 'Y', 'P', 'E', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\t', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'G', 'R', 'O', +'U', 'P', '\020', '\n', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'S', 'S', 'A', 'G', 'E', '\020', '\013', '\022', '\016', '\n', +'\n', 'T', 'Y', 'P', 'E', '_', 'B', 'Y', 'T', 'E', 'S', '\020', '\014', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', +'T', '3', '2', '\020', '\r', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '\020', '\016', '\022', '\021', '\n', '\r', 'T', +'Y', 'P', 'E', '_', 'S', 'F', 'I', 'X', 'E', 'D', '3', '2', '\020', '\017', '\022', '\021', '\n', '\r', 'T', 'Y', 'P', 'E', '_', 'S', 'F', +'I', 'X', 'E', 'D', '6', '4', '\020', '\020', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '3', '2', '\020', '\021', +'\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '6', '4', '\020', '\022', '\"', 'C', '\n', '\005', 'L', 'a', 'b', 'e', +'l', '\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', '_', 'O', 'P', 'T', 'I', 'O', 'N', 'A', 'L', '\020', '\001', '\022', '\022', '\n', '\016', +'L', 'A', 'B', 'E', 'L', '_', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D', '\020', '\002', '\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', +'_', 'R', 'E', 'P', 'E', 'A', 'T', 'E', 'D', '\020', '\003', '\"', 'c', '\n', '\024', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', +'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', +'\004', 'n', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\035', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', +'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', '\343', '\002', '\n', '\023', 'E', 'n', 'u', 'm', 'D', 'e', 's', 'c', +'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', +'R', '\004', 'n', 'a', 'm', 'e', '\022', '?', '\n', '\005', 'v', 'a', 'l', 'u', 'e', '\030', '\002', ' ', '\003', '(', '\013', '2', ')', '.', 'g', +'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', +'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'v', 'a', 'l', 'u', 'e', '\022', '6', '\n', '\007', +'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', +'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', +'n', 's', '\022', ']', '\n', '\016', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\004', ' ', '\003', '(', +'\013', '2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'D', +'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', +'e', 'd', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', +'\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\005', ' ', '\003', '(', '\t', 'R', '\014', 'r', 'e', 's', +'e', 'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', ';', '\n', '\021', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', +'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', '\005', 's', 't', 'a', +'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', '\203', '\001', '\n', '\030', +'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', +'\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', 'u', +'m', 'b', 'e', 'r', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', ';', '\n', '\007', 'o', 'p', 't', +'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '!', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', +'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', +'i', 'o', 'n', 's', '\"', '\247', '\001', '\n', '\026', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', +'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', +'e', '\022', '>', '\n', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\030', '\002', ' ', '\003', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', 'l', +'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', +'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', +'s', '\030', '\003', ' ', '\001', '(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', +'.', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', +'\211', '\002', '\n', '\025', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', +'\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\035', '\n', '\n', 'i', +'n', 'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\t', 'i', 'n', 'p', 'u', 't', 'T', 'y', 'p', +'e', '\022', '\037', '\n', '\013', 'o', 'u', 't', 'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\n', 'o', +'u', 't', 'p', 'u', 't', 'T', 'y', 'p', 'e', '\022', '8', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\004', ' ', '\001', '(', +'\013', '2', '\036', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', +'d', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '0', '\n', '\020', 'c', 'l', 'i', 'e', +'n', 't', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', +'R', '\017', 'c', 'l', 'i', 'e', 'n', 't', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\022', '0', '\n', '\020', 's', 'e', 'r', 'v', +'e', 'r', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\006', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', +'R', '\017', 's', 'e', 'r', 'v', 'e', 'r', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\"', '\221', '\t', '\n', '\013', 'F', 'i', 'l', +'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '!', '\n', '\014', 'j', 'a', 'v', 'a', '_', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', +'\001', ' ', '\001', '(', '\t', 'R', '\013', 'j', 'a', 'v', 'a', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '0', '\n', '\024', 'j', 'a', 'v', +'a', '_', 'o', 'u', 't', 'e', 'r', '_', 'c', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\022', +'j', 'a', 'v', 'a', 'O', 'u', 't', 'e', 'r', 'C', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\022', '5', '\n', '\023', 'j', 'a', 'v', +'a', '_', 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', '_', 'f', 'i', 'l', 'e', 's', '\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', +'a', 'l', 's', 'e', 'R', '\021', 'j', 'a', 'v', 'a', 'M', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'F', 'i', 'l', 'e', 's', '\022', 'D', +'\n', '\035', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'a', 't', 'e', '_', 'e', 'q', 'u', 'a', 'l', 's', '_', 'a', 'n', +'d', '_', 'h', 'a', 's', 'h', '\030', '\024', ' ', '\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\031', 'j', 'a', 'v', 'a', 'G', 'e', 'n', +'e', 'r', 'a', 't', 'e', 'E', 'q', 'u', 'a', 'l', 's', 'A', 'n', 'd', 'H', 'a', 's', 'h', '\022', ':', '\n', '\026', 'j', 'a', 'v', +'a', '_', 's', 't', 'r', 'i', 'n', 'g', '_', 'c', 'h', 'e', 'c', 'k', '_', 'u', 't', 'f', '8', '\030', '\033', ' ', '\001', '(', '\010', +':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'S', 't', 'r', 'i', 'n', 'g', 'C', 'h', 'e', 'c', 'k', 'U', +'t', 'f', '8', '\022', 'S', '\n', '\014', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', '_', 'f', 'o', 'r', '\030', '\t', ' ', '\001', '(', '\016', +'2', ')', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'O', 'p', +'t', 'i', 'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o', 'd', 'e', ':', '\005', 'S', 'P', 'E', 'E', 'D', +'R', '\013', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'F', 'o', 'r', '\022', '\035', '\n', '\n', 'g', 'o', '_', 'p', 'a', 'c', 'k', 'a', +'g', 'e', '\030', '\013', ' ', '\001', '(', '\t', 'R', '\t', 'g', 'o', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '5', '\n', '\023', 'c', 'c', +'_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '\020', ' ', '\001', '(', '\010', ':', '\005', +'f', 'a', 'l', 's', 'e', 'R', '\021', 'c', 'c', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', +'9', '\n', '\025', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', +'\021', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'G', 'e', 'n', 'e', 'r', 'i', 'c', +'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '5', '\n', '\023', 'p', 'y', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', +'r', 'v', 'i', 'c', 'e', 's', '\030', '\022', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\021', 'p', 'y', 'G', 'e', +'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '7', '\n', '\024', 'p', 'h', 'p', '_', 'g', 'e', 'n', 'e', +'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '*', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', +'R', '\022', 'p', 'h', 'p', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '%', '\n', '\n', 'd', +'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\027', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', +'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '.', '\n', '\020', 'c', 'c', '_', 'e', 'n', 'a', 'b', 'l', 'e', '_', 'a', 'r', +'e', 'n', 'a', 's', '\030', '\037', ' ', '\001', '(', '\010', ':', '\004', 't', 'r', 'u', 'e', 'R', '\016', 'c', 'c', 'E', 'n', 'a', 'b', 'l', +'e', 'A', 'r', 'e', 'n', 'a', 's', '\022', '*', '\n', '\021', 'o', 'b', 'j', 'c', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', +'f', 'i', 'x', '\030', '$', ' ', '\001', '(', '\t', 'R', '\017', 'o', 'b', 'j', 'c', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', +'x', '\022', ')', '\n', '\020', 'c', 's', 'h', 'a', 'r', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', '%', ' ', '\001', +'(', '\t', 'R', '\017', 'c', 's', 'h', 'a', 'r', 'p', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 's', 'w', +'i', 'f', 't', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '\'', ' ', '\001', '(', '\t', 'R', '\013', 's', 'w', 'i', 'f', 't', 'P', 'r', +'e', 'f', 'i', 'x', '\022', '(', '\n', '\020', 'p', 'h', 'p', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', +'(', ' ', '\001', '(', '\t', 'R', '\016', 'p', 'h', 'p', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', '\022', '#', '\n', '\r', +'p', 'h', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ')', ' ', '\001', '(', '\t', 'R', '\014', 'p', 'h', 'p', 'N', +'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '4', '\n', '\026', 'p', 'h', 'p', '_', 'm', 'e', 't', 'a', 'd', 'a', 't', 'a', '_', +'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ',', ' ', '\001', '(', '\t', 'R', '\024', 'p', 'h', 'p', 'M', 'e', 't', 'a', 'd', +'a', 't', 'a', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 'r', 'u', 'b', 'y', '_', 'p', 'a', 'c', 'k', +'a', 'g', 'e', '\030', '-', ' ', '\001', '(', '\t', 'R', '\013', 'r', 'u', 'b', 'y', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', 'X', '\n', +'\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', +'\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', +'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', +'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', ':', '\n', '\014', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', +'o', 'd', 'e', '\022', '\t', '\n', '\005', 'S', 'P', 'E', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'C', 'O', 'D', 'E', '_', 'S', 'I', +'Z', 'E', '\020', '\002', '\022', '\020', '\n', '\014', 'L', 'I', 'T', 'E', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', '\020', '\003', '*', '\t', '\010', +'\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '&', '\020', '\'', '\"', '\343', '\002', '\n', '\016', 'M', 'e', 's', 's', 'a', 'g', +'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '<', '\n', '\027', 'm', 'e', 's', 's', 'a', 'g', 'e', '_', 's', 'e', 't', '_', 'w', +'i', 'r', 'e', '_', 'f', 'o', 'r', 'm', 'a', 't', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\024', +'m', 'e', 's', 's', 'a', 'g', 'e', 'S', 'e', 't', 'W', 'i', 'r', 'e', 'F', 'o', 'r', 'm', 'a', 't', '\022', 'L', '\n', '\037', 'n', +'o', '_', 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', '_', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '_', 'a', 'c', 'c', +'e', 's', 's', 'o', 'r', '\030', '\002', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\034', 'n', 'o', 'S', 't', 'a', +'n', 'd', 'a', 'r', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'A', 'c', 'c', 'e', 's', 's', 'o', 'r', '\022', '%', +'\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', +'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\033', '\n', '\t', 'm', 'a', 'p', '_', 'e', 'n', 't', 'r', 'y', +'\030', '\007', ' ', '\001', '(', '\010', 'R', '\010', 'm', 'a', 'p', 'E', 'n', 't', 'r', 'y', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', +'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', +'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', +'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', 'J', '\004', +'\010', '\005', '\020', '\006', 'J', '\004', '\010', '\006', '\020', '\007', 'J', '\004', '\010', '\010', '\020', '\t', 'J', '\004', '\010', '\t', '\020', '\n', '\"', '\222', '\004', +'\n', '\014', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'A', '\n', '\005', 'c', 't', 'y', 'p', 'e', '\030', '\001', +' ', '\001', '(', '\016', '2', '#', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', +'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'C', 'T', 'y', 'p', 'e', ':', '\006', 'S', 'T', 'R', 'I', 'N', 'G', 'R', +'\005', 'c', 't', 'y', 'p', 'e', '\022', '\026', '\n', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\006', 'p', +'a', 'c', 'k', 'e', 'd', '\022', 'G', '\n', '\006', 'j', 's', 't', 'y', 'p', 'e', '\030', '\006', ' ', '\001', '(', '\016', '2', '$', '.', 'g', +'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', +'n', 's', '.', 'J', 'S', 'T', 'y', 'p', 'e', ':', '\t', 'J', 'S', '_', 'N', 'O', 'R', 'M', 'A', 'L', 'R', '\006', 'j', 's', 't', +'y', 'p', 'e', '\022', '\031', '\n', '\004', 'l', 'a', 'z', 'y', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', +'\004', 'l', 'a', 'z', 'y', '\022', '.', '\n', '\017', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', '_', 'l', 'a', 'z', 'y', '\030', +'\017', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\016', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'L', +'a', 'z', 'y', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', +'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\031', '\n', '\004', 'w', 'e', 'a', 'k', +'\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', 'w', 'e', 'a', 'k', '\022', 'X', '\n', '\024', 'u', 'n', +'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', +'2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', +'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', +'t', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', '/', '\n', '\005', 'C', 'T', 'y', 'p', 'e', '\022', '\n', '\n', '\006', 'S', 'T', 'R', +'I', 'N', 'G', '\020', '\000', '\022', '\010', '\n', '\004', 'C', 'O', 'R', 'D', '\020', '\001', '\022', '\020', '\n', '\014', 'S', 'T', 'R', 'I', 'N', 'G', +'_', 'P', 'I', 'E', 'C', 'E', '\020', '\002', '\"', '5', '\n', '\006', 'J', 'S', 'T', 'y', 'p', 'e', '\022', '\r', '\n', '\t', 'J', 'S', '_', +'N', 'O', 'R', 'M', 'A', 'L', '\020', '\000', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\001', '\022', '\r', +'\n', '\t', 'J', 'S', '_', 'N', 'U', 'M', 'B', 'E', 'R', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', +'\004', '\010', '\004', '\020', '\005', '\"', 's', '\n', '\014', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'X', '\n', '\024', +'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', +'(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', +'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', +'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\300', '\001', +'\n', '\013', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '\037', '\n', '\013', 'a', 'l', 'l', 'o', 'w', '_', 'a', 'l', +'i', 'a', 's', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\n', 'a', 'l', 'l', 'o', 'w', 'A', 'l', 'i', 'a', 's', '\022', '%', '\n', '\n', +'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', +'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', +'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', +'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', +'t', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', +'*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\005', '\020', '\006', '\"', '\236', '\001', '\n', '\020', 'E', 'n', 'u', +'m', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', +'e', 'd', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', +'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', +'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', +'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', +'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', +'\200', '\200', '\002', '\"', '\234', '\001', '\n', '\016', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', +'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', +'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', +'t', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', +'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', +'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', +'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\340', '\002', '\n', '\r', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', +'t', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', +':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'q', '\n', '\021', 'i', 'd', +'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', '_', 'l', 'e', 'v', 'e', 'l', '\030', '\"', ' ', '\001', '(', '\016', '2', '/', '.', 'g', +'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', +'o', 'n', 's', '.', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', ':', '\023', 'I', 'D', 'E', +'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', 'R', '\020', 'i', 'd', 'e', 'm', 'p', 'o', 't', +'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', +'d', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', +'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', +'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', +'P', '\n', '\020', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', '\027', '\n', '\023', 'I', 'D', +'E', 'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\017', 'N', 'O', +'_', 'S', 'I', 'D', 'E', '_', 'E', 'F', 'F', 'E', 'C', 'T', 'S', '\020', '\001', '\022', '\016', '\n', '\n', 'I', 'D', 'E', 'M', 'P', 'O', +'T', 'E', 'N', 'T', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\232', '\003', '\n', '\023', 'U', 'n', 'i', +'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\022', 'A', '\n', '\004', 'n', 'a', 'm', 'e', '\030', +'\002', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', +'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '.', 'N', 'a', 'm', 'e', 'P', 'a', +'r', 't', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ')', '\n', '\020', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', '_', 'v', 'a', +'l', 'u', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', 'V', 'a', 'l', 'u', +'e', '\022', ',', '\n', '\022', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\004', +' ', '\001', '(', '\004', 'R', '\020', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', ',', '\n', +'\022', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\005', ' ', '\001', '(', '\003', +'R', '\020', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', '\014', 'd', 'o', 'u', +'b', 'l', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\006', ' ', '\001', '(', '\001', 'R', '\013', 'd', 'o', 'u', 'b', 'l', 'e', 'V', 'a', +'l', 'u', 'e', '\022', '!', '\n', '\014', 's', 't', 'r', 'i', 'n', 'g', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\007', ' ', '\001', '(', '\014', +'R', '\013', 's', 't', 'r', 'i', 'n', 'g', 'V', 'a', 'l', 'u', 'e', '\022', '\'', '\n', '\017', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', +'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\016', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', 'e', 'V', +'a', 'l', 'u', 'e', '\032', 'J', '\n', '\010', 'N', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '\033', '\n', '\t', 'n', 'a', 'm', 'e', '_', +'p', 'a', 'r', 't', '\030', '\001', ' ', '\002', '(', '\t', 'R', '\010', 'n', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '!', '\n', '\014', 'i', +'s', '_', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\002', ' ', '\002', '(', '\010', 'R', '\013', 'i', 's', 'E', 'x', 't', 'e', +'n', 's', 'i', 'o', 'n', '\"', '\247', '\002', '\n', '\016', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', +'D', '\n', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '(', '.', 'g', 'o', 'o', 'g', 'l', +'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', +'.', 'L', 'o', 'c', 'a', 't', 'i', 'o', 'n', 'R', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\032', '\316', '\001', '\n', '\010', 'L', +'o', 'c', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', +'R', '\004', 'p', 'a', 't', 'h', '\022', '\026', '\n', '\004', 's', 'p', 'a', 'n', '\030', '\002', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', +'\004', 's', 'p', 'a', 'n', '\022', ')', '\n', '\020', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', +'\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', '+', +'\n', '\021', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\004', ' ', '\001', '(', '\t', +'R', '\020', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', ':', '\n', '\031', 'l', 'e', 'a', +'d', 'i', 'n', 'g', '_', 'd', 'e', 't', 'a', 'c', 'h', 'e', 'd', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\006', ' ', +'\003', '(', '\t', 'R', '\027', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'D', 'e', 't', 'a', 'c', 'h', 'e', 'd', 'C', 'o', 'm', 'm', 'e', +'n', 't', 's', '\"', '\320', '\002', '\n', '\021', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', +'\022', 'M', '\n', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', +'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', +'d', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 'R', '\n', 'a', 'n', 'n', 'o', 't', 'a', +'t', 'i', 'o', 'n', '\032', '\353', '\001', '\n', '\n', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', +'t', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', '\037', '\n', '\013', 's', 'o', 'u', +'r', 'c', 'e', '_', 'f', 'i', 'l', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\n', 's', 'o', 'u', 'r', 'c', 'e', 'F', 'i', 'l', +'e', '\022', '\024', '\n', '\005', 'b', 'e', 'g', 'i', 'n', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\005', 'b', 'e', 'g', 'i', 'n', '\022', '\020', +'\n', '\003', 'e', 'n', 'd', '\030', '\004', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\022', 'R', '\n', '\010', 's', 'e', 'm', 'a', 'n', +'t', 'i', 'c', '\030', '\005', ' ', '\001', '(', '\016', '2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', +'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', +'t', 'a', 't', 'i', 'o', 'n', '.', 'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', 'R', '\010', 's', 'e', 'm', 'a', 'n', 't', 'i', 'c', +'\"', '(', '\n', '\010', 'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\022', '\010', '\n', '\004', 'N', 'O', 'N', 'E', '\020', '\000', '\022', '\007', '\n', +'\003', 'S', 'E', 'T', '\020', '\001', '\022', '\t', '\n', '\005', 'A', 'L', 'I', 'A', 'S', '\020', '\002', 'B', '~', '\n', '\023', 'c', 'o', 'm', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', +'o', 'r', 'P', 'r', 'o', 't', 'o', 's', 'H', '\001', 'Z', '-', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a', 'n', 'g', +'.', 'o', 'r', 'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'd', 'e', 's', 'c', 'r', +'i', 'p', 't', 'o', 'r', 'p', 'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', 'e', +'.', 'P', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n', }; static _upb_DefPool_Init *deps[1] = { @@ -1415,16 +1605,19 @@ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { return r; } -bool _upb_extreg_add(upb_ExtensionRegistry* r, - const upb_MiniTable_Extension** e, size_t count) { +bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, + const upb_MiniTable_Extension** e, + size_t count) { char buf[EXTREG_KEY_SIZE]; const upb_MiniTable_Extension** start = e; const upb_MiniTable_Extension** end = UPB_PTRADD(e, count); for (; e < end; e++) { - // TODO: we should gracefully handle the case where this already exists. - // Right now we're only checking for out of memory. const upb_MiniTable_Extension* ext = *e; extreg_key(buf, ext->extendee, ext->field.number); + upb_value v; + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + goto failure; + } if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, upb_value_constptr(ext), r->arena)) { goto failure; @@ -1442,12 +1635,11 @@ failure: return false; } -const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, - const upb_MiniTable* l, - uint32_t num) { +const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup( + const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { char buf[EXTREG_KEY_SIZE]; upb_value v; - extreg_key(buf, l, num); + extreg_key(buf, t, num); if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { return upb_value_getconstptr(v); } else { @@ -3321,7 +3513,8 @@ static void jsondec_tomsg(jsondec* d, upb_Message* msg, static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - upb_Message* msg = upb_Message_New(m, d->arena); + const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); + upb_Message* msg = upb_Message_New(layout, d->arena); upb_MessageValue val; jsondec_tomsg(d, msg, m); @@ -3583,11 +3776,12 @@ static void jsondec_listvalue(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); + const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array; jsondec_arrstart(d); while (jsondec_arrnext(d)) { - upb_Message* value_msg = upb_Message_New(value_m, d->arena); + upb_Message* value_msg = upb_Message_New(value_layout, d->arena); upb_MessageValue value; value.msg_val = value_msg; upb_Array_Append(values, value, d->arena); @@ -3602,12 +3796,13 @@ static void jsondec_struct(jsondec* d, upb_Message* msg, const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f); + const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map; jsondec_objstart(d); while (jsondec_objnext(d)) { upb_MessageValue key, value; - upb_Message* value_msg = upb_Message_New(value_m, d->arena); + upb_Message* value_msg = upb_Message_New(value_layout, d->arena); key.str_val = jsondec_string(d); value.msg_val = value_msg; upb_Map_Set(fields, key, value, d->arena); @@ -3809,7 +4004,8 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { jsondec_err(d, "Any object didn't contain a '@type' field"); } - any_msg = upb_Message_New(any_m, d->arena); + const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); + any_msg = upb_Message_New(any_layout, d->arena); if (pre_type_data) { size_t len = pre_type_end - pre_type_data + 1; @@ -4281,7 +4477,7 @@ static void jsonenc_any(jsonenc* e, const upb_Message* msg, const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url); const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); upb_Arena* arena = jsonenc_arena(e); - upb_Message* any = upb_Message_New(any_m, arena); + upb_Message* any = upb_Message_New(any_layout, arena); if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { @@ -4672,315 +4868,293 @@ size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, } -#include -#include +#include + +// Must be last. + +static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, + size_t size) { + UPB_UNUSED(alloc); + UPB_UNUSED(oldsize); + if (size == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, size); + } +} + +upb_alloc upb_alloc_global = {&upb_global_allocfunc}; // Must be last. -typedef enum { - kUpb_EncodedType_Double = 0, - kUpb_EncodedType_Float = 1, - kUpb_EncodedType_Fixed32 = 2, - kUpb_EncodedType_Fixed64 = 3, - kUpb_EncodedType_SFixed32 = 4, - kUpb_EncodedType_SFixed64 = 5, - kUpb_EncodedType_Int32 = 6, - kUpb_EncodedType_UInt32 = 7, - kUpb_EncodedType_SInt32 = 8, - kUpb_EncodedType_Int64 = 9, - kUpb_EncodedType_UInt64 = 10, - kUpb_EncodedType_SInt64 = 11, - kUpb_EncodedType_Enum = 12, - kUpb_EncodedType_Bool = 13, - kUpb_EncodedType_Bytes = 14, - kUpb_EncodedType_String = 15, - kUpb_EncodedType_Group = 16, - kUpb_EncodedType_Message = 17, - - kUpb_EncodedType_RepeatedBase = 20, -} upb_EncodedType; +static uint32_t* upb_cleanup_pointer(uintptr_t cleanup_metadata) { + return (uint32_t*)(cleanup_metadata & ~0x1); +} -typedef enum { - kUpb_EncodedFieldModifier_FlipPacked = 1 << 0, - kUpb_EncodedFieldModifier_IsClosedEnum = 1 << 1, - // upb only. - kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2, - kUpb_EncodedFieldModifier_IsRequired = 1 << 3, -} upb_EncodedFieldModifier; +static bool upb_cleanup_has_initial_block(uintptr_t cleanup_metadata) { + return cleanup_metadata & 0x1; +} -enum { - kUpb_EncodedValue_MinField = ' ', - kUpb_EncodedValue_MaxField = 'K', - kUpb_EncodedValue_MinModifier = 'L', - kUpb_EncodedValue_MaxModifier = '[', - kUpb_EncodedValue_End = '^', - kUpb_EncodedValue_MinSkip = '_', - kUpb_EncodedValue_MaxSkip = '~', - kUpb_EncodedValue_OneofSeparator = '~', - kUpb_EncodedValue_FieldSeparator = '|', - kUpb_EncodedValue_MinOneofField = ' ', - kUpb_EncodedValue_MaxOneofField = 'b', - kUpb_EncodedValue_MaxEnumMask = 'A', +static uintptr_t upb_cleanup_metadata(uint32_t* cleanup, + bool has_initial_block) { + return (uintptr_t)cleanup | has_initial_block; +} + +struct mem_block { + struct mem_block* next; + uint32_t size; + uint32_t cleanups; + /* Data follows. */ }; -char upb_ToBase92(int8_t ch) { - static const char kUpb_ToBase92[] = { - ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', - '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', - 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', - 'Z', '[', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '{', '|', '}', '~', - }; +typedef struct cleanup_ent { + upb_CleanupFunc* cleanup; + void* ud; +} cleanup_ent; - UPB_ASSERT(0 <= ch && ch < 92); - return kUpb_ToBase92[ch]; +static const size_t memblock_reserve = + UPB_ALIGN_UP(sizeof(mem_block), UPB_MALLOC_ALIGN); + +static upb_Arena* arena_findroot(upb_Arena* a) { + /* Path splitting keeps time complexity down, see: + * https://en.wikipedia.org/wiki/Disjoint-set_data_structure */ + while (a->parent != a) { + upb_Arena* next = a->parent; + a->parent = next->parent; + a = next; + } + return a; } -char upb_FromBase92(uint8_t ch) { - static const int8_t kUpb_FromBase92[] = { - 0, 1, -1, 2, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, - 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, 58, 59, 60, - 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, - 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, - }; +size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { + arena = arena_findroot(arena); + size_t memsize = 0; + + mem_block* block = arena->freelist; + + while (block) { + memsize += sizeof(mem_block) + block->size; + block = block->next; + } - if (' ' > ch || ch > '~') return -1; - return kUpb_FromBase92[ch - ' ']; + return memsize; } -bool upb_IsTypePackable(upb_FieldType type) { - // clang-format off - static const unsigned kUnpackableTypes = - (1 << kUpb_FieldType_String) | - (1 << kUpb_FieldType_Bytes) | - (1 << kUpb_FieldType_Message) | - (1 << kUpb_FieldType_Group); - // clang-format on - return (1 << type) & ~kUnpackableTypes; +uint32_t upb_Arena_DebugRefCount(upb_Arena* arena) { + return arena_findroot(arena)->refcount; } -/** upb_MtDataEncoder *********************************************************/ +static void upb_Arena_addblock(upb_Arena* a, upb_Arena* root, void* ptr, + size_t size) { + mem_block* block = ptr; -typedef struct { - uint64_t present_values_mask; - uint32_t last_written_value; -} upb_MtDataEncoderInternal_EnumState; + /* The block is for arena |a|, but should appear in the freelist of |root|. */ + block->next = root->freelist; + block->size = (uint32_t)size; + block->cleanups = 0; + root->freelist = block; + a->last_size = block->size; + if (!root->freelist_tail) root->freelist_tail = block; -typedef struct { - uint64_t msg_modifiers; - uint32_t last_field_num; - enum { - kUpb_OneofState_NotStarted, - kUpb_OneofState_StartedOneof, - kUpb_OneofState_EmittedOneofField, - } oneof_state; -} upb_MtDataEncoderInternal_MsgState; + a->head.ptr = UPB_PTR_AT(block, memblock_reserve, char); + a->head.end = UPB_PTR_AT(block, size, char); + a->cleanup_metadata = upb_cleanup_metadata( + &block->cleanups, upb_cleanup_has_initial_block(a->cleanup_metadata)); -typedef struct { - char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. - union { - upb_MtDataEncoderInternal_EnumState enum_state; - upb_MtDataEncoderInternal_MsgState msg_state; - } state; -} upb_MtDataEncoderInternal; + UPB_POISON_MEMORY_REGION(a->head.ptr, a->head.end - a->head.ptr); +} -static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( - upb_MtDataEncoder* e, char* buf_start) { - UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); - upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; - ret->buf_start = buf_start; - return ret; +static bool upb_Arena_Allocblock(upb_Arena* a, size_t size) { + upb_Arena* root = arena_findroot(a); + size_t block_size = UPB_MAX(size, a->last_size * 2) + memblock_reserve; + mem_block* block = upb_malloc(root->block_alloc, block_size); + + if (!block) return false; + upb_Arena_addblock(a, root, block, block_size); + return true; } -static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); - if (ptr == e->end) return NULL; - *ptr++ = upb_ToBase92(ch); - return ptr; +void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size) { + if (!upb_Arena_Allocblock(a, size)) return NULL; /* Out of memory. */ + UPB_ASSERT(_upb_ArenaHas(a) >= size); + return upb_Arena_Malloc(a, size); } -static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, - uint32_t val, int min, int max) { - int shift = _upb_Log2Ceiling(upb_FromBase92(max) - upb_FromBase92(min) + 1); - UPB_ASSERT(shift <= 6); - uint32_t mask = (1 << shift) - 1; - do { - uint32_t bits = val & mask; - ptr = upb_MtDataEncoder_Put(e, ptr, bits + upb_FromBase92(min)); - if (!ptr) return NULL; - val >>= shift; - } while (val); - return ptr; +static void* upb_Arena_doalloc(upb_alloc* alloc, void* ptr, size_t oldsize, + size_t size) { + upb_Arena* a = (upb_Arena*)alloc; /* upb_alloc is initial member. */ + return upb_Arena_Realloc(a, ptr, oldsize, size); } -char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, - uint64_t mod) { - if (mod) { - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier); +/* Public Arena API ***********************************************************/ + +static upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { + const size_t first_block_overhead = sizeof(upb_Arena) + memblock_reserve; + upb_Arena* a; + + /* We need to malloc the initial block. */ + n = first_block_overhead + 256; + if (!alloc || !(mem = upb_malloc(alloc, n))) { + return NULL; } - return ptr; -} -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = msg_mod; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); + a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); + n -= sizeof(*a); + + a->head.alloc.func = &upb_Arena_doalloc; + a->block_alloc = alloc; + a->parent = a; + a->refcount = 1; + a->freelist = NULL; + a->freelist_tail = NULL; + a->cleanup_metadata = upb_cleanup_metadata(NULL, false); + + upb_Arena_addblock(a, a, mem, n); + + return a; } -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - static const char kUpb_TypeToEncoded[] = { - [kUpb_FieldType_Double] = kUpb_EncodedType_Double, - [kUpb_FieldType_Float] = kUpb_EncodedType_Float, - [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, - [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, - [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, - [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, - [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, - [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, - [kUpb_FieldType_String] = kUpb_EncodedType_String, - [kUpb_FieldType_Group] = kUpb_EncodedType_Group, - [kUpb_FieldType_Message] = kUpb_EncodedType_Message, - [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, - [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, - [kUpb_FieldType_Enum] = kUpb_EncodedType_Enum, - [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, - [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, - [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, - [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, - }; +upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { + upb_Arena* a; - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (field_num <= in->state.msg_state.last_field_num) return NULL; - if (in->state.msg_state.last_field_num + 1 != field_num) { - // Put skip. - UPB_ASSERT(field_num > in->state.msg_state.last_field_num); - uint32_t skip = field_num - in->state.msg_state.last_field_num; - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - if (!ptr) return NULL; + if (n) { + /* Align initial pointer up so that we return properly-aligned pointers. */ + void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, UPB_MALLOC_ALIGN); + size_t delta = (uintptr_t)aligned - (uintptr_t)mem; + n = delta <= n ? n - delta : 0; + mem = aligned; } - in->state.msg_state.last_field_num = field_num; - uint32_t encoded_modifiers = 0; + /* Round block size down to alignof(*a) since we will allocate the arena + * itself at the end. */ + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena)); - // Put field type. - if (type == kUpb_FieldType_Enum && - !(field_mod & kUpb_FieldModifier_IsClosedEnum)) { - type = kUpb_FieldType_Int32; + if (UPB_UNLIKELY(n < sizeof(upb_Arena))) { + return arena_initslow(mem, n, alloc); } - int encoded_type = kUpb_TypeToEncoded[type]; - if (field_mod & kUpb_FieldModifier_IsRepeated) { - // Repeated fields shift the type number up (unlike other modifiers which - // are bit flags). - encoded_type += kUpb_EncodedType_RepeatedBase; + a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); - if (upb_IsTypePackable(type)) { - bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; - bool default_is_packed = in->state.msg_state.msg_modifiers & - kUpb_MessageModifier_DefaultIsPacked; - if (field_is_packed != default_is_packed) { - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; + a->head.alloc.func = &upb_Arena_doalloc; + a->block_alloc = alloc; + a->parent = a; + a->refcount = 1; + a->last_size = UPB_MAX(128, n); + a->head.ptr = mem; + a->head.end = UPB_PTR_AT(mem, n - sizeof(*a), char); + a->freelist = NULL; + a->freelist_tail = NULL; + a->cleanup_metadata = upb_cleanup_metadata(NULL, true); + + return a; +} + +static void arena_dofree(upb_Arena* a) { + mem_block* block = a->freelist; + UPB_ASSERT(a->parent == a); + UPB_ASSERT(a->refcount == 0); + + while (block) { + /* Load first since we are deleting block. */ + mem_block* next = block->next; + + if (block->cleanups > 0) { + cleanup_ent* end = UPB_PTR_AT(block, block->size, void); + cleanup_ent* ptr = end - block->cleanups; + + for (; ptr < end; ptr++) { + ptr->cleanup(ptr->ud); } } - } - ptr = upb_MtDataEncoder_Put(e, ptr, encoded_type); - if (!ptr) return NULL; - if (field_mod & kUpb_FieldModifier_IsProto3Singular) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; - } - if (field_mod & kUpb_FieldModifier_IsRequired) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; + upb_free(a->block_alloc, block); + block = next; } - return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); } -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { - ptr = upb_MtDataEncoder_Put(e, ptr, upb_FromBase92(kUpb_EncodedValue_End)); - } else { - ptr = upb_MtDataEncoder_Put( - e, ptr, upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); - } - in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; - return ptr; +void upb_Arena_Free(upb_Arena* a) { + a = arena_findroot(a); + if (--a->refcount == 0) arena_dofree(a); } -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { - ptr = upb_MtDataEncoder_Put( - e, ptr, upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); - if (!ptr) return NULL; +bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func) { + cleanup_ent* ent; + uint32_t* cleanups = upb_cleanup_pointer(a->cleanup_metadata); + + if (!cleanups || _upb_ArenaHas(a) < sizeof(cleanup_ent)) { + if (!upb_Arena_Allocblock(a, 128)) return false; /* Out of memory. */ + UPB_ASSERT(_upb_ArenaHas(a) >= sizeof(cleanup_ent)); + cleanups = upb_cleanup_pointer(a->cleanup_metadata); } - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, upb_ToBase92(0), - upb_ToBase92(63)); - in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; - return ptr; -} -void upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, NULL); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value = 0; -} + a->head.end -= sizeof(cleanup_ent); + ent = (cleanup_ent*)a->head.end; + (*cleanups)++; + UPB_UNPOISON_MEMORY_REGION(ent, sizeof(cleanup_ent)); -static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, - char* ptr) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value += 5; - return ptr; + ent->cleanup = func; + ent->ud = ud; + + return true; } -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val) { - // TODO(b/229641772): optimize this encoding. - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - UPB_ASSERT(val >= in->state.enum_state.last_written_value); - uint32_t delta = val - in->state.enum_state.last_written_value; - if (delta >= 5 && in->state.enum_state.present_values_mask) { - ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; - } - delta -= 5; - } +bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { + upb_Arena* r1 = arena_findroot(a1); + upb_Arena* r2 = arena_findroot(a2); - if (delta >= 5) { - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - in->state.enum_state.last_written_value += delta; - delta = 0; + if (r1 == r2) return true; /* Already fused. */ + + /* Do not fuse initial blocks since we cannot lifetime extend them. */ + if (upb_cleanup_has_initial_block(r1->cleanup_metadata)) return false; + if (upb_cleanup_has_initial_block(r2->cleanup_metadata)) return false; + + /* Only allow fuse with a common allocator */ + if (r1->block_alloc != r2->block_alloc) return false; + + /* We want to join the smaller tree to the larger tree. + * So swap first if they are backwards. */ + if (r1->refcount < r2->refcount) { + upb_Arena* tmp = r1; + r1 = r2; + r2 = tmp; } - UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); - in->state.enum_state.present_values_mask |= 1ULL << delta; - return ptr; + /* r1 takes over r2's freelist and refcount. */ + r1->refcount += r2->refcount; + if (r2->freelist_tail) { + UPB_ASSERT(r2->freelist_tail->next == NULL); + r2->freelist_tail->next = r1->freelist; + r1->freelist = r2->freelist; + } + r2->parent = r1; + return true; } -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (!in->state.enum_state.present_values_mask) return ptr; - return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); -} + +#include + + +// Must be last. + +const char _kUpb_ToBase92[] = { + ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', + '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', + 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', + 'Z', '[', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', + 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '{', '|', '}', '~', +}; + +const int8_t _kUpb_FromBase92[] = { + 0, 1, -1, 2, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, -1, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, +}; const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber( const upb_MiniTable* table, uint32_t number) { @@ -4993,7 +5167,24 @@ const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber( return NULL; } -/** Data decoder **************************************************************/ +upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field) { + if (field->mode & kUpb_LabelFlags_IsAlternate) { + if (field->descriptortype == kUpb_FieldType_Int32) { + return kUpb_FieldType_Enum; + } else if (field->descriptortype == kUpb_FieldType_Bytes) { + return kUpb_FieldType_String; + } else { + UPB_ASSERT(false); + } + } + return field->descriptortype; +} + + +#include + + +// Must be last. // Note: we sort by this number when calculating layout order. typedef enum { @@ -5073,10 +5264,10 @@ static const char* upb_MiniTable_DecodeBase92Varint(upb_MtDecoder* d, uint32_t val = 0; uint32_t shift = 0; const int bits_per_char = - _upb_Log2Ceiling(upb_FromBase92(max) - upb_FromBase92(min)); + _upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min)); char ch = first_ch; while (1) { - uint32_t bits = upb_FromBase92(ch) - upb_FromBase92(min); + uint32_t bits = _upb_FromBase92(ch) - _upb_FromBase92(min); val |= bits << shift; if (ptr == d->end || *ptr < min || max < *ptr) { *out_val = val; @@ -5098,6 +5289,7 @@ static bool upb_MiniTable_HasSub(upb_MiniTable_Field* field, case kUpb_FieldType_String: if (!(msg_modifiers & kUpb_MessageModifier_ValidateUtf8)) { field->descriptortype = kUpb_FieldType_Bytes; + field->mode |= kUpb_LabelFlags_IsAlternate; } return false; default: @@ -5107,15 +5299,23 @@ static bool upb_MiniTable_HasSub(upb_MiniTable_Field* field, static bool upb_MtDecoder_FieldIsPackable(upb_MiniTable_Field* field) { return (field->mode & kUpb_FieldMode_Array) && - upb_IsTypePackable(field->descriptortype); + _upb_FieldType_IsPackable(field->descriptortype); } static void upb_MiniTable_SetTypeAndSub(upb_MiniTable_Field* field, upb_FieldType type, uint32_t* sub_count, - uint64_t msg_modifiers) { + uint64_t msg_modifiers, + bool is_proto3_enum) { field->descriptortype = type; - if (upb_MiniTable_HasSub(field, msg_modifiers)) { - field->submsg_index = sub_count ? (*sub_count)++ : 0; + + if (is_proto3_enum) { + UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum); + field->descriptortype = kUpb_FieldType_Int32; + field->mode |= kUpb_LabelFlags_IsAlternate; + } + + if (upb_MiniTable_HasSub(field, msg_modifiers)) { + field->submsg_index = sub_count ? (*sub_count)++ : 0; } else { field->submsg_index = kUpb_NoSub; } @@ -5126,6 +5326,28 @@ static void upb_MiniTable_SetTypeAndSub(upb_MiniTable_Field* field, } } +static const char kUpb_EncodedToType[] = { + [kUpb_EncodedType_Double] = kUpb_FieldType_Double, + [kUpb_EncodedType_Float] = kUpb_FieldType_Float, + [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, + [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, + [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, + [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, + [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, + [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, + [kUpb_EncodedType_String] = kUpb_FieldType_String, + [kUpb_EncodedType_Group] = kUpb_FieldType_Group, + [kUpb_EncodedType_Message] = kUpb_FieldType_Message, + [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, + [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, + [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, + [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, + [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, + [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, + [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, + [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, +}; + static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, upb_MiniTable_Field* field, uint64_t msg_modifiers, @@ -5140,59 +5362,44 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, [kUpb_EncodedType_Fixed32] = kUpb_FieldRep_4Byte, [kUpb_EncodedType_Bool] = kUpb_FieldRep_1Byte, [kUpb_EncodedType_String] = kUpb_FieldRep_StringView, - [kUpb_EncodedType_Group] = kUpb_FieldRep_Pointer, - [kUpb_EncodedType_Message] = kUpb_FieldRep_Pointer, [kUpb_EncodedType_Bytes] = kUpb_FieldRep_StringView, [kUpb_EncodedType_UInt32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Enum] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_OpenEnum] = kUpb_FieldRep_4Byte, [kUpb_EncodedType_SFixed32] = kUpb_FieldRep_4Byte, [kUpb_EncodedType_SFixed64] = kUpb_FieldRep_8Byte, [kUpb_EncodedType_SInt32] = kUpb_FieldRep_4Byte, [kUpb_EncodedType_SInt64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_ClosedEnum] = kUpb_FieldRep_4Byte, }; - static const char kUpb_EncodedToType[] = { - [kUpb_EncodedType_Double] = kUpb_FieldType_Double, - [kUpb_EncodedType_Float] = kUpb_FieldType_Float, - [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, - [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, - [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, - [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, - [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, - [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, - [kUpb_EncodedType_String] = kUpb_FieldType_String, - [kUpb_EncodedType_Group] = kUpb_FieldType_Group, - [kUpb_EncodedType_Message] = kUpb_FieldType_Message, - [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, - [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, - [kUpb_EncodedType_Enum] = kUpb_FieldType_Enum, - [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, - [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, - [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, - [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, - }; + char pointer_rep = d->platform == kUpb_MiniTablePlatform_32Bit + ? kUpb_FieldRep_4Byte + : kUpb_FieldRep_8Byte; - int8_t type = upb_FromBase92(ch); - if (ch >= upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { + int8_t type = _upb_FromBase92(ch); + if (ch >= _upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { type -= kUpb_EncodedType_RepeatedBase; field->mode = kUpb_FieldMode_Array; - field->mode |= kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift; + field->mode |= pointer_rep << kUpb_FieldRep_Shift; field->offset = kNoPresence; } else { - if (type >= sizeof(kUpb_EncodedToFieldRep)) { + field->mode = kUpb_FieldMode_Scalar; + field->offset = kHasbitPresence; + if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { + field->mode |= pointer_rep << kUpb_FieldRep_Shift; + } else if (type >= sizeof(kUpb_EncodedToFieldRep)) { upb_MtDecoder_ErrorFormat(d, "Invalid field type: %d", (int)type); UPB_UNREACHABLE(); + } else { + field->mode |= kUpb_EncodedToFieldRep[type] << kUpb_FieldRep_Shift; } - field->mode = kUpb_FieldMode_Scalar; - field->mode |= kUpb_EncodedToFieldRep[type] << kUpb_FieldRep_Shift; - field->offset = kHasbitPresence; } if (type >= sizeof(kUpb_EncodedToType)) { upb_MtDecoder_ErrorFormat(d, "Invalid field type: %d", (int)type); UPB_UNREACHABLE(); } upb_MiniTable_SetTypeAndSub(field, kUpb_EncodedToType[type], sub_count, - msg_modifiers); + msg_modifiers, type == kUpb_EncodedType_OpenEnum); } static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, @@ -5260,13 +5467,15 @@ static void upb_MtDecoder_PushOneof(upb_MtDecoder* d, upb_LayoutItem item) { size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, upb_MiniTablePlatform platform) { static const uint8_t kRepToSize32[] = { - [kUpb_FieldRep_1Byte] = 1, [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_Pointer] = 4, [kUpb_FieldRep_StringView] = 8, + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 8, [kUpb_FieldRep_8Byte] = 8, }; static const uint8_t kRepToSize64[] = { - [kUpb_FieldRep_1Byte] = 1, [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_Pointer] = 8, [kUpb_FieldRep_StringView] = 16, + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 16, [kUpb_FieldRep_8Byte] = 8, }; UPB_ASSERT(sizeof(upb_StringView) == @@ -5278,13 +5487,15 @@ size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, size_t upb_MtDecoder_AlignOfRep(upb_FieldRep rep, upb_MiniTablePlatform platform) { static const uint8_t kRepToAlign32[] = { - [kUpb_FieldRep_1Byte] = 1, [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_Pointer] = 4, [kUpb_FieldRep_StringView] = 4, + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 4, [kUpb_FieldRep_8Byte] = 8, }; static const uint8_t kRepToAlign64[] = { - [kUpb_FieldRep_1Byte] = 1, [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_Pointer] = 8, [kUpb_FieldRep_StringView] = 8, + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 8, [kUpb_FieldRep_8Byte] = 8, }; UPB_ASSERT(UPB_ALIGN_OF(upb_StringView) == @@ -5377,7 +5588,9 @@ static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d, static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, uint32_t sub_count) { size_t subs_bytes = sizeof(*d->table->subs) * sub_count; - d->table->subs = upb_Arena_Malloc(d->arena, subs_bytes); + void* subs = upb_Arena_Malloc(d->arena, subs_bytes); + memset(subs, 0, subs_bytes); + d->table->subs = subs; upb_MtDecoder_CheckOutOfMemory(d, d->table->subs); } @@ -5429,6 +5642,9 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, kUpb_EncodedValue_MaxSkip, &skip); last_field_number += skip; last_field_number--; // Next field seen will increment. + } else { + upb_MtDecoder_ErrorFormat(d, "Invalid char: %c", ch); + UPB_UNREACHABLE(); } } @@ -5592,6 +5808,110 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { d->table->size = UPB_ALIGN_UP(d->table->size, 8); } +static void upb_MiniTable_BuildMapEntry(upb_MtDecoder* d, + upb_FieldType key_type, + upb_FieldType value_type, + bool value_is_proto3_enum) { + upb_MiniTable_Field* fields = upb_Arena_Malloc(d->arena, sizeof(*fields) * 2); + if (!fields) { + upb_MtDecoder_ErrorFormat(d, "OOM while building map mini table field"); + UPB_UNREACHABLE(); + } + + upb_MiniTable_Sub* subs = NULL; + if (value_is_proto3_enum) { + UPB_ASSERT(value_type == kUpb_FieldType_Enum); + // No sub needed. + } else if (value_type == kUpb_FieldType_Message || + value_type == kUpb_FieldType_Group || + value_type == kUpb_FieldType_Enum) { + subs = upb_Arena_Malloc(d->arena, sizeof(*subs)); + if (!subs) { + upb_MtDecoder_ErrorFormat(d, "OOM while building map mini table sub"); + UPB_UNREACHABLE(); + } + } + + size_t field_size = + upb_MtDecoder_SizeOfRep(kUpb_FieldRep_StringView, d->platform); + + fields[0].number = 1; + fields[1].number = 2; + fields[0].mode = kUpb_FieldMode_Scalar; + fields[1].mode = kUpb_FieldMode_Scalar; + fields[0].presence = 0; + fields[1].presence = 0; + fields[0].offset = 0; + fields[1].offset = field_size; + + upb_MiniTable_SetTypeAndSub(&fields[0], key_type, NULL, 0, false); + upb_MiniTable_SetTypeAndSub(&fields[1], value_type, NULL, 0, + value_is_proto3_enum); + + upb_MiniTable* ret = d->table; + ret->size = UPB_ALIGN_UP(2 * field_size, 8); + ret->field_count = 2; + ret->ext = kUpb_ExtMode_NonExtendable | kUpb_ExtMode_IsMapEntry; + ret->dense_below = 2; + ret->table_mask = -1; + ret->required_count = 0; + ret->subs = subs; + ret->fields = fields; +} + +static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, + size_t len) { + if (len < 2) { + upb_MtDecoder_ErrorFormat(d, "Invalid map encode length: %zu", len); + UPB_UNREACHABLE(); + } + const upb_EncodedType e0 = _upb_FromBase92(data[0]); + const upb_EncodedType e1 = _upb_FromBase92(data[1]); + switch (e0) { + case kUpb_EncodedType_Fixed32: + case kUpb_EncodedType_Fixed64: + case kUpb_EncodedType_SFixed32: + case kUpb_EncodedType_SFixed64: + case kUpb_EncodedType_Int32: + case kUpb_EncodedType_UInt32: + case kUpb_EncodedType_SInt32: + case kUpb_EncodedType_Int64: + case kUpb_EncodedType_UInt64: + case kUpb_EncodedType_SInt64: + case kUpb_EncodedType_Bool: + case kUpb_EncodedType_String: + break; + + default: + upb_MtDecoder_ErrorFormat(d, "Invalid map key field type: %d", e0); + UPB_UNREACHABLE(); + } + if (e1 >= sizeof(kUpb_EncodedToType)) { + upb_MtDecoder_ErrorFormat(d, "Invalid map value field type: %d", e1); + UPB_UNREACHABLE(); + } + const upb_FieldType key_type = kUpb_EncodedToType[e0]; + const upb_FieldType val_type = kUpb_EncodedToType[e1]; + const bool value_is_proto3_enum = (e1 == kUpb_EncodedType_OpenEnum); + upb_MiniTable_BuildMapEntry(d, key_type, val_type, value_is_proto3_enum); +} + +static void upb_MtDecoder_ParseMessageSet(upb_MtDecoder* d, const char* data, + size_t len) { + if (len > 0) { + upb_MtDecoder_ErrorFormat(d, "Invalid message set encode length: %zu", len); + UPB_UNREACHABLE(); + } + + upb_MiniTable* ret = d->table; + ret->size = 0; + ret->field_count = 0; + ret->ext = kUpb_ExtMode_IsMessageSet; + ret->dense_below = 0; + ret->table_mask = -1; + ret->required_count = 0; +} + upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, upb_MiniTablePlatform platform, upb_Arena* arena, void** buf, @@ -5624,72 +5944,35 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, decoder.table->table_mask = -1; decoder.table->required_count = 0; - upb_MtDecoder_ParseMessage(&decoder, data, len); - upb_MtDecoder_AssignHasbits(decoder.table); - upb_MtDecoder_SortLayoutItems(&decoder); - upb_MtDecoder_AssignOffsets(&decoder); - -done: - *buf = decoder.vec.data; - *buf_size = decoder.vec.capacity * sizeof(*decoder.vec.data); - return decoder.table; -} + // Strip off and verify the version tag. + if (!len--) goto done; + const char vers = *data++; -upb_MiniTable* upb_MiniTable_BuildMessageSet(upb_MiniTablePlatform platform, - upb_Arena* arena) { - upb_MiniTable* ret = upb_Arena_Malloc(arena, sizeof(*ret)); - if (!ret) return NULL; + switch (vers) { + case kUpb_EncodedVersion_MapV1: + upb_MtDecoder_ParseMap(&decoder, data, len); + break; - ret->size = 0; - ret->field_count = 0; - ret->ext = kUpb_ExtMode_IsMessageSet; - ret->dense_below = 0; - ret->table_mask = -1; - ret->required_count = 0; - return ret; -} + case kUpb_EncodedVersion_MessageV1: + upb_MtDecoder_ParseMessage(&decoder, data, len); + upb_MtDecoder_AssignHasbits(decoder.table); + upb_MtDecoder_SortLayoutItems(&decoder); + upb_MtDecoder_AssignOffsets(&decoder); + break; -upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type, - upb_FieldType value_type, - bool value_is_proto3_enum, - upb_MiniTablePlatform platform, - upb_Arena* arena) { - upb_MiniTable* ret = upb_Arena_Malloc(arena, sizeof(*ret)); - upb_MiniTable_Field* fields = upb_Arena_Malloc(arena, sizeof(*fields) * 2); - if (!ret || !fields) return NULL; + case kUpb_EncodedVersion_MessageSetV1: + upb_MtDecoder_ParseMessageSet(&decoder, data, len); + break; - upb_MiniTable_Sub* subs = NULL; - if (value_is_proto3_enum) value_type = kUpb_FieldType_Int32; - if (value_type == kUpb_FieldType_Message || - value_type == kUpb_FieldType_Group || value_type == kUpb_FieldType_Enum) { - subs = upb_Arena_Malloc(arena, sizeof(*subs)); - if (!subs) return NULL; + default: + upb_MtDecoder_ErrorFormat(&decoder, "Invalid message version: %c", vers); + UPB_UNREACHABLE(); } - size_t field_size = - upb_MtDecoder_SizeOfRep(kUpb_FieldRep_StringView, platform); - - fields[0].number = 1; - fields[1].number = 2; - fields[0].mode = kUpb_FieldMode_Scalar; - fields[1].mode = kUpb_FieldMode_Scalar; - fields[0].presence = 0; - fields[1].presence = 0; - fields[0].offset = 0; - fields[1].offset = field_size; - - upb_MiniTable_SetTypeAndSub(&fields[0], key_type, NULL, 0); - upb_MiniTable_SetTypeAndSub(&fields[1], value_type, NULL, 0); - - ret->size = UPB_ALIGN_UP(2 * field_size, 8); - ret->field_count = 2; - ret->ext = kUpb_ExtMode_NonExtendable | kUpb_ExtMode_IsMapEntry; - ret->dense_below = 2; - ret->table_mask = -1; - ret->required_count = 0; - ret->subs = subs; - ret->fields = fields; - return ret; +done: + *buf = decoder.vec.data; + *buf_size = decoder.vec.capacity * sizeof(*decoder.vec.data); + return decoder.table; } static size_t upb_MiniTable_EnumSize(size_t count) { @@ -5731,7 +6014,7 @@ static void upb_MiniTable_BuildEnumValue(upb_MtDecoder* d, uint32_t val) { upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, upb_Arena* arena, upb_Status* status) { - upb_MtDecoder d = { + upb_MtDecoder decoder = { .enum_table = upb_Arena_Malloc(arena, upb_MiniTable_EnumSize(2)), .enum_value_count = 0, .enum_data_count = 0, @@ -5741,33 +6024,41 @@ upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, .arena = arena, }; - if (UPB_SETJMP(d.err)) { - return NULL; + if (UPB_SETJMP(decoder.err)) return NULL; + + // If the string is non-empty then it must begin with a version tag. + if (len) { + if (*data != kUpb_EncodedVersion_EnumV1) { + upb_MtDecoder_ErrorFormat(&decoder, "Invalid enum version: %c", *data); + UPB_UNREACHABLE(); + } + data++; + len--; } - upb_MtDecoder_CheckOutOfMemory(&d, d.enum_table); + upb_MtDecoder_CheckOutOfMemory(&decoder, decoder.enum_table); // Guarantee at least 64 bits of mask without checking mask size. - d.enum_table->mask_limit = 64; - d.enum_table = _upb_MiniTable_AddEnumDataMember(&d, 0); - d.enum_table = _upb_MiniTable_AddEnumDataMember(&d, 0); + decoder.enum_table->mask_limit = 64; + decoder.enum_table = _upb_MiniTable_AddEnumDataMember(&decoder, 0); + decoder.enum_table = _upb_MiniTable_AddEnumDataMember(&decoder, 0); - d.enum_table->value_count = 0; + decoder.enum_table->value_count = 0; const char* ptr = data; uint32_t base = 0; - while (ptr < d.end) { + while (ptr < decoder.end) { char ch = *ptr++; if (ch <= kUpb_EncodedValue_MaxEnumMask) { - uint32_t mask = upb_FromBase92(ch); + uint32_t mask = _upb_FromBase92(ch); for (int i = 0; i < 5; i++, base++, mask >>= 1) { - if (mask & 1) upb_MiniTable_BuildEnumValue(&d, base); + if (mask & 1) upb_MiniTable_BuildEnumValue(&decoder, base); } } else if (kUpb_EncodedValue_MinSkip <= ch && ch <= kUpb_EncodedValue_MaxSkip) { uint32_t skip; - ptr = upb_MiniTable_DecodeBase92Varint(&d, ptr, ch, + ptr = upb_MiniTable_DecodeBase92Varint(&decoder, ptr, ch, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip, &skip); base += skip; @@ -5777,7 +6068,7 @@ upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, } } - return d.enum_table; + return decoder.enum_table; } const char* upb_MiniTable_BuildExtension(const char* data, size_t len, @@ -5791,8 +6082,16 @@ const char* upb_MiniTable_BuildExtension(const char* data, size_t len, .table = NULL, }; - if (UPB_SETJMP(decoder.err)) { - return NULL; + if (UPB_SETJMP(decoder.err)) return NULL; + + // If the string is non-empty then it must begin with a version tag. + if (len) { + if (*data != kUpb_EncodedVersion_ExtensionV1) { + upb_MtDecoder_ErrorFormat(&decoder, "Invalid ext version: %c", *data); + UPB_UNREACHABLE(); + } + data++; + len--; } uint16_t count = 0; @@ -5838,8 +6137,7 @@ void upb_MiniTable_SetSubMessage(upb_MiniTable* table, (uintptr_t)field < (uintptr_t)(table->fields + table->field_count)); if (sub->ext & kUpb_ExtMode_IsMapEntry) { - field->mode = - (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift) | kUpb_FieldMode_Map; + field->mode = (field->mode & ~kUpb_FieldMode_Mask) | kUpb_FieldMode_Map; } upb_MiniTable_Sub* table_sub = (void*)&table->subs[field->submsg_index]; table_sub->submsg = sub; @@ -5854,105 +6152,372 @@ void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field, table_sub->subenum = sub; } - -#include +#include // Must be last. -/* The upb core does not generally have a concept of default instances. However - * for descriptor options we make an exception since the max size is known and - * modest (<200 bytes). All types can share a default instance since it is - * initialized to zeroes. - * - * We have to allocate an extra pointer for upb's internal metadata. */ -static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; -const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; +typedef struct { + uint64_t present_values_mask; + uint32_t last_written_value; +} upb_MtDataEncoderInternal_EnumState; -const char* _upb_DefBuilder_FullToShort(const char* fullname) { - const char* p; +typedef struct { + uint64_t msg_modifiers; + uint32_t last_field_num; + enum { + kUpb_OneofState_NotStarted, + kUpb_OneofState_StartedOneof, + kUpb_OneofState_EmittedOneofField, + } oneof_state; +} upb_MtDataEncoderInternal_MsgState; - if (fullname == NULL) { - return NULL; - } else if ((p = strrchr(fullname, '.')) == NULL) { - /* No '.' in the name, return the full string. */ - return fullname; - } else { - /* Return one past the last '.'. */ - return p + 1; - } +typedef struct { + char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. + union { + upb_MtDataEncoderInternal_EnumState enum_state; + upb_MtDataEncoderInternal_MsgState msg_state; + } state; +} upb_MtDataEncoderInternal; + +static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( + upb_MtDataEncoder* e, char* buf_start) { + UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); + upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; + ret->buf_start = buf_start; + return ret; } -void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } +static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, + char ch) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); + if (ptr == e->end) return NULL; + *ptr++ = ch; + return ptr; +} -void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { - va_list argp; - va_start(argp, fmt); - upb_Status_VSetErrorFormat(ctx->status, fmt, argp); - va_end(argp); - _upb_DefBuilder_FailJmp(ctx); +static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { + return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); } -void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { - upb_Status_SetErrorMessage(ctx->status, "out of memory"); - _upb_DefBuilder_FailJmp(ctx); +static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, + uint32_t val, int min, int max) { + int shift = _upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); + UPB_ASSERT(shift <= 6); + uint32_t mask = (1 << shift) - 1; + do { + uint32_t bits = val & mask; + ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); + if (!ptr) return NULL; + val >>= shift; + } while (val); + return ptr; } -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name) { - if (prefix) { - // ret = prefix + '.' + name; - size_t n = strlen(prefix); - char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); - strcpy(ret, prefix); - ret[n] = '.'; - memcpy(&ret[n + 1], name.data, name.size); - ret[n + 1 + name.size] = '\0'; - return ret; - } else { - char* ret = upb_strdup2(name.data, name.size, ctx->arena); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; +char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, + uint64_t mod) { + if (mod) { + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, + kUpb_EncodedValue_MinModifier, + kUpb_EncodedValue_MaxModifier); } + return ptr; } -static bool remove_component(char* base, size_t* len) { - if (*len == 0) return false; +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - for (size_t i = *len - 1; i > 0; i--) { - if (base[i] == '.') { - *len = i; - return true; - } - } + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); + if (!ptr) return NULL; - *len = 0; - return true; + return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); } -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type) { - if (sym.size == 0) goto notfound; - upb_value v; - if (sym.data[0] == '.') { - /* Symbols starting with '.' are absolute, so we do a single lookup. - * Slice to omit the leading '.' */ - if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { - goto notfound; - } - } else { - /* Remove components from base until we find an entry or run out. */ - size_t baselen = base ? strlen(base) : 0; - char* tmp = malloc(sym.size + baselen + 1); - while (1) { - char* p = tmp; - if (baselen) { - memcpy(p, base, baselen); - p[baselen] = '.'; - p += baselen + 1; +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, + uint64_t value_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); + if (!ptr) return NULL; + + ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, 0); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); +} + +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { + (void)upb_MtDataEncoder_GetInternal(e, ptr); + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); +} + +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = msg_mod; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); +} + +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + static const char kUpb_TypeToEncoded[] = { + [kUpb_FieldType_Double] = kUpb_EncodedType_Double, + [kUpb_FieldType_Float] = kUpb_EncodedType_Float, + [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, + [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, + [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, + [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, + [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, + [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, + [kUpb_FieldType_String] = kUpb_EncodedType_String, + [kUpb_FieldType_Group] = kUpb_EncodedType_Group, + [kUpb_FieldType_Message] = kUpb_EncodedType_Message, + [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, + [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, + [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, + [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, + [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, + [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, + [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, + }; + + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (field_num <= in->state.msg_state.last_field_num) return NULL; + if (in->state.msg_state.last_field_num + 1 != field_num) { + // Put skip. + UPB_ASSERT(field_num > in->state.msg_state.last_field_num); + uint32_t skip = field_num - in->state.msg_state.last_field_num; + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + if (!ptr) return NULL; + } + in->state.msg_state.last_field_num = field_num; + + uint32_t encoded_modifiers = 0; + + // Put field type. + int encoded_type = kUpb_TypeToEncoded[type]; + if (field_mod & kUpb_FieldModifier_IsClosedEnum) { + UPB_ASSERT(type == kUpb_FieldType_Enum); + encoded_type = kUpb_EncodedType_ClosedEnum; + } + if (field_mod & kUpb_FieldModifier_IsRepeated) { + // Repeated fields shift the type number up (unlike other modifiers which + // are bit flags). + encoded_type += kUpb_EncodedType_RepeatedBase; + + if (_upb_FieldType_IsPackable(type)) { + bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; + bool default_is_packed = in->state.msg_state.msg_modifiers & + kUpb_MessageModifier_DefaultIsPacked; + if (field_is_packed != default_is_packed) { + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; + } + } + } + ptr = upb_MtDataEncoder_Put(e, ptr, encoded_type); + if (!ptr) return NULL; + + if (field_mod & kUpb_FieldModifier_IsProto3Singular) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; + } + if (field_mod & kUpb_FieldModifier_IsRequired) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; + } + return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); +} + +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { + ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); + } else { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); + } + in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; + return ptr; +} + +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); + if (!ptr) return NULL; + } + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), + _upb_ToBase92(63)); + in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; + return ptr; +} + +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value = 0; + + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); +} + +static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, + char* ptr) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value += 5; + return ptr; +} + +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val) { + // TODO(b/229641772): optimize this encoding. + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + UPB_ASSERT(val >= in->state.enum_state.last_written_value); + uint32_t delta = val - in->state.enum_state.last_written_value; + if (delta >= 5 && in->state.enum_state.present_values_mask) { + ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); + if (!ptr) { + return NULL; + } + delta -= 5; + } + + if (delta >= 5) { + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + in->state.enum_state.last_written_value += delta; + delta = 0; + } + + UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); + in->state.enum_state.present_values_mask |= 1ULL << delta; + return ptr; +} + +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (!in->state.enum_state.present_values_mask) return ptr; + return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); +} + +#include + + +// Must be last. + +/* The upb core does not generally have a concept of default instances. However + * for descriptor options we make an exception since the max size is known and + * modest (<200 bytes). All types can share a default instance since it is + * initialized to zeroes. + * + * We have to allocate an extra pointer for upb's internal metadata. */ +static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; +const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; + +const char* _upb_DefBuilder_FullToShort(const char* fullname) { + const char* p; + + if (fullname == NULL) { + return NULL; + } else if ((p = strrchr(fullname, '.')) == NULL) { + /* No '.' in the name, return the full string. */ + return fullname; + } else { + /* Return one past the last '.'. */ + return p + 1; + } +} + +void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } + +void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { + va_list argp; + va_start(argp, fmt); + upb_Status_VSetErrorFormat(ctx->status, fmt, argp); + va_end(argp); + _upb_DefBuilder_FailJmp(ctx); +} + +void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { + upb_Status_SetErrorMessage(ctx->status, "out of memory"); + _upb_DefBuilder_FailJmp(ctx); +} + +const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, + const char* prefix, + upb_StringView name) { + if (prefix) { + // ret = prefix + '.' + name; + size_t n = strlen(prefix); + char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); + strcpy(ret, prefix); + ret[n] = '.'; + memcpy(&ret[n + 1], name.data, name.size); + ret[n + 1 + name.size] = '\0'; + return ret; + } else { + char* ret = upb_strdup2(name.data, name.size, ctx->arena); + if (!ret) _upb_DefBuilder_OomErr(ctx); + return ret; + } +} + +static bool remove_component(char* base, size_t* len) { + if (*len == 0) return false; + + for (size_t i = *len - 1; i > 0; i--) { + if (base[i] == '.') { + *len = i; + return true; + } + } + + *len = 0; + return true; +} + +const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, + const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t* type) { + if (sym.size == 0) goto notfound; + upb_value v; + if (sym.data[0] == '.') { + /* Symbols starting with '.' are absolute, so we do a single lookup. + * Slice to omit the leading '.' */ + if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { + goto notfound; + } + } else { + /* Remove components from base until we find an entry or run out. */ + size_t baselen = base ? strlen(base) : 0; + char* tmp = malloc(sym.size + baselen + 1); + while (1) { + char* p = tmp; + if (baselen) { + memcpy(p, base, baselen); + p[baselen] = '.'; + p += baselen + 1; } memcpy(p, sym.data, sym.size); p += sym.size; @@ -6164,7 +6729,6 @@ void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, } - // Must be last. struct upb_DefPool { @@ -6529,7 +7093,7 @@ size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } -const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( +const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( const upb_DefPool* s, const upb_MiniTable_Extension* ext) { upb_value v; bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); @@ -6540,9 +7104,10 @@ const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, const upb_MessageDef* m, int32_t fieldnum) { - const upb_MiniTable* l = upb_MessageDef_MiniTable(m); - const upb_MiniTable_Extension* ext = _upb_extreg_get(s->extreg, l, fieldnum); - return ext ? _upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; + const upb_MiniTable* t = upb_MessageDef_MiniTable(m); + const upb_MiniTable_Extension* ext = + upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); + return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; } const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( @@ -6626,7 +7191,6 @@ bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { return true; } - #include @@ -6735,6 +7299,11 @@ const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { return _upb_EnumValueDef_At(e->values, i); } +bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; + return upb_FileDef_Syntax(e->file) == kUpb_Syntax_Proto2; +} + bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, upb_StringView* out) { upb_DescState s; @@ -6746,7 +7315,8 @@ bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, if (!sorted) return false; } - upb_MtDataEncoder_StartEnum(&s.e); + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_StartEnum(&s.e, s.ptr); // Duplicate values are allowed but we only encode each value once. uint32_t previous = 0; @@ -6822,7 +7392,7 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, e->full_name); } - UBP_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); + UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); upb_inttable_compact(&e->iton, ctx->arena); @@ -6857,7 +7427,6 @@ upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, } - // Must be last. struct upb_EnumValueDef { @@ -6931,7 +7500,7 @@ static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, _upb_DefBuilder_Add(ctx, v->full_name, _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - UBP_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, + UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, val_proto); bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); @@ -6969,7 +7538,6 @@ upb_EnumValueDef* _upb_EnumValueDefs_New( } - // Must be last. struct upb_ExtensionRange { @@ -7024,14 +7592,13 @@ upb_ExtensionRange* _upb_ExtensionRanges_New( r[i].start = start; r[i].end = end; - UBP_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, + UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, ExtensionRangeOptions, protos[i]); } return r; } - #include #include @@ -7243,13 +7810,6 @@ bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f) { if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; if (f->type_ != kUpb_FieldType_Enum) return false; - // TODO(https://github.com/protocolbuffers/upb/issues/541): - // fix map enum values to check for unknown enum values and put - // them in the unknown field set. - if (upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f))) { - return false; - } - // TODO: Maybe make is_proto2 a bool at creation? const upb_FileDef* file = upb_EnumDef_File(f->sub.enumdef); return upb_FileDef_Syntax(file) == kUpb_Syntax_Proto2; @@ -7643,7 +8203,7 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, if (!ok) _upb_DefBuilder_OomErr(ctx); } - UBP_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); + UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); if (google_protobuf_FieldOptions_has_packed(f->opts)) { f->is_packed_ = google_protobuf_FieldOptions_packed(f->opts); @@ -7819,16 +8379,12 @@ bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, upb_DescState s; _upb_DescState_Init(&s); - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartMessage(&s.e, s.ptr, 0); - const int number = upb_FieldDef_Number(f); const uint64_t modifiers = _upb_FieldDef_Modifiers(f); if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutField(&s.e, s.ptr, f->type_, number, modifiers); - - if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_EncodeExtension(&s.e, s.ptr, f->type_, number, + modifiers); *s.ptr = '\0'; out->data = s.buf; @@ -7867,21 +8423,16 @@ static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, } upb_MiniTable_Extension* mut_ext = (upb_MiniTable_Extension*)ext; - upb_MiniTable_Sub sub; - sub.submsg = NULL; - sub.subenum = NULL; + upb_MiniTable_Sub sub = {NULL}; + if (upb_FieldDef_IsSubMessage(f)) { + sub.submsg = upb_MessageDef_MiniTable(f->sub.msgdef); + } else if (_upb_FieldDef_IsClosedEnum(f)) { + sub.subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); + } bool ok2 = upb_MiniTable_BuildExtension(desc.data, desc.size, mut_ext, upb_MessageDef_MiniTable(m), sub, ctx->status); if (!ok2) _upb_DefBuilder_Errf(ctx, "Could not build extension mini table"); - - assert(mut_ext->field.number == f->number_); - mut_ext->extendee = upb_MessageDef_MiniTable(m); - if (upb_FieldDef_IsSubMessage(f)) { - mut_ext->sub.submsg = upb_MessageDef_MiniTable(f->sub.msgdef); - } else if (mut_ext->field.descriptortype == kUpb_FieldType_Enum) { - mut_ext->sub.subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); - } } bool ok = _upb_DefPool_InsertExt(ctx->symtab, ext, f); @@ -7930,7 +8481,6 @@ void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, } - // Must be last. struct upb_FileDef { @@ -8150,7 +8700,7 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, } // Read options. - UBP_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); + UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); // Verify dependencies. strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n); @@ -8235,8 +8785,8 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, } if (file->ext_count) { - bool ok = _upb_extreg_add(_upb_DefPool_ExtReg(ctx->symtab), - file->ext_layouts, file->ext_count); + bool ok = upb_ExtensionRegistry_AddArray( + _upb_DefPool_ExtReg(ctx->symtab), file->ext_layouts, file->ext_count); if (!ok) _upb_DefBuilder_OomErr(ctx); } } @@ -8272,10 +8822,6 @@ static size_t get_field_size(const upb_MiniTable_Field* f) { return upb_IsRepeatedOrMap(f) ? sizeof(void*) : sizes[f->descriptortype]; } -upb_Message* upb_Message_New(const upb_MessageDef* m, upb_Arena* a) { - return _upb_Message_New(upb_MessageDef_MiniTable(m), a); -} - static bool in_oneof(const upb_MiniTable_Field* field) { return field->presence < 0; } @@ -8370,7 +8916,8 @@ make: ret.array = upb_Array_New(a, upb_FieldDef_CType(f)); } else { UPB_ASSERT(upb_FieldDef_IsSubMessage(f)); - ret.msg = upb_Message_New(upb_FieldDef_MessageSubDef(f), a); + const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); + ret.msg = upb_Message_New(upb_MessageDef_MiniTable(m), a); } val.array_val = ret.array; @@ -8476,7 +9023,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (i - n < count) { ext += count - 1 - (i - n); memcpy(out_val, &ext->data, sizeof(*out_val)); - *out_f = _upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); + *out_f = upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); *iter = i; return true; } @@ -8542,7 +9089,6 @@ bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, } - // Must be last. struct upb_MessageDef { @@ -8581,7 +9127,7 @@ struct upb_MessageDef { }; static void assign_msg_wellknowntype(upb_MessageDef* m) { - const char* name = upb_MessageDef_FullName(m); + const char* name = m->full_name; if (name == NULL) { m->well_known_type = kUpb_WellKnown_Unspecified; return; @@ -8637,8 +9183,7 @@ bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { return false; } -const google_protobuf_MessageOptions* upb_MessageDef_Options( - const upb_MessageDef* m) { +const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDef* m) { return m->opts; } @@ -8812,40 +9357,15 @@ const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, } bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_map_entry(upb_MessageDef_Options(m)); + return google_protobuf_MessageOptions_map_entry(m->opts); } bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_message_set_wire_format( - upb_MessageDef_Options(m)); + return google_protobuf_MessageOptions_message_set_wire_format(m->opts); } static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, const upb_MessageDef* m) { - if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { - return upb_MiniTable_BuildMessageSet(kUpb_MiniTablePlatform_Native, - ctx->arena); - } - - if (upb_MessageDef_IsMapEntry(m)) { - if (m->field_count != 2) { - _upb_DefBuilder_Errf(ctx, "invalid map (%s)", m->full_name); - } - - const upb_FieldDef* f0 = upb_MessageDef_Field(m, 0); - const upb_FieldDef* f1 = upb_MessageDef_Field(m, 1); - const upb_FieldType t0 = upb_FieldDef_Type(f0); - const upb_FieldType t1 = upb_FieldDef_Type(f1); - - const bool is_proto3_enum = - (t1 == kUpb_FieldType_Enum) && !_upb_FieldDef_IsClosedEnum(f1); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(f0) == 0); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(f1) == 1); - - return upb_MiniTable_BuildMapEntry( - t0, t1, is_proto3_enum, kUpb_MiniTablePlatform_Native, ctx->arena); - } - upb_StringView desc; bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); if (!ok) _upb_DefBuilder_OomErr(ctx); @@ -8862,7 +9382,7 @@ static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { for (int i = 0; i < m->field_count; i++) { upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); - _upb_FieldDef_Resolve(ctx, upb_MessageDef_FullName(m), f); + _upb_FieldDef_Resolve(ctx, m->full_name, f); } if (!ctx->layout) { @@ -8870,10 +9390,20 @@ void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { if (!m->layout) _upb_DefBuilder_OomErr(ctx); } +#ifndef NDEBUG + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + const int layout_index = _upb_FieldDef_LayoutIndex(f); + UPB_ASSERT(layout_index < m->layout->field_count); + const upb_MiniTable_Field* mt_f = &m->layout->fields[layout_index]; + UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f)); + } +#endif + m->in_message_set = false; for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_Resolve(ctx, upb_MessageDef_FullName(m), ext); + _upb_FieldDef_Resolve(ctx, m->full_name, ext); if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && upb_FieldDef_Label(ext) == kUpb_Label_Optional && upb_FieldDef_MessageSubDef(ext) == m && @@ -8973,20 +9503,40 @@ static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { return out; } -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); +static bool _upb_MessageDef_EncodeMap(upb_DescState* s, const upb_MessageDef* m, + upb_Arena* a) { + if (m->field_count != 2) return false; + + const upb_FieldDef* key_field = upb_MessageDef_Field(m, 0); + const upb_FieldDef* val_field = upb_MessageDef_Field(m, 1); + if (key_field == NULL || val_field == NULL) return false; + + UPB_ASSERT(_upb_FieldDef_LayoutIndex(key_field) == 0); + UPB_ASSERT(_upb_FieldDef_LayoutIndex(val_field) == 1); + const upb_FieldType key_type = upb_FieldDef_Type(key_field); + const upb_FieldType val_type = upb_FieldDef_Type(val_field); + + const uint64_t val_mod = _upb_FieldDef_IsClosedEnum(val_field) + ? kUpb_FieldModifier_IsClosedEnum + : 0; + + s->ptr = + upb_MtDataEncoder_EncodeMap(&s->e, s->ptr, key_type, val_type, val_mod); + return true; +} + +static bool _upb_MessageDef_EncodeMessage(upb_DescState* s, + const upb_MessageDef* m, + upb_Arena* a) { const upb_FieldDef** sorted = NULL; if (!m->is_sorted) { sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); if (!sorted) return false; } - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = - upb_MtDataEncoder_StartMessage(&s.e, s.ptr, _upb_MessageDef_Modifiers(m)); + s->ptr = upb_MtDataEncoder_StartMessage(&s->e, s->ptr, + _upb_MessageDef_Modifiers(m)); for (int i = 0; i < m->field_count; i++) { const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); @@ -8994,24 +9544,50 @@ bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, const int number = upb_FieldDef_Number(f); const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutField(&s.e, s.ptr, type, number, modifiers); + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_PutField(&s->e, s->ptr, type, number, modifiers); } - for (int i = 0; i < m->oneof_count; i++) { - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartOneof(&s.e, s.ptr); + for (int i = 0; i < m->real_oneof_count; i++) { + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_StartOneof(&s->e, s->ptr); const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); const int field_count = upb_OneofDef_FieldCount(o); for (int j = 0; j < field_count; j++) { const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutOneofField(&s.e, s.ptr, number); + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_PutOneofField(&s->e, s->ptr, number); } } + return true; +} + +static bool _upb_MessageDef_EncodeMessageSet(upb_DescState* s, + const upb_MessageDef* m, + upb_Arena* a) { + s->ptr = upb_MtDataEncoder_EncodeMessageSet(&s->e, s->ptr); + + return true; +} + +bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, + upb_StringView* out) { + upb_DescState s; + _upb_DescState_Init(&s); + + if (!_upb_DescState_Grow(&s, a)) return false; + + if (upb_MessageDef_IsMapEntry(m)) { + if (!_upb_MessageDef_EncodeMap(&s, m, a)) return false; + } else if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { + if (!_upb_MessageDef_EncodeMessageSet(&s, m, a)) return false; + } else { + if (!_upb_MessageDef_EncodeMessage(&s, m, a)) return false; + } + if (!_upb_DescState_Grow(&s, a)) return false; *s.ptr = '\0'; @@ -9063,7 +9639,7 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, ctx, sizeof(*m->layout) + sizeof(_upb_FastTable_Entry)); } - UBP_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); m->oneof_count = n_oneof; m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m); @@ -9072,6 +9648,13 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->full_name, m, &m->is_sorted); + // Message Sets may not contain fields. + if (UPB_UNLIKELY(google_protobuf_MessageOptions_message_set_wire_format(m->opts))) { + if (UPB_UNLIKELY(n_field > 0)) { + _upb_DefBuilder_Errf(ctx, "invalid message set (%s)", m->full_name); + } + } + m->ext_range_count = n_ext_range; m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, m); @@ -9114,7 +9697,6 @@ upb_MessageDef* _upb_MessageDefs_New( } - // Must be last. struct upb_MethodDef { @@ -9189,7 +9771,7 @@ static void create_method(upb_DefBuilder* ctx, ctx, m->full_name, m->full_name, google_protobuf_MethodDescriptorProto_output_type(method_proto), UPB_DEFTYPE_MSG); - UBP_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, + UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, method_proto); } @@ -9205,7 +9787,6 @@ upb_MethodDef* _upb_MethodDefs_New( return m; } - #include #include #include @@ -9348,7 +9929,7 @@ static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, o->field_count = 0; o->synthetic = false; - UBP_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); @@ -9379,7 +9960,6 @@ upb_OneofDef* _upb_OneofDefs_New( } - // Must be last. struct upb_ServiceDef { @@ -9458,7 +10038,7 @@ static void create_service(upb_DefBuilder* ctx, s->method_count = n; s->methods = _upb_MethodDefs_New(ctx, n, methods, s); - UBP_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, + UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, svc_proto); } @@ -10403,372 +10983,302 @@ int upb_Unicode_ToUTF8(uint32_t cp, char* out) { } -#include - -// Must be last. +#include -static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size) { - UPB_UNUSED(alloc); - UPB_UNUSED(oldsize); - if (size == 0) { - free(ptr); - return NULL; - } else { - return realloc(ptr, size); - } -} -upb_alloc upb_alloc_global = {&upb_global_allocfunc}; +// Must be last. +/** upb_Message ***************************************************************/ -// Must be last. +static const size_t overhead = sizeof(upb_Message_InternalData); -static uint32_t* upb_cleanup_pointer(uintptr_t cleanup_metadata) { - return (uint32_t*)(cleanup_metadata & ~0x1); +static const upb_Message_Internal* upb_Message_Getinternal_const( + const upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); } -static bool upb_cleanup_has_initial_block(uintptr_t cleanup_metadata) { - return cleanup_metadata & 0x1; +upb_Message* upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + return _upb_Message_New(mini_table, arena); } -static uintptr_t upb_cleanup_metadata(uint32_t* cleanup, - bool has_initial_block) { - return (uintptr_t)cleanup | has_initial_block; +void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { + void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); + memset(mem, 0, upb_msg_sizeof(l)); } -struct mem_block { - struct mem_block* next; - uint32_t size; - uint32_t cleanups; - /* Data follows. */ -}; - -typedef struct cleanup_ent { - upb_CleanupFunc* cleanup; - void* ud; -} cleanup_ent; - -static const size_t memblock_reserve = - UPB_ALIGN_UP(sizeof(mem_block), UPB_MALLOC_ALIGN); - -static upb_Arena* arena_findroot(upb_Arena* a) { - /* Path splitting keeps time complexity down, see: - * https://en.wikipedia.org/wiki/Disjoint-set_data_structure */ - while (a->parent != a) { - upb_Arena* next = a->parent; - a->parent = next->parent; - a = next; +static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) { + /* No internal data, allocate from scratch. */ + size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + /* Internal data is too small, reallocate. */ + size_t new_size = _upb_Log2CeilingSize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + /* Need to move extension data to the end. */ + char* ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; } - return a; + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; } -size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - arena = arena_findroot(arena); - size_t memsize = 0; +bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena) { + if (!realloc_internal(msg, len, arena)) return false; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); + in->internal->unknown_end += len; + return true; +} - mem_block* block = arena->freelist; +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + in->internal->unknown_end = overhead; + } +} - while (block) { - memsize += sizeof(mem_block) + block->size; - block = block->next; +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); + if (in->internal) { + *len = in->internal->unknown_end - overhead; + return (char*)(in->internal + 1); + } else { + *len = 0; + return NULL; } +} - return memsize; +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + const char* internal_unknown_end = + UPB_PTR_AT(in->internal, in->internal->unknown_end, char); +#ifndef NDEBUG + size_t full_unknown_size; + const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); + UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); + UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); + UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); + UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); +#endif + if ((data + len) != internal_unknown_end) { + memmove((char*)data, data + len, internal_unknown_end - data - len); + } + in->internal->unknown_end -= len; } -uint32_t upb_Arena_DebugRefCount(upb_Arena* arena) { - return arena_findroot(arena)->refcount; +const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); + if (in->internal) { + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(upb_Message_Extension); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; + } } -static void upb_Arena_addblock(upb_Arena* a, upb_Arena* root, void* ptr, - size_t size) { - mem_block* block = ptr; +const upb_Message_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTable_Extension* e) { + size_t n; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); - /* The block is for arena |a|, but should appear in the freelist of |root|. */ - block->next = root->freelist; - block->size = (uint32_t)size; - block->cleanups = 0; - root->freelist = block; - a->last_size = block->size; - if (!root->freelist_tail) root->freelist_tail = block; + /* For now we use linear search exclusively to find extensions. If this + * becomes an issue due to messages with lots of extensions, we can introduce + * a table of some sort. */ + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } - a->head.ptr = UPB_PTR_AT(block, memblock_reserve, char); - a->head.end = UPB_PTR_AT(block, size, char); - a->cleanup_metadata = upb_cleanup_metadata( - &block->cleanups, upb_cleanup_has_initial_block(a->cleanup_metadata)); + return NULL; +} - UPB_POISON_MEMORY_REGION(a->head.ptr, a->head.end - a->head.ptr); +void _upb_Message_Clearext(upb_Message* msg, + const upb_MiniTable_Extension* ext_l) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) return; + const upb_Message_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); + if (ext) { + *ext = *base; + in->internal->ext_begin += sizeof(upb_Message_Extension); + } } -static bool upb_Arena_Allocblock(upb_Arena* a, size_t size) { - upb_Arena* root = arena_findroot(a); - size_t block_size = UPB_MAX(size, a->last_size * 2) + memblock_reserve; - mem_block* block = upb_malloc(root->block_alloc, block_size); - - if (!block) return false; - upb_Arena_addblock(a, root, block, block_size); - return true; -} - -void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size) { - if (!upb_Arena_Allocblock(a, size)) return NULL; /* Out of memory. */ - UPB_ASSERT(_upb_ArenaHas(a) >= size); - return upb_Arena_Malloc(a, size); +upb_Message_Extension* _upb_Message_GetOrCreateExtension( + upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(upb_Message_Extension); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(upb_Message_Extension)); + ext->ext = e; + return ext; } -static void* upb_Arena_doalloc(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size) { - upb_Arena* a = (upb_Arena*)alloc; /* upb_alloc is initial member. */ - return upb_Arena_Realloc(a, ptr, oldsize, size); +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + _upb_Message_Getexts(msg, &count); + return count; } -/* Public Arena API ***********************************************************/ +/** upb_Map *******************************************************************/ -static upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { - const size_t first_block_overhead = sizeof(upb_Arena) + memblock_reserve; - upb_Arena* a; +upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { + upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - /* We need to malloc the initial block. */ - n = first_block_overhead + 256; - if (!alloc || !(mem = upb_malloc(alloc, n))) { + if (!map) { return NULL; } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); - n -= sizeof(*a); - - a->head.alloc.func = &upb_Arena_doalloc; - a->block_alloc = alloc; - a->parent = a; - a->refcount = 1; - a->freelist = NULL; - a->freelist_tail = NULL; - a->cleanup_metadata = upb_cleanup_metadata(NULL, false); - - upb_Arena_addblock(a, a, mem, n); + upb_strtable_init(&map->table, 4, a); + map->key_size = key_size; + map->val_size = value_size; - return a; + return map; } -upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { - upb_Arena* a; - - if (n) { - /* Align initial pointer up so that we return properly-aligned pointers. */ - void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, UPB_MALLOC_ALIGN); - size_t delta = (uintptr_t)aligned - (uintptr_t)mem; - n = delta <= n ? n - delta : 0; - mem = aligned; - } - - /* Round block size down to alignof(*a) since we will allocate the arena - * itself at the end. */ - n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena)); +const float kUpb_FltInfinity = INFINITY; +const double kUpb_Infinity = INFINITY; - if (UPB_UNLIKELY(n < sizeof(upb_Arena))) { - return arena_initslow(mem, n, alloc); - } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); +#include +#include +#include +#include +#include +#include - a->head.alloc.func = &upb_Arena_doalloc; - a->block_alloc = alloc; - a->parent = a; - a->refcount = 1; - a->last_size = UPB_MAX(128, n); - a->head.ptr = mem; - a->head.end = UPB_PTR_AT(mem, n - sizeof(*a), char); - a->freelist = NULL; - a->freelist_tail = NULL; - a->cleanup_metadata = upb_cleanup_metadata(NULL, true); +// Must be last. - return a; +void upb_Status_Clear(upb_Status* status) { + if (!status) return; + status->ok = true; + status->msg[0] = '\0'; } -static void arena_dofree(upb_Arena* a) { - mem_block* block = a->freelist; - UPB_ASSERT(a->parent == a); - UPB_ASSERT(a->refcount == 0); +bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } - while (block) { - /* Load first since we are deleting block. */ - mem_block* next = block->next; +const char* upb_Status_ErrorMessage(const upb_Status* status) { + return status->msg; +} - if (block->cleanups > 0) { - cleanup_ent* end = UPB_PTR_AT(block, block->size, void); - cleanup_ent* ptr = end - block->cleanups; +void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { + if (!status) return; + status->ok = false; + strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} - for (; ptr < end; ptr++) { - ptr->cleanup(ptr->ud); - } - } +void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { + va_list args; + va_start(args, fmt); + upb_Status_VSetErrorFormat(status, fmt, args); + va_end(args); +} - upb_free(a->block_alloc, block); - block = next; - } +void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, + va_list args) { + if (!status) return; + status->ok = false; + vsnprintf(status->msg, sizeof(status->msg), fmt, args); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; } -void upb_Arena_Free(upb_Arena* a) { - a = arena_findroot(a); - if (--a->refcount == 0) arena_dofree(a); +void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, + va_list args) { + size_t len; + if (!status) return; + status->ok = false; + len = strlen(status->msg); + vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; } -bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func) { - cleanup_ent* ent; - uint32_t* cleanups = upb_cleanup_pointer(a->cleanup_metadata); +#include +#include +#include - if (!cleanups || _upb_ArenaHas(a) < sizeof(cleanup_ent)) { - if (!upb_Arena_Allocblock(a, 128)) return false; /* Out of memory. */ - UPB_ASSERT(_upb_ArenaHas(a) >= sizeof(cleanup_ent)); - cleanups = upb_cleanup_pointer(a->cleanup_metadata); - } - a->head.end -= sizeof(cleanup_ent); - ent = (cleanup_ent*)a->head.end; - (*cleanups)++; - UPB_UNPOISON_MEMORY_REGION(ent, sizeof(cleanup_ent)); +// Must be last. - ent->cleanup = func; - ent->ud = ud; +/* Miscellaneous utilities ****************************************************/ - return true; +static void upb_FixLocale(char* p) { + /* printf() is dependent on locales; sadly there is no easy and portable way + * to avoid this. This little post-processing step will translate 1,2 -> 1.2 + * since JSON needs the latter. Arguably a hack, but it is simple and the + * alternatives are far more complicated, platform-dependent, and/or larger + * in code size. */ + for (; *p; p++) { + if (*p == ',') *p = '.'; + } } -bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { - upb_Arena* r1 = arena_findroot(a1); - upb_Arena* r2 = arena_findroot(a2); - - if (r1 == r2) return true; /* Already fused. */ - - /* Do not fuse initial blocks since we cannot lifetime extend them. */ - if (upb_cleanup_has_initial_block(r1->cleanup_metadata)) return false; - if (upb_cleanup_has_initial_block(r2->cleanup_metadata)) return false; - - /* Only allow fuse with a common allocator */ - if (r1->block_alloc != r2->block_alloc) return false; - - /* We want to join the smaller tree to the larger tree. - * So swap first if they are backwards. */ - if (r1->refcount < r2->refcount) { - upb_Arena* tmp = r1; - r1 = r2; - r2 = tmp; +void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", DBL_DIG, val); + if (strtod(buf, NULL) != val) { + snprintf(buf, size, "%.*g", DBL_DIG + 2, val); + assert(strtod(buf, NULL) == val); } + upb_FixLocale(buf); +} - /* r1 takes over r2's freelist and refcount. */ - r1->refcount += r2->refcount; - if (r2->freelist_tail) { - UPB_ASSERT(r2->freelist_tail->next == NULL); - r2->freelist_tail->next = r1->freelist; - r1->freelist = r2->freelist; +void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", FLT_DIG, val); + if (strtof(buf, NULL) != val) { + snprintf(buf, size, "%.*g", FLT_DIG + 3, val); + assert(strtof(buf, NULL) == val); } - r2->parent = r1; - return true; + upb_FixLocale(buf); } #include + // Must be last. -static const char _upb_CTypeo_sizelg2[12] = { - 0, - 0, /* kUpb_CType_Bool */ - 2, /* kUpb_CType_Float */ - 2, /* kUpb_CType_Int32 */ - 2, /* kUpb_CType_UInt32 */ - 2, /* kUpb_CType_Enum */ - UPB_SIZE(2, 3), /* kUpb_CType_Message */ - 3, /* kUpb_CType_Double */ - 3, /* kUpb_CType_Int64 */ - 3, /* kUpb_CType_UInt64 */ - UPB_SIZE(3, 4), /* kUpb_CType_String */ - UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ +// A few fake field types for our tables. +enum { + kUpb_FakeFieldType_FieldNotFound = 0, + kUpb_FakeFieldType_MessageSetItem = 19, }; -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); -} - -size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } - -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - upb_MessageValue ret; - const char* data = _upb_array_constptr(arr); - int lg2 = arr->data & 7; - UPB_ASSERT(i < arr->size); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} - -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - char* data = _upb_array_ptr(arr); - int lg2 = arr->data & 7; - UPB_ASSERT(i < arr->size); - memcpy(data + (i << lg2), &val, 1 << lg2); -} - -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - if (!upb_Array_Resize(arr, arr->size + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->size - 1, val); - return true; -} - -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - char* data = _upb_array_ptr(arr); - int lg2 = arr->data & 7; - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); -} - -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(i <= arr->size); - UPB_ASSERT(count + arr->size >= count); - size_t oldsize = arr->size; - if (!upb_Array_Resize(arr, arr->size + count, arena)) { - return false; - } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->size); - upb_Array_Move(arr, i, end, arr->size - end); - arr->size -= count; -} - -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - return _upb_Array_Resize(arr, size, arena); -} - - -#include - - -// Must be last. - -// A few fake field types for our tables. -enum { - kUpb_FakeFieldType_FieldNotFound = 0, - kUpb_FakeFieldType_MessageSetItem = 19, -}; - -// DecodeOp: an action to be performed for a wire-type/field-type combination. -enum { - // Special ops: we don't write data to regular fields for these. - kUpb_DecodeOp_UnknownField = -1, - kUpb_DecodeOp_MessageSetItem = -2, +// DecodeOp: an action to be performed for a wire-type/field-type combination. +enum { + // Special ops: we don't write data to regular fields for these. + kUpb_DecodeOp_UnknownField = -1, + kUpb_DecodeOp_MessageSetItem = -2, // Scalar-only ops. kUpb_DecodeOp_Scalar1Byte = 0, @@ -10928,7 +11438,8 @@ static upb_Message* _upb_Decoder_NewSubMessage( upb_Decoder* d, const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) { const upb_MiniTable* subl = subs[field->submsg_index].submsg; - upb_Message* msg = _upb_Message_New_inl(subl, &d->arena); + UPB_ASSERT(subl); + upb_Message* msg = _upb_Message_New(subl, &d->arena); if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return msg; } @@ -10979,6 +11490,7 @@ static const char* _upb_Decoder_DecodeSubMessage( const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, int size) { int saved_delta = _upb_Decoder_PushLimit(d, ptr, size); const upb_MiniTable* subl = subs[field->submsg_index].submsg; + UPB_ASSERT(subl); ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); _upb_Decoder_PopLimit(d, ptr, saved_delta); return ptr; @@ -11009,6 +11521,7 @@ static const char* _upb_Decoder_DecodeKnownGroup( upb_Decoder* d, const char* ptr, upb_Message* submsg, const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) { const upb_MiniTable* subl = subs[field->submsg_index].submsg; + UPB_ASSERT(subl); return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number); } @@ -11513,11 +12026,11 @@ static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, } static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, - const upb_MiniTable* layout, + const upb_MiniTable* t, uint32_t type_id, const char* data, uint32_t size) { const upb_MiniTable_Extension* item_mt = - _upb_extreg_get(d->extreg, layout, type_id); + upb_ExtensionRegistry_Lookup(d->extreg, t, type_id); if (item_mt) { upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); } else { @@ -11579,40 +12092,40 @@ static const char* upb_Decoder_DecodeMessageSetItem( } static const upb_MiniTable_Field* _upb_Decoder_FindField( - upb_Decoder* d, const upb_MiniTable* l, uint32_t field_number, + upb_Decoder* d, const upb_MiniTable* t, uint32_t field_number, int* last_field_index) { static upb_MiniTable_Field none = { 0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0}; - if (l == NULL) return &none; + if (t == NULL) return &none; size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX - if (idx < l->dense_below) { + if (idx < t->dense_below) { /* Fastest case: index into dense fields. */ goto found; } - if (l->dense_below < l->field_count) { + if (t->dense_below < t->field_count) { /* Linear search non-dense fields. Resume scanning from last_field_index * since fields are usually in order. */ int last = *last_field_index; - for (idx = last; idx < l->field_count; idx++) { - if (l->fields[idx].number == field_number) { + for (idx = last; idx < t->field_count; idx++) { + if (t->fields[idx].number == field_number) { goto found; } } - for (idx = l->dense_below; idx < last; idx++) { - if (l->fields[idx].number == field_number) { + for (idx = t->dense_below; idx < last; idx++) { + if (t->fields[idx].number == field_number) { goto found; } } } if (d->extreg) { - switch (l->ext) { + switch (t->ext) { case kUpb_ExtMode_Extendable: { const upb_MiniTable_Extension* ext = - _upb_extreg_get(d->extreg, l, field_number); + upb_ExtensionRegistry_Lookup(d->extreg, t, field_number); if (ext) return &ext->field; break; } @@ -11629,9 +12142,9 @@ static const upb_MiniTable_Field* _upb_Decoder_FindField( return &none; /* Unknown field. */ found: - UPB_ASSERT(l->fields[idx].number == field_number); + UPB_ASSERT(t->fields[idx].number == field_number); *last_field_index = idx; - return &l->fields[idx]; + return &t->fields[idx]; } int _upb_Decoder_GetVarintOp(const upb_MiniTable_Field* field) { @@ -12010,7 +12523,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, #undef OP_FIXPCK_LG2 #undef OP_VARPCK_LG2 -/* We encode backwards, to avoid pre-computing lengths (one-pass encode). */ +// We encode backwards, to avoid pre-computing lengths (one-pass encode). #include @@ -12432,17 +12945,11 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, memcpy(&ch, mem, 1); return ch != 0; } -#if UINTPTR_MAX == 0xffffffff - case kUpb_FieldRep_Pointer: -#endif case kUpb_FieldRep_4Byte: { uint32_t u32; memcpy(&u32, mem, 4); return u32 != 0; } -#if UINTPTR_MAX != 0xffffffff - case kUpb_FieldRep_Pointer: -#endif case kUpb_FieldRep_8Byte: { uint64_t u64; memcpy(&u64, mem, 8); @@ -12593,375 +13100,6 @@ upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, return status; } - -// Must be last. - -static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, - void* b_key, size_t size) { - const upb_tabent* const* a = _a; - const upb_tabent* const* b = _b; - upb_StringView a_tabkey = upb_tabstrview((*a)->key); - upb_StringView b_tabkey = upb_tabstrview((*b)->key); - _upb_map_fromkey(a_tabkey, a_key, size); - _upb_map_fromkey(b_tabkey, b_key, size); -} - -static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { - int64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { - uint64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { - int32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { - uint32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { - bool a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { - upb_StringView a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); - size_t common_size = UPB_MIN(a.size, b.size); - int cmp = memcmp(a.data, b.data, common_size); - if (cmp) return -cmp; - return a.size < b.size ? -1 : a.size > b.size; -} - -static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { - [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, - - [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, - [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, - - [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - - [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, - [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, - - [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, - - [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, - [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, -}; - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted) { - int map_size = _upb_Map_Size(map); - sorted->start = s->size; - sorted->pos = sorted->start; - sorted->end = sorted->start + map_size; - - // Grow s->entries if necessary. - if (sorted->end > s->cap) { - s->cap = _upb_Log2CeilingSize(sorted->end); - s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); - if (!s->entries) return false; - } - - s->size = sorted->end; - - // Copy non-empty entries from the table to s->entries. - upb_tabent const** dst = &s->entries[sorted->start]; - const upb_tabent* src = map->table.t.entries; - const upb_tabent* end = src + upb_table_size(&map->table.t); - for (; src < end; src++) { - if (!upb_tabent_isempty(src)) { - *dst = src; - dst++; - } - } - UPB_ASSERT(dst == &s->entries[sorted->end]); - - // Sort entries according to the key type. - qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), - compar[key_type]); - return true; -} - - -#include - - -// Must be last. - -/** upb_Message ***************************************************************/ - -static const size_t overhead = sizeof(upb_Message_InternalData); - -static const upb_Message_Internal* upb_Message_Getinternal_const( - const upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); -} - -upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a) { - return _upb_Message_New_inl(l, a); -} - -void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { - void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); - memset(mem, 0, upb_msg_sizeof(l)); -} - -static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { - /* No internal data, allocate from scratch. */ - size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { - /* Internal data is too small, reallocate. */ - size_t new_size = _upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; - if (ext_bytes) { - /* Need to move extension data to the end. */ - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); - } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; - } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); - return true; -} - -bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, - upb_Arena* arena) { - if (!realloc_internal(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; - return true; -} - -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = overhead; - } -} - -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); - if (in->internal) { - *len = in->internal->unknown_end - overhead; - return (char*)(in->internal + 1); - } else { - *len = 0; - return NULL; - } -} - -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(upb_Message_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - } else { - *count = 0; - return NULL; - } -} - -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTable_Extension* e) { - size_t n; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); - - /* For now we use linear search exclusively to find extensions. If this - * becomes an issue due to messages with lots of extensions, we can introduce - * a table of some sort. */ - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } - - return NULL; -} - -void _upb_Message_Clearext(upb_Message* msg, - const upb_MiniTable_Extension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; - const upb_Message_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); - if (ext) { - *ext = *base; - in->internal->ext_begin += sizeof(upb_Message_Extension); - } -} - -upb_Message_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Message_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Message_Extension)); - ext->ext = e; - return ext; -} - -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - size_t count; - _upb_Message_Getexts(msg, &count); - return count; -} - -/** upb_Map *******************************************************************/ - -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { - upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - - if (!map) { - return NULL; - } - - upb_strtable_init(&map->table, 4, a); - map->key_size = key_size; - map->val_size = value_size; - - return map; -} - -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; - - -#include -#include -#include -#include -#include -#include - -// Must be last. - -void upb_Status_Clear(upb_Status* status) { - if (!status) return; - status->ok = true; - status->msg[0] = '\0'; -} - -bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } - -const char* upb_Status_ErrorMessage(const upb_Status* status) { - return status->msg; -} - -void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { - if (!status) return; - status->ok = false; - strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { - va_list args; - va_start(args, fmt); - upb_Status_VSetErrorFormat(status, fmt, args); - va_end(args); -} - -void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - if (!status) return; - status->ok = false; - vsnprintf(status->msg, sizeof(status->msg), fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - size_t len; - if (!status) return; - status->ok = false; - len = strlen(status->msg); - vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -#include -#include -#include - - -// Must be last. - -/* Miscellaneous utilities ****************************************************/ - -static void upb_FixLocale(char* p) { - /* printf() is dependent on locales; sadly there is no easy and portable way - * to avoid this. This little post-processing step will translate 1,2 -> 1.2 - * since JSON needs the latter. Arguably a hack, but it is simple and the - * alternatives are far more complicated, platform-dependent, and/or larger - * in code size. */ - for (; *p; p++) { - if (*p == ',') *p = '.'; - } -} - -void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - snprintf(buf, size, "%.*g", DBL_DIG, val); - if (strtod(buf, NULL) != val) { - snprintf(buf, size, "%.*g", DBL_DIG + 2, val); - assert(strtod(buf, NULL) == val); - } - upb_FixLocale(buf); -} - -void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - snprintf(buf, size, "%.*g", FLT_DIG, val); - if (strtof(buf, NULL) != val) { - snprintf(buf, size, "%.*g", FLT_DIG + 3, val); - assert(strtof(buf, NULL) == val); - } - upb_FixLocale(buf); -} - /* See port_def.inc. This should #undef all macros #defined there. */ #undef UPB_SIZE diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 42874797c6..d0552eeaf2 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -24,9 +24,9 @@ */ #if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ - (defined(__cplusplus) && __cplusplus >= 201103L) || \ + (defined(__cplusplus) && __cplusplus >= 201402L) || \ (defined(_MSC_VER) && _MSC_VER >= 1900)) -#error upb requires C99 or C++11 or MSVC >= 2015. +#error upb requires C99 or C++14 or MSVC >= 2015. #endif // Portable check for GCC minimum version: @@ -267,14 +267,39 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define UPB_DEPRECATED #endif -#ifndef UPB_INTERNAL_ARRAY_H_ -#define UPB_INTERNAL_ARRAY_H_ +#ifndef UPB_INTERNAL_ATOI_H_ +#define UPB_INTERNAL_ATOI_H_ + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// We use these hand-written routines instead of strto[u]l() because the "long +// long" variants aren't in c89. Also our version allows setting a ptr limit. +// Return the new position of the pointer after parsing the int, or NULL on +// integer overflow. + +const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val); +const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, + bool* is_neg); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_INTERNAL_ATOI_H_ */ + +#ifndef UPB_INTERNAL_ARRAY_INTERNAL_H_ +#define UPB_INTERNAL_ARRAY_INTERNAL_H_ #include -#ifndef UPB_ARRAY_H_ -#define UPB_ARRAY_H_ +#ifndef UPB_COLLECTIONS_ARRAY_H_ +#define UPB_COLLECTIONS_ARRAY_H_ #ifndef UPB_MESSAGE_VALUE_H_ @@ -293,14 +318,14 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define UPB_MSG_H_ -#ifndef UPB_ARENA_H_ -#define UPB_ARENA_H_ +#ifndef UPB_MEM_ARENA_H_ +#define UPB_MEM_ARENA_H_ #include -#ifndef UPB_ALLOC_H_ -#define UPB_ALLOC_H_ +#ifndef UPB_MEM_ALLOC_H_ +#define UPB_MEM_ALLOC_H_ // Must be last. @@ -343,7 +368,7 @@ UPB_INLINE void upb_free(upb_alloc* alloc, void* ptr) { alloc->func(alloc, ptr, 0, 0); } -/* The global allocator used by upb. Uses the standard malloc()/free(). */ +// The global allocator used by upb. Uses the standard malloc()/free(). extern upb_alloc upb_alloc_global; @@ -367,7 +392,7 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } #endif -#endif /* UPB_ALLOC_H_ */ +#endif /* UPB_MEM_ALLOC_H_ */ // Must be last. @@ -500,7 +525,7 @@ UPB_INLINE upb_Arena* upb_Arena_New(void) { #endif -#endif /* UPB_ARENA_H_ */ +#endif /* UPB_MEM_ARENA_H_ */ // Must be last. @@ -514,6 +539,9 @@ typedef void upb_Message; * upb_MessageDef_MiniTable() but users cannot access any of the members. */ typedef struct upb_MiniTable upb_MiniTable; +/* Creates a new message with the given mini_table on the given arena. */ +upb_Message* upb_Message_New(const upb_MiniTable* mini_table, upb_Arena* arena); + /* Adds unknown data (serialized protobuf data) to the given message. The data * is copied into the message instance. */ void upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, @@ -522,6 +550,9 @@ void upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, /* Returns a reference to the message's unknown data. */ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); +/* Removes partial unknown data from message. */ +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); + /* Returns the number of extensions present in this message. */ size_t upb_Message_ExtensionCount(const upb_Message* msg); @@ -749,12 +780,6 @@ UPB_INLINE int _upb_Log2CeilingSize(int x) { return 1 << _upb_Log2Ceiling(x); } // Must be last. -#ifdef __cplusplus -extern "C" { -#endif - -// Definitions common to both upb_Array and upb_Map. - typedef union { bool bool_val; float float_val; @@ -775,10 +800,6 @@ typedef union { upb_Message* msg; } upb_MutableMessageValue; -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif /* UPB_MESSAGE_VALUE_H_ */ @@ -829,7 +850,7 @@ bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); #endif -#endif /* UPB_ARRAY_H_ */ +#endif /* UPB_COLLECTIONS_ARRAY_H_ */ // Must be last. @@ -837,7 +858,7 @@ bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); extern "C" { #endif -/* Our internal representation for repeated fields. */ +// Our internal representation for repeated fields. struct upb_Array { uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ size_t size; /* The number of elements in the array. */ @@ -876,10 +897,10 @@ UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, size_t init_capacity, return arr; } -/* Resizes the capacity of the array to be at least min_size. */ +// Resizes the capacity of the array to be at least min_size. bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena); -/* Fallback functions for when the accessors require a resize. */ +// Fallback functions for when the accessors require a resize. void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, int elem_size_lg2, upb_Arena* arena); bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, @@ -955,7 +976,7 @@ UPB_INLINE bool _upb_Array_Append_accessor2(void* msg, size_t ofs, return true; } -/* Used by old generated code, remove once all code has been regenerated. */ +// Used by old generated code, remove once all code has been regenerated. UPB_INLINE int _upb_sizelg2(upb_CType type) { switch (type) { case kUpb_CType_Bool: @@ -997,35 +1018,10 @@ UPB_INLINE bool _upb_Array_Append_accessor(void* msg, size_t ofs, #endif -#endif /* UPB_INTERNAL_ARRAY_H_ */ - -#ifndef UPB_INTERNAL_ATOI_H_ -#define UPB_INTERNAL_ATOI_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// We use these hand-written routines instead of strto[u]l() because the "long -// long" variants aren't in c89. Also our version allows setting a ptr limit. -// Return the new position of the pointer after parsing the int, or NULL on -// integer overflow. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val); -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_ATOI_H_ */ +#endif /* UPB_INTERNAL_ARRAY_INTERNAL_H_ */ -#ifndef UPB_MAP_H_ -#define UPB_MAP_H_ +#ifndef UPB_COLLECTIONS_MAP_H_ +#define UPB_COLLECTIONS_MAP_H_ // Must be last. @@ -1109,7 +1105,7 @@ void upb_MapIterator_SetValue(upb_Map* map, size_t iter, #endif -#endif /* UPB_MAP_H_ */ +#endif /* UPB_COLLECTIONS_MAP_H_ */ /* ** Our memory representation for parsing tables and messages themselves. @@ -1170,28 +1166,25 @@ extern "C" { */ typedef struct upb_ExtensionRegistry upb_ExtensionRegistry; +typedef struct upb_MiniTable_Extension upb_MiniTable_Extension; // Creates a upb_ExtensionRegistry in the given arena. // The arena must outlive any use of the extreg. upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -typedef struct upb_MiniTable upb_MiniTable; -typedef struct upb_MiniTable_Extension upb_MiniTable_Extension; +// Adds the given extension info for the array |e| of size |count| into the +// registry. If there are any errors, the entire array is backed out. +// The extensions must outlive the registry. +// Possible errors include OOM or an extension number that already exists. +// TODO: There is currently no way to determine the exact reason for failure. +bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, + const upb_MiniTable_Extension** e, + size_t count); -// Adds the given extension info for message type |l| and field number |num| -// into the registry. Returns false if this message type and field number were -// already in the map, or if memory allocation fails. -bool _upb_extreg_add(upb_ExtensionRegistry* r, - const upb_MiniTable_Extension** e, size_t count); - -// Looks up the extension (if any) defined for message type |l| and field -// number |num|. If an extension was found, copies the field info into |*ext| -// and returns true. Otherwise returns false. -const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, - const upb_MiniTable* l, - uint32_t num); +// Looks up the extension (if any) defined for message type |t| and field +// number |num|. Returns the extension if found, otherwise NULL. +const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup( + const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num); #ifdef __cplusplus } /* extern "C" */ @@ -1607,6 +1600,12 @@ typedef enum { typedef enum { kUpb_LabelFlags_IsPacked = 4, kUpb_LabelFlags_IsExtension = 8, + // Indicates that this descriptor type is an "alternate type": + // - for Int32, this indicates that the actual type is Enum (but was + // rewritten to Int32 because it is an open enum that requires no check). + // - for Bytes, this indicates that the actual type is String (but does + // not require any UTF-8 check). + kUpb_LabelFlags_IsAlternate = 16, } upb_LabelFlags; // Note: we sort by this number when calculating layout order. @@ -1614,10 +1613,9 @@ typedef enum { kUpb_FieldRep_1Byte = 0, kUpb_FieldRep_4Byte = 1, kUpb_FieldRep_StringView = 2, - kUpb_FieldRep_Pointer = 3, - kUpb_FieldRep_8Byte = 4, + kUpb_FieldRep_8Byte = 3, - kUpb_FieldRep_Shift = 5, // Bit offset of the rep in upb_MiniTable_Field.mode + kUpb_FieldRep_Shift = 6, // Bit offset of the rep in upb_MiniTable_Field.mode kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, } upb_FieldRep; @@ -1737,8 +1735,6 @@ struct upb_MiniTable { _upb_FastTable_Entry fasttable[]; }; -typedef struct upb_MiniTable_Extension upb_MiniTable_Extension; - struct upb_MiniTable_Extension { upb_MiniTable_Field field; const upb_MiniTable* extendee; @@ -1809,20 +1805,17 @@ UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* l) { return l->size + sizeof(upb_Message_Internal); } -UPB_INLINE upb_Message* _upb_Message_New_inl(const upb_MiniTable* l, - upb_Arena* a) { - size_t size = upb_msg_sizeof(l); - void* mem = upb_Arena_Malloc(a, size + sizeof(upb_Message_Internal)); - upb_Message* msg; +/* Inline version upb_Message_New(), for internal use */ +UPB_INLINE upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + size_t size = upb_msg_sizeof(mini_table); + void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); if (UPB_UNLIKELY(!mem)) return NULL; - msg = UPB_PTR_AT(mem, sizeof(upb_Message_Internal), upb_Message); + upb_Message* msg = UPB_PTR_AT(mem, sizeof(upb_Message_Internal), upb_Message); memset(mem, 0, size); return msg; } -/* Creates a new messages with the given layout on the given arena. */ -upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a); - UPB_INLINE upb_Message_Internal* upb_Message_Getinternal(upb_Message* msg) { ptrdiff_t size = sizeof(upb_Message_Internal); return (upb_Message_Internal*)((char*)msg - size); @@ -1877,9 +1870,6 @@ const upb_Message_Extension* _upb_Message_Getext( void _upb_Message_Clearext(upb_Message* msg, const upb_MiniTable_Extension* ext); -void _upb_Message_Clearext(upb_Message* msg, - const upb_MiniTable_Extension* ext); - /** Hasbit access *************************************************************/ UPB_INLINE bool _upb_hasbit(const upb_Message* msg, size_t idx) { @@ -2167,6 +2157,70 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #endif /* UPB_MSG_INT_H_ */ + +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// + +#ifndef UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_ +#define UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// _upb_mapsorter sorts maps and provides ordered iteration over the entries. +// Since maps can be recursive (map values can be messages which contain other +// maps), _upb_mapsorter can contain a stack of maps. + +typedef struct { + upb_tabent const** entries; + int size; + int cap; +} _upb_mapsorter; + +typedef struct { + int start; + int pos; + int end; +} _upb_sortedmap; + +UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { + s->entries = NULL; + s->size = 0; + s->cap = 0; +} + +UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { + if (s->entries) free(s->entries); +} + +UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, + _upb_sortedmap* sorted, upb_MapEntry* ent) { + if (sorted->pos == sorted->end) return false; + const upb_tabent* tabent = s->entries[sorted->pos++]; + upb_StringView key = upb_tabstrview(tabent->key); + _upb_map_fromkey(key, &ent->k, map->key_size); + upb_value val = {tabent->val.val}; + _upb_map_fromvalue(val, &ent->v, map->val_size); + return true; +} + +UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, + _upb_sortedmap* sorted) { + s->size = sorted->start; +} + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_ */ /* This file was generated by upbc (the upb compiler) from the input * file: * @@ -2179,12 +2233,10 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -/* - * upb_decode: parsing into a upb_Message using a upb_MiniTable. - */ +// upb_decode: parsing into a upb_Message using a upb_MiniTable. -#ifndef UPB_DECODE_H_ -#define UPB_DECODE_H_ +#ifndef UPB_WIRE_DECODE_H_ +#define UPB_WIRE_DECODE_H_ // Must be last. @@ -2242,7 +2294,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, #endif -#endif /* UPB_DECODE_H_ */ +#endif /* UPB_WIRE_DECODE_H_ */ // These are the specialized field parser functions for the fast parser. // Generated tables will refer to these by name. @@ -2278,8 +2330,8 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_DECODE_FAST_H_ -#define UPB_DECODE_FAST_H_ +#ifndef UPB_WIRE_DECODE_FAST_H_ +#define UPB_WIRE_DECODE_FAST_H_ // Must be last. @@ -2380,14 +2432,14 @@ TAGBYTES(r) #endif -#endif /* UPB_DECODE_FAST_H_ */ +#endif /* UPB_WIRE_DECODE_FAST_H_ */ /* * upb_Encode: parsing from a upb_Message using a upb_MiniTable. */ -#ifndef UPB_ENCODE_H_ -#define UPB_ENCODE_H_ +#ifndef UPB_WIRE_ENCODE_H_ +#define UPB_WIRE_ENCODE_H_ // Must be last. @@ -2432,7 +2484,7 @@ upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, #endif -#endif /* UPB_ENCODE_H_ */ +#endif /* UPB_WIRE_ENCODE_H_ */ #ifdef __cplusplus @@ -2657,95 +2709,95 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protob return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(48, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(48, 24), upb_StringView); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(20, 40)); + _upb_array_detach(msg, UPB_SIZE(4, 40)); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); + return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(4, 40), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(24, 48)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(8, 48)); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(24, 48)); + _upb_array_detach(msg, UPB_SIZE(8, 48)); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); + return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(8, 48), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 56)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 56)); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(28, 56)); + _upb_array_detach(msg, UPB_SIZE(12, 56)); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); + return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 56), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(32, 64)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 64)); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(32, 64)); + _upb_array_detach(msg, UPB_SIZE(16, 64)); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(32, 64), len); + return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 64), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(36, 72)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 72)); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(36, 72)); + _upb_array_detach(msg, UPB_SIZE(20, 72)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); + return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 72), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(40, 80), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(24, 80), const upb_Message*) = NULL; _upb_clearhas(msg, 3); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(40, 80), const google_protobuf_FileOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(24, 80), const google_protobuf_FileOptions*); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 4); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(44, 88), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(28, 88), const upb_Message*) = NULL; _upb_clearhas(msg, 4); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(44, 88), const google_protobuf_SourceCodeInfo*); + return *UPB_PTR_AT(msg, UPB_SIZE(28, 88), const google_protobuf_SourceCodeInfo*); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(48, 96)); + _upb_array_detach(msg, UPB_SIZE(32, 96)); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(48, 96), len); + return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(32, 96), len); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(52, 104)); + _upb_array_detach(msg, UPB_SIZE(36, 104)); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(52, 104), len); + return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(36, 104), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 5); @@ -2770,72 +2822,72 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_edition(const goog UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(48, 24), upb_StringView) = value; } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 40), len); } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(3, 4), arena); + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 40), len, UPB_SIZE(3, 4), arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), UPB_SIZE(3, 4), &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 40), UPB_SIZE(3, 4), &val, arena); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); + return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 48), len); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 48), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(8, 48), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); + return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 56), len); } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 56), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 56), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 64), len); + return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 64), len); } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_ServiceDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(32, 64), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_ServiceDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 64), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(32, 64), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 64), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); + return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 72), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 72), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 72), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 72), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(40, 80), google_protobuf_FileOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 80), google_protobuf_FileOptions*) = value; } UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); @@ -2848,7 +2900,7 @@ UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorPro } UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(44, 88), google_protobuf_SourceCodeInfo*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 88), google_protobuf_SourceCodeInfo*) = value; } UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); @@ -2860,22 +2912,22 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptor return sub; } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(48, 96), len); + return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 96), len); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(48, 96), len, 2, arena); + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(32, 96), len, 2, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(48, 96), 2, &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(32, 96), 2, &val, arena); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(52, 104), len); + return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 104), len); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(52, 104), len, 2, arena); + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 104), len, 2, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(52, 104), 2, &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 104), 2, &val, arena); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 5); @@ -2925,159 +2977,159 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_D return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(const google_protobuf_DescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView); } UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 24)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 24)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(12, 24)); + _upb_array_detach(msg, UPB_SIZE(4, 24)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 24), len); + return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(4, 24), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(8, 32)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(16, 32)); + _upb_array_detach(msg, UPB_SIZE(8, 32)); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); + return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(8, 32), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 40)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(20, 40)); + _upb_array_detach(msg, UPB_SIZE(12, 40)); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); + return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 40), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(24, 48)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 48)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(24, 48)); + _upb_array_detach(msg, UPB_SIZE(16, 48)); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); + return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_accessor(msg, UPB_SIZE(16, 48), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 56)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 56)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(28, 56)); + _upb_array_detach(msg, UPB_SIZE(20, 56)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); + return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 56), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(const google_protobuf_DescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(24, 64), const upb_Message*) = NULL; _upb_clearhas(msg, 2); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_MessageOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(24, 64), const google_protobuf_MessageOptions*); } UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(36, 72)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 72)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(36, 72)); + _upb_array_detach(msg, UPB_SIZE(28, 72)); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); + return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(28, 72), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(32, 80)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(40, 80)); + _upb_array_detach(msg, UPB_SIZE(32, 80)); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); + return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(32, 80), len); } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(44, 88)); + _upb_array_detach(msg, UPB_SIZE(36, 88)); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); + return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(36, 88), len); } UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 24), len); + return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 24), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len); + return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 32), len); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 32), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 32), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(8, 32), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); + return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 40), len); } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 40), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 40), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); + return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 48), len); } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 48), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 48), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); + return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 56), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 56), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 56), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(32, 64), google_protobuf_MessageOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 64), google_protobuf_MessageOptions*) = value; } UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); @@ -3089,37 +3141,37 @@ UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProt return sub; } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); + return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 72), len); } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_OneofDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_OneofDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 72), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 72), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 72), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len); + return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 80), len); } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(40, 80), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_DescriptorProto_ReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(32, 80), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(40, 80), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(32, 80), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* len) { - return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len); + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 88), len); } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(44, 88), len, UPB_SIZE(3, 4), arena); + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 88), len, UPB_SIZE(3, 4), arena); } UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(44, 88), UPB_SIZE(3, 4), &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 88), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.DescriptorProto.ExtensionRange */ @@ -3372,21 +3424,21 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_proto return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(28, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(28, 24), upb_StringView); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_StringView); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 3); @@ -3422,41 +3474,41 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_ return _upb_hasbit(msg, 6); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 6); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_StringView); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 7); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 7); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_StringView); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 8); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(56, 88), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(16, 88), const upb_Message*) = NULL; _upb_clearhas(msg, 8); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(56, 88), const google_protobuf_FieldOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 88), const google_protobuf_FieldOptions*); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 9); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(20, 16), int32_t) = 0; _upb_clearhas(msg, 9); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); + return *UPB_PTR_AT(msg, UPB_SIZE(20, 16), int32_t); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 10); @@ -3472,20 +3524,20 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const g return _upb_hasbit(msg, 11); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(24, 20), bool) = 0; _upb_clearhas(msg, 11); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool); + return *UPB_PTR_AT(msg, UPB_SIZE(24, 20), bool); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 3); @@ -3501,15 +3553,15 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 7); - *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { _upb_sethas(msg, 8); - *UPB_PTR_AT(msg, UPB_SIZE(56, 88), google_protobuf_FieldOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 88), google_protobuf_FieldOptions*) = value; } UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); @@ -3522,7 +3574,7 @@ UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorP } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 9); - *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 16), int32_t) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 10); @@ -3530,7 +3582,7 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protob } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) { _upb_sethas(msg, 11); - *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 20), bool) = value; } /* google.protobuf.OneofDescriptorProto */ @@ -3572,30 +3624,30 @@ UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_proto return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(const google_protobuf_OneofDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView); } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(const google_protobuf_OneofDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(4, 24), const upb_Message*) = NULL; _upb_clearhas(msg, 2); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_OneofOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 24), const google_protobuf_OneofOptions*); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_OneofOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 24), google_protobuf_OneofOptions*) = value; } UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); @@ -3646,66 +3698,66 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protob return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(const google_protobuf_EnumDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(20, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(20, 8), upb_StringView); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 24)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 24)); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(const google_protobuf_EnumDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(12, 24)); + _upb_array_detach(msg, UPB_SIZE(4, 24)); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 24), len); + return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(4, 24), len); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(const google_protobuf_EnumDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(8, 32), const upb_Message*) = NULL; _upb_clearhas(msg, 2); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const google_protobuf_EnumOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(8, 32), const google_protobuf_EnumOptions*); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 40)); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(const google_protobuf_EnumDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(20, 40)); + _upb_array_detach(msg, UPB_SIZE(12, 40)); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); + return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(12, 40), len); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(const google_protobuf_EnumDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(24, 48)); + _upb_array_detach(msg, UPB_SIZE(16, 48)); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); + return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(16, 48), len); } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 24), len); + return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 24), len); } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_EnumValueDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_EnumValueDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(16, 32), google_protobuf_EnumOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 32), google_protobuf_EnumOptions*) = value; } UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); @@ -3717,25 +3769,25 @@ UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorPro return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 40), len); } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 40), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 40), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 48), len); } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(3, 4), arena); + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 48), len, UPB_SIZE(3, 4), arena); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(3, 4), &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 48), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.EnumDescriptorProto.EnumReservedRange */ @@ -3842,11 +3894,11 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_p return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(const google_protobuf_EnumValueDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView); } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { return _upb_hasbit(msg, 2); @@ -3862,16 +3914,16 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const googl return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(const google_protobuf_EnumValueDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(8, 24), const upb_Message*) = NULL; _upb_clearhas(msg, 3); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(8, 24), const google_protobuf_EnumValueOptions*); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 2); @@ -3879,7 +3931,7 @@ UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_proto } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(16, 24), google_protobuf_EnumValueOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 24), google_protobuf_EnumValueOptions*) = value; } UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); @@ -3930,51 +3982,51 @@ UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_pro return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(const google_protobuf_ServiceDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView); } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 24)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 24)); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(const google_protobuf_ServiceDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(12, 24)); + _upb_array_detach(msg, UPB_SIZE(4, 24)); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* len) { - return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 24), len); + return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(4, 24), len); } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(const google_protobuf_ServiceDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(8, 32), const upb_Message*) = NULL; _upb_clearhas(msg, 2); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const google_protobuf_ServiceOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(8, 32), const google_protobuf_ServiceOptions*); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto* msg, size_t* len) { - return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 24), len); + return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 24), len); } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_MethodDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_MethodDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(16, 32), google_protobuf_ServiceOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 32), google_protobuf_ServiceOptions*) = value; } UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); @@ -4025,78 +4077,78 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_prot return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 3); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 4); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const upb_Message*) = NULL; + *UPB_PTR_AT(msg, UPB_SIZE(4, 56), const upb_Message*) = NULL; _upb_clearhas(msg, 4); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 56), const google_protobuf_MethodOptions*); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 5); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(8, 1), bool) = 0; _upb_clearhas(msg, 5); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); + return *UPB_PTR_AT(msg, UPB_SIZE(8, 1), bool); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 6); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(9, 2), bool) = 0; _upb_clearhas(msg, 6); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); + return *UPB_PTR_AT(msg, UPB_SIZE(9, 2), bool); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_MethodOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 56), google_protobuf_MethodOptions*) = value; } UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); @@ -4109,11 +4161,11 @@ UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescripto } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 1), bool) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value; + *UPB_PTR_AT(msg, UPB_SIZE(9, 2), bool) = value; } /* google.protobuf.FileOptions */ @@ -4155,21 +4207,21 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protob return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 3); @@ -4195,11 +4247,11 @@ UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf return _upb_hasbit(msg, 5); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 5); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 6); @@ -4275,51 +4327,51 @@ UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_p return _upb_hasbit(msg, 13); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 13); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 14); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 14); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 15); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(64, 104), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 15); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(64, 104), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 16); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(72, 120), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 16); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(72, 120), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 17); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(80, 136), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 17); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(80, 136), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 18); @@ -4335,39 +4387,39 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const goo return _upb_hasbit(msg, 19); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(88, 152), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 19); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(88, 152), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 20); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(96, 168), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 20); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(96, 168), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(100, 184)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 184)); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(const google_protobuf_FileOptions* msg) { - _upb_array_detach(msg, UPB_SIZE(100, 184)); + _upb_array_detach(msg, UPB_SIZE(20, 184)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* len) { - return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(100, 184), len); + return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(20, 184), len); } UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { _upb_sethas(msg, 3); @@ -4379,7 +4431,7 @@ UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_proto } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 6); @@ -4411,23 +4463,23 @@ UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 13); - *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 14); - *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 15); - *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(64, 104), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 16); - *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(72, 120), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 17); - *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(80, 136), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 18); @@ -4435,21 +4487,21 @@ UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_prot } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 19); - *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(88, 152), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 20); - *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(96, 168), upb_StringView) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* len) { - return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(100, 184), len); + return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 184), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(100, 184), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 184), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(100, 184), UPB_SIZE(2, 3), &sub, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 184), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } @@ -5156,51 +5208,51 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(32, 64), uint64_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(16, 32), uint64_t) = 0; _upb_clearhas(msg, 2); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), uint64_t); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), uint64_t); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(40, 72), int64_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(24, 40), int64_t) = 0; _upb_clearhas(msg, 3); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(40, 72), int64_t); + return *UPB_PTR_AT(msg, UPB_SIZE(24, 40), int64_t); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { return _upb_hasbit(msg, 4); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(48, 80), double) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(32, 48), double) = 0; _upb_clearhas(msg, 4); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(48, 80), double); + return *UPB_PTR_AT(msg, UPB_SIZE(32, 48), double); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { return _upb_hasbit(msg, 5); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 32), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 5); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { return _upb_hasbit(msg, 6); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(24, 48), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 6); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(24, 48), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* len) { @@ -5221,23 +5273,23 @@ UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_ } UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(32, 64), uint64_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 32), uint64_t) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(40, 72), int64_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 40), int64_t) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(48, 80), double) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 48), double) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(16, 32), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(24, 48), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = value; } /* google.protobuf.UninterpretedOption.NamePart */ @@ -5414,27 +5466,27 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(con return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(24, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(24, 40), upb_StringView); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - _upb_array_detach(msg, UPB_SIZE(28, 56)); + _upb_array_detach(msg, UPB_SIZE(12, 56)); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* len) { - return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); + return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(12, 56), len); } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* len) { @@ -5457,20 +5509,20 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 40), upb_StringView) = value; } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t* len) { - return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 56), len); } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t len, upb_Arena* arena) { - return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(3, 4), arena); + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 56), len, UPB_SIZE(3, 4), arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(3, 4), &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 56), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.GeneratedCodeInfo */ @@ -5567,10 +5619,10 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - _upb_array_detach(msg, UPB_SIZE(16, 16)); + _upb_array_detach(msg, UPB_SIZE(4, 16)); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* len) { - return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(16, 16), len); + return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(4, 16), len); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return _upb_hasbit(msg, 1); @@ -5586,41 +5638,41 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const goo return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(8, 4), int32_t) = 0; _upb_clearhas(msg, 2); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); + return *UPB_PTR_AT(msg, UPB_SIZE(8, 4), int32_t); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(12, 8), int32_t) = 0; _upb_clearhas(msg, 3); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); + return *UPB_PTR_AT(msg, UPB_SIZE(12, 8), int32_t); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return _upb_hasbit(msg, 4); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(16, 12), int32_t) = 0; _upb_clearhas(msg, 4); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 12), int32_t); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* len) { - return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 16), len); + return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 16), len); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t len, upb_Arena* arena) { - return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 16), len, 2, arena); + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 16), len, 2, arena); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 16), 2, &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 16), 2, &val, arena); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { _upb_sethas(msg, 1); @@ -5628,15 +5680,15 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(goo } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 4), int32_t) = value; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 8), int32_t) = value; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 12), int32_t) = value; } extern const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout; @@ -5771,12 +5823,19 @@ const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, const char* name, size_t len); -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size); +const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTable_Extension* ext); const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, const char* sym); +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* name, size_t size); + +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum); + const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, const char* name); @@ -5790,10 +5849,6 @@ const upb_FileDef* upb_DefPool_AddFile( upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, upb_Status* status); -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum); - const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( const upb_DefPool* s); @@ -5801,47 +5856,14 @@ const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, const upb_MessageDef* m, size_t* count); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +#ifdef __cplusplus +} /* extern "C" */ +#endif -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s); -const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTable_Extension* ext); -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext, - upb_FieldDef* f); -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status); -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v); +#endif /* UPB_REFLECTION_DEF_POOL_H_ */ -void** _upb_DefPool_ScratchData(const upb_DefPool* s); -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s); - -// For generated code only: loads a generated descriptor. -typedef struct _upb_DefPool_Init { - struct _upb_DefPool_Init** deps; // Dependencies of this file. - const upb_MiniTable_File* layout; - const char* filename; - upb_StringView descriptor; // Serialized descriptor. -} _upb_DefPool_Init; - -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init); - -// Should only be directly called by tests. This variant lets us suppress -// the use of compiled-in tables, forcing a rebuild of the tables at runtime. -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DEF_POOL_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" +// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" #ifndef UPB_REFLECTION_ENUM_DEF_H_ #define UPB_REFLECTION_ENUM_DEF_H_ @@ -5865,6 +5887,7 @@ const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, int32_t num); const char* upb_EnumDef_FullName(const upb_EnumDef* e); bool upb_EnumDef_HasOptions(const upb_EnumDef* e); +bool upb_EnumDef_IsClosed(const upb_EnumDef* e); // Creates a mini descriptor string for an enum, returns true on success. bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, @@ -5875,17 +5898,6 @@ const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e); const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i); int upb_EnumDef_ValueCount(const upb_EnumDef* e); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i); -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); -const upb_MiniTable_Enum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); - -// Allocate and initialize an array of |n| enum defs. -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const upb_MessageDef* containing_type); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -5914,19 +5926,6 @@ int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v); const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( const upb_EnumValueDef* v); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); - -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e, - bool* is_sorted); - -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - int n, upb_Arena* a); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -5953,16 +5952,6 @@ bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( const upb_ExtensionRange* r); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); - -// Allocate and initialize an array of |n| extension ranges owned by |m|. -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, - const upb_MessageDef* m); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -6023,30 +6012,6 @@ const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f); const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f); upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i); - -const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f); -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f); -bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f); -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f); -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f); - -// Allocate and initialize an array of |n| field defs. -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted); - -// Allocate and return a list of pointers to the |n| field defs in |ff|, -// sorted by field number. -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -6094,19 +6059,6 @@ int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f); const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i); int upb_FileDef_WeakDependencyCount(const upb_FileDef* f); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -const upb_MiniTable_Extension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i); -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f); -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); - -// upb_FileDef_Package() returns "" if f->package is NULL, this does not. -const char* _upb_FileDef_RawPackage(const upb_FileDef* f); - -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -6241,24 +6193,6 @@ const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDe upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m); upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i); -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m); -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t size, - upb_value v, upb_Arena* a); -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f); -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n); -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m); -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); - -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, - const upb_MessageDef* containing_type); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -6289,15 +6223,6 @@ const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); - -// Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -6335,19 +6260,6 @@ const char* upb_OneofDef_Name(const upb_OneofDef* o); int upb_OneofDef_numfields(const upb_OneofDef* o); const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); -bool _upb_OneofDef_Insert(upb_OneofDef* o, const upb_FieldDef* f, - const char* name, size_t size, upb_Arena* a); - -// Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m); - -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -6378,15 +6290,6 @@ int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); const char* upb_ServiceDef_Name(const upb_ServiceDef* s); const google_protobuf_ServiceOptions* upb_ServiceDef_Options(const upb_ServiceDef* s); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); - -// Allocate and initialize an array of |n| service defs. -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -6406,6 +6309,52 @@ upb_ServiceDef* _upb_ServiceDefs_New( #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPBDEFS_H_ #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPBDEFS_H_ + +#ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_ +#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); +upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s); + +bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext, + upb_FieldDef* f); +bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, + upb_Status* status); +bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, + upb_value* v); + +void** _upb_DefPool_ScratchData(const upb_DefPool* s); +size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s); + +// For generated code only: loads a generated descriptor. +typedef struct _upb_DefPool_Init { + struct _upb_DefPool_Init** deps; // Dependencies of this file. + const upb_MiniTable_File* layout; + const char* filename; + upb_StringView descriptor; // Serialized descriptor. +} _upb_DefPool_Init; + +bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init); + +// Should only be directly called by tests. This variant lets us suppress +// the use of compiled-in tables, forcing a rebuild of the tables at runtime. +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */ #ifdef __cplusplus extern "C" { #endif @@ -6561,12 +6510,12 @@ UPB_INLINE const upb_MessageDef *google_protobuf_GeneratedCodeInfo_Annotation_ge * decode.c and decode_fast.c. */ -#ifndef UPB_INTERNAL_DECODE_H_ -#define UPB_INTERNAL_DECODE_H_ +#ifndef UPB_WIRE_DECODE_INTERNAL_H_ +#define UPB_WIRE_DECODE_INTERNAL_H_ -#ifndef UPB_INTERNAL_ARENA_H_ -#define UPB_INTERNAL_ARENA_H_ +#ifndef UPB_MEM_ARENA_INTERNAL_H_ +#define UPB_MEM_ARENA_INTERNAL_H_ // Must be last. @@ -6604,8 +6553,7 @@ struct upb_Arena { #endif -#endif /* UPB_INTERNAL_ARENA_H_ */ - +#endif /* UPB_MEM_ARENA_INTERNAL_H_ */ #include "third_party/utf8_range/utf8_range.h" // Must be last. @@ -6776,7 +6724,7 @@ UPB_INLINE void _upb_Decoder_PopLimit(upb_Decoder* d, const char* ptr, } -#endif /* UPB_INTERNAL_DECODE_H_ */ +#endif /* UPB_WIRE_DECODE_INTERNAL_H_ */ #ifndef UPB_JSON_DECODE_H_ #define UPB_JSON_DECODE_H_ @@ -6862,9 +6810,6 @@ extern "C" { upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f); -/* Creates a new message of the given type in the given arena. */ -upb_Message* upb_Message_New(const upb_MessageDef* m, upb_Arena* a); - /* Returns the value associated with this field. */ upb_MessageValue upb_Message_Get(const upb_Message* msg, const upb_FieldDef* f); @@ -6967,8 +6912,32 @@ size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, #endif /* UPB_JSONENCODE_H_ */ -#ifndef UPB_INTERNAL_ENCODE_H_ -#define UPB_INTERNAL_ENCODE_H_ +#ifndef UPB_INTERNAL_VSNPRINTF_COMPAT_H_ +#define UPB_INTERNAL_VSNPRINTF_COMPAT_H_ + +#include + +// Must be last. + +UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, + va_list ap) { +#if defined(__MINGW64__) || defined(__MINGW32__) || defined(_MSC_VER) + // The msvc runtime has a non-conforming vsnprintf() that requires the + // following compatibility code to become conformant. + int n = -1; + if (size != 0) n = _vsnprintf_s(buf, size, _TRUNCATE, fmt, ap); + if (n == -1) n = _vscprintf(fmt, ap); + return n; +#else + return vsnprintf(buf, size, fmt, ap); +#endif +} + + +#endif // UPB_INTERNAL_VSNPRINTF_COMPAT_H_ + +#ifndef UPB_WIRE_ENCODE_INTERNAL_H_ +#define UPB_WIRE_ENCODE_INTERNAL_H_ // Must be last. @@ -6991,37 +6960,27 @@ void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); #endif -#endif /* UPB_INTERNAL_ENCODE_H_ */ +#endif /* UPB_WIRE_ENCODE_INTERNAL_H_ */ -#ifndef UPB_INTERNAL_VSNPRINTF_COMPAT_H_ -#define UPB_INTERNAL_VSNPRINTF_COMPAT_H_ +#ifndef UPB_MINI_TABLE_COMMON_H_ +#define UPB_MINI_TABLE_COMMON_H_ -#include // Must be last. -UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, - va_list ap) { -#if defined(__MINGW64__) || defined(__MINGW32__) || defined(_MSC_VER) - // The msvc runtime has a non-conforming vsnprintf() that requires the - // following compatibility code to become conformant. - int n = -1; - if (size != 0) n = _vsnprintf_s(buf, size, _TRUNCATE, fmt, ap); - if (n == -1) n = _vscprintf(fmt, ap); - return n; -#else - return vsnprintf(buf, size, fmt, ap); -#endif -} - - -#endif // UPB_INTERNAL_VSNPRINTF_COMPAT_H_ - -#ifndef UPB_MINI_TABLE_H_ -#define UPB_MINI_TABLE_H_ - +typedef enum { + kUpb_FieldModifier_IsRepeated = 1 << 0, + kUpb_FieldModifier_IsPacked = 1 << 1, + kUpb_FieldModifier_IsClosedEnum = 1 << 2, + kUpb_FieldModifier_IsProto3Singular = 1 << 3, + kUpb_FieldModifier_IsRequired = 1 << 4, +} kUpb_FieldModifier; -// Must be last. +typedef enum { + kUpb_MessageModifier_ValidateUtf8 = 1 << 0, + kUpb_MessageModifier_DefaultIsPacked = 1 << 1, + kUpb_MessageModifier_IsExtendable = 1 << 2, +} kUpb_MessageModifier; #ifdef __cplusplus extern "C" { @@ -7030,6 +6989,8 @@ extern "C" { const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber( const upb_MiniTable* table, uint32_t number); +upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field); + UPB_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( const upb_MiniTable* mini_table, const upb_MiniTable_Field* field) { return mini_table->subs[field->submsg_index].submsg; @@ -7040,76 +7001,112 @@ UPB_INLINE const upb_MiniTable_Enum* upb_MiniTable_GetSubEnumTable( return mini_table->subs[field->submsg_index].subenum; } -/** upb_MtDataEncoder *********************************************************/ +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_COMMON_H_ */ + +#ifndef UPB_MINI_TABLE_COMMON_INTERNAL_H_ +#define UPB_MINI_TABLE_COMMON_INTERNAL_H_ -// Functions to encode a string in a format that can be loaded by -// upb_MiniTable_Build(). + +// Must be last. typedef enum { - kUpb_MessageModifier_ValidateUtf8 = 1 << 0, - kUpb_MessageModifier_DefaultIsPacked = 1 << 1, - kUpb_MessageModifier_IsExtendable = 1 << 2, -} kUpb_MessageModifier; + kUpb_EncodedType_Double = 0, + kUpb_EncodedType_Float = 1, + kUpb_EncodedType_Fixed32 = 2, + kUpb_EncodedType_Fixed64 = 3, + kUpb_EncodedType_SFixed32 = 4, + kUpb_EncodedType_SFixed64 = 5, + kUpb_EncodedType_Int32 = 6, + kUpb_EncodedType_UInt32 = 7, + kUpb_EncodedType_SInt32 = 8, + kUpb_EncodedType_Int64 = 9, + kUpb_EncodedType_UInt64 = 10, + kUpb_EncodedType_SInt64 = 11, + kUpb_EncodedType_OpenEnum = 12, + kUpb_EncodedType_Bool = 13, + kUpb_EncodedType_Bytes = 14, + kUpb_EncodedType_String = 15, + kUpb_EncodedType_Group = 16, + kUpb_EncodedType_Message = 17, + kUpb_EncodedType_ClosedEnum = 18, + + kUpb_EncodedType_RepeatedBase = 20, +} upb_EncodedType; typedef enum { - kUpb_FieldModifier_IsRepeated = 1 << 0, - kUpb_FieldModifier_IsPacked = 1 << 1, - kUpb_FieldModifier_IsClosedEnum = 1 << 2, - kUpb_FieldModifier_IsProto3Singular = 1 << 3, - kUpb_FieldModifier_IsRequired = 1 << 4, -} kUpb_FieldModifier; + kUpb_EncodedFieldModifier_FlipPacked = 1 << 0, + // upb only. + kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2, + kUpb_EncodedFieldModifier_IsRequired = 1 << 3, +} upb_EncodedFieldModifier; -typedef struct { - char* end; // Limit of the buffer passed as a parameter. - // Aliased to internal-only members in .cc. - char internal[32]; -} upb_MtDataEncoder; +enum { + kUpb_EncodedValue_MinField = ' ', + kUpb_EncodedValue_MaxField = 'I', + kUpb_EncodedValue_MinModifier = 'L', + kUpb_EncodedValue_MaxModifier = '[', + kUpb_EncodedValue_End = '^', + kUpb_EncodedValue_MinSkip = '_', + kUpb_EncodedValue_MaxSkip = '~', + kUpb_EncodedValue_OneofSeparator = '~', + kUpb_EncodedValue_FieldSeparator = '|', + kUpb_EncodedValue_MinOneofField = ' ', + kUpb_EncodedValue_MaxOneofField = 'b', + kUpb_EncodedValue_MaxEnumMask = 'A', +}; -// If the input buffer has at least this many bytes available, the encoder call -// is guaranteed to succeed (as long as field number order is maintained). -#define kUpb_MtDataEncoder_MinSize 16 +enum { + kUpb_EncodedVersion_EnumV1 = '!', + kUpb_EncodedVersion_ExtensionV1 = '#', + kUpb_EncodedVersion_MapV1 = '%', + kUpb_EncodedVersion_MessageV1 = '$', + kUpb_EncodedVersion_MessageSetV1 = '&', +}; -// Encodes field/oneof information for a given message. The sequence of calls -// should look like: -// -// upb_MtDataEncoder e; -// char buf[256]; -// char* ptr = buf; -// e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); -// // Fields *must* be in field number order. -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// -// // If oneofs are present. Oneofs must be encoded after regular fields. -// ptr = upb_MiniTable_StartOneof(&e, ptr) -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// ptr = upb_MiniTable_StartOneof(&e, ptr); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// Oneofs must be encoded after all regular fields. -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod); -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num); +#ifdef __cplusplus +extern "C" { +#endif -// Encodes the set of values for a given enum. The values must be given in -// order (after casting to uint32_t), and repeats are not allowed. -void upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e); -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val); -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); +UPB_INLINE char _upb_ToBase92(int8_t ch) { + extern const char _kUpb_ToBase92[]; + UPB_ASSERT(0 <= ch && ch < 92); + return _kUpb_ToBase92[ch]; +} -/** upb_MiniTable *************************************************************/ +UPB_INLINE char _upb_FromBase92(uint8_t ch) { + extern const int8_t _kUpb_FromBase92[]; + if (' ' > ch || ch > '~') return -1; + return _kUpb_FromBase92[ch - ' ']; +} + +UPB_INLINE bool _upb_FieldType_IsPackable(upb_FieldType type) { + // clang-format off + const unsigned kUnpackableTypes = + (1 << kUpb_FieldType_String) | + (1 << kUpb_FieldType_Bytes) | + (1 << kUpb_FieldType_Message) | + (1 << kUpb_FieldType_Group); + // clang-format on + return (1 << type) & ~kUnpackableTypes; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_COMMON_INTERNAL_H_ */ + +#ifndef UPB_MINI_TABLE_DECODE_H_ +#define UPB_MINI_TABLE_DECODE_H_ + + +// Must be last. typedef enum { kUpb_MiniTablePlatform_32Bit, @@ -7118,6 +7115,10 @@ typedef enum { UPB_SIZE(kUpb_MiniTablePlatform_32Bit, kUpb_MiniTablePlatform_64Bit), } upb_MiniTablePlatform; +#ifdef __cplusplus +extern "C" { +#endif + // Builds a mini table from the data encoded in the buffer [data, len]. If any // errors occur, returns NULL and sets a status message. In the success case, // the caller must call upb_MiniTable_SetSub*() for all message or proto2 enum @@ -7147,15 +7148,6 @@ const char* upb_MiniTable_BuildExtension(const char* data, size_t len, upb_MiniTable_Sub sub, upb_Status* status); -// Special-case functions for MessageSet layout and map entries. -upb_MiniTable* upb_MiniTable_BuildMessageSet(upb_MiniTablePlatform platform, - upb_Arena* arena); -upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type, - upb_FieldType value_type, - bool value_is_proto3_enum, - upb_MiniTablePlatform platform, - upb_Arena* arena); - upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, upb_Arena* arena, upb_Status* status); @@ -7171,27 +7163,102 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, upb_Arena* arena, void** buf, size_t* buf_size, upb_Status* status); -// For testing only. -char upb_ToBase92(int8_t ch); -char upb_FromBase92(uint8_t ch); -bool upb_IsTypePackable(upb_FieldType type); +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_DECODE_H_ */ + +#ifndef UPB_MINI_TABLE_ENCODE_INTERNAL_H_ +#define UPB_MINI_TABLE_ENCODE_INTERNAL_H_ + + +// Must be last. + +// If the input buffer has at least this many bytes available, the encoder call +// is guaranteed to succeed (as long as field number order is maintained). +#define kUpb_MtDataEncoder_MinSize 16 + +typedef struct { + char* end; // Limit of the buffer passed as a parameter. + // Aliased to internal-only members in .cc. + char internal[32]; +} upb_MtDataEncoder; + +#ifdef __cplusplus +extern "C" { +#endif + +// Encodes field/oneof information for a given message. The sequence of calls +// should look like: +// +// upb_MtDataEncoder e; +// char buf[256]; +// char* ptr = buf; +// e.end = ptr + sizeof(buf); +// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero +// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); +// // Fields *must* be in field number order. +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// +// // If oneofs are present. Oneofs must be encoded after regular fields. +// ptr = upb_MiniTable_StartOneof(&e, ptr) +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// ptr = upb_MiniTable_StartOneof(&e, ptr); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// Oneofs must be encoded after all regular fields. +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod); +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num); + +// Encodes the set of values for a given enum. The values must be given in +// order (after casting to uint32_t), and repeats are not allowed. +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val); +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); + +// Encodes an entire mini descriptor for an extension. +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); + +// Encodes an entire mini descriptor for a map. +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t value_mod); + +// Encodes an entire mini descriptor for a message set. +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_H_ */ +#endif /* UPB_MINI_TABLE_ENCODE_INTERNAL_H_ */ -#ifndef UPB_REFLECTION_DEF_BUILDER_H_ -#define UPB_REFLECTION_DEF_BUILDER_H_ +#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ +#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ // Must be last. // We want to copy the options verbatim into the destination options proto. // We use serialize+parse as our deep copy. -#define UBP_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ +#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ if (google_protobuf_##desc_type##_has_options(proto)) { \ size_t size; \ char* pb = google_protobuf_##options_type##_serialize( \ @@ -7323,10 +7390,188 @@ UPB_INLINE void _upb_DefBuilder_CheckIdentFull(upb_DefBuilder* ctx, #endif -#endif /* UPB_REFLECTION_DEF_BUILDER_H_ */ +#endif /* UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ +#define UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i); +bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); +const upb_MiniTable_Enum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); + +// Allocate and initialize an array of |n| enum defs. +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const google_protobuf_EnumDescriptorProto* const* protos, + const upb_MessageDef* containing_type); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ +#define UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); + +// Allocate and initialize an array of |n| enum value defs owned by |e|. +upb_EnumValueDef* _upb_EnumValueDefs_New( + upb_DefBuilder* ctx, const char* prefix, int n, + const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e, + bool* is_sorted); + +const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, + int n, upb_Arena* a); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ +#define UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i); + +const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( + const upb_FieldDef* f); +bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f); +bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); +int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f); +uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f); +void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, + upb_FieldDef* f); + +// Allocate and initialize an array of |n| field defs. +upb_FieldDef* _upb_FieldDefs_New( + upb_DefBuilder* ctx, int n, + const google_protobuf_FieldDescriptorProto* const* protos, const char* prefix, + upb_MessageDef* m, bool* is_sorted); + +// Allocate and return a list of pointers to the |n| field defs in |ff|, +// sorted by field number. +const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, + upb_Arena* a); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_FILE_DEF_INTERNAL_H_ +#define UPB_REFLECTION_FILE_DEF_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +const upb_MiniTable_Extension* _upb_FileDef_ExtensionMiniTable( + const upb_FileDef* f, int i); +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f); +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); + +// upb_FileDef_Package() returns "" if f->package is NULL, this does not. +const char* _upb_FileDef_RawPackage(const upb_FileDef* f); + +void _upb_FileDef_Create(upb_DefBuilder* ctx, + const google_protobuf_FileDescriptorProto* file_proto); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_REFLECTION_FILE_DEF_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ +#define UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i); +bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m); +bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t size, + upb_value v, upb_Arena* a); +void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, + const upb_FieldDef* f); +bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n); +void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, + const upb_MessageDef* m); +void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); + +// Allocate and initialize an array of |n| message defs. +upb_MessageDef* _upb_MessageDefs_New( + upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, + const upb_MessageDef* containing_type); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ */ -#ifndef UPB_REFLECTION_DESC_STATE_H_ -#define UPB_REFLECTION_DESC_STATE_H_ +#ifndef UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ +#define UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); + +// Allocate and initialize an array of |n| service defs. +upb_ServiceDef* _upb_ServiceDefs_New( + upb_DefBuilder* ctx, int n, + const google_protobuf_ServiceDescriptorProto* const* protos); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ +#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ // Must be last. @@ -7357,12 +7602,35 @@ bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a); #endif -#endif /* UPB_REFLECTION_DESC_STATE_H_ */ +#endif /* UPB_REFLECTION_DESC_STATE_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ +#define UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); + +// Allocate and initialize an array of |n| extension ranges owned by |m|. +upb_ExtensionRange* _upb_ExtensionRanges_New( + upb_DefBuilder* ctx, int n, + const google_protobuf_DescriptorProto_ExtensionRange* const* protos, + const upb_MessageDef* m); + +#ifdef __cplusplus +} /* extern "C" */ +#endif -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#ifndef UPB_MAP_SORTER_H_ -#define UPB_MAP_SORTER_H_ +#endif /* UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ +#define UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ // Must be last. @@ -7371,57 +7639,47 @@ bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a); extern "C" { #endif -// _upb_mapsorter sorts maps and provides ordered iteration over the entries. -// Since maps can be recursive (map values can be messages which contain other -// maps), _upb_mapsorter can contain a stack of maps. +upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); +bool _upb_OneofDef_Insert(upb_OneofDef* o, const upb_FieldDef* f, + const char* name, size_t size, upb_Arena* a); -typedef struct { - upb_tabent const** entries; - int size; - int cap; -} _upb_mapsorter; +// Allocate and initialize an array of |n| oneof defs owned by |m|. +upb_OneofDef* _upb_OneofDefs_New( + upb_DefBuilder* ctx, int n, + const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m); -typedef struct { - int start; - int pos; - int end; -} _upb_sortedmap; +size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); -UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { - s->entries = NULL; - s->size = 0; - s->cap = 0; -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { - if (s->entries) free(s->entries); -} -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, - _upb_sortedmap* sorted, upb_MapEntry* ent) { - if (sorted->pos == sorted->end) return false; - const upb_tabent* tabent = s->entries[sorted->pos++]; - upb_StringView key = upb_tabstrview(tabent->key); - _upb_map_fromkey(key, &ent->k, map->key_size); - upb_value val = {tabent->val.val}; - _upb_map_fromvalue(val, &ent->v, map->val_size); - return true; -} +#endif /* UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ */ -UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, - _upb_sortedmap* sorted) { - s->size = sorted->start; -} +#ifndef UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ +#define UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted); + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); + +// Allocate and initialize an array of |n| method defs owned by |s|. +upb_MethodDef* _upb_MethodDefs_New( + upb_DefBuilder* ctx, int n, + const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MAP_SORTER_H_ */ +#endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ /* See port_def.inc. This should #undef all macros #defined there. */ diff --git a/php/ext/google/protobuf/template_package.xml b/php/ext/google/protobuf/template_package.xml new file mode 100644 index 0000000000..f8d6e66f6f --- /dev/null +++ b/php/ext/google/protobuf/template_package.xml @@ -0,0 +1,42 @@ + + + protobuf + pecl.php.net + Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. + https://developers.google.com/protocol-buffers/ + + Protobuf Team + protobufpackages + protobuf-packages@google.com + yes + + TEMPLATE_DATE + + + TEMPLATE_PHP_RELEASE + TEMPLATE_PHP_API + + + TEMPLATE_PHP_STABILITY + TEMPLATE_PHP_STABILITY + + BSD-3-Clause + + * See github.com/protocolbuffers/protobuf/releases/tag/vTEMPLATE_PROTOC_VERSION for release notes. + + + TEMPLATE_FILES + + + + + 7.0.0 + + + 1.4.0 + + + + protobuf + + diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index b1784f6a67..934e785126 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -344,15 +344,8 @@ cc_dist_library( }), tags = ["manual"], deps = [ - "//src/google/protobuf:arena", "//src/google/protobuf:arena_align", - "//src/google/protobuf:arena_allocation_policy", - "//src/google/protobuf:arena_cleanup", - "//src/google/protobuf:arena_config", "//src/google/protobuf:protobuf_lite", - "//src/google/protobuf/io", - "//src/google/protobuf/io:io_win32", - "//src/google/protobuf/stubs:lite", ], ) @@ -367,33 +360,11 @@ cc_dist_library( }), tags = ["manual"], deps = [ - "//src/google/protobuf:wkt_cc_proto", - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf:arena", "//src/google/protobuf:arena_align", - "//src/google/protobuf:arena_allocation_policy", - "//src/google/protobuf:arena_cleanup", - "//src/google/protobuf:arena_config", - "//src/google/protobuf:protobuf_lite", - "//src/google/protobuf:port_def", + "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf:wkt_cc_proto", "//src/google/protobuf/compiler:importer", - "//src/google/protobuf/io", - "//src/google/protobuf/io:gzip_stream", - "//src/google/protobuf/io:io_win32", - "//src/google/protobuf/io:printer", - "//src/google/protobuf/io:tokenizer", - "//src/google/protobuf/io:zero_copy_sink", "//src/google/protobuf/json", - "//src/google/protobuf/json:descriptor_traits", - "//src/google/protobuf/json:lexer", - "//src/google/protobuf/json:message_path", - "//src/google/protobuf/json:parser", - "//src/google/protobuf/json:unparser", - "//src/google/protobuf/json:untyped_message", - "//src/google/protobuf/json:writer", - "//src/google/protobuf/json:zero_copy_buffered_stream", - "//src/google/protobuf/stubs", - "//src/google/protobuf/stubs:lite", "//src/google/protobuf/util:delimited_message_util", "//src/google/protobuf/util:differencer", "//src/google/protobuf/util:field_mask_util", @@ -407,25 +378,19 @@ cc_dist_library( name = "protoc", tags = ["manual"], deps = [ - "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:command_line_interface", "//src/google/protobuf/compiler/cpp", - "//src/google/protobuf/compiler/cpp:names", - "//src/google/protobuf/compiler/cpp:names_internal", "//src/google/protobuf/compiler/csharp", - "//src/google/protobuf/compiler/csharp:names", "//src/google/protobuf/compiler/java", - "//src/google/protobuf/compiler/java:names", - "//src/google/protobuf/compiler/java:names_internal", "//src/google/protobuf/compiler/objectivec", - "//src/google/protobuf/compiler/objectivec:line_consumer", - "//src/google/protobuf/compiler/objectivec:names", - "//src/google/protobuf/compiler/objectivec:names_internal", "//src/google/protobuf/compiler/php", - "//src/google/protobuf/compiler/php:names", "//src/google/protobuf/compiler/python", "//src/google/protobuf/compiler/ruby", ], + dist_deps = [ + ":protobuf", + ":protobuf_lite", + ], ) cc_dist_library( @@ -433,6 +398,7 @@ cc_dist_library( testonly = 1, tags = ["manual"], deps = ["//src/google/protobuf:lite_test_util"], + dist_deps = [":protobuf_lite"], ) cc_dist_library( @@ -440,11 +406,19 @@ cc_dist_library( testonly = 1, tags = ["manual"], deps = [ + "//src/google/protobuf:lite_test_util", "//src/google/protobuf:test_util", "//src/google/protobuf:test_util2", "//src/google/protobuf/compiler:annotation_test_util", "//src/google/protobuf/compiler/cpp:unittest_lib", ], + dist_deps = [ + ":common_test", + ":lite_test_util", + ":protoc", + ":protobuf", + ":protobuf_lite", + ], ) cc_dist_library( @@ -452,12 +426,16 @@ cc_dist_library( testonly = 1, tags = ["manual"], deps = [ - "//src/google/protobuf/testing", "//src/google/protobuf/compiler:mock_code_generator", + "//src/google/protobuf/testing", + ], + dist_deps = [ + ":protobuf", + ":protobuf_lite", + ":protoc", ], ) - ################################################################################ # Distribution sources ################################################################################ diff --git a/pkg/build_systems.bzl b/pkg/build_systems.bzl index ce6d42959c..c1369c7e92 100644 --- a/pkg/build_systems.bzl +++ b/pkg/build_systems.bzl @@ -281,7 +281,10 @@ def _cmake_var_fragment(owner, varname, prefix, entries): ).format( owner = owner, varname = varname, - entries = "\n".join([" %s%s" % (prefix, f) for f in entries]), + # Strip out "wkt/google/protobuf/" from the well-known type file paths. + # This is currently necessary to allow checked-in and generated + # versions of the well-known type generated code to coexist. + entries = "\n".join([" %s%s" % (prefix, f.replace("wkt/google/protobuf/", "")) for f in entries]), ) def _cmake_file_list_impl(ctx): diff --git a/pkg/cc_dist_library.bzl b/pkg/cc_dist_library.bzl index 383979e6cd..42553ca3f8 100644 --- a/pkg/cc_dist_library.bzl +++ b/pkg/cc_dist_library.bzl @@ -134,12 +134,16 @@ CcFileList = provider( ) def _flatten_target_files(targets): - return depset(transitive = [target.files for target in targets]) + return depset(transitive = [ + target.files + for target in targets + # Filter out targets from external workspaces + if target.label.workspace_name == "" or + target.label.workspace_name == "com_google_protobuf" + ]) - files = [] - for target in targets: - files.extend(target.files.to_list()) - return files +def _get_transitive_sources(targets, attr, deps): + return depset(targets, transitive = [getattr(dep[CcFileList], attr) for dep in deps if CcFileList in dep]) def _cc_file_list_aspect_impl(target, ctx): # Extract sources from a `cc_library` (or similar): @@ -165,14 +169,22 @@ def _cc_file_list_aspect_impl(target, ctx): internal_hdrs.append(src) return [CcFileList( - hdrs = _flatten_target_files(getattr(rule_attr, "hdrs", depset())), - textual_hdrs = _flatten_target_files(getattr( - rule_attr, + hdrs = _get_transitive_sources( + _flatten_target_files(rule_attr.hdrs).to_list(), + "hdrs", + rule_attr.deps, + ), + textual_hdrs = _get_transitive_sources( + _flatten_target_files(rule_attr.textual_hdrs).to_list(), "textual_hdrs", - depset(), - )), - internal_hdrs = depset(internal_hdrs), - srcs = depset(srcs), + rule_attr.deps, + ), + internal_hdrs = _get_transitive_sources( + internal_hdrs, + "internal_hdrs", + rule_attr.deps, + ), + srcs = _get_transitive_sources(srcs, "srcs", rule_attr.deps), )] cc_file_list_aspect = aspect( @@ -198,7 +210,9 @@ Output is CcFileList. Example: # srcs = depset([File("foo.cc")]), # ) """, + required_providers = [CcInfo], implementation = _cc_file_list_aspect_impl, + attr_aspects = ["deps"], ) ################################################################################ @@ -206,10 +220,10 @@ Output is CcFileList. Example: ################################################################################ def _collect_inputs(deps): - """Collects files from a list of immediate deps. + """Collects files from a list of deps. - This rule collects source files and linker inputs for C++ deps. Only - these immediate deps are considered, not transitive deps. + This rule collects source files and linker inputs transitively for C++ + deps. The return value is a struct with object files (linker inputs), partitioned by PIC and non-pic, and the rules' source and header files: @@ -221,9 +235,8 @@ def _collect_inputs(deps): ) Args: - deps: Iterable of immediate deps. These will be treated as the "inputs," - but not the transitive deps. - + deps: Iterable of immediate deps, which will be treated as roots to + recurse transitively. Returns: A struct with linker inputs, source files, and header files. """ @@ -265,6 +278,27 @@ def _collect_inputs(deps): ), ) +# Given structs a and b returned from _collect_inputs(), returns a copy of a +# but with all files from b subtracted out. +def _subtract_files(a, b): + result_args = {} + + top_level_fields = ["objects", "pic_objects"] + for field in top_level_fields: + to_remove = {e: None for e in getattr(b, field)} + result_args[field] = [e for e in getattr(a, field) if not e in to_remove] + + cc_file_list_args = {} + file_list_fields = ["srcs", "hdrs", "internal_hdrs", "textual_hdrs"] + for field in file_list_fields: + to_remove = {e: None for e in getattr(b.cc_file_list, field).to_list()} + cc_file_list_args[field] = depset( + [e for e in getattr(a.cc_file_list, field).to_list() if not e in to_remove], + ) + result_args["cc_file_list"] = CcFileList(**cc_file_list_args) + + return struct(**result_args) + # Implementation for cc_dist_library rule. def _cc_dist_library_impl(ctx): cc_toolchain_info = find_cc_toolchain(ctx) @@ -274,7 +308,7 @@ def _cc_dist_library_impl(ctx): cc_toolchain = cc_toolchain_info, ) - inputs = _collect_inputs(ctx.attr.deps) + inputs = _subtract_files(_collect_inputs(ctx.attr.deps), _collect_inputs(ctx.attr.dist_deps)) # For static libraries, build separately with and without pic. @@ -346,20 +380,17 @@ Create libraries suitable for distribution. This rule creates static and dynamic libraries from the libraries listed in 'deps'. The resulting libraries are suitable for distributing all of 'deps' in a single logical library, for example, in an installable binary package. -Only the targets listed in 'deps' are included in the result (i.e., the -output does not include transitive dependencies), allowing precise control -over the library boundary. +The result includes all transitive dependencies, excluding those reachable +from 'dist_deps' or defined in a separate repository (e.g. Abseil). The outputs of this rule are a dynamic library and a static library. (If the build produces both PIC and non-PIC object files, then there is also a second static library.) The example below illustrates additional details. -This rule is different from Bazel's experimental `shared_cc_library` in -several ways. First, this rule ignores transitive dependencies, which means -that dynamic library dependencies generally need to be specified via -'linkopts'. Second, this rule produces a static archive library in addition -to the dynamic shared library. Third, this rule is not directly usable as a -C++ dependency (although the outputs could be used, e.g., by `cc_import`). +This rule is different from Bazel's experimental `shared_cc_library` in two +ways. First, this rule produces a static archive library in addition to the +dynamic shared library. Second, this rule is not directly usable as a C++ +dependency (although the outputs could be used, e.g., by `cc_import`). Example: @@ -372,15 +403,18 @@ Example: cc_dist_library( name = "dist", linkopts = ["-la"], # libdist.so dynamically links against liba.so. - deps = [":b", ":c"], # Output contains b.o and c.o, but not a.o. + deps = [":b", ":c"], # Output contains a.o, b.o, and c.o. ) """, attrs = { "deps": attr.label_list( - doc = ("The list of libraries to be included in the outputs. " + - "Only these targets' compilation outputs will be " + - "included (i.e., the transitive dependencies are not " + - "included in the output)."), + doc = ("The list of libraries to be included in the outputs, " + + "along with their transitive dependencies."), + aspects = [cc_file_list_aspect], + ), + "dist_deps": attr.label_list( + doc = ("The list of cc_dist_library dependencies that " + + "should be excluded."), aspects = [cc_file_list_aspect], ), "linkopts": attr.string_list( diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index fb2248a2dd..52e71aea3f 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -135,6 +135,6 @@ def protobuf_deps(): _github_archive( name = "upb", repo = "https://github.com/protocolbuffers/upb", - commit = "9e2d7f02da5440bfb0dfb069f61baa278aa2fbf6", - sha256 = "9eb13368a136af314855e1497838cf3124846b6a73a7e7c882455a52b8c04662", + commit = "73661563dbb82bf7fdd614dd8da1186c0acc6b17", + sha256 = "0b2789aa957c665165fa66892a6402489d6491cb097391fd8ea5b5a248dbde35", ) diff --git a/protobuf_version.bzl b/protobuf_version.bzl index 4c44f3da5d..3777e23d8a 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,3 +1,4 @@ PROTOC_VERSION = "21.9" PROTOBUF_JAVA_VERSION = "3.21.9" PROTOBUF_PYTHON_VERSION = "4.21.9" +PROTOBUF_PHP_VERSION = "3.21.9" diff --git a/push_auto_update.sh b/push_auto_update.sh new file mode 100755 index 0000000000..52fe90361a --- /dev/null +++ b/push_auto_update.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# This script updates src/file_lists.cmake and the checked-in generated code +# for the well-known types, commits the resulting changes, and pushes them. +# This does not do anything useful when run manually, but should be run by our +# GitHub action instead. + +set -ex + +# Cd to the repo root. +cd $(dirname -- "$0") + +previous_commit_title=$(git log -1 --pretty='%s') + +# Exit early if the previous commit was auto-generated. This reduces the risk +# of a bug causing an infinite loop of auto-generated commits. +if (echo "$previous_commit_title" | grep -q "^Auto-generate files"); then + echo "Previous commit was auto-generated" + exit 0 +fi + +# Run the staleness tests and use them to update any stale files. +bazel test //src:cmake_lists_staleness_test || ./bazel-bin/src/cmake_lists_staleness_test --fix +bazel test //src/google/protobuf:well_known_types_staleness_test || ./bazel-bin/src/google/protobuf/well_known_types_staleness_test --fix + +# Try to determine the most recent CL or pull request. +pr_from_merge=$(echo "$previous_commit_title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p') +pr_from_squash=$(echo "$previous_commit_title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p') +cl=$(git log -1 --pretty='%b' | sed -n 's/^PiperOrigin-RevId: \([0-9]*\)$/\1/p') + +if [ ! -z "$pr_from_merge" ]; then + commit_message="Auto-generate files after PR #$pr_from_merge" +elif [ ! -z "$pr_from_squash" ]; then + commit_message="Auto-generate files after PR #$pr_from_squash" +elif [ ! -z "$cl" ]; then + commit_message="Auto-generate files after cl/$cl" +else + # If we are unable to determine the CL or pull request number, we fall back + # on this default commit message. Typically this should not occur, but could + # happen if a pull request was merged via a rebase. + commit_message="Auto-generate files" +fi + +git add -A +git diff --staged --quiet || git commit -am "$commit_message" +git push diff --git a/python/docs/make.bat b/python/docs/make.bat index 27f573b87a..7893348a1b 100644 --- a/python/docs/make.bat +++ b/python/docs/make.bat @@ -1,35 +1,35 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=. -set BUILDDIR=_build - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% - -:end -popd +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index 997f6db6f5..e5d547a3bb 100644 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py @@ -66,6 +66,7 @@ if _USE_C_DESCRIPTORS: # and make it return True when the descriptor is an instance of the extension # type written in C++. class DescriptorMetaclass(type): + def __instancecheck__(cls, obj): if super(DescriptorMetaclass, cls).__instancecheck__(obj): return True @@ -633,13 +634,29 @@ class FieldDescriptor(DescriptorBase): if (self.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE or self.containing_oneof): return True - if hasattr(self.file, 'syntax'): - return self.file.syntax == 'proto2' - if hasattr(self.message_type, 'syntax'): - return self.message_type.syntax == 'proto2' - raise RuntimeError( - 'has_presence is not ready to use because field %s is not' - ' linked with message type nor file' % self.full_name) + # self.containing_type is used here instead of self.file for legacy + # compatibility. FieldDescriptor.file was added in cl/153110619 + # Some old/generated code didn't link file to FieldDescriptor. + # TODO(jieluo): remove syntax usage b/240619313 + return self.containing_type.syntax == 'proto2' + + @property + def is_packed(self): + """Returns if the field is packed.""" + if self.label != FieldDescriptor.LABEL_REPEATED: + return False + field_type = self.type + if (field_type == FieldDescriptor.TYPE_STRING or + field_type == FieldDescriptor.TYPE_GROUP or + field_type == FieldDescriptor.TYPE_MESSAGE or + field_type == FieldDescriptor.TYPE_BYTES): + return False + if self.containing_type.syntax == 'proto2': + return self.has_options and self.GetOptions().packed + else: + return (not self.has_options or + not self.GetOptions().HasField('packed') or + self.GetOptions().packed) @staticmethod def ProtoTypeToCppProtoType(proto_type): @@ -720,6 +737,18 @@ class EnumDescriptor(_NestedDescriptorBase): # Values are reversed to ensure that the first alias is retained. self.values_by_number = dict((v.number, v) for v in reversed(values)) + @property + def is_closed(self): + """If the enum is closed. + + closed enum means: + - Has a fixed set of named values. + - Encountering values not in this set causes them to be treated as + unknown fields. + - The first value (i.e., the default) may be nonzero. + """ + return self.file.syntax == 'proto2' + def CopyToProto(self, proto): """Copies this to a descriptor_pb2.EnumDescriptorProto. diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index 8b1a379997..bf385d2195 100644 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -35,7 +35,6 @@ __author__ = 'robinson@google.com (Will Robinson)' import unittest import warnings -from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_pb2 from google.protobuf import descriptor_pb2 @@ -45,6 +44,7 @@ from google.protobuf import descriptor from google.protobuf import descriptor_pool from google.protobuf import symbol_database from google.protobuf import text_format +from google.protobuf import unittest_custom_options_pb2 TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII = """ diff --git a/python/google/protobuf/internal/field_mask_test.py b/python/google/protobuf/internal/field_mask_test.py index 82664185f6..9ef6e00f2f 100644 --- a/python/google/protobuf/internal/field_mask_test.py +++ b/python/google/protobuf/internal/field_mask_test.py @@ -33,11 +33,11 @@ import unittest from google.protobuf import field_mask_pb2 -from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_pb2 from google.protobuf.internal import field_mask from google.protobuf.internal import test_util from google.protobuf import descriptor +from google.protobuf import map_unittest_pb2 class FieldMaskTest(unittest.TestCase): diff --git a/python/google/protobuf/internal/generator_test.py b/python/google/protobuf/internal/generator_test.py index 9883fce31e..82baa56fbb 100644 --- a/python/google/protobuf/internal/generator_test.py +++ b/python/google/protobuf/internal/generator_test.py @@ -42,15 +42,15 @@ __author__ = 'robinson@google.com (Will Robinson)' import unittest from google.protobuf.internal import test_bad_identifiers_pb2 -from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_import_public_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_mset_wire_format_pb2 -from google.protobuf import unittest_no_generic_services_pb2 from google.protobuf import unittest_pb2 from google.protobuf import service from google.protobuf import symbol_database +from google.protobuf import unittest_custom_options_pb2 +from google.protobuf import unittest_no_generic_services_pb2 MAX_EXTENSION = 536870912 diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index d018c3f2e6..6cf8b51f81 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -44,12 +44,12 @@ from google.protobuf import field_mask_pb2 from google.protobuf import struct_pb2 from google.protobuf import timestamp_pb2 from google.protobuf import wrappers_pb2 -from google.protobuf import any_test_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 from google.protobuf.internal import test_proto3_optional_pb2 from google.protobuf import descriptor_pool from google.protobuf import json_format +from google.protobuf import any_test_pb2 from google.protobuf.util import json_format_pb2 from google.protobuf.util import json_format_proto3_pb2 diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index a83cf85dea..1631d0417b 100644 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -50,20 +50,20 @@ import warnings cmp = lambda x, y: (x > y) - (x < y) -from google.protobuf import map_proto2_unittest_pb2 -from google.protobuf import map_unittest_pb2 -from google.protobuf import unittest_pb2 -from google.protobuf import unittest_proto3_arena_pb2 -from google.protobuf import descriptor +from google.protobuf import unittest_pb2 # pylint: disable=g-import-not-at-top from google.protobuf.internal import api_implementation from google.protobuf.internal import encoder from google.protobuf.internal import more_extensions_pb2 from google.protobuf.internal import packed_field_test_pb2 -from google.protobuf.internal import test_util from google.protobuf.internal import test_proto3_optional_pb2 +from google.protobuf.internal import test_util from google.protobuf.internal import testing_refleaks +from google.protobuf import descriptor from google.protobuf import message from google.protobuf.internal import _parameterized +from google.protobuf import map_proto2_unittest_pb2 +from google.protobuf import map_unittest_pb2 +from google.protobuf import unittest_proto3_arena_pb2 UCS2_MAXUNICODE = 65535 diff --git a/python/google/protobuf/internal/python_message.py b/python/google/protobuf/internal/python_message.py index 5550b425c4..1e71aa2a62 100644 --- a/python/google/protobuf/internal/python_message.py +++ b/python/google/protobuf/internal/python_message.py @@ -283,20 +283,8 @@ def _IsMessageMapField(field): def _AttachFieldHelpers(cls, field_descriptor): is_repeated = (field_descriptor.label == _FieldDescriptor.LABEL_REPEATED) - is_packable = (is_repeated and - wire_format.IsTypePackable(field_descriptor.type)) - is_proto3 = field_descriptor.containing_type.syntax == 'proto3' - if not is_packable: - is_packed = False - elif field_descriptor.containing_type.syntax == 'proto2': - is_packed = (field_descriptor.has_options and - field_descriptor.GetOptions().packed) - else: - has_packed_false = (field_descriptor.has_options and - field_descriptor.GetOptions().HasField('packed') and - field_descriptor.GetOptions().packed == False) - is_packed = not has_packed_false is_map_entry = _IsMapField(field_descriptor) + is_packed = field_descriptor.is_packed if is_map_entry: field_encoder = encoder.MapEncoder(field_descriptor) @@ -320,16 +308,12 @@ def _AttachFieldHelpers(cls, field_descriptor): tag_bytes = encoder.TagBytes(field_descriptor.number, wiretype) decode_type = field_descriptor.type if (decode_type == _FieldDescriptor.TYPE_ENUM and - type_checkers.SupportsOpenEnums(field_descriptor)): + not field_descriptor.enum_type.is_closed): decode_type = _FieldDescriptor.TYPE_INT32 oneof_descriptor = None - clear_if_default = False if field_descriptor.containing_oneof is not None: oneof_descriptor = field_descriptor - elif (is_proto3 and not is_repeated and - field_descriptor.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE): - clear_if_default = True if is_map_entry: is_message_map = _IsMessageMapField(field_descriptor) @@ -341,7 +325,7 @@ def _AttachFieldHelpers(cls, field_descriptor): field_decoder = decoder.StringDecoder( field_descriptor.number, is_repeated, is_packed, field_descriptor, field_descriptor._default_constructor, - clear_if_default) + not field_descriptor.has_presence) elif field_descriptor.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE: field_decoder = type_checkers.TYPE_TO_DECODER[decode_type]( field_descriptor.number, is_repeated, is_packed, @@ -351,7 +335,7 @@ def _AttachFieldHelpers(cls, field_descriptor): field_descriptor.number, is_repeated, is_packed, # pylint: disable=protected-access field_descriptor, field_descriptor._default_constructor, - clear_if_default) + not field_descriptor.has_presence) cls._decoders_by_tag[tag_bytes] = (field_decoder, oneof_descriptor) @@ -683,7 +667,6 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls): property_name = _PropertyName(proto_field_name) type_checker = type_checkers.GetTypeChecker(field) default_value = field.default_value - is_proto3 = field.containing_type.syntax == 'proto3' def getter(self): # TODO(protobuf-team): This may be broken since there may not be @@ -692,8 +675,6 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls): getter.__module__ = None getter.__doc__ = 'Getter for %s.' % proto_field_name - clear_when_set_to_default = is_proto3 and not field.containing_oneof - def field_setter(self, new_value): # pylint: disable=protected-access # Testing the value for truthiness captures all of the proto3 defaults @@ -703,7 +684,7 @@ def _AddPropertiesForNonRepeatedScalarField(field, cls): except TypeError as e: raise TypeError( 'Cannot set %s to %.1024r: %s' % (field.full_name, new_value, e)) - if clear_when_set_to_default and not new_value: + if not field.has_presence and not new_value: self._fields.pop(field, None) else: self._fields[field] = new_value @@ -825,24 +806,16 @@ def _AddListFieldsMethod(message_descriptor, cls): cls.ListFields = ListFields -_PROTO3_ERROR_TEMPLATE = \ - ('Protocol message %s has no non-repeated submessage field "%s" ' - 'nor marked as optional') -_PROTO2_ERROR_TEMPLATE = 'Protocol message %s has no non-repeated field "%s"' def _AddHasFieldMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" - is_proto3 = (message_descriptor.syntax == "proto3") - error_msg = _PROTO3_ERROR_TEMPLATE if is_proto3 else _PROTO2_ERROR_TEMPLATE - hassable_fields = {} for field in message_descriptor.fields: if field.label == _FieldDescriptor.LABEL_REPEATED: continue # For proto3, only submessages and fields inside a oneof have presence. - if (is_proto3 and field.cpp_type != _FieldDescriptor.CPPTYPE_MESSAGE and - not field.containing_oneof): + if not field.has_presence: continue hassable_fields[field.name] = field @@ -853,8 +826,10 @@ def _AddHasFieldMethod(message_descriptor, cls): def HasField(self, field_name): try: field = hassable_fields[field_name] - except KeyError: - raise ValueError(error_msg % (message_descriptor.full_name, field_name)) + except KeyError as exc: + raise ValueError('Protocol message %s has no non-repeated field "%s" ' + 'nor has presence is not available for this field.' % ( + message_descriptor.full_name, field_name)) from exc if isinstance(field, descriptor_mod.OneofDescriptor): try: diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index f35e514dd2..878cb4b415 100644 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -44,7 +44,6 @@ import unittest from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 -from google.protobuf import unittest_proto3_arena_pb2 from google.protobuf import descriptor_pb2 from google.protobuf import descriptor from google.protobuf import message @@ -59,6 +58,7 @@ from google.protobuf.internal import test_util from google.protobuf.internal import testing_refleaks from google.protobuf.internal import decoder from google.protobuf.internal import _parameterized +from google.protobuf import unittest_proto3_arena_pb2 warnings.simplefilter('error', DeprecationWarning) diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 5f2c2deaf5..c44a565ac7 100644 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -41,12 +41,8 @@ import unittest from google.protobuf import any_pb2 from google.protobuf import struct_pb2 -from google.protobuf import any_test_pb2 -from google.protobuf import map_unittest_pb2 -from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 -from google.protobuf import unittest_proto3_arena_pb2 from google.protobuf import descriptor_pb2 from google.protobuf.internal import any_test_pb2 as test_extend_any from google.protobuf.internal import api_implementation @@ -56,6 +52,10 @@ from google.protobuf.internal import test_util from google.protobuf import descriptor_pool from google.protobuf import text_format from google.protobuf.internal import _parameterized +from google.protobuf import any_test_pb2 +from google.protobuf import map_unittest_pb2 +from google.protobuf import unittest_custom_options_pb2 +from google.protobuf import unittest_proto3_arena_pb2 # pylint: enable=g-import-not-at-top diff --git a/python/google/protobuf/internal/type_checkers.py b/python/google/protobuf/internal/type_checkers.py index a53e71fe8e..165dcd8c2e 100644 --- a/python/google/protobuf/internal/type_checkers.py +++ b/python/google/protobuf/internal/type_checkers.py @@ -75,10 +75,6 @@ def ToShortestFloat(original): return rounded -def SupportsOpenEnums(field_descriptor): - return field_descriptor.containing_type.syntax == 'proto3' - - def GetTypeChecker(field): """Returns a type checker for a message field of the specified types. @@ -93,11 +89,11 @@ def GetTypeChecker(field): field.type == _FieldDescriptor.TYPE_STRING): return UnicodeValueChecker() if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM: - if SupportsOpenEnums(field): + if field.enum_type.is_closed: + return EnumValueChecker(field.enum_type) + else: # When open enums are supported, any int32 can be assigned. return _VALUE_CHECKERS[_FieldDescriptor.CPPTYPE_INT32] - else: - return EnumValueChecker(field.enum_type) return _VALUE_CHECKERS[field.cpp_type] diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index 64a0367828..16ecb03ac7 100644 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -36,10 +36,8 @@ __author__ = 'bohdank@google.com (Bohdan Koval)' import sys import unittest -from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 -from google.protobuf import unittest_proto3_arena_pb2 from google.protobuf.internal import api_implementation from google.protobuf.internal import encoder from google.protobuf.internal import message_set_extensions_pb2 @@ -50,6 +48,8 @@ from google.protobuf.internal import type_checkers from google.protobuf.internal import wire_format from google.protobuf import descriptor from google.protobuf import unknown_fields +from google.protobuf import map_unittest_pb2 +from google.protobuf import unittest_proto3_arena_pb2 try: import tracemalloc # pylint: disable=g-import-not-at-top except ImportError: diff --git a/python/google/protobuf/internal/wire_format.py b/python/google/protobuf/internal/wire_format.py index 883f525585..94346a75ab 100644 --- a/python/google/protobuf/internal/wire_format.py +++ b/python/google/protobuf/internal/wire_format.py @@ -43,7 +43,7 @@ TAG_TYPE_MASK = (1 << TAG_TYPE_BITS) - 1 # 0x7 # These numbers identify the wire type of a protocol buffer value. # We use the least-significant TAG_TYPE_BITS bits of the varint-encoded # tag-and-type to store one of these WIRETYPE_* constants. -# These values must match WireType enum in google/protobuf/wire_format.h. +# These values must match WireType enum in //net/proto2/public/wire_format.h. WIRETYPE_VARINT = 0 WIRETYPE_FIXED64 = 1 WIRETYPE_LENGTH_DELIMITED = 2 diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index f35a432126..1cf29d1393 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py @@ -287,10 +287,11 @@ class _Printer(object): if enum_value is not None: return enum_value.name else: - if field.file.syntax == 'proto3': + if field.enum_type.is_closed: + raise SerializeToJsonError('Enum field contains an integer value ' + 'which can not mapped to an enum value.') + else: return value - raise SerializeToJsonError('Enum field contains an integer value ' - 'which can not mapped to an enum value.') elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING: if field.type == descriptor.FieldDescriptor.TYPE_BYTES: # Use base64 Data encoding for bytes @@ -799,11 +800,11 @@ def _ConvertScalarFieldValue(value, field, path, require_str=False): raise ParseError('Invalid enum value {0} for enum type {1}'.format( value, field.enum_type.full_name)) if enum_value is None: - if field.file.syntax == 'proto3': - # Proto3 accepts unknown enums. + if field.enum_type.is_closed: + raise ParseError('Invalid enum value {0} for enum type {1}'.format( + value, field.enum_type.full_name)) + else: return number - raise ParseError('Invalid enum value {0} for enum type {1}'.format( - value, field.enum_type.full_name)) return enum_value.number except ParseError as e: raise ParseError('{0} at {1}'.format(e, path)) diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index fc97b0fa6c..f6db77a160 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -1182,6 +1182,11 @@ static PyObject* GetHasOptions(PyBaseDescriptor *self, void *closure) { Py_RETURN_FALSE; } } + +static PyObject* GetIsClosed(PyBaseDescriptor* self, void* closure) { + return PyBool_FromLong(_GetDescriptor(self)->is_closed()); +} + static int SetHasOptions(PyBaseDescriptor *self, PyObject *value, void *closure) { return CheckCalledFromGeneratedFile("has_options"); @@ -1225,6 +1230,7 @@ static PyGetSetDef Getters[] = { "Containing type"}, {"has_options", (getter)GetHasOptions, (setter)SetHasOptions, "Has Options"}, + {"is_closed", (getter)GetIsClosed, nullptr, "If the enum is closed"}, {"_options", (getter) nullptr, (setter)SetOptions, "Options"}, {"_serialized_options", (getter) nullptr, (setter)SetSerializedOptions, "Serialized Options"}, diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index cab7cb700d..4f38324b55 100644 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -340,7 +340,7 @@ def _BuildMessageFromTypeName(type_name, descriptor_pool): return message_type() -# These values must match WireType enum in google/protobuf/wire_format.h. +# These values must match WireType enum in //net/proto2/public/wire_format.h. WIRETYPE_LENGTH_DELIMITED = 2 WIRETYPE_START_GROUP = 3 @@ -1852,12 +1852,8 @@ def ParseEnum(field, value): raise ValueError('Enum type "%s" has no value named %s.' % (enum_descriptor.full_name, value)) else: - # Numeric value. - if hasattr(field.file, 'syntax'): - # Attribute is checked for compatibility. - if field.file.syntax == 'proto3': - # Proto3 accept numeric unknown enums. - return number + if not field.enum_type.is_closed: + return number enum_value = enum_descriptor.values_by_number.get(number, None) if enum_value is None: raise ValueError('Enum type "%s" has no value with number %d.' % diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index b9de9d9532..46c5f5f81e 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1300,7 +1300,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { return mod; } -// Internal only; used by Google::Protobuf.deep_copy. +// Internal to the library; used by Google::Protobuf.deep_copy. upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m, upb_Arena* arena) { // Serialize and parse. diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 3be0900ee1..6f767d09ac 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -269,10 +269,132 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #endif +// Must be last. + +const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { + uint64_t u64 = 0; + while (ptr < end) { + unsigned ch = *ptr - '0'; + if (ch >= 10) break; + if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { + return NULL; // integer overflow + } + u64 *= 10; + u64 += ch; + ptr++; + } + + *val = u64; + return ptr; +} + +const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, + bool* is_neg) { + bool neg = false; + uint64_t u64; + + if (ptr != end && *ptr == '-') { + ptr++; + neg = true; + } + + ptr = upb_BufToUint64(ptr, end, &u64); + if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { + return NULL; // integer overflow + } + + *val = neg ? -u64 : u64; + if (is_neg) *is_neg = neg; + return ptr; +} + #include + // Must be last. +static const char _upb_CTypeo_sizelg2[12] = { + 0, + 0, /* kUpb_CType_Bool */ + 2, /* kUpb_CType_Float */ + 2, /* kUpb_CType_Int32 */ + 2, /* kUpb_CType_UInt32 */ + 2, /* kUpb_CType_Enum */ + UPB_SIZE(2, 3), /* kUpb_CType_Message */ + 3, /* kUpb_CType_Double */ + 3, /* kUpb_CType_Int64 */ + 3, /* kUpb_CType_UInt64 */ + UPB_SIZE(3, 4), /* kUpb_CType_String */ + UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ +}; + +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); +} + +size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } + +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; + const char* data = _upb_array_constptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->size); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->size); + memcpy(data + (i << lg2), &val, 1 << lg2); +} + +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + if (!upb_Array_Resize(arr, arr->size + 1, arena)) { + return false; + } + upb_Array_Set(arr, arr->size - 1, val); + return true; +} + +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +} + +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(i <= arr->size); + UPB_ASSERT(count + arr->size >= count); + size_t oldsize = arr->size; + if (!upb_Array_Resize(arr, arr->size + count, arena)) { + return false; + } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; +} + +/* + * i end arr->size + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->size); + upb_Array_Move(arr, i, end, arr->size - end); + arr->size -= count; +} + +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + return _upb_Array_Resize(arr, size, arena); +} + +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// + bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) { size_t new_capacity = UPB_MAX(arr->capacity, 4); int elem_size_lg2 = arr->data & 7; @@ -280,7 +402,7 @@ bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) { size_t new_bytes; void* ptr = _upb_array_ptr(arr); - /* Log2 ceiling of size. */ + // Log2 ceiling of size. while (new_capacity < min_capacity) new_capacity *= 2; new_bytes = new_capacity << elem_size_lg2; @@ -330,46 +452,6 @@ bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, } -// Must be last. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { - uint64_t u64 = 0; - while (ptr < end) { - unsigned ch = *ptr - '0'; - if (ch >= 10) break; - if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { - return NULL; // integer overflow - } - u64 *= 10; - u64 += ch; - ptr++; - } - - *val = u64; - return ptr; -} - -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg) { - bool neg = false; - uint64_t u64; - - if (ptr != end && *ptr == '-') { - ptr++; - neg = true; - } - - ptr = upb_BufToUint64(ptr, end, &u64); - if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { - return NULL; // integer overflow - } - - *val = neg ? -u64 : u64; - if (is_neg) *is_neg = neg; - return ptr; -} - - #include @@ -448,75 +530,183 @@ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { /* void upb_MapIterator_SetValue(upb_Map *map, size_t iter, upb_MessageValue * value); */ -/* This file was generated by upbc (the upb compiler) from the input - * file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. */ - -#include -static const upb_MiniTable_Sub google_protobuf_FileDescriptorSet_submsgs[1] = { - {.submsg = &google_protobuf_FileDescriptorProto_msg_init}, -}; +// Must be last. -static const upb_MiniTable_Field google_protobuf_FileDescriptorSet__fields[1] = { - {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, -}; +static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, + void* b_key, size_t size) { + const upb_tabent* const* a = _a; + const upb_tabent* const* b = _b; + upb_StringView a_tabkey = upb_tabstrview((*a)->key); + upb_StringView b_tabkey = upb_tabstrview((*b)->key); + _upb_map_fromkey(a_tabkey, a_key, size); + _upb_map_fromkey(b_tabkey, b_key, size); +} -const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init = { - &google_protobuf_FileDescriptorSet_submsgs[0], - &google_protobuf_FileDescriptorSet__fields[0], - UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, -}; +static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { + int64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return a < b ? -1 : a > b; +} -static const upb_MiniTable_Sub google_protobuf_FileDescriptorProto_submsgs[6] = { - {.submsg = &google_protobuf_DescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, - {.submsg = &google_protobuf_ServiceDescriptorProto_msg_init}, - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_FileOptions_msg_init}, - {.submsg = &google_protobuf_SourceCodeInfo_msg_init}, -}; +static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { + uint64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return a < b ? -1 : a > b; +} -static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[13] = { - {1, UPB_SIZE(40, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(48, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(4, 40), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(8, 48), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(12, 56), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(16, 64), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(20, 72), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(24, 80), UPB_SIZE(3, 3), 4, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(28, 88), UPB_SIZE(4, 4), 5, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(32, 96), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(36, 104), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {12, UPB_SIZE(56, 112), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {13, UPB_SIZE(64, 128), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, -}; +static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { + int32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return a < b ? -1 : a > b; +} -const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init = { - &google_protobuf_FileDescriptorProto_submsgs[0], - &google_protobuf_FileDescriptorProto__fields[0], - UPB_SIZE(72, 144), 13, kUpb_ExtMode_NonExtendable, 13, 255, 0, -}; +static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { + uint32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return a < b ? -1 : a > b; +} -static const upb_MiniTable_Sub google_protobuf_DescriptorProto_submsgs[8] = { - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msg_init}, - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_MessageOptions_msg_init}, - {.submsg = &google_protobuf_OneofDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msg_init}, -}; +static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { + bool a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); + return a < b ? -1 : a > b; +} -static const upb_MiniTable_Field google_protobuf_DescriptorProto__fields[10] = { - {1, UPB_SIZE(40, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { + upb_StringView a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); + size_t common_size = UPB_MIN(a.size, b.size); + int cmp = memcmp(a.data, b.data, common_size); + if (cmp) return -cmp; + return a.size < b.size ? -1 : a.size > b.size; +} + +static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { + [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, + [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, + [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, + + [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, + [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, + + [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, + + [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, + [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, + + [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, + + [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, + [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, +}; + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted) { + int map_size = _upb_Map_Size(map); + sorted->start = s->size; + sorted->pos = sorted->start; + sorted->end = sorted->start + map_size; + + // Grow s->entries if necessary. + if (sorted->end > s->cap) { + s->cap = _upb_Log2CeilingSize(sorted->end); + s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); + if (!s->entries) return false; + } + + s->size = sorted->end; + + // Copy non-empty entries from the table to s->entries. + upb_tabent const** dst = &s->entries[sorted->start]; + const upb_tabent* src = map->table.t.entries; + const upb_tabent* end = src + upb_table_size(&map->table.t); + for (; src < end; src++) { + if (!upb_tabent_isempty(src)) { + *dst = src; + dst++; + } + } + UPB_ASSERT(dst == &s->entries[sorted->end]); + + // Sort entries according to the key type. + qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), + compar[key_type]); + return true; +} +/* This file was generated by upbc (the upb compiler) from the input + * file: + * + * google/protobuf/descriptor.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#include + + +static const upb_MiniTable_Sub google_protobuf_FileDescriptorSet_submsgs[1] = { + {.submsg = &google_protobuf_FileDescriptorProto_msg_init}, +}; + +static const upb_MiniTable_Field google_protobuf_FileDescriptorSet__fields[1] = { + {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init = { + &google_protobuf_FileDescriptorSet_submsgs[0], + &google_protobuf_FileDescriptorSet__fields[0], + UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, +}; + +static const upb_MiniTable_Sub google_protobuf_FileDescriptorProto_submsgs[6] = { + {.submsg = &google_protobuf_DescriptorProto_msg_init}, + {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, + {.submsg = &google_protobuf_ServiceDescriptorProto_msg_init}, + {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, + {.submsg = &google_protobuf_FileOptions_msg_init}, + {.submsg = &google_protobuf_SourceCodeInfo_msg_init}, +}; + +static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[13] = { + {1, UPB_SIZE(40, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(48, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(4, 40), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(8, 48), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(12, 56), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(16, 64), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(20, 72), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(24, 80), UPB_SIZE(3, 3), 4, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {9, UPB_SIZE(28, 88), UPB_SIZE(4, 4), 5, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {10, UPB_SIZE(32, 96), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {11, UPB_SIZE(36, 104), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {12, UPB_SIZE(56, 112), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {13, UPB_SIZE(64, 128), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init = { + &google_protobuf_FileDescriptorProto_submsgs[0], + &google_protobuf_FileDescriptorProto__fields[0], + UPB_SIZE(72, 144), 13, kUpb_ExtMode_NonExtendable, 13, 255, 0, +}; + +static const upb_MiniTable_Sub google_protobuf_DescriptorProto_submsgs[8] = { + {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, + {.submsg = &google_protobuf_DescriptorProto_msg_init}, + {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, + {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msg_init}, + {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, + {.submsg = &google_protobuf_MessageOptions_msg_init}, + {.submsg = &google_protobuf_OneofDescriptorProto_msg_init}, + {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msg_init}, +}; + +static const upb_MiniTable_Field google_protobuf_DescriptorProto__fields[10] = { + {1, UPB_SIZE(40, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {2, UPB_SIZE(4, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(8, 32), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, {4, UPB_SIZE(12, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, @@ -1088,10 +1278,12 @@ bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, const upb_MiniTable_Extension** start = e; const upb_MiniTable_Extension** end = UPB_PTRADD(e, count); for (; e < end; e++) { - // TODO: we should gracefully handle the case where this already exists. - // Right now we're only checking for out of memory. const upb_MiniTable_Extension* ext = *e; extreg_key(buf, ext->extendee, ext->field.number); + upb_value v; + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + goto failure; + } if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, upb_value_constptr(ext), r->arena)) { goto failure; @@ -4342,359 +4534,307 @@ size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, } -#include -#include - +#include // Must be last. -typedef enum { - kUpb_EncodedType_Double = 0, - kUpb_EncodedType_Float = 1, - kUpb_EncodedType_Fixed32 = 2, - kUpb_EncodedType_Fixed64 = 3, - kUpb_EncodedType_SFixed32 = 4, - kUpb_EncodedType_SFixed64 = 5, - kUpb_EncodedType_Int32 = 6, - kUpb_EncodedType_UInt32 = 7, - kUpb_EncodedType_SInt32 = 8, - kUpb_EncodedType_Int64 = 9, - kUpb_EncodedType_UInt64 = 10, - kUpb_EncodedType_SInt64 = 11, - kUpb_EncodedType_OpenEnum = 12, - kUpb_EncodedType_Bool = 13, - kUpb_EncodedType_Bytes = 14, - kUpb_EncodedType_String = 15, - kUpb_EncodedType_Group = 16, - kUpb_EncodedType_Message = 17, - kUpb_EncodedType_ClosedEnum = 18, - - kUpb_EncodedType_RepeatedBase = 20, -} upb_EncodedType; - -typedef enum { - kUpb_EncodedFieldModifier_FlipPacked = 1 << 0, - // upb only. - kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2, - kUpb_EncodedFieldModifier_IsRequired = 1 << 3, -} upb_EncodedFieldModifier; +static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, + size_t size) { + UPB_UNUSED(alloc); + UPB_UNUSED(oldsize); + if (size == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, size); + } +} -enum { - kUpb_EncodedValue_MinField = ' ', - kUpb_EncodedValue_MaxField = 'I', - kUpb_EncodedValue_MinModifier = 'L', - kUpb_EncodedValue_MaxModifier = '[', - kUpb_EncodedValue_End = '^', - kUpb_EncodedValue_MinSkip = '_', - kUpb_EncodedValue_MaxSkip = '~', - kUpb_EncodedValue_OneofSeparator = '~', - kUpb_EncodedValue_FieldSeparator = '|', - kUpb_EncodedValue_MinOneofField = ' ', - kUpb_EncodedValue_MaxOneofField = 'b', - kUpb_EncodedValue_MaxEnumMask = 'A', -}; +upb_alloc upb_alloc_global = {&upb_global_allocfunc}; -enum { - kUpb_EncodedVersion_EnumV1 = '!', - kUpb_EncodedVersion_ExtensionV1 = '#', - kUpb_EncodedVersion_MessageV1 = '$', -}; -char upb_ToBase92(int8_t ch) { - static const char kUpb_ToBase92[] = { - ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', - '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', - 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', - 'Z', '[', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '{', '|', '}', '~', - }; +// Must be last. - UPB_ASSERT(0 <= ch && ch < 92); - return kUpb_ToBase92[ch]; +static uint32_t* upb_cleanup_pointer(uintptr_t cleanup_metadata) { + return (uint32_t*)(cleanup_metadata & ~0x1); } -char upb_FromBase92(uint8_t ch) { - static const int8_t kUpb_FromBase92[] = { - 0, 1, -1, 2, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, - 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, 58, 59, 60, - 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, - 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, - }; - - if (' ' > ch || ch > '~') return -1; - return kUpb_FromBase92[ch - ' ']; +static bool upb_cleanup_has_initial_block(uintptr_t cleanup_metadata) { + return cleanup_metadata & 0x1; } -bool upb_IsTypePackable(upb_FieldType type) { - // clang-format off - static const unsigned kUnpackableTypes = - (1 << kUpb_FieldType_String) | - (1 << kUpb_FieldType_Bytes) | - (1 << kUpb_FieldType_Message) | - (1 << kUpb_FieldType_Group); - // clang-format on - return (1 << type) & ~kUnpackableTypes; +static uintptr_t upb_cleanup_metadata(uint32_t* cleanup, + bool has_initial_block) { + return (uintptr_t)cleanup | has_initial_block; } -/** upb_MtDataEncoder *********************************************************/ - -typedef struct { - uint64_t present_values_mask; - uint32_t last_written_value; -} upb_MtDataEncoderInternal_EnumState; - -typedef struct { - uint64_t msg_modifiers; - uint32_t last_field_num; - enum { - kUpb_OneofState_NotStarted, - kUpb_OneofState_StartedOneof, - kUpb_OneofState_EmittedOneofField, - } oneof_state; -} upb_MtDataEncoderInternal_MsgState; +struct mem_block { + struct mem_block* next; + uint32_t size; + uint32_t cleanups; + /* Data follows. */ +}; -typedef struct { - char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. - union { - upb_MtDataEncoderInternal_EnumState enum_state; - upb_MtDataEncoderInternal_MsgState msg_state; - } state; -} upb_MtDataEncoderInternal; +typedef struct cleanup_ent { + upb_CleanupFunc* cleanup; + void* ud; +} cleanup_ent; -static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( - upb_MtDataEncoder* e, char* buf_start) { - UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); - upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; - ret->buf_start = buf_start; - return ret; -} +static const size_t memblock_reserve = + UPB_ALIGN_UP(sizeof(mem_block), UPB_MALLOC_ALIGN); -static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, - char ch) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); - if (ptr == e->end) return NULL; - *ptr++ = ch; - return ptr; +static upb_Arena* arena_findroot(upb_Arena* a) { + /* Path splitting keeps time complexity down, see: + * https://en.wikipedia.org/wiki/Disjoint-set_data_structure */ + while (a->parent != a) { + upb_Arena* next = a->parent; + a->parent = next->parent; + a = next; + } + return a; } -static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { - return upb_MtDataEncoder_PutRaw(e, ptr, upb_ToBase92(ch)); -} +size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { + arena = arena_findroot(arena); + size_t memsize = 0; -static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, - uint32_t val, int min, int max) { - int shift = _upb_Log2Ceiling(upb_FromBase92(max) - upb_FromBase92(min) + 1); - UPB_ASSERT(shift <= 6); - uint32_t mask = (1 << shift) - 1; - do { - uint32_t bits = val & mask; - ptr = upb_MtDataEncoder_Put(e, ptr, bits + upb_FromBase92(min)); - if (!ptr) return NULL; - val >>= shift; - } while (val); - return ptr; -} + mem_block* block = arena->freelist; -char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, - uint64_t mod) { - if (mod) { - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier); + while (block) { + memsize += sizeof(mem_block) + block->size; + block = block->next; } - return ptr; + + return memsize; } -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +uint32_t upb_Arena_DebugRefCount(upb_Arena* arena) { + return arena_findroot(arena)->refcount; +} - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); - if (!ptr) return NULL; +static void upb_Arena_addblock(upb_Arena* a, upb_Arena* root, void* ptr, + size_t size) { + mem_block* block = ptr; - return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); + /* The block is for arena |a|, but should appear in the freelist of |root|. */ + block->next = root->freelist; + block->size = (uint32_t)size; + block->cleanups = 0; + root->freelist = block; + a->last_size = block->size; + if (!root->freelist_tail) root->freelist_tail = block; + + a->head.ptr = UPB_PTR_AT(block, memblock_reserve, char); + a->head.end = UPB_PTR_AT(block, size, char); + a->cleanup_metadata = upb_cleanup_metadata( + &block->cleanups, upb_cleanup_has_initial_block(a->cleanup_metadata)); + + UPB_POISON_MEMORY_REGION(a->head.ptr, a->head.end - a->head.ptr); } -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = msg_mod; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +static bool upb_Arena_Allocblock(upb_Arena* a, size_t size) { + upb_Arena* root = arena_findroot(a); + size_t block_size = UPB_MAX(size, a->last_size * 2) + memblock_reserve; + mem_block* block = upb_malloc(root->block_alloc, block_size); - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); - if (!ptr) return NULL; + if (!block) return false; + upb_Arena_addblock(a, root, block, block_size); + return true; +} - return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); +void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size) { + if (!upb_Arena_Allocblock(a, size)) return NULL; /* Out of memory. */ + UPB_ASSERT(_upb_ArenaHas(a) >= size); + return upb_Arena_Malloc(a, size); } -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - static const char kUpb_TypeToEncoded[] = { - [kUpb_FieldType_Double] = kUpb_EncodedType_Double, - [kUpb_FieldType_Float] = kUpb_EncodedType_Float, - [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, - [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, - [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, - [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, - [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, - [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, - [kUpb_FieldType_String] = kUpb_EncodedType_String, - [kUpb_FieldType_Group] = kUpb_EncodedType_Group, - [kUpb_FieldType_Message] = kUpb_EncodedType_Message, - [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, - [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, - [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, - [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, - [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, - [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, - [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, - }; +static void* upb_Arena_doalloc(upb_alloc* alloc, void* ptr, size_t oldsize, + size_t size) { + upb_Arena* a = (upb_Arena*)alloc; /* upb_alloc is initial member. */ + return upb_Arena_Realloc(a, ptr, oldsize, size); +} - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (field_num <= in->state.msg_state.last_field_num) return NULL; - if (in->state.msg_state.last_field_num + 1 != field_num) { - // Put skip. - UPB_ASSERT(field_num > in->state.msg_state.last_field_num); - uint32_t skip = field_num - in->state.msg_state.last_field_num; - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - if (!ptr) return NULL; - } - in->state.msg_state.last_field_num = field_num; +/* Public Arena API ***********************************************************/ - uint32_t encoded_modifiers = 0; +static upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { + const size_t first_block_overhead = sizeof(upb_Arena) + memblock_reserve; + upb_Arena* a; - // Put field type. - int encoded_type = kUpb_TypeToEncoded[type]; - if (field_mod & kUpb_FieldModifier_IsClosedEnum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - encoded_type = kUpb_EncodedType_ClosedEnum; + /* We need to malloc the initial block. */ + n = first_block_overhead + 256; + if (!alloc || !(mem = upb_malloc(alloc, n))) { + return NULL; } - if (field_mod & kUpb_FieldModifier_IsRepeated) { - // Repeated fields shift the type number up (unlike other modifiers which - // are bit flags). - encoded_type += kUpb_EncodedType_RepeatedBase; - if (upb_IsTypePackable(type)) { - bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; - bool default_is_packed = in->state.msg_state.msg_modifiers & - kUpb_MessageModifier_DefaultIsPacked; - if (field_is_packed != default_is_packed) { - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; - } - } - } - ptr = upb_MtDataEncoder_Put(e, ptr, encoded_type); - if (!ptr) return NULL; + a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); + n -= sizeof(*a); - if (field_mod & kUpb_FieldModifier_IsProto3Singular) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; - } - if (field_mod & kUpb_FieldModifier_IsRequired) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; - } - return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); + a->head.alloc.func = &upb_Arena_doalloc; + a->block_alloc = alloc; + a->parent = a; + a->refcount = 1; + a->freelist = NULL; + a->freelist_tail = NULL; + a->cleanup_metadata = upb_cleanup_metadata(NULL, false); + + upb_Arena_addblock(a, a, mem, n); + + return a; } -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { - ptr = upb_MtDataEncoder_Put(e, ptr, upb_FromBase92(kUpb_EncodedValue_End)); - } else { - ptr = upb_MtDataEncoder_Put( - e, ptr, upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); +upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { + upb_Arena* a; + + if (n) { + /* Align initial pointer up so that we return properly-aligned pointers. */ + void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, UPB_MALLOC_ALIGN); + size_t delta = (uintptr_t)aligned - (uintptr_t)mem; + n = delta <= n ? n - delta : 0; + mem = aligned; } - in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; - return ptr; -} -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { - ptr = upb_MtDataEncoder_Put( - e, ptr, upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); - if (!ptr) return NULL; + /* Round block size down to alignof(*a) since we will allocate the arena + * itself at the end. */ + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena)); + + if (UPB_UNLIKELY(n < sizeof(upb_Arena))) { + return arena_initslow(mem, n, alloc); } - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, upb_ToBase92(0), - upb_ToBase92(63)); - in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; - return ptr; -} -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value = 0; + a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); -} + a->head.alloc.func = &upb_Arena_doalloc; + a->block_alloc = alloc; + a->parent = a; + a->refcount = 1; + a->last_size = UPB_MAX(128, n); + a->head.ptr = mem; + a->head.end = UPB_PTR_AT(mem, n - sizeof(*a), char); + a->freelist = NULL; + a->freelist_tail = NULL; + a->cleanup_metadata = upb_cleanup_metadata(NULL, true); -static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, - char* ptr) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value += 5; - return ptr; + return a; } -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val) { - // TODO(b/229641772): optimize this encoding. - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - UPB_ASSERT(val >= in->state.enum_state.last_written_value); - uint32_t delta = val - in->state.enum_state.last_written_value; - if (delta >= 5 && in->state.enum_state.present_values_mask) { - ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; +static void arena_dofree(upb_Arena* a) { + mem_block* block = a->freelist; + UPB_ASSERT(a->parent == a); + UPB_ASSERT(a->refcount == 0); + + while (block) { + /* Load first since we are deleting block. */ + mem_block* next = block->next; + + if (block->cleanups > 0) { + cleanup_ent* end = UPB_PTR_AT(block, block->size, void); + cleanup_ent* ptr = end - block->cleanups; + + for (; ptr < end; ptr++) { + ptr->cleanup(ptr->ud); + } } - delta -= 5; - } - if (delta >= 5) { - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - in->state.enum_state.last_written_value += delta; - delta = 0; + upb_free(a->block_alloc, block); + block = next; } - - UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); - in->state.enum_state.present_values_mask |= 1ULL << delta; - return ptr; } -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (!in->state.enum_state.present_values_mask) return ptr; - return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); +void upb_Arena_Free(upb_Arena* a) { + a = arena_findroot(a); + if (--a->refcount == 0) arena_dofree(a); } -const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* table, uint32_t number) { - int n = table->field_count; - for (int i = 0; i < n; i++) { - if (table->fields[i].number == number) { - return &table->fields[i]; - } - } - return NULL; -} +bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func) { + cleanup_ent* ent; + uint32_t* cleanups = upb_cleanup_pointer(a->cleanup_metadata); -upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field) { - if (field->mode & kUpb_LabelFlags_IsAlternate) { + if (!cleanups || _upb_ArenaHas(a) < sizeof(cleanup_ent)) { + if (!upb_Arena_Allocblock(a, 128)) return false; /* Out of memory. */ + UPB_ASSERT(_upb_ArenaHas(a) >= sizeof(cleanup_ent)); + cleanups = upb_cleanup_pointer(a->cleanup_metadata); + } + + a->head.end -= sizeof(cleanup_ent); + ent = (cleanup_ent*)a->head.end; + (*cleanups)++; + UPB_UNPOISON_MEMORY_REGION(ent, sizeof(cleanup_ent)); + + ent->cleanup = func; + ent->ud = ud; + + return true; +} + +bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { + upb_Arena* r1 = arena_findroot(a1); + upb_Arena* r2 = arena_findroot(a2); + + if (r1 == r2) return true; /* Already fused. */ + + /* Do not fuse initial blocks since we cannot lifetime extend them. */ + if (upb_cleanup_has_initial_block(r1->cleanup_metadata)) return false; + if (upb_cleanup_has_initial_block(r2->cleanup_metadata)) return false; + + /* Only allow fuse with a common allocator */ + if (r1->block_alloc != r2->block_alloc) return false; + + /* We want to join the smaller tree to the larger tree. + * So swap first if they are backwards. */ + if (r1->refcount < r2->refcount) { + upb_Arena* tmp = r1; + r1 = r2; + r2 = tmp; + } + + /* r1 takes over r2's freelist and refcount. */ + r1->refcount += r2->refcount; + if (r2->freelist_tail) { + UPB_ASSERT(r2->freelist_tail->next == NULL); + r2->freelist_tail->next = r1->freelist; + r1->freelist = r2->freelist; + } + r2->parent = r1; + return true; +} + + +#include + + +// Must be last. + +const char _kUpb_ToBase92[] = { + ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', + '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', + 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', + 'Z', '[', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', + 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '{', '|', '}', '~', +}; + +const int8_t _kUpb_FromBase92[] = { + 0, 1, -1, 2, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, -1, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, +}; + +const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* table, uint32_t number) { + int n = table->field_count; + for (int i = 0; i < n; i++) { + if (table->fields[i].number == number) { + return &table->fields[i]; + } + } + return NULL; +} + +upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field) { + if (field->mode & kUpb_LabelFlags_IsAlternate) { if (field->descriptortype == kUpb_FieldType_Int32) { return kUpb_FieldType_Enum; } else if (field->descriptortype == kUpb_FieldType_Bytes) { @@ -4706,7 +4846,11 @@ upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field) { return field->descriptortype; } -/** Data decoder **************************************************************/ + +#include + + +// Must be last. // Note: we sort by this number when calculating layout order. typedef enum { @@ -4786,10 +4930,10 @@ static const char* upb_MiniTable_DecodeBase92Varint(upb_MtDecoder* d, uint32_t val = 0; uint32_t shift = 0; const int bits_per_char = - _upb_Log2Ceiling(upb_FromBase92(max) - upb_FromBase92(min)); + _upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min)); char ch = first_ch; while (1) { - uint32_t bits = upb_FromBase92(ch) - upb_FromBase92(min); + uint32_t bits = _upb_FromBase92(ch) - _upb_FromBase92(min); val |= bits << shift; if (ptr == d->end || *ptr < min || max < *ptr) { *out_val = val; @@ -4821,7 +4965,7 @@ static bool upb_MiniTable_HasSub(upb_MiniTable_Field* field, static bool upb_MtDecoder_FieldIsPackable(upb_MiniTable_Field* field) { return (field->mode & kUpb_FieldMode_Array) && - upb_IsTypePackable(field->descriptortype); + _upb_FieldType_IsPackable(field->descriptortype); } static void upb_MiniTable_SetTypeAndSub(upb_MiniTable_Field* field, @@ -4848,6 +4992,28 @@ static void upb_MiniTable_SetTypeAndSub(upb_MiniTable_Field* field, } } +static const char kUpb_EncodedToType[] = { + [kUpb_EncodedType_Double] = kUpb_FieldType_Double, + [kUpb_EncodedType_Float] = kUpb_FieldType_Float, + [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, + [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, + [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, + [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, + [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, + [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, + [kUpb_EncodedType_String] = kUpb_FieldType_String, + [kUpb_EncodedType_Group] = kUpb_FieldType_Group, + [kUpb_EncodedType_Message] = kUpb_FieldType_Message, + [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, + [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, + [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, + [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, + [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, + [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, + [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, + [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, +}; + static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, upb_MiniTable_Field* field, uint64_t msg_modifiers, @@ -4872,34 +5038,12 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, [kUpb_EncodedType_ClosedEnum] = kUpb_FieldRep_4Byte, }; - static const char kUpb_EncodedToType[] = { - [kUpb_EncodedType_Double] = kUpb_FieldType_Double, - [kUpb_EncodedType_Float] = kUpb_FieldType_Float, - [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, - [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, - [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, - [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, - [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, - [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, - [kUpb_EncodedType_String] = kUpb_FieldType_String, - [kUpb_EncodedType_Group] = kUpb_FieldType_Group, - [kUpb_EncodedType_Message] = kUpb_FieldType_Message, - [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, - [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, - [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, - [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, - [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, - [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, - }; - char pointer_rep = d->platform == kUpb_MiniTablePlatform_32Bit ? kUpb_FieldRep_4Byte : kUpb_FieldRep_8Byte; - int8_t type = upb_FromBase92(ch); - if (ch >= upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { + int8_t type = _upb_FromBase92(ch); + if (ch >= _upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { type -= kUpb_EncodedType_RepeatedBase; field->mode = kUpb_FieldMode_Array; field->mode |= pointer_rep << kUpb_FieldRep_Shift; @@ -5330,6 +5474,110 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { d->table->size = UPB_ALIGN_UP(d->table->size, 8); } +static void upb_MiniTable_BuildMapEntry(upb_MtDecoder* d, + upb_FieldType key_type, + upb_FieldType value_type, + bool value_is_proto3_enum) { + upb_MiniTable_Field* fields = upb_Arena_Malloc(d->arena, sizeof(*fields) * 2); + if (!fields) { + upb_MtDecoder_ErrorFormat(d, "OOM while building map mini table field"); + UPB_UNREACHABLE(); + } + + upb_MiniTable_Sub* subs = NULL; + if (value_is_proto3_enum) { + UPB_ASSERT(value_type == kUpb_FieldType_Enum); + // No sub needed. + } else if (value_type == kUpb_FieldType_Message || + value_type == kUpb_FieldType_Group || + value_type == kUpb_FieldType_Enum) { + subs = upb_Arena_Malloc(d->arena, sizeof(*subs)); + if (!subs) { + upb_MtDecoder_ErrorFormat(d, "OOM while building map mini table sub"); + UPB_UNREACHABLE(); + } + } + + size_t field_size = + upb_MtDecoder_SizeOfRep(kUpb_FieldRep_StringView, d->platform); + + fields[0].number = 1; + fields[1].number = 2; + fields[0].mode = kUpb_FieldMode_Scalar; + fields[1].mode = kUpb_FieldMode_Scalar; + fields[0].presence = 0; + fields[1].presence = 0; + fields[0].offset = 0; + fields[1].offset = field_size; + + upb_MiniTable_SetTypeAndSub(&fields[0], key_type, NULL, 0, false); + upb_MiniTable_SetTypeAndSub(&fields[1], value_type, NULL, 0, + value_is_proto3_enum); + + upb_MiniTable* ret = d->table; + ret->size = UPB_ALIGN_UP(2 * field_size, 8); + ret->field_count = 2; + ret->ext = kUpb_ExtMode_NonExtendable | kUpb_ExtMode_IsMapEntry; + ret->dense_below = 2; + ret->table_mask = -1; + ret->required_count = 0; + ret->subs = subs; + ret->fields = fields; +} + +static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, + size_t len) { + if (len < 2) { + upb_MtDecoder_ErrorFormat(d, "Invalid map encode length: %zu", len); + UPB_UNREACHABLE(); + } + const upb_EncodedType e0 = _upb_FromBase92(data[0]); + const upb_EncodedType e1 = _upb_FromBase92(data[1]); + switch (e0) { + case kUpb_EncodedType_Fixed32: + case kUpb_EncodedType_Fixed64: + case kUpb_EncodedType_SFixed32: + case kUpb_EncodedType_SFixed64: + case kUpb_EncodedType_Int32: + case kUpb_EncodedType_UInt32: + case kUpb_EncodedType_SInt32: + case kUpb_EncodedType_Int64: + case kUpb_EncodedType_UInt64: + case kUpb_EncodedType_SInt64: + case kUpb_EncodedType_Bool: + case kUpb_EncodedType_String: + break; + + default: + upb_MtDecoder_ErrorFormat(d, "Invalid map key field type: %d", e0); + UPB_UNREACHABLE(); + } + if (e1 >= sizeof(kUpb_EncodedToType)) { + upb_MtDecoder_ErrorFormat(d, "Invalid map value field type: %d", e1); + UPB_UNREACHABLE(); + } + const upb_FieldType key_type = kUpb_EncodedToType[e0]; + const upb_FieldType val_type = kUpb_EncodedToType[e1]; + const bool value_is_proto3_enum = (e1 == kUpb_EncodedType_OpenEnum); + upb_MiniTable_BuildMapEntry(d, key_type, val_type, value_is_proto3_enum); +} + +static void upb_MtDecoder_ParseMessageSet(upb_MtDecoder* d, const char* data, + size_t len) { + if (len > 0) { + upb_MtDecoder_ErrorFormat(d, "Invalid message set encode length: %zu", len); + UPB_UNREACHABLE(); + } + + upb_MiniTable* ret = d->table; + ret->size = 0; + ret->field_count = 0; + ret->ext = kUpb_ExtMode_IsMessageSet; + ret->dense_below = 0; + ret->table_mask = -1; + ret->required_count = 0; +} + upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, upb_MiniTablePlatform platform, upb_Arena* arena, void** buf, @@ -5353,16 +5601,6 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, goto done; } - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_MessageV1) { - upb_MtDecoder_ErrorFormat(&decoder, "Invalid message version: %c", *data); - UPB_UNREACHABLE(); - } - data++; - len--; - } - upb_MtDecoder_CheckOutOfMemory(&decoder, decoder.table); decoder.table->size = 0; @@ -5372,76 +5610,35 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, decoder.table->table_mask = -1; decoder.table->required_count = 0; - upb_MtDecoder_ParseMessage(&decoder, data, len); - upb_MtDecoder_AssignHasbits(decoder.table); - upb_MtDecoder_SortLayoutItems(&decoder); - upb_MtDecoder_AssignOffsets(&decoder); - -done: - *buf = decoder.vec.data; - *buf_size = decoder.vec.capacity * sizeof(*decoder.vec.data); - return decoder.table; -} + // Strip off and verify the version tag. + if (!len--) goto done; + const char vers = *data++; -upb_MiniTable* upb_MiniTable_BuildMessageSet(upb_MiniTablePlatform platform, - upb_Arena* arena) { - upb_MiniTable* ret = upb_Arena_Malloc(arena, sizeof(*ret)); - if (!ret) return NULL; + switch (vers) { + case kUpb_EncodedVersion_MapV1: + upb_MtDecoder_ParseMap(&decoder, data, len); + break; - ret->size = 0; - ret->field_count = 0; - ret->ext = kUpb_ExtMode_IsMessageSet; - ret->dense_below = 0; - ret->table_mask = -1; - ret->required_count = 0; - return ret; -} + case kUpb_EncodedVersion_MessageV1: + upb_MtDecoder_ParseMessage(&decoder, data, len); + upb_MtDecoder_AssignHasbits(decoder.table); + upb_MtDecoder_SortLayoutItems(&decoder); + upb_MtDecoder_AssignOffsets(&decoder); + break; -upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type, - upb_FieldType value_type, - bool value_is_proto3_enum, - upb_MiniTablePlatform platform, - upb_Arena* arena) { - upb_MiniTable* ret = upb_Arena_Malloc(arena, sizeof(*ret)); - upb_MiniTable_Field* fields = upb_Arena_Malloc(arena, sizeof(*fields) * 2); - if (!ret || !fields) return NULL; + case kUpb_EncodedVersion_MessageSetV1: + upb_MtDecoder_ParseMessageSet(&decoder, data, len); + break; - upb_MiniTable_Sub* subs = NULL; - if (value_is_proto3_enum) { - UPB_ASSERT(value_type == kUpb_FieldType_Enum); - // No sub needed. - } else if (value_type == kUpb_FieldType_Message || - value_type == kUpb_FieldType_Group || - value_type == kUpb_FieldType_Enum) { - subs = upb_Arena_Malloc(arena, sizeof(*subs)); - if (!subs) return NULL; + default: + upb_MtDecoder_ErrorFormat(&decoder, "Invalid message version: %c", vers); + UPB_UNREACHABLE(); } - size_t field_size = - upb_MtDecoder_SizeOfRep(kUpb_FieldRep_StringView, platform); - - fields[0].number = 1; - fields[1].number = 2; - fields[0].mode = kUpb_FieldMode_Scalar; - fields[1].mode = kUpb_FieldMode_Scalar; - fields[0].presence = 0; - fields[1].presence = 0; - fields[0].offset = 0; - fields[1].offset = field_size; - - upb_MiniTable_SetTypeAndSub(&fields[0], key_type, NULL, 0, false); - upb_MiniTable_SetTypeAndSub(&fields[1], value_type, NULL, 0, - value_is_proto3_enum); - - ret->size = UPB_ALIGN_UP(2 * field_size, 8); - ret->field_count = 2; - ret->ext = kUpb_ExtMode_NonExtendable | kUpb_ExtMode_IsMapEntry; - ret->dense_below = 2; - ret->table_mask = -1; - ret->required_count = 0; - ret->subs = subs; - ret->fields = fields; - return ret; +done: + *buf = decoder.vec.data; + *buf_size = decoder.vec.capacity * sizeof(*decoder.vec.data); + return decoder.table; } static size_t upb_MiniTable_EnumSize(size_t count) { @@ -5520,7 +5717,7 @@ upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, while (ptr < decoder.end) { char ch = *ptr++; if (ch <= kUpb_EncodedValue_MaxEnumMask) { - uint32_t mask = upb_FromBase92(ch); + uint32_t mask = _upb_FromBase92(ch); for (int i = 0; i < 5; i++, base++, mask >>= 1) { if (mask & 1) upb_MiniTable_BuildEnumValue(&decoder, base); } @@ -5621,38 +5818,306 @@ void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field, table_sub->subenum = sub; } -#include +#include // Must be last. -/* The upb core does not generally have a concept of default instances. However - * for descriptor options we make an exception since the max size is known and - * modest (<200 bytes). All types can share a default instance since it is - * initialized to zeroes. - * - * We have to allocate an extra pointer for upb's internal metadata. */ -static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; -const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; +typedef struct { + uint64_t present_values_mask; + uint32_t last_written_value; +} upb_MtDataEncoderInternal_EnumState; -const char* _upb_DefBuilder_FullToShort(const char* fullname) { - const char* p; +typedef struct { + uint64_t msg_modifiers; + uint32_t last_field_num; + enum { + kUpb_OneofState_NotStarted, + kUpb_OneofState_StartedOneof, + kUpb_OneofState_EmittedOneofField, + } oneof_state; +} upb_MtDataEncoderInternal_MsgState; - if (fullname == NULL) { - return NULL; - } else if ((p = strrchr(fullname, '.')) == NULL) { - /* No '.' in the name, return the full string. */ - return fullname; - } else { - /* Return one past the last '.'. */ - return p + 1; - } -} +typedef struct { + char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. + union { + upb_MtDataEncoderInternal_EnumState enum_state; + upb_MtDataEncoderInternal_MsgState msg_state; + } state; +} upb_MtDataEncoderInternal; -void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } +static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( + upb_MtDataEncoder* e, char* buf_start) { + UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); + upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; + ret->buf_start = buf_start; + return ret; +} -void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { - va_list argp; +static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, + char ch) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); + if (ptr == e->end) return NULL; + *ptr++ = ch; + return ptr; +} + +static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { + return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +} + +static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, + uint32_t val, int min, int max) { + int shift = _upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); + UPB_ASSERT(shift <= 6); + uint32_t mask = (1 << shift) - 1; + do { + uint32_t bits = val & mask; + ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); + if (!ptr) return NULL; + val >>= shift; + } while (val); + return ptr; +} + +char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, + uint64_t mod) { + if (mod) { + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, + kUpb_EncodedValue_MinModifier, + kUpb_EncodedValue_MaxModifier); + } + return ptr; +} + +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); +} + +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, + uint64_t value_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); + if (!ptr) return NULL; + + ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, 0); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); +} + +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { + (void)upb_MtDataEncoder_GetInternal(e, ptr); + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); +} + +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = msg_mod; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); +} + +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + static const char kUpb_TypeToEncoded[] = { + [kUpb_FieldType_Double] = kUpb_EncodedType_Double, + [kUpb_FieldType_Float] = kUpb_EncodedType_Float, + [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, + [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, + [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, + [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, + [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, + [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, + [kUpb_FieldType_String] = kUpb_EncodedType_String, + [kUpb_FieldType_Group] = kUpb_EncodedType_Group, + [kUpb_FieldType_Message] = kUpb_EncodedType_Message, + [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, + [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, + [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, + [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, + [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, + [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, + [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, + }; + + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (field_num <= in->state.msg_state.last_field_num) return NULL; + if (in->state.msg_state.last_field_num + 1 != field_num) { + // Put skip. + UPB_ASSERT(field_num > in->state.msg_state.last_field_num); + uint32_t skip = field_num - in->state.msg_state.last_field_num; + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + if (!ptr) return NULL; + } + in->state.msg_state.last_field_num = field_num; + + uint32_t encoded_modifiers = 0; + + // Put field type. + int encoded_type = kUpb_TypeToEncoded[type]; + if (field_mod & kUpb_FieldModifier_IsClosedEnum) { + UPB_ASSERT(type == kUpb_FieldType_Enum); + encoded_type = kUpb_EncodedType_ClosedEnum; + } + if (field_mod & kUpb_FieldModifier_IsRepeated) { + // Repeated fields shift the type number up (unlike other modifiers which + // are bit flags). + encoded_type += kUpb_EncodedType_RepeatedBase; + + if (_upb_FieldType_IsPackable(type)) { + bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; + bool default_is_packed = in->state.msg_state.msg_modifiers & + kUpb_MessageModifier_DefaultIsPacked; + if (field_is_packed != default_is_packed) { + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; + } + } + } + ptr = upb_MtDataEncoder_Put(e, ptr, encoded_type); + if (!ptr) return NULL; + + if (field_mod & kUpb_FieldModifier_IsProto3Singular) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; + } + if (field_mod & kUpb_FieldModifier_IsRequired) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; + } + return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); +} + +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { + ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); + } else { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); + } + in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; + return ptr; +} + +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); + if (!ptr) return NULL; + } + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), + _upb_ToBase92(63)); + in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; + return ptr; +} + +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value = 0; + + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); +} + +static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, + char* ptr) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value += 5; + return ptr; +} + +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val) { + // TODO(b/229641772): optimize this encoding. + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + UPB_ASSERT(val >= in->state.enum_state.last_written_value); + uint32_t delta = val - in->state.enum_state.last_written_value; + if (delta >= 5 && in->state.enum_state.present_values_mask) { + ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); + if (!ptr) { + return NULL; + } + delta -= 5; + } + + if (delta >= 5) { + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + in->state.enum_state.last_written_value += delta; + delta = 0; + } + + UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); + in->state.enum_state.present_values_mask |= 1ULL << delta; + return ptr; +} + +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (!in->state.enum_state.present_values_mask) return ptr; + return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); +} + +#include + + +// Must be last. + +/* The upb core does not generally have a concept of default instances. However + * for descriptor options we make an exception since the max size is known and + * modest (<200 bytes). All types can share a default instance since it is + * initialized to zeroes. + * + * We have to allocate an extra pointer for upb's internal metadata. */ +static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; +const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; + +const char* _upb_DefBuilder_FullToShort(const char* fullname) { + const char* p; + + if (fullname == NULL) { + return NULL; + } else if ((p = strrchr(fullname, '.')) == NULL) { + /* No '.' in the name, return the full string. */ + return fullname; + } else { + /* Return one past the last '.'. */ + return p + 1; + } +} + +void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } + +void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { + va_list argp; va_start(argp, fmt); upb_Status_VSetErrorFormat(ctx->status, fmt, argp); va_end(argp); @@ -8328,7 +8793,7 @@ struct upb_MessageDef { }; static void assign_msg_wellknowntype(upb_MessageDef* m) { - const char* name = upb_MessageDef_FullName(m); + const char* name = m->full_name; if (name == NULL) { m->well_known_type = kUpb_WellKnown_Unspecified; return; @@ -8384,8 +8849,7 @@ bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { return false; } -const google_protobuf_MessageOptions* upb_MessageDef_Options( - const upb_MessageDef* m) { +const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDef* m) { return m->opts; } @@ -8559,40 +9023,15 @@ const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, } bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_map_entry(upb_MessageDef_Options(m)); + return google_protobuf_MessageOptions_map_entry(m->opts); } bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_message_set_wire_format( - upb_MessageDef_Options(m)); + return google_protobuf_MessageOptions_message_set_wire_format(m->opts); } static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, const upb_MessageDef* m) { - if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { - return upb_MiniTable_BuildMessageSet(kUpb_MiniTablePlatform_Native, - ctx->arena); - } - - if (upb_MessageDef_IsMapEntry(m)) { - if (m->field_count != 2) { - _upb_DefBuilder_Errf(ctx, "invalid map (%s)", m->full_name); - } - - const upb_FieldDef* f0 = upb_MessageDef_Field(m, 0); - const upb_FieldDef* f1 = upb_MessageDef_Field(m, 1); - const upb_FieldType t0 = upb_FieldDef_Type(f0); - const upb_FieldType t1 = upb_FieldDef_Type(f1); - - const bool is_proto3_enum = - (t1 == kUpb_FieldType_Enum) && !_upb_FieldDef_IsClosedEnum(f1); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(f0) == 0); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(f1) == 1); - - return upb_MiniTable_BuildMapEntry( - t0, t1, is_proto3_enum, kUpb_MiniTablePlatform_Native, ctx->arena); - } - upb_StringView desc; bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); if (!ok) _upb_DefBuilder_OomErr(ctx); @@ -8609,7 +9048,7 @@ static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { for (int i = 0; i < m->field_count; i++) { upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); - _upb_FieldDef_Resolve(ctx, upb_MessageDef_FullName(m), f); + _upb_FieldDef_Resolve(ctx, m->full_name, f); } if (!ctx->layout) { @@ -8620,8 +9059,9 @@ void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { #ifndef NDEBUG for (int i = 0; i < m->field_count; i++) { const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MiniTable_Field* mt_f = - &m->layout->fields[_upb_FieldDef_LayoutIndex(f)]; + const int layout_index = _upb_FieldDef_LayoutIndex(f); + UPB_ASSERT(layout_index < m->layout->field_count); + const upb_MiniTable_Field* mt_f = &m->layout->fields[layout_index]; UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f)); } #endif @@ -8629,7 +9069,7 @@ void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { m->in_message_set = false; for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_Resolve(ctx, upb_MessageDef_FullName(m), ext); + _upb_FieldDef_Resolve(ctx, m->full_name, ext); if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && upb_FieldDef_Label(ext) == kUpb_Label_Optional && upb_FieldDef_MessageSubDef(ext) == m && @@ -8729,20 +9169,40 @@ static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { return out; } -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); +static bool _upb_MessageDef_EncodeMap(upb_DescState* s, const upb_MessageDef* m, + upb_Arena* a) { + if (m->field_count != 2) return false; + + const upb_FieldDef* key_field = upb_MessageDef_Field(m, 0); + const upb_FieldDef* val_field = upb_MessageDef_Field(m, 1); + if (key_field == NULL || val_field == NULL) return false; + + UPB_ASSERT(_upb_FieldDef_LayoutIndex(key_field) == 0); + UPB_ASSERT(_upb_FieldDef_LayoutIndex(val_field) == 1); + + const upb_FieldType key_type = upb_FieldDef_Type(key_field); + const upb_FieldType val_type = upb_FieldDef_Type(val_field); + + const uint64_t val_mod = _upb_FieldDef_IsClosedEnum(val_field) + ? kUpb_FieldModifier_IsClosedEnum + : 0; + s->ptr = + upb_MtDataEncoder_EncodeMap(&s->e, s->ptr, key_type, val_type, val_mod); + return true; +} + +static bool _upb_MessageDef_EncodeMessage(upb_DescState* s, + const upb_MessageDef* m, + upb_Arena* a) { const upb_FieldDef** sorted = NULL; if (!m->is_sorted) { sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); if (!sorted) return false; } - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = - upb_MtDataEncoder_StartMessage(&s.e, s.ptr, _upb_MessageDef_Modifiers(m)); + s->ptr = upb_MtDataEncoder_StartMessage(&s->e, s->ptr, + _upb_MessageDef_Modifiers(m)); for (int i = 0; i < m->field_count; i++) { const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); @@ -8750,24 +9210,50 @@ bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, const int number = upb_FieldDef_Number(f); const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutField(&s.e, s.ptr, type, number, modifiers); + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_PutField(&s->e, s->ptr, type, number, modifiers); } - for (int i = 0; i < m->oneof_count; i++) { - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartOneof(&s.e, s.ptr); + for (int i = 0; i < m->real_oneof_count; i++) { + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_StartOneof(&s->e, s->ptr); const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); const int field_count = upb_OneofDef_FieldCount(o); for (int j = 0; j < field_count; j++) { const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutOneofField(&s.e, s.ptr, number); + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_PutOneofField(&s->e, s->ptr, number); } } + return true; +} + +static bool _upb_MessageDef_EncodeMessageSet(upb_DescState* s, + const upb_MessageDef* m, + upb_Arena* a) { + s->ptr = upb_MtDataEncoder_EncodeMessageSet(&s->e, s->ptr); + + return true; +} + +bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, + upb_StringView* out) { + upb_DescState s; + _upb_DescState_Init(&s); + + if (!_upb_DescState_Grow(&s, a)) return false; + + if (upb_MessageDef_IsMapEntry(m)) { + if (!_upb_MessageDef_EncodeMap(&s, m, a)) return false; + } else if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { + if (!_upb_MessageDef_EncodeMessageSet(&s, m, a)) return false; + } else { + if (!_upb_MessageDef_EncodeMessage(&s, m, a)) return false; + } + if (!_upb_DescState_Grow(&s, a)) return false; *s.ptr = '\0'; @@ -8828,6 +9314,13 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->full_name, m, &m->is_sorted); + // Message Sets may not contain fields. + if (UPB_UNLIKELY(google_protobuf_MessageOptions_message_set_wire_format(m->opts))) { + if (UPB_UNLIKELY(n_field > 0)) { + _upb_DefBuilder_Errf(ctx, "invalid message set (%s)", m->full_name); + } + } + m->ext_range_count = n_ext_range; m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, m); @@ -10156,427 +10649,357 @@ int upb_Unicode_ToUTF8(uint32_t cp, char* out) { } -#include +#include + // Must be last. -static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size) { - UPB_UNUSED(alloc); - UPB_UNUSED(oldsize); - if (size == 0) { - free(ptr); - return NULL; - } else { - return realloc(ptr, size); - } -} +/** upb_Message ***************************************************************/ -upb_alloc upb_alloc_global = {&upb_global_allocfunc}; +static const size_t overhead = sizeof(upb_Message_InternalData); +static const upb_Message_Internal* upb_Message_Getinternal_const( + const upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); +} -// Must be last. +upb_Message* upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + return _upb_Message_New(mini_table, arena); +} -static uint32_t* upb_cleanup_pointer(uintptr_t cleanup_metadata) { - return (uint32_t*)(cleanup_metadata & ~0x1); +void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { + void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); + memset(mem, 0, upb_msg_sizeof(l)); } -static bool upb_cleanup_has_initial_block(uintptr_t cleanup_metadata) { - return cleanup_metadata & 0x1; +static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) { + /* No internal data, allocate from scratch. */ + size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + /* Internal data is too small, reallocate. */ + size_t new_size = _upb_Log2CeilingSize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + /* Need to move extension data to the end. */ + char* ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; + } + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; } -static uintptr_t upb_cleanup_metadata(uint32_t* cleanup, - bool has_initial_block) { - return (uintptr_t)cleanup | has_initial_block; +bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena) { + if (!realloc_internal(msg, len, arena)) return false; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); + in->internal->unknown_end += len; + return true; } -struct mem_block { - struct mem_block* next; - uint32_t size; - uint32_t cleanups; - /* Data follows. */ -}; +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + in->internal->unknown_end = overhead; + } +} -typedef struct cleanup_ent { - upb_CleanupFunc* cleanup; - void* ud; -} cleanup_ent; +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); + if (in->internal) { + *len = in->internal->unknown_end - overhead; + return (char*)(in->internal + 1); + } else { + *len = 0; + return NULL; + } +} -static const size_t memblock_reserve = - UPB_ALIGN_UP(sizeof(mem_block), UPB_MALLOC_ALIGN); +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + const char* internal_unknown_end = + UPB_PTR_AT(in->internal, in->internal->unknown_end, char); +#ifndef NDEBUG + size_t full_unknown_size; + const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); + UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); + UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); + UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); + UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); +#endif + if ((data + len) != internal_unknown_end) { + memmove((char*)data, data + len, internal_unknown_end - data - len); + } + in->internal->unknown_end -= len; +} -static upb_Arena* arena_findroot(upb_Arena* a) { - /* Path splitting keeps time complexity down, see: - * https://en.wikipedia.org/wiki/Disjoint-set_data_structure */ - while (a->parent != a) { - upb_Arena* next = a->parent; - a->parent = next->parent; - a = next; +const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); + if (in->internal) { + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(upb_Message_Extension); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; } - return a; } -size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - arena = arena_findroot(arena); - size_t memsize = 0; +const upb_Message_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTable_Extension* e) { + size_t n; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); - mem_block* block = arena->freelist; + /* For now we use linear search exclusively to find extensions. If this + * becomes an issue due to messages with lots of extensions, we can introduce + * a table of some sort. */ + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } - while (block) { - memsize += sizeof(mem_block) + block->size; - block = block->next; + return NULL; +} + +void _upb_Message_Clearext(upb_Message* msg, + const upb_MiniTable_Extension* ext_l) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) return; + const upb_Message_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); + if (ext) { + *ext = *base; + in->internal->ext_begin += sizeof(upb_Message_Extension); } +} - return memsize; +upb_Message_Extension* _upb_Message_GetOrCreateExtension( + upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(upb_Message_Extension); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(upb_Message_Extension)); + ext->ext = e; + return ext; } -uint32_t upb_Arena_DebugRefCount(upb_Arena* arena) { - return arena_findroot(arena)->refcount; +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + _upb_Message_Getexts(msg, &count); + return count; } -static void upb_Arena_addblock(upb_Arena* a, upb_Arena* root, void* ptr, - size_t size) { - mem_block* block = ptr; +/** upb_Map *******************************************************************/ - /* The block is for arena |a|, but should appear in the freelist of |root|. */ - block->next = root->freelist; - block->size = (uint32_t)size; - block->cleanups = 0; - root->freelist = block; - a->last_size = block->size; - if (!root->freelist_tail) root->freelist_tail = block; +upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { + upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - a->head.ptr = UPB_PTR_AT(block, memblock_reserve, char); - a->head.end = UPB_PTR_AT(block, size, char); - a->cleanup_metadata = upb_cleanup_metadata( - &block->cleanups, upb_cleanup_has_initial_block(a->cleanup_metadata)); + if (!map) { + return NULL; + } - UPB_POISON_MEMORY_REGION(a->head.ptr, a->head.end - a->head.ptr); -} + upb_strtable_init(&map->table, 4, a); + map->key_size = key_size; + map->val_size = value_size; -static bool upb_Arena_Allocblock(upb_Arena* a, size_t size) { - upb_Arena* root = arena_findroot(a); - size_t block_size = UPB_MAX(size, a->last_size * 2) + memblock_reserve; - mem_block* block = upb_malloc(root->block_alloc, block_size); + return map; +} - if (!block) return false; - upb_Arena_addblock(a, root, block, block_size); - return true; -} - -void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size) { - if (!upb_Arena_Allocblock(a, size)) return NULL; /* Out of memory. */ - UPB_ASSERT(_upb_ArenaHas(a) >= size); - return upb_Arena_Malloc(a, size); -} +const float kUpb_FltInfinity = INFINITY; +const double kUpb_Infinity = INFINITY; -static void* upb_Arena_doalloc(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size) { - upb_Arena* a = (upb_Arena*)alloc; /* upb_alloc is initial member. */ - return upb_Arena_Realloc(a, ptr, oldsize, size); -} -/* Public Arena API ***********************************************************/ +#include +#include +#include +#include +#include +#include -static upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { - const size_t first_block_overhead = sizeof(upb_Arena) + memblock_reserve; - upb_Arena* a; +// Must be last. - /* We need to malloc the initial block. */ - n = first_block_overhead + 256; - if (!alloc || !(mem = upb_malloc(alloc, n))) { - return NULL; - } +void upb_Status_Clear(upb_Status* status) { + if (!status) return; + status->ok = true; + status->msg[0] = '\0'; +} - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); - n -= sizeof(*a); +bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } - a->head.alloc.func = &upb_Arena_doalloc; - a->block_alloc = alloc; - a->parent = a; - a->refcount = 1; - a->freelist = NULL; - a->freelist_tail = NULL; - a->cleanup_metadata = upb_cleanup_metadata(NULL, false); +const char* upb_Status_ErrorMessage(const upb_Status* status) { + return status->msg; +} - upb_Arena_addblock(a, a, mem, n); +void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { + if (!status) return; + status->ok = false; + strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} - return a; +void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { + va_list args; + va_start(args, fmt); + upb_Status_VSetErrorFormat(status, fmt, args); + va_end(args); } -upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { - upb_Arena* a; +void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, + va_list args) { + if (!status) return; + status->ok = false; + vsnprintf(status->msg, sizeof(status->msg), fmt, args); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} - if (n) { - /* Align initial pointer up so that we return properly-aligned pointers. */ - void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, UPB_MALLOC_ALIGN); - size_t delta = (uintptr_t)aligned - (uintptr_t)mem; - n = delta <= n ? n - delta : 0; - mem = aligned; - } +void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, + va_list args) { + size_t len; + if (!status) return; + status->ok = false; + len = strlen(status->msg); + vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} - /* Round block size down to alignof(*a) since we will allocate the arena - * itself at the end. */ - n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena)); +#include +#include +#include - if (UPB_UNLIKELY(n < sizeof(upb_Arena))) { - return arena_initslow(mem, n, alloc); - } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); +// Must be last. - a->head.alloc.func = &upb_Arena_doalloc; - a->block_alloc = alloc; - a->parent = a; - a->refcount = 1; - a->last_size = UPB_MAX(128, n); - a->head.ptr = mem; - a->head.end = UPB_PTR_AT(mem, n - sizeof(*a), char); - a->freelist = NULL; - a->freelist_tail = NULL; - a->cleanup_metadata = upb_cleanup_metadata(NULL, true); +/* Miscellaneous utilities ****************************************************/ - return a; +static void upb_FixLocale(char* p) { + /* printf() is dependent on locales; sadly there is no easy and portable way + * to avoid this. This little post-processing step will translate 1,2 -> 1.2 + * since JSON needs the latter. Arguably a hack, but it is simple and the + * alternatives are far more complicated, platform-dependent, and/or larger + * in code size. */ + for (; *p; p++) { + if (*p == ',') *p = '.'; + } } -static void arena_dofree(upb_Arena* a) { - mem_block* block = a->freelist; - UPB_ASSERT(a->parent == a); - UPB_ASSERT(a->refcount == 0); +void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", DBL_DIG, val); + if (strtod(buf, NULL) != val) { + snprintf(buf, size, "%.*g", DBL_DIG + 2, val); + assert(strtod(buf, NULL) == val); + } + upb_FixLocale(buf); +} - while (block) { - /* Load first since we are deleting block. */ - mem_block* next = block->next; +void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", FLT_DIG, val); + if (strtof(buf, NULL) != val) { + snprintf(buf, size, "%.*g", FLT_DIG + 3, val); + assert(strtof(buf, NULL) == val); + } + upb_FixLocale(buf); +} - if (block->cleanups > 0) { - cleanup_ent* end = UPB_PTR_AT(block, block->size, void); - cleanup_ent* ptr = end - block->cleanups; - for (; ptr < end; ptr++) { - ptr->cleanup(ptr->ud); - } - } +#include - upb_free(a->block_alloc, block); - block = next; - } -} -void upb_Arena_Free(upb_Arena* a) { - a = arena_findroot(a); - if (--a->refcount == 0) arena_dofree(a); -} +// Must be last. -bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func) { - cleanup_ent* ent; - uint32_t* cleanups = upb_cleanup_pointer(a->cleanup_metadata); +// A few fake field types for our tables. +enum { + kUpb_FakeFieldType_FieldNotFound = 0, + kUpb_FakeFieldType_MessageSetItem = 19, +}; - if (!cleanups || _upb_ArenaHas(a) < sizeof(cleanup_ent)) { - if (!upb_Arena_Allocblock(a, 128)) return false; /* Out of memory. */ - UPB_ASSERT(_upb_ArenaHas(a) >= sizeof(cleanup_ent)); - cleanups = upb_cleanup_pointer(a->cleanup_metadata); - } +// DecodeOp: an action to be performed for a wire-type/field-type combination. +enum { + // Special ops: we don't write data to regular fields for these. + kUpb_DecodeOp_UnknownField = -1, + kUpb_DecodeOp_MessageSetItem = -2, - a->head.end -= sizeof(cleanup_ent); - ent = (cleanup_ent*)a->head.end; - (*cleanups)++; - UPB_UNPOISON_MEMORY_REGION(ent, sizeof(cleanup_ent)); + // Scalar-only ops. + kUpb_DecodeOp_Scalar1Byte = 0, + kUpb_DecodeOp_Scalar4Byte = 2, + kUpb_DecodeOp_Scalar8Byte = 3, + kUpb_DecodeOp_Enum = 1, - ent->cleanup = func; - ent->ud = ud; + // Scalar/repeated ops. + kUpb_DecodeOp_String = 4, + kUpb_DecodeOp_Bytes = 5, + kUpb_DecodeOp_SubMessage = 6, - return true; -} + // Repeated-only ops (also see macros below). + kUpb_DecodeOp_PackedEnum = 13, +}; -bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { - upb_Arena* r1 = arena_findroot(a1); - upb_Arena* r2 = arena_findroot(a2); +// For packed fields it is helpful to be able to recover the lg2 of the data +// size from the op. +#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ +#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ - if (r1 == r2) return true; /* Already fused. */ +typedef union { + bool bool_val; + uint32_t uint32_val; + uint64_t uint64_val; + uint32_t size; +} wireval; - /* Do not fuse initial blocks since we cannot lifetime extend them. */ - if (upb_cleanup_has_initial_block(r1->cleanup_metadata)) return false; - if (upb_cleanup_has_initial_block(r2->cleanup_metadata)) return false; +static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable* layout); - /* Only allow fuse with a common allocator */ - if (r1->block_alloc != r2->block_alloc) return false; +UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d, + upb_DecodeStatus status) { + assert(status != kUpb_DecodeStatus_Ok); + UPB_LONGJMP(d->err, status); +} - /* We want to join the smaller tree to the larger tree. - * So swap first if they are backwards. */ - if (r1->refcount < r2->refcount) { - upb_Arena* tmp = r1; - r1 = r2; - r2 = tmp; +const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) { + assert(status != kUpb_DecodeStatus_Ok); + UPB_LONGJMP(d->err, status); + return NULL; +} +static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { + if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); } +} - /* r1 takes over r2's freelist and refcount. */ - r1->refcount += r2->refcount; - if (r2->freelist_tail) { - UPB_ASSERT(r2->freelist_tail->next == NULL); - r2->freelist_tail->next = r1->freelist; - r1->freelist = r2->freelist; +static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { + bool need_realloc = arr->capacity - arr->size < elem; + if (need_realloc && !_upb_array_realloc(arr, arr->size + elem, &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } - r2->parent = r1; - return true; -} - - -#include - -// Must be last. - -static const char _upb_CTypeo_sizelg2[12] = { - 0, - 0, /* kUpb_CType_Bool */ - 2, /* kUpb_CType_Float */ - 2, /* kUpb_CType_Int32 */ - 2, /* kUpb_CType_UInt32 */ - 2, /* kUpb_CType_Enum */ - UPB_SIZE(2, 3), /* kUpb_CType_Message */ - 3, /* kUpb_CType_Double */ - 3, /* kUpb_CType_Int64 */ - 3, /* kUpb_CType_UInt64 */ - UPB_SIZE(3, 4), /* kUpb_CType_String */ - UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ -}; - -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); -} - -size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } - -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - upb_MessageValue ret; - const char* data = _upb_array_constptr(arr); - int lg2 = arr->data & 7; - UPB_ASSERT(i < arr->size); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} - -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - char* data = _upb_array_ptr(arr); - int lg2 = arr->data & 7; - UPB_ASSERT(i < arr->size); - memcpy(data + (i << lg2), &val, 1 << lg2); -} - -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - if (!upb_Array_Resize(arr, arr->size + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->size - 1, val); - return true; -} - -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - char* data = _upb_array_ptr(arr); - int lg2 = arr->data & 7; - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); -} - -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(i <= arr->size); - UPB_ASSERT(count + arr->size >= count); - size_t oldsize = arr->size; - if (!upb_Array_Resize(arr, arr->size + count, arena)) { - return false; - } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->size); - upb_Array_Move(arr, i, end, arr->size - end); - arr->size -= count; -} - -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - return _upb_Array_Resize(arr, size, arena); -} - - -#include - - -// Must be last. - -// A few fake field types for our tables. -enum { - kUpb_FakeFieldType_FieldNotFound = 0, - kUpb_FakeFieldType_MessageSetItem = 19, -}; - -// DecodeOp: an action to be performed for a wire-type/field-type combination. -enum { - // Special ops: we don't write data to regular fields for these. - kUpb_DecodeOp_UnknownField = -1, - kUpb_DecodeOp_MessageSetItem = -2, - - // Scalar-only ops. - kUpb_DecodeOp_Scalar1Byte = 0, - kUpb_DecodeOp_Scalar4Byte = 2, - kUpb_DecodeOp_Scalar8Byte = 3, - kUpb_DecodeOp_Enum = 1, - - // Scalar/repeated ops. - kUpb_DecodeOp_String = 4, - kUpb_DecodeOp_Bytes = 5, - kUpb_DecodeOp_SubMessage = 6, - - // Repeated-only ops (also see macros below). - kUpb_DecodeOp_PackedEnum = 13, -}; - -// For packed fields it is helpful to be able to recover the lg2 of the data -// size from the op. -#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ -#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ - -typedef union { - bool bool_val; - uint32_t uint32_val; - uint64_t uint64_val; - uint32_t size; -} wireval; - -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout); - -UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d, - upb_DecodeStatus status) { - assert(status != kUpb_DecodeStatus_Ok); - UPB_LONGJMP(d->err, status); -} - -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) { - assert(status != kUpb_DecodeStatus_Ok); - UPB_LONGJMP(d->err, status); - return NULL; -} -static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { - if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); - } -} - -static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = arr->capacity - arr->size < elem; - if (need_realloc && !_upb_array_realloc(arr, arr->size + elem, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - return need_realloc; + return need_realloc; } typedef struct { @@ -11766,7 +12189,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, #undef OP_FIXPCK_LG2 #undef OP_VARPCK_LG2 -/* We encode backwards, to avoid pre-computing lengths (one-pass encode). */ +// We encode backwards, to avoid pre-computing lengths (one-pass encode). #include @@ -12343,394 +12766,6 @@ upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, return status; } - -// Must be last. - -static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, - void* b_key, size_t size) { - const upb_tabent* const* a = _a; - const upb_tabent* const* b = _b; - upb_StringView a_tabkey = upb_tabstrview((*a)->key); - upb_StringView b_tabkey = upb_tabstrview((*b)->key); - _upb_map_fromkey(a_tabkey, a_key, size); - _upb_map_fromkey(b_tabkey, b_key, size); -} - -static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { - int64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { - uint64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { - int32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { - uint32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { - bool a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { - upb_StringView a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); - size_t common_size = UPB_MIN(a.size, b.size); - int cmp = memcmp(a.data, b.data, common_size); - if (cmp) return -cmp; - return a.size < b.size ? -1 : a.size > b.size; -} - -static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { - [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, - - [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, - [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, - - [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - - [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, - [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, - - [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, - - [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, - [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, -}; - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted) { - int map_size = _upb_Map_Size(map); - sorted->start = s->size; - sorted->pos = sorted->start; - sorted->end = sorted->start + map_size; - - // Grow s->entries if necessary. - if (sorted->end > s->cap) { - s->cap = _upb_Log2CeilingSize(sorted->end); - s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); - if (!s->entries) return false; - } - - s->size = sorted->end; - - // Copy non-empty entries from the table to s->entries. - upb_tabent const** dst = &s->entries[sorted->start]; - const upb_tabent* src = map->table.t.entries; - const upb_tabent* end = src + upb_table_size(&map->table.t); - for (; src < end; src++) { - if (!upb_tabent_isempty(src)) { - *dst = src; - dst++; - } - } - UPB_ASSERT(dst == &s->entries[sorted->end]); - - // Sort entries according to the key type. - qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), - compar[key_type]); - return true; -} - - -#include - - -// Must be last. - -/** upb_Message ***************************************************************/ - -static const size_t overhead = sizeof(upb_Message_InternalData); - -static const upb_Message_Internal* upb_Message_Getinternal_const( - const upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); -} - -upb_Message* upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - return _upb_Message_New(mini_table, arena); -} - -void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { - void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); - memset(mem, 0, upb_msg_sizeof(l)); -} - -static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { - /* No internal data, allocate from scratch. */ - size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { - /* Internal data is too small, reallocate. */ - size_t new_size = _upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; - if (ext_bytes) { - /* Need to move extension data to the end. */ - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); - } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; - } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); - return true; -} - -bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, - upb_Arena* arena) { - if (!realloc_internal(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; - return true; -} - -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = overhead; - } -} - -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); - if (in->internal) { - *len = in->internal->unknown_end - overhead; - return (char*)(in->internal + 1); - } else { - *len = 0; - return NULL; - } -} - -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - const char* internal_unknown_end = - UPB_PTR_AT(in->internal, in->internal->unknown_end, char); -#ifndef NDEBUG - size_t full_unknown_size; - const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); - UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); - UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); - UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); - UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); -#endif - if ((data + len) != internal_unknown_end) { - memmove((char*)data, data + len, internal_unknown_end - data - len); - } - in->internal->unknown_end -= len; -} - -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(upb_Message_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - } else { - *count = 0; - return NULL; - } -} - -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTable_Extension* e) { - size_t n; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); - - /* For now we use linear search exclusively to find extensions. If this - * becomes an issue due to messages with lots of extensions, we can introduce - * a table of some sort. */ - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } - - return NULL; -} - -void _upb_Message_Clearext(upb_Message* msg, - const upb_MiniTable_Extension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; - const upb_Message_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); - if (ext) { - *ext = *base; - in->internal->ext_begin += sizeof(upb_Message_Extension); - } -} - -upb_Message_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Message_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Message_Extension)); - ext->ext = e; - return ext; -} - -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - size_t count; - _upb_Message_Getexts(msg, &count); - return count; -} - -/** upb_Map *******************************************************************/ - -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { - upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - - if (!map) { - return NULL; - } - - upb_strtable_init(&map->table, 4, a); - map->key_size = key_size; - map->val_size = value_size; - - return map; -} - -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; - - -#include -#include -#include -#include -#include -#include - -// Must be last. - -void upb_Status_Clear(upb_Status* status) { - if (!status) return; - status->ok = true; - status->msg[0] = '\0'; -} - -bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } - -const char* upb_Status_ErrorMessage(const upb_Status* status) { - return status->msg; -} - -void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { - if (!status) return; - status->ok = false; - strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { - va_list args; - va_start(args, fmt); - upb_Status_VSetErrorFormat(status, fmt, args); - va_end(args); -} - -void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - if (!status) return; - status->ok = false; - vsnprintf(status->msg, sizeof(status->msg), fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - size_t len; - if (!status) return; - status->ok = false; - len = strlen(status->msg); - vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -#include -#include -#include - - -// Must be last. - -/* Miscellaneous utilities ****************************************************/ - -static void upb_FixLocale(char* p) { - /* printf() is dependent on locales; sadly there is no easy and portable way - * to avoid this. This little post-processing step will translate 1,2 -> 1.2 - * since JSON needs the latter. Arguably a hack, but it is simple and the - * alternatives are far more complicated, platform-dependent, and/or larger - * in code size. */ - for (; *p; p++) { - if (*p == ',') *p = '.'; - } -} - -void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - snprintf(buf, size, "%.*g", DBL_DIG, val); - if (strtod(buf, NULL) != val) { - snprintf(buf, size, "%.*g", DBL_DIG + 2, val); - assert(strtod(buf, NULL) == val); - } - upb_FixLocale(buf); -} - -void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - snprintf(buf, size, "%.*g", FLT_DIG, val); - if (strtof(buf, NULL) != val) { - snprintf(buf, size, "%.*g", FLT_DIG + 3, val); - assert(strtof(buf, NULL) == val); - } - upb_FixLocale(buf); -} - /* See port_def.inc. This should #undef all macros #defined there. */ #undef UPB_SIZE diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index b9572d3ddf..615018c950 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -269,14 +269,39 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define UPB_DEPRECATED #endif -#ifndef UPB_INTERNAL_ARRAY_H_ -#define UPB_INTERNAL_ARRAY_H_ +#ifndef UPB_INTERNAL_ATOI_H_ +#define UPB_INTERNAL_ATOI_H_ + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// We use these hand-written routines instead of strto[u]l() because the "long +// long" variants aren't in c89. Also our version allows setting a ptr limit. +// Return the new position of the pointer after parsing the int, or NULL on +// integer overflow. + +const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val); +const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, + bool* is_neg); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_INTERNAL_ATOI_H_ */ + +#ifndef UPB_INTERNAL_ARRAY_INTERNAL_H_ +#define UPB_INTERNAL_ARRAY_INTERNAL_H_ #include -#ifndef UPB_ARRAY_H_ -#define UPB_ARRAY_H_ +#ifndef UPB_COLLECTIONS_ARRAY_H_ +#define UPB_COLLECTIONS_ARRAY_H_ #ifndef UPB_MESSAGE_VALUE_H_ @@ -295,14 +320,14 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define UPB_MSG_H_ -#ifndef UPB_ARENA_H_ -#define UPB_ARENA_H_ +#ifndef UPB_MEM_ARENA_H_ +#define UPB_MEM_ARENA_H_ #include -#ifndef UPB_ALLOC_H_ -#define UPB_ALLOC_H_ +#ifndef UPB_MEM_ALLOC_H_ +#define UPB_MEM_ALLOC_H_ // Must be last. @@ -345,7 +370,7 @@ UPB_INLINE void upb_free(upb_alloc* alloc, void* ptr) { alloc->func(alloc, ptr, 0, 0); } -/* The global allocator used by upb. Uses the standard malloc()/free(). */ +// The global allocator used by upb. Uses the standard malloc()/free(). extern upb_alloc upb_alloc_global; @@ -369,7 +394,7 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } #endif -#endif /* UPB_ALLOC_H_ */ +#endif /* UPB_MEM_ALLOC_H_ */ // Must be last. @@ -502,7 +527,7 @@ UPB_INLINE upb_Arena* upb_Arena_New(void) { #endif -#endif /* UPB_ARENA_H_ */ +#endif /* UPB_MEM_ARENA_H_ */ // Must be last. @@ -757,12 +782,6 @@ UPB_INLINE int _upb_Log2CeilingSize(int x) { return 1 << _upb_Log2Ceiling(x); } // Must be last. -#ifdef __cplusplus -extern "C" { -#endif - -// Definitions common to both upb_Array and upb_Map. - typedef union { bool bool_val; float float_val; @@ -783,10 +802,6 @@ typedef union { upb_Message* msg; } upb_MutableMessageValue; -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif /* UPB_MESSAGE_VALUE_H_ */ @@ -837,7 +852,7 @@ bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); #endif -#endif /* UPB_ARRAY_H_ */ +#endif /* UPB_COLLECTIONS_ARRAY_H_ */ // Must be last. @@ -845,7 +860,7 @@ bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); extern "C" { #endif -/* Our internal representation for repeated fields. */ +// Our internal representation for repeated fields. struct upb_Array { uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ size_t size; /* The number of elements in the array. */ @@ -884,10 +899,10 @@ UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, size_t init_capacity, return arr; } -/* Resizes the capacity of the array to be at least min_size. */ +// Resizes the capacity of the array to be at least min_size. bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena); -/* Fallback functions for when the accessors require a resize. */ +// Fallback functions for when the accessors require a resize. void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, int elem_size_lg2, upb_Arena* arena); bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, @@ -963,7 +978,7 @@ UPB_INLINE bool _upb_Array_Append_accessor2(void* msg, size_t ofs, return true; } -/* Used by old generated code, remove once all code has been regenerated. */ +// Used by old generated code, remove once all code has been regenerated. UPB_INLINE int _upb_sizelg2(upb_CType type) { switch (type) { case kUpb_CType_Bool: @@ -1005,35 +1020,10 @@ UPB_INLINE bool _upb_Array_Append_accessor(void* msg, size_t ofs, #endif -#endif /* UPB_INTERNAL_ARRAY_H_ */ +#endif /* UPB_INTERNAL_ARRAY_INTERNAL_H_ */ -#ifndef UPB_INTERNAL_ATOI_H_ -#define UPB_INTERNAL_ATOI_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// We use these hand-written routines instead of strto[u]l() because the "long -// long" variants aren't in c89. Also our version allows setting a ptr limit. -// Return the new position of the pointer after parsing the int, or NULL on -// integer overflow. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val); -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_ATOI_H_ */ - -#ifndef UPB_MAP_H_ -#define UPB_MAP_H_ +#ifndef UPB_COLLECTIONS_MAP_H_ +#define UPB_COLLECTIONS_MAP_H_ // Must be last. @@ -1117,7 +1107,7 @@ void upb_MapIterator_SetValue(upb_Map* map, size_t iter, #endif -#endif /* UPB_MAP_H_ */ +#endif /* UPB_COLLECTIONS_MAP_H_ */ /* ** Our memory representation for parsing tables and messages themselves. @@ -1187,6 +1177,8 @@ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena); // Adds the given extension info for the array |e| of size |count| into the // registry. If there are any errors, the entire array is backed out. // The extensions must outlive the registry. +// Possible errors include OOM or an extension number that already exists. +// TODO: There is currently no way to determine the exact reason for failure. bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, const upb_MiniTable_Extension** e, size_t count); @@ -2167,6 +2159,70 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #endif /* UPB_MSG_INT_H_ */ + +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// + +#ifndef UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_ +#define UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// _upb_mapsorter sorts maps and provides ordered iteration over the entries. +// Since maps can be recursive (map values can be messages which contain other +// maps), _upb_mapsorter can contain a stack of maps. + +typedef struct { + upb_tabent const** entries; + int size; + int cap; +} _upb_mapsorter; + +typedef struct { + int start; + int pos; + int end; +} _upb_sortedmap; + +UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { + s->entries = NULL; + s->size = 0; + s->cap = 0; +} + +UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { + if (s->entries) free(s->entries); +} + +UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, + _upb_sortedmap* sorted, upb_MapEntry* ent) { + if (sorted->pos == sorted->end) return false; + const upb_tabent* tabent = s->entries[sorted->pos++]; + upb_StringView key = upb_tabstrview(tabent->key); + _upb_map_fromkey(key, &ent->k, map->key_size); + upb_value val = {tabent->val.val}; + _upb_map_fromvalue(val, &ent->v, map->val_size); + return true; +} + +UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, + _upb_sortedmap* sorted) { + s->size = sorted->start; +} + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_COLLECTIONS_MAP_SORTER_INTERNAL_H_ */ /* This file was generated by upbc (the upb compiler) from the input * file: * @@ -2179,12 +2235,10 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -/* - * upb_decode: parsing into a upb_Message using a upb_MiniTable. - */ +// upb_decode: parsing into a upb_Message using a upb_MiniTable. -#ifndef UPB_DECODE_H_ -#define UPB_DECODE_H_ +#ifndef UPB_WIRE_DECODE_H_ +#define UPB_WIRE_DECODE_H_ // Must be last. @@ -2242,7 +2296,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, #endif -#endif /* UPB_DECODE_H_ */ +#endif /* UPB_WIRE_DECODE_H_ */ // These are the specialized field parser functions for the fast parser. // Generated tables will refer to these by name. @@ -2278,8 +2332,8 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_DECODE_FAST_H_ -#define UPB_DECODE_FAST_H_ +#ifndef UPB_WIRE_DECODE_FAST_H_ +#define UPB_WIRE_DECODE_FAST_H_ // Must be last. @@ -2380,14 +2434,14 @@ TAGBYTES(r) #endif -#endif /* UPB_DECODE_FAST_H_ */ +#endif /* UPB_WIRE_DECODE_FAST_H_ */ /* * upb_Encode: parsing from a upb_Message using a upb_MiniTable. */ -#ifndef UPB_ENCODE_H_ -#define UPB_ENCODE_H_ +#ifndef UPB_WIRE_ENCODE_H_ +#define UPB_WIRE_ENCODE_H_ // Must be last. @@ -2432,7 +2486,7 @@ upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, #endif -#endif /* UPB_ENCODE_H_ */ +#endif /* UPB_WIRE_ENCODE_H_ */ #ifdef __cplusplus @@ -5657,12 +5711,12 @@ extern const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout * decode.c and decode_fast.c. */ -#ifndef UPB_INTERNAL_DECODE_H_ -#define UPB_INTERNAL_DECODE_H_ +#ifndef UPB_WIRE_DECODE_INTERNAL_H_ +#define UPB_WIRE_DECODE_INTERNAL_H_ -#ifndef UPB_INTERNAL_ARENA_H_ -#define UPB_INTERNAL_ARENA_H_ +#ifndef UPB_MEM_ARENA_INTERNAL_H_ +#define UPB_MEM_ARENA_INTERNAL_H_ // Must be last. @@ -5700,8 +5754,7 @@ struct upb_Arena { #endif -#endif /* UPB_INTERNAL_ARENA_H_ */ - +#endif /* UPB_MEM_ARENA_INTERNAL_H_ */ #include "third_party/utf8_range/utf8_range.h" // Must be last. @@ -5872,7 +5925,7 @@ UPB_INLINE void _upb_Decoder_PopLimit(upb_Decoder* d, const char* ptr, } -#endif /* UPB_INTERNAL_DECODE_H_ */ +#endif /* UPB_WIRE_DECODE_INTERNAL_H_ */ #ifndef UPB_JSON_DECODE_H_ #define UPB_JSON_DECODE_H_ @@ -6655,8 +6708,32 @@ size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, #endif /* UPB_JSONENCODE_H_ */ -#ifndef UPB_INTERNAL_ENCODE_H_ -#define UPB_INTERNAL_ENCODE_H_ +#ifndef UPB_INTERNAL_VSNPRINTF_COMPAT_H_ +#define UPB_INTERNAL_VSNPRINTF_COMPAT_H_ + +#include + +// Must be last. + +UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, + va_list ap) { +#if defined(__MINGW64__) || defined(__MINGW32__) || defined(_MSC_VER) + // The msvc runtime has a non-conforming vsnprintf() that requires the + // following compatibility code to become conformant. + int n = -1; + if (size != 0) n = _vsnprintf_s(buf, size, _TRUNCATE, fmt, ap); + if (n == -1) n = _vscprintf(fmt, ap); + return n; +#else + return vsnprintf(buf, size, fmt, ap); +#endif +} + + +#endif // UPB_INTERNAL_VSNPRINTF_COMPAT_H_ + +#ifndef UPB_WIRE_ENCODE_INTERNAL_H_ +#define UPB_WIRE_ENCODE_INTERNAL_H_ // Must be last. @@ -6679,37 +6756,27 @@ void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); #endif -#endif /* UPB_INTERNAL_ENCODE_H_ */ +#endif /* UPB_WIRE_ENCODE_INTERNAL_H_ */ -#ifndef UPB_INTERNAL_VSNPRINTF_COMPAT_H_ -#define UPB_INTERNAL_VSNPRINTF_COMPAT_H_ +#ifndef UPB_MINI_TABLE_COMMON_H_ +#define UPB_MINI_TABLE_COMMON_H_ -#include // Must be last. -UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, - va_list ap) { -#if defined(__MINGW64__) || defined(__MINGW32__) || defined(_MSC_VER) - // The msvc runtime has a non-conforming vsnprintf() that requires the - // following compatibility code to become conformant. - int n = -1; - if (size != 0) n = _vsnprintf_s(buf, size, _TRUNCATE, fmt, ap); - if (n == -1) n = _vscprintf(fmt, ap); - return n; -#else - return vsnprintf(buf, size, fmt, ap); -#endif -} - - -#endif // UPB_INTERNAL_VSNPRINTF_COMPAT_H_ - -#ifndef UPB_MINI_TABLE_H_ -#define UPB_MINI_TABLE_H_ - +typedef enum { + kUpb_FieldModifier_IsRepeated = 1 << 0, + kUpb_FieldModifier_IsPacked = 1 << 1, + kUpb_FieldModifier_IsClosedEnum = 1 << 2, + kUpb_FieldModifier_IsProto3Singular = 1 << 3, + kUpb_FieldModifier_IsRequired = 1 << 4, +} kUpb_FieldModifier; -// Must be last. +typedef enum { + kUpb_MessageModifier_ValidateUtf8 = 1 << 0, + kUpb_MessageModifier_DefaultIsPacked = 1 << 1, + kUpb_MessageModifier_IsExtendable = 1 << 2, +} kUpb_MessageModifier; #ifdef __cplusplus extern "C" { @@ -6730,81 +6797,112 @@ UPB_INLINE const upb_MiniTable_Enum* upb_MiniTable_GetSubEnumTable( return mini_table->subs[field->submsg_index].subenum; } -/** upb_MtDataEncoder *********************************************************/ +#ifdef __cplusplus +} /* extern "C" */ +#endif -// Functions to encode a string in a format that can be loaded by -// upb_MiniTable_Build(). + +#endif /* UPB_MINI_TABLE_COMMON_H_ */ + +#ifndef UPB_MINI_TABLE_COMMON_INTERNAL_H_ +#define UPB_MINI_TABLE_COMMON_INTERNAL_H_ + + +// Must be last. typedef enum { - kUpb_MessageModifier_ValidateUtf8 = 1 << 0, - kUpb_MessageModifier_DefaultIsPacked = 1 << 1, - kUpb_MessageModifier_IsExtendable = 1 << 2, -} kUpb_MessageModifier; + kUpb_EncodedType_Double = 0, + kUpb_EncodedType_Float = 1, + kUpb_EncodedType_Fixed32 = 2, + kUpb_EncodedType_Fixed64 = 3, + kUpb_EncodedType_SFixed32 = 4, + kUpb_EncodedType_SFixed64 = 5, + kUpb_EncodedType_Int32 = 6, + kUpb_EncodedType_UInt32 = 7, + kUpb_EncodedType_SInt32 = 8, + kUpb_EncodedType_Int64 = 9, + kUpb_EncodedType_UInt64 = 10, + kUpb_EncodedType_SInt64 = 11, + kUpb_EncodedType_OpenEnum = 12, + kUpb_EncodedType_Bool = 13, + kUpb_EncodedType_Bytes = 14, + kUpb_EncodedType_String = 15, + kUpb_EncodedType_Group = 16, + kUpb_EncodedType_Message = 17, + kUpb_EncodedType_ClosedEnum = 18, + + kUpb_EncodedType_RepeatedBase = 20, +} upb_EncodedType; typedef enum { - kUpb_FieldModifier_IsRepeated = 1 << 0, - kUpb_FieldModifier_IsPacked = 1 << 1, - kUpb_FieldModifier_IsClosedEnum = 1 << 2, - kUpb_FieldModifier_IsProto3Singular = 1 << 3, - kUpb_FieldModifier_IsRequired = 1 << 4, -} kUpb_FieldModifier; + kUpb_EncodedFieldModifier_FlipPacked = 1 << 0, + // upb only. + kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2, + kUpb_EncodedFieldModifier_IsRequired = 1 << 3, +} upb_EncodedFieldModifier; -typedef struct { - char* end; // Limit of the buffer passed as a parameter. - // Aliased to internal-only members in .cc. - char internal[32]; -} upb_MtDataEncoder; +enum { + kUpb_EncodedValue_MinField = ' ', + kUpb_EncodedValue_MaxField = 'I', + kUpb_EncodedValue_MinModifier = 'L', + kUpb_EncodedValue_MaxModifier = '[', + kUpb_EncodedValue_End = '^', + kUpb_EncodedValue_MinSkip = '_', + kUpb_EncodedValue_MaxSkip = '~', + kUpb_EncodedValue_OneofSeparator = '~', + kUpb_EncodedValue_FieldSeparator = '|', + kUpb_EncodedValue_MinOneofField = ' ', + kUpb_EncodedValue_MaxOneofField = 'b', + kUpb_EncodedValue_MaxEnumMask = 'A', +}; -// If the input buffer has at least this many bytes available, the encoder call -// is guaranteed to succeed (as long as field number order is maintained). -#define kUpb_MtDataEncoder_MinSize 16 +enum { + kUpb_EncodedVersion_EnumV1 = '!', + kUpb_EncodedVersion_ExtensionV1 = '#', + kUpb_EncodedVersion_MapV1 = '%', + kUpb_EncodedVersion_MessageV1 = '$', + kUpb_EncodedVersion_MessageSetV1 = '&', +}; -// Encodes field/oneof information for a given message. The sequence of calls -// should look like: -// -// upb_MtDataEncoder e; -// char buf[256]; -// char* ptr = buf; -// e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); -// // Fields *must* be in field number order. -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// -// // If oneofs are present. Oneofs must be encoded after regular fields. -// ptr = upb_MiniTable_StartOneof(&e, ptr) -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// ptr = upb_MiniTable_StartOneof(&e, ptr); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// Oneofs must be encoded after all regular fields. -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod); -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num); +#ifdef __cplusplus +extern "C" { +#endif -// Encodes the set of values for a given enum. The values must be given in -// order (after casting to uint32_t), and repeats are not allowed. -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val); -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); +UPB_INLINE char _upb_ToBase92(int8_t ch) { + extern const char _kUpb_ToBase92[]; + UPB_ASSERT(0 <= ch && ch < 92); + return _kUpb_ToBase92[ch]; +} -// Encodes an entire mini descriptor for one extension. -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); +UPB_INLINE char _upb_FromBase92(uint8_t ch) { + extern const int8_t _kUpb_FromBase92[]; + if (' ' > ch || ch > '~') return -1; + return _kUpb_FromBase92[ch - ' ']; +} -/** upb_MiniTable *************************************************************/ +UPB_INLINE bool _upb_FieldType_IsPackable(upb_FieldType type) { + // clang-format off + const unsigned kUnpackableTypes = + (1 << kUpb_FieldType_String) | + (1 << kUpb_FieldType_Bytes) | + (1 << kUpb_FieldType_Message) | + (1 << kUpb_FieldType_Group); + // clang-format on + return (1 << type) & ~kUnpackableTypes; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_COMMON_INTERNAL_H_ */ + +#ifndef UPB_MINI_TABLE_DECODE_H_ +#define UPB_MINI_TABLE_DECODE_H_ + + +// Must be last. typedef enum { kUpb_MiniTablePlatform_32Bit, @@ -6813,6 +6911,10 @@ typedef enum { UPB_SIZE(kUpb_MiniTablePlatform_32Bit, kUpb_MiniTablePlatform_64Bit), } upb_MiniTablePlatform; +#ifdef __cplusplus +extern "C" { +#endif + // Builds a mini table from the data encoded in the buffer [data, len]. If any // errors occur, returns NULL and sets a status message. In the success case, // the caller must call upb_MiniTable_SetSub*() for all message or proto2 enum @@ -6842,15 +6944,6 @@ const char* upb_MiniTable_BuildExtension(const char* data, size_t len, upb_MiniTable_Sub sub, upb_Status* status); -// Special-case functions for MessageSet layout and map entries. -upb_MiniTable* upb_MiniTable_BuildMessageSet(upb_MiniTablePlatform platform, - upb_Arena* arena); -upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type, - upb_FieldType value_type, - bool value_is_proto3_enum, - upb_MiniTablePlatform platform, - upb_Arena* arena); - upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, upb_Arena* arena, upb_Status* status); @@ -6866,17 +6959,92 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, upb_Arena* arena, void** buf, size_t* buf_size, upb_Status* status); -// For testing only. -char upb_ToBase92(int8_t ch); -char upb_FromBase92(uint8_t ch); -bool upb_IsTypePackable(upb_FieldType type); +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_DECODE_H_ */ + +#ifndef UPB_MINI_TABLE_ENCODE_INTERNAL_H_ +#define UPB_MINI_TABLE_ENCODE_INTERNAL_H_ + + +// Must be last. + +// If the input buffer has at least this many bytes available, the encoder call +// is guaranteed to succeed (as long as field number order is maintained). +#define kUpb_MtDataEncoder_MinSize 16 + +typedef struct { + char* end; // Limit of the buffer passed as a parameter. + // Aliased to internal-only members in .cc. + char internal[32]; +} upb_MtDataEncoder; + +#ifdef __cplusplus +extern "C" { +#endif + +// Encodes field/oneof information for a given message. The sequence of calls +// should look like: +// +// upb_MtDataEncoder e; +// char buf[256]; +// char* ptr = buf; +// e.end = ptr + sizeof(buf); +// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero +// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); +// // Fields *must* be in field number order. +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// +// // If oneofs are present. Oneofs must be encoded after regular fields. +// ptr = upb_MiniTable_StartOneof(&e, ptr) +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// ptr = upb_MiniTable_StartOneof(&e, ptr); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// Oneofs must be encoded after all regular fields. +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod); +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num); + +// Encodes the set of values for a given enum. The values must be given in +// order (after casting to uint32_t), and repeats are not allowed. +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val); +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); + +// Encodes an entire mini descriptor for an extension. +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); + +// Encodes an entire mini descriptor for a map. +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t value_mod); + +// Encodes an entire mini descriptor for a message set. +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_H_ */ +#endif /* UPB_MINI_TABLE_ENCODE_INTERNAL_H_ */ #ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ #define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ @@ -7355,70 +7523,6 @@ upb_MethodDef* _upb_MethodDefs_New( #endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -#ifndef UPB_MAP_SORTER_H_ -#define UPB_MAP_SORTER_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// _upb_mapsorter sorts maps and provides ordered iteration over the entries. -// Since maps can be recursive (map values can be messages which contain other -// maps), _upb_mapsorter can contain a stack of maps. - -typedef struct { - upb_tabent const** entries; - int size; - int cap; -} _upb_mapsorter; - -typedef struct { - int start; - int pos; - int end; -} _upb_sortedmap; - -UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { - s->entries = NULL; - s->size = 0; - s->cap = 0; -} - -UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { - if (s->entries) free(s->entries); -} - -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, - _upb_sortedmap* sorted, upb_MapEntry* ent) { - if (sorted->pos == sorted->end) return false; - const upb_tabent* tabent = s->entries[sorted->pos++]; - upb_StringView key = upb_tabstrview(tabent->key); - _upb_map_fromkey(key, &ent->k, map->key_size); - upb_value val = {tabent->val.val}; - _upb_map_fromvalue(val, &ent->v, map->val_size); - return true; -} - -UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, - _upb_sortedmap* sorted) { - s->size = sorted->start; -} - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MAP_SORTER_H_ */ - /* See port_def.inc. This should #undef all macros #defined there. */ #undef UPB_SIZE diff --git a/ruby/internal.bzl b/ruby/internal.bzl index 10ae10824c..b7ec0262d5 100644 --- a/ruby/internal.bzl +++ b/ruby/internal.bzl @@ -15,7 +15,6 @@ def internal_ruby_extension( **kwargs: extra arguments to forward to the genrule. """ - native.genrule( name = name, srcs = deps + [ @@ -31,5 +30,5 @@ def internal_ruby_extension( "BAZEL=true rake\n" + "popd\n" + "cp `dirname $(location Rakefile)`/%s $(OUTS)\n" % extension, - **kwargs, + **kwargs ) diff --git a/src/file_lists.cmake b/src/file_lists.cmake index e49ab6b0d0..1e326bcc8a 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -254,6 +254,8 @@ set(libprotobuf_lite_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/metadata_lite.h ${protobuf_SOURCE_DIR}/src/google/protobuf/parse_context.h ${protobuf_SOURCE_DIR}/src/google/protobuf/port.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/port_def.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/port_undef.inc ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.h ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h @@ -545,6 +547,8 @@ set(lite_test_util_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_test_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test_util_impl.h ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_lite_unittest.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util2.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util_lite.h ) @@ -567,8 +571,6 @@ set(test_util_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_tester.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util2.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util_lite.h ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_unittest.inc ) diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 7ba289cda8..859b953543 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -5,6 +5,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") +load("@upb//cmake:build_defs.bzl", "staleness_test") load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS") package( @@ -106,15 +107,22 @@ WELL_KNOWN_TYPES = [ "wrappers", ] +# When we generate code for the well-known types, we put the resulting files in +# wkt/google/protobuf and add ./wkt to the include paths below. This is a +# somewhat strange setup but is necessary to satisfy these two constraints: +# - We need to keep the checked-in sources for now, since Cocoapods relies on +# them. +# - The Bazel build should always use the generated sources so that developers +# don't have to worry about manually updating the checked-in sources. genrule( name = "gen_wkt_cc_sources", srcs = [wkt + ".proto" for wkt in WELL_KNOWN_TYPES], outs = - [wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] + - [wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], + ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] + + ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], cmd = """ $(execpath //src/google/protobuf/compiler:protoc_nowkt) \ - --cpp_out=$(RULEDIR)/../.. \ + --cpp_out=dllexport_decl=PROTOBUF_EXPORT:$(RULEDIR)/wkt \ --proto_path=$$(dirname $$(dirname $$(dirname $(location any.proto)))) \ $(SRCS) """, @@ -122,12 +130,21 @@ genrule( visibility = ["//visibility:private"], ) +staleness_test( + name = "well_known_types_staleness_test", + outs = + [wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] + + [wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], + generated_pattern = "wkt/google/protobuf/%s", + tags = ["manual"], +) + cc_library( name = "wkt_cc_proto", - srcs = [wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], - hdrs = [wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES], + srcs = ["wkt/google/protobuf/" + wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], + hdrs = ["wkt/google/protobuf/" + wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES], copts = COPTS, - include_prefix = "google/protobuf", + includes = ["wkt"], linkopts = LINK_OPTS, visibility = ["//pkg:__pkg__"], deps = [":protobuf_nowkt"], diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 9649411d68..73314186a9 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -45,7 +45,7 @@ static constexpr const ::_pb::EnumDescriptor** file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto = nullptr; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2fany_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fany_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2fany_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _internal_metadata_), @@ -208,7 +208,7 @@ void Any::SetCachedSize(int size) const { void Any::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Any) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -221,27 +221,29 @@ const char* Any::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string type_url = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_type_url(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Any.type_url")); - } else + } else { goto handle_unusual; + } continue; // bytes value = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 18)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { auto str = _internal_mutable_value(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -266,11 +268,11 @@ failure: #undef CHK_ } -uint8_t* Any::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Any::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Any) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string type_url = 1; @@ -297,12 +299,12 @@ uint8_t* Any::_InternalSerialize( return target; } -size_t Any::ByteSizeLong() const { +::size_t Any::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Any) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -336,7 +338,7 @@ void Any::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_N // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_type_url().empty()) { diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index ef4109d0c3..032ac9998b 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -46,7 +46,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fany_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto; @@ -189,10 +189,10 @@ class PROTOBUF_EXPORT Any final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: diff --git a/src/google/protobuf/any.proto b/src/google/protobuf/any.proto index 5ba0a33705..561da0cb15 100644 --- a/src/google/protobuf/any.proto +++ b/src/google/protobuf/any.proto @@ -63,6 +63,10 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; // if (any.is(Foo.class)) { // foo = any.unpack(Foo.class); // } +// // or ... +// if (any.isSameTypeAs(Foo.getDefaultInstance())) { +// foo = any.unpack(Foo.getDefaultInstance()); +// } // // Example 3: Pack and unpack a message in Python. // diff --git a/src/google/protobuf/any_lite.cc b/src/google/protobuf/any_lite.cc index a15d19fa09..6f689af1a3 100644 --- a/src/google/protobuf/any_lite.cc +++ b/src/google/protobuf/any_lite.cc @@ -28,12 +28,12 @@ // (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 "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "google/protobuf/any.h" #include "google/protobuf/arenastring.h" #include "google/protobuf/generated_message_util.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/any_test.cc b/src/google/protobuf/any_test.cc index 7e6ecb277d..6398b883d1 100644 --- a/src/google/protobuf/any_test.cc +++ b/src/google/protobuf/any_test.cc @@ -28,10 +28,11 @@ // (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 "google/protobuf/any_test.pb.h" +#include "google/protobuf/any.pb.h" #include "google/protobuf/unittest.pb.h" #include #include "absl/strings/str_cat.h" +#include "google/protobuf/any_test.pb.h" // Must be included last. diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index da04763dbe..7f23f9ac61 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -80,7 +80,7 @@ static constexpr const ::_pb::EnumDescriptor** file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto = nullptr; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fapi_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2fapi_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _internal_metadata_), @@ -311,7 +311,7 @@ void Api::SetCachedSize(int size) const { void Api::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Api) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -332,22 +332,23 @@ const char* Api::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string name = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Api.name")); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Method methods = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 18)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { ptr -= 1; do { ptr += 1; @@ -355,12 +356,13 @@ const char* Api::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Option options = 3; case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 26)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { ptr -= 1; do { ptr += 1; @@ -368,30 +370,33 @@ const char* Api::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); - } else + } else { goto handle_unusual; + } continue; // string version = 4; case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 34)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 34)) { auto str = _internal_mutable_version(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Api.version")); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.SourceContext source_context = 5; case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 42)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 42)) { ptr = ctx->ParseMessage(_internal_mutable_source_context(), ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Mixin mixins = 6; case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 50)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 50)) { ptr -= 1; do { ptr += 1; @@ -399,17 +404,19 @@ const char* Api::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<50>(ptr)); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.Syntax syntax = 7; case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 56)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 56)) { + ::uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); _internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val)); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -434,11 +441,11 @@ failure: #undef CHK_ } -uint8_t* Api::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Api::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Api) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string name = 1; @@ -507,12 +514,12 @@ uint8_t* Api::_InternalSerialize( return target; } -size_t Api::ByteSizeLong() const { +::size_t Api::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Api) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -580,7 +587,7 @@ void Api::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_N // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.methods_.MergeFrom(from._impl_.methods_); @@ -697,7 +704,7 @@ Method::Method(const Method& from) _this->GetArenaForAllocation()); } ::memcpy(&_impl_.request_streaming_, &from._impl_.request_streaming_, - static_cast(reinterpret_cast(&_impl_.syntax_) - + static_cast<::size_t>(reinterpret_cast(&_impl_.syntax_) - reinterpret_cast(&_impl_.request_streaming_)) + sizeof(_impl_.syntax_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.Method) } @@ -753,7 +760,7 @@ void Method::SetCachedSize(int size) const { void Method::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Method) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -761,7 +768,7 @@ void Method::Clear() { _impl_.name_.ClearToEmpty(); _impl_.request_type_url_.ClearToEmpty(); _impl_.response_type_url_.ClearToEmpty(); - ::memset(&_impl_.request_streaming_, 0, static_cast( + ::memset(&_impl_.request_streaming_, 0, static_cast<::size_t>( reinterpret_cast(&_impl_.syntax_) - reinterpret_cast(&_impl_.request_streaming_)) + sizeof(_impl_.syntax_)); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); @@ -771,58 +778,63 @@ const char* Method::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string name = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Method.name")); - } else + } else { goto handle_unusual; + } continue; // string request_type_url = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 18)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { auto str = _internal_mutable_request_type_url(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Method.request_type_url")); - } else + } else { goto handle_unusual; + } continue; // bool request_streaming = 3; case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 24)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 24)) { _impl_.request_streaming_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // string response_type_url = 4; case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 34)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 34)) { auto str = _internal_mutable_response_type_url(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Method.response_type_url")); - } else + } else { goto handle_unusual; + } continue; // bool response_streaming = 5; case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 40)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 40)) { _impl_.response_streaming_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Option options = 6; case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 50)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 50)) { ptr -= 1; do { ptr += 1; @@ -830,17 +842,19 @@ const char* Method::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<50>(ptr)); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.Syntax syntax = 7; case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 56)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 56)) { + ::uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); _internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val)); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -865,11 +879,11 @@ failure: #undef CHK_ } -uint8_t* Method::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Method::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Method) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string name = 1; @@ -937,12 +951,12 @@ uint8_t* Method::_InternalSerialize( return target; } -size_t Method::ByteSizeLong() const { +::size_t Method::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Method) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1006,7 +1020,7 @@ void Method::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBU // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.options_.MergeFrom(from._impl_.options_); @@ -1154,7 +1168,7 @@ void Mixin::SetCachedSize(int size) const { void Mixin::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Mixin) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1167,28 +1181,30 @@ const char* Mixin::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string name = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Mixin.name")); - } else + } else { goto handle_unusual; + } continue; // string root = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 18)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { auto str = _internal_mutable_root(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Mixin.root")); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1213,11 +1229,11 @@ failure: #undef CHK_ } -uint8_t* Mixin::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Mixin::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Mixin) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string name = 1; @@ -1248,12 +1264,12 @@ uint8_t* Mixin::_InternalSerialize( return target; } -size_t Mixin::ByteSizeLong() const { +::size_t Mixin::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Mixin) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1287,7 +1303,7 @@ void Mixin::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_name().empty()) { diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index ea210ec6f4..8e95525ba6 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -48,7 +48,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fapi_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto; @@ -166,10 +166,10 @@ class PROTOBUF_EXPORT Api final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -425,10 +425,10 @@ class PROTOBUF_EXPORT Method final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -662,10 +662,10 @@ class PROTOBUF_EXPORT Mixin final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index d3dec65170..e76e66fabb 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -114,53 +114,35 @@ void arena_delete_object(void* object) { struct ArenaOptions { // This defines the size of the first block requested from the system malloc. // Subsequent block sizes will increase in a geometric series up to a maximum. - size_t start_block_size; + size_t start_block_size = internal::AllocationPolicy::kDefaultStartBlockSize; // This defines the maximum block size requested from system malloc (unless an // individual arena allocation request occurs with a size larger than this // maximum). Requested block sizes increase up to this value, then remain // here. - size_t max_block_size; + size_t max_block_size = internal::GetDefaultArenaMaxBlockSize(); // An initial block of memory for the arena to use, or nullptr for none. If // provided, the block must live at least as long as the arena itself. The // creator of the Arena retains ownership of the block after the Arena is // destroyed. - char* initial_block; + char* initial_block = nullptr; // The size of the initial block, if provided. - size_t initial_block_size; + size_t initial_block_size = 0; // A function pointer to an alloc method that returns memory blocks of size // requested. By default, it contains a ptr to the malloc function. // // NOTE: block_alloc and dealloc functions are expected to behave like // malloc and free, including Asan poisoning. - void* (*block_alloc)(size_t); + void* (*block_alloc)(size_t) = nullptr; // A function pointer to a dealloc method that takes ownership of the blocks // from the arena. By default, it contains a ptr to a wrapper function that // calls free. - void (*block_dealloc)(void*, size_t); - - ArenaOptions() - : start_block_size(internal::AllocationPolicy::kDefaultStartBlockSize), - max_block_size(internal::GetDefaultArenaMaxBlockSize()), - initial_block(nullptr), - initial_block_size(0), - block_alloc(nullptr), - block_dealloc(nullptr), - make_metrics_collector(nullptr) {} + void (*block_dealloc)(void*, size_t) = nullptr; private: - // If make_metrics_collector is not nullptr, it will be called at Arena init - // time. It may return a pointer to a collector instance that will be notified - // of interesting events related to the arena. - internal::ArenaMetricsCollector* (*make_metrics_collector)(); - - internal::ArenaMetricsCollector* MetricsCollector() const { - return make_metrics_collector ? (*make_metrics_collector)() : nullptr; - } - internal::AllocationPolicy AllocationPolicy() const { internal::AllocationPolicy res; res.start_block_size = start_block_size; @@ -170,8 +152,6 @@ struct ArenaOptions { return res; } - friend void arena_metrics::EnableArenaMetrics(ArenaOptions*); - friend class Arena; friend class ArenaOptionsTestFriend; }; diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index 3539c18922..0339af2cda 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -42,7 +42,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_arena.pb.h" #include #include #include "absl/strings/string_view.h" @@ -56,6 +55,7 @@ #include "google/protobuf/message_lite.h" #include "google/protobuf/repeated_field.h" #include "google/protobuf/test_util.h" +#include "google/protobuf/unittest_arena.pb.h" #include "google/protobuf/unknown_field_set.h" #include "google/protobuf/wire_format_lite.h" diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc index 9a0a223825..8c21b1dd0c 100644 --- a/src/google/protobuf/arenastring.cc +++ b/src/google/protobuf/arenastring.cc @@ -34,9 +34,9 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/message_lite.h" #include "google/protobuf/parse_context.h" diff --git a/src/google/protobuf/arenastring_unittest.cc b/src/google/protobuf/arenastring_unittest.cc index efb4bf3ce9..6aa500bd83 100644 --- a/src/google/protobuf/arenastring_unittest.cc +++ b/src/google/protobuf/arenastring_unittest.cc @@ -39,12 +39,12 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/generated_message_util.h" #include "google/protobuf/message_lite.h" #include #include "absl/strings/string_view.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" // Must be included last. diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index d60d78f65f..8cc1186b0d 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -60,6 +60,8 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//src/google/protobuf:protobuf_nowkt", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", ], ) @@ -245,9 +247,9 @@ cc_test( ":command_line_interface", ":mock_code_generator", "//:protobuf", - "//src/google/protobuf/compiler/cpp:names", "//src/google/protobuf:cc_test_protos", "//src/google/protobuf:test_util2", + "//src/google/protobuf/compiler/cpp:names", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", diff --git a/src/google/protobuf/compiler/annotation_test_util.cc b/src/google/protobuf/compiler/annotation_test_util.cc index 76d39abce9..f8ffeec584 100644 --- a/src/google/protobuf/compiler/annotation_test_util.cc +++ b/src/google/protobuf/compiler/annotation_test_util.cc @@ -37,12 +37,12 @@ #include "google/protobuf/testing/file.h" #include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/testing/googletest.h" #include +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 80916fdc7a..6a44b04a47 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -34,7 +34,7 @@ #include "google/protobuf/compiler/command_line_interface.h" -#include "absl/container/btree_map.h" +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "google/protobuf/stubs/platform_macros.h" @@ -806,95 +806,95 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { } it->second.swap(data_); - } else { - // This was an OpenForInsert(). + return; + } + // This was an OpenForInsert(). - // If the data doesn't end with a clean line break, add one. - if (!data_.empty() && data_[data_.size() - 1] != '\n') { - data_.push_back('\n'); - } + // If the data doesn't end with a clean line break, add one. + if (!data_.empty() && data_[data_.size() - 1] != '\n') { + data_.push_back('\n'); + } - // Find the file we are going to insert into. - if (!already_present) { - std::cerr << filename_ - << ": Tried to insert into file that doesn't exist." - << std::endl; - directory_->had_error_ = true; - return; - } - std::string* target = &it->second; + // Find the file we are going to insert into. + if (!already_present) { + std::cerr << filename_ << ": Tried to insert into file that doesn't exist." + << std::endl; + directory_->had_error_ = true; + return; + } + std::string* target = &it->second; - // Find the insertion point. - std::string magic_string = - absl::Substitute("@@protoc_insertion_point($0)", insertion_point_); - std::string::size_type pos = target->find(magic_string); + // Find the insertion point. + std::string magic_string = + absl::Substitute("@@protoc_insertion_point($0)", insertion_point_); + std::string::size_type pos = target->find(magic_string); - if (pos == std::string::npos) { - std::cerr << filename_ << ": insertion point \"" << insertion_point_ - << "\" not found." << std::endl; - directory_->had_error_ = true; - return; - } + if (pos == std::string::npos) { + std::cerr << filename_ << ": insertion point \"" << insertion_point_ + << "\" not found." << std::endl; + directory_->had_error_ = true; + return; + } - if ((pos > 3) && (target->substr(pos - 3, 2) == "/*")) { - // Support for inline "/* @@protoc_insertion_point() */" - pos = pos - 3; + if ((pos > 3) && (target->substr(pos - 3, 2) == "/*")) { + // Support for inline "/* @@protoc_insertion_point() */" + pos = pos - 3; + } else { + // Seek backwards to the beginning of the line, which is where we will + // insert the data. Note that this has the effect of pushing the + // insertion point down, so the data is inserted before it. This is + // intentional because it means that multiple insertions at the same point + // will end up in the expected order in the final output. + pos = target->find_last_of('\n', pos); + if (pos == std::string::npos) { + // Insertion point is on the first line. + pos = 0; } else { - // Seek backwards to the beginning of the line, which is where we will - // insert the data. Note that this has the effect of pushing the - // insertion point down, so the data is inserted before it. This is - // intentional because it means that multiple insertions at the same point - // will end up in the expected order in the final output. - pos = target->find_last_of('\n', pos); - if (pos == std::string::npos) { - // Insertion point is on the first line. - pos = 0; - } else { - // Advance to character after '\n'. - ++pos; - } + // Advance to character after '\n'. + ++pos; } + } - // Extract indent. - std::string indent_(*target, pos, - target->find_first_not_of(" \t", pos) - pos); + // Extract indent. + std::string indent_(*target, pos, + target->find_first_not_of(" \t", pos) - pos); - if (indent_.empty()) { - // No indent. This makes things easier. - target->insert(pos, data_); - UpdateMetadata(data_, pos, data_.size(), 0); - } else { - // Calculate how much space we need. - int indent_size = 0; - for (int i = 0; i < data_.size(); i++) { - if (data_[i] == '\n') indent_size += indent_.size(); - } + if (indent_.empty()) { + // No indent. This makes things easier. + target->insert(pos, data_); + UpdateMetadata(data_, pos, data_.size(), 0); + return; + } + // Calculate how much space we need. + int indent_size = 0; + for (int i = 0; i < data_.size(); i++) { + if (data_[i] == '\n') indent_size += indent_.size(); + } - // Make a hole for it. - target->insert(pos, data_.size() + indent_size, '\0'); - - // Now copy in the data. - std::string::size_type data_pos = 0; - char* target_ptr = &(*target)[pos]; - while (data_pos < data_.size()) { - // Copy indent. - memcpy(target_ptr, indent_.data(), indent_.size()); - target_ptr += indent_.size(); - - // Copy line from data_. - // We already guaranteed that data_ ends with a newline (above), so this - // search can't fail. - std::string::size_type line_length = - data_.find_first_of('\n', data_pos) + 1 - data_pos; - memcpy(target_ptr, data_.data() + data_pos, line_length); - target_ptr += line_length; - data_pos += line_length; - } - UpdateMetadata(data_, pos, data_.size() + indent_size, indent_.size()); + // Make a hole for it. + target->insert(pos, data_.size() + indent_size, '\0'); - GOOGLE_CHECK_EQ(target_ptr, &(*target)[pos] + data_.size() + indent_size); - } + // Now copy in the data. + std::string::size_type data_pos = 0; + char* target_ptr = &(*target)[pos]; + while (data_pos < data_.size()) { + // Copy indent. + memcpy(target_ptr, indent_.data(), indent_.size()); + target_ptr += indent_.size(); + + // Copy line from data_. + // We already guaranteed that data_ ends with a newline (above), so this + // search can't fail. + std::string::size_type line_length = + data_.find_first_of('\n', data_pos) + 1 - data_pos; + memcpy(target_ptr, data_.data() + data_pos, line_length); + target_ptr += line_length; + data_pos += line_length; } + + GOOGLE_CHECK_EQ(target_ptr, &(*target)[pos] + data_.size() + indent_size); + + UpdateMetadata(data_, pos, data_.size() + indent_size, indent_.size()); } // =================================================================== @@ -2212,7 +2212,7 @@ bool CommandLineInterface::GenerateDependencyManifestFile( DiskSourceTree* source_tree) { FileDescriptorSet file_set; - std::set already_seen; + absl::flat_hash_set already_seen; for (int i = 0; i < parsed_files.size(); i++) { GetTransitiveDependencies(parsed_files[i], false, false, &already_seen, file_set.mutable_file()); @@ -2293,7 +2293,7 @@ bool CommandLineInterface::GeneratePluginOutput( } - std::set already_seen; + absl::flat_hash_set already_seen; for (int i = 0; i < parsed_files.size(); i++) { request.add_file_to_generate(parsed_files[i]->name()); GetTransitiveDependencies(parsed_files[i], @@ -2442,13 +2442,13 @@ bool CommandLineInterface::WriteDescriptorSet( const std::vector& parsed_files) { FileDescriptorSet file_set; - std::set already_seen; + absl::flat_hash_set already_seen; if (!imports_in_descriptor_set_) { // Since we don't want to output transitive dependencies, but we do want // things to be in dependency order, add all dependencies that aren't in // parsed_files to already_seen. This will short circuit the recursion // in GetTransitiveDependencies. - std::set to_output; + absl::flat_hash_set to_output; to_output.insert(parsed_files.begin(), parsed_files.end()); for (int i = 0; i < parsed_files.size(); i++) { const FileDescriptor* file = parsed_files[i]; @@ -2506,7 +2506,7 @@ bool CommandLineInterface::WriteDescriptorSet( void CommandLineInterface::GetTransitiveDependencies( const FileDescriptor* file, bool include_json_name, bool include_source_code_info, - std::set* already_seen, + absl::flat_hash_set* already_seen, RepeatedPtrField* output) { if (!already_seen->insert(file).second) { // Already saw this file. Skip. @@ -2579,9 +2579,9 @@ namespace { // order of the nested messages is also preserved. typedef std::pair FieldRange; void GatherOccupiedFieldRanges( - const Descriptor* descriptor, std::set* ranges, + const Descriptor* descriptor, absl::btree_set* ranges, std::vector* nested_messages) { - std::set groups; + absl::flat_hash_set groups; for (int i = 0; i < descriptor->field_count(); ++i) { const FieldDescriptor* fd = descriptor->field(i); ranges->insert(FieldRange(fd->number(), fd->number() + 1)); @@ -2613,27 +2613,26 @@ void GatherOccupiedFieldRanges( // Actually prints the formatted free field numbers for given message name and // occupied ranges. void FormatFreeFieldNumbers(const std::string& name, - const std::set& ranges) { + const absl::btree_set& ranges) { std::string output; absl::StrAppendFormat(&output, "%-35s free:", name.c_str()); int next_free_number = 1; - for (std::set::const_iterator i = ranges.begin(); - i != ranges.end(); ++i) { + for (const auto& range : ranges) { // This happens when groups re-use parent field numbers, in which // case we skip the FieldRange entirely. - if (next_free_number >= i->second) continue; + if (next_free_number >= range.second) continue; - if (next_free_number < i->first) { - if (next_free_number + 1 == i->first) { + if (next_free_number < range.first) { + if (next_free_number + 1 == range.first) { // Singleton absl::StrAppendFormat(&output, " %d", next_free_number); } else { // Range absl::StrAppendFormat(&output, " %d-%d", next_free_number, - i->first - 1); + range.first - 1); } } - next_free_number = i->second; + next_free_number = range.second; } if (next_free_number <= FieldDescriptor::kMaxNumber) { absl::StrAppendFormat(&output, " %d-INF", next_free_number); @@ -2644,7 +2643,7 @@ void FormatFreeFieldNumbers(const std::string& name, } // namespace void CommandLineInterface::PrintFreeFieldNumbers(const Descriptor* descriptor) { - std::set ranges; + absl::btree_set ranges; std::vector nested_messages; GatherOccupiedFieldRanges(descriptor, &ranges, &nested_messages); diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 7e1cd58f5d..4abe0d6160 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -40,13 +40,12 @@ #include #include -#include #include -#include #include #include #include +#include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/string_view.h" @@ -322,7 +321,7 @@ class PROTOC_EXPORT CommandLineInterface { static void GetTransitiveDependencies( const FileDescriptor* file, bool include_json_name, bool include_source_code_info, - std::set* already_seen, + absl::flat_hash_set* already_seen, RepeatedPtrField* output); // Implements the --print_free_field_numbers. This function prints free field @@ -360,9 +359,8 @@ class PROTOC_EXPORT CommandLineInterface { const GeneratorInfo* FindGeneratorByFlag(const std::string& name) const; const GeneratorInfo* FindGeneratorByOption(const std::string& option) const; - using GeneratorMap = std::map; - GeneratorMap generators_by_flag_name_; - GeneratorMap generators_by_option_name_; + absl::btree_map generators_by_flag_name_; + absl::flat_hash_map generators_by_option_name_; // A map from generator names to the parameters specified using the option // flag. For example, if the user invokes the compiler with: // protoc --foo_out=outputdir --foo_opt=enable_bar ... @@ -412,7 +410,7 @@ class PROTOC_EXPORT CommandLineInterface { // Names of proto files which are allowed to be imported. Used by build // systems to enforce depend-on-what-you-import. - std::set direct_dependencies_; + absl::flat_hash_set direct_dependencies_; bool direct_dependencies_explicitly_set_ = false; // If there's a violation of depend-on-what-you-import, this string will be diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index f825cd58b0..b1e44821e0 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -51,9 +51,7 @@ #include "google/protobuf/testing/file.h" #include "google/protobuf/testing/file.h" #include "google/protobuf/any.pb.h" -#include "google/protobuf/test_util2.h" #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_custom_options.pb.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/testing/googletest.h" #include @@ -64,12 +62,14 @@ #include "absl/strings/substitute.h" #include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/compiler/cpp/names.h" #include "google/protobuf/compiler/mock_code_generator.h" #include "google/protobuf/compiler/subprocess.h" -#include "google/protobuf/compiler/cpp/names.h" #include "google/protobuf/io/io_win32.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/unittest_custom_options.pb.h" // Must be included last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/cpp/BUILD.bazel b/src/google/protobuf/compiler/cpp/BUILD.bazel index 7f0ef6a27d..2f2b709cd8 100644 --- a/src/google/protobuf/compiler/cpp/BUILD.bazel +++ b/src/google/protobuf/compiler/cpp/BUILD.bazel @@ -79,6 +79,7 @@ cc_library( visibility = [ "//pkg:__pkg__", "//src/google/protobuf/compiler:__pkg__", + "@io_kythe//kythe/cxx/tools:__subpackages__", ], deps = [ ":names_internal", diff --git a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc index 8d2b60e9ad..0e5a8df101 100644 --- a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc @@ -42,13 +42,13 @@ // "generate_descriptor_proto.sh" and add // descriptor.pb.{h,cc} to your changelist. +#include #include #include "google/protobuf/testing/file.h" #include "google/protobuf/testing/file.h" #include "google/protobuf/compiler/cpp/generator.h" #include "google/protobuf/compiler/importer.h" -#include "google/protobuf/test_util2.h" #include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/testing/googletest.h" @@ -56,6 +56,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/test_util2.h" namespace google { namespace protobuf { @@ -123,7 +124,7 @@ class MockGeneratorContext : public GeneratorContext { } private: - std::map> files_; + absl::flat_hash_map> files_; }; const char kDescriptorParameter[] = "dllexport_decl=PROTOBUF_EXPORT"; diff --git a/src/google/protobuf/compiler/cpp/enum.h b/src/google/protobuf/compiler/cpp/enum.h index 49a262d40d..58a62f5533 100644 --- a/src/google/protobuf/compiler/cpp/enum.h +++ b/src/google/protobuf/compiler/cpp/enum.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ -#include #include #include "google/protobuf/descriptor.h" diff --git a/src/google/protobuf/compiler/cpp/enum_field.cc b/src/google/protobuf/compiler/cpp/enum_field.cc index 10768f9041..d5181cd9a3 100644 --- a/src/google/protobuf/compiler/cpp/enum_field.cc +++ b/src/google/protobuf/compiler/cpp/enum_field.cc @@ -36,10 +36,10 @@ #include -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/enum_field.h b/src/google/protobuf/compiler/cpp/enum_field.h index e5d476c4a1..496f146d70 100644 --- a/src/google/protobuf/compiler/cpp/enum_field.h +++ b/src/google/protobuf/compiler/cpp/enum_field.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ -#include #include #include "google/protobuf/compiler/cpp/field.h" diff --git a/src/google/protobuf/compiler/cpp/extension.h b/src/google/protobuf/compiler/cpp/extension.h index 4d7d081194..70441897c8 100644 --- a/src/google/protobuf/compiler/cpp/extension.h +++ b/src/google/protobuf/compiler/cpp/extension.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_EXTENSION_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_EXTENSION_H__ -#include #include #include "absl/container/flat_hash_map.h" diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index 50f86e1e7f..86a1f6c475 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -47,11 +47,11 @@ #include "google/protobuf/compiler/cpp/string_field.h" #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/wire_format.h" #include "google/protobuf/compiler/cpp/enum_field.h" #include "google/protobuf/compiler/cpp/map_field.h" #include "google/protobuf/compiler/cpp/message_field.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { @@ -68,8 +68,8 @@ void MaySetAnnotationVariable( absl::string_view prepared_template, int field_index, absl::string_view access_type, absl::flat_hash_map* variables) { - if (options.field_listener_options.forbidden_field_listener_events.count( - std::string(annotation_name))) + if (options.field_listener_options.forbidden_field_listener_events.contains( + annotation_name)) return; (*variables)[absl::StrCat("annotate_", annotation_name)] = absl::Substitute( absl::StrCat(substitute_template_prefix, prepared_template, ");\n"), diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 759b43d12a..afba7ef906 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -36,7 +36,6 @@ #include #include -#include #include #include #include diff --git a/src/google/protobuf/compiler/cpp/file.h b/src/google/protobuf/compiler/cpp/file.h index 3cb297e4a6..5f8ffcfc3e 100644 --- a/src/google/protobuf/compiler/cpp/file.h +++ b/src/google/protobuf/compiler/cpp/file.h @@ -38,7 +38,6 @@ #include #include #include -#include #include #include diff --git a/src/google/protobuf/compiler/cpp/generator.cc b/src/google/protobuf/compiler/cpp/generator.cc index 278354ca06..b45b16b379 100644 --- a/src/google/protobuf/compiler/cpp/generator.cc +++ b/src/google/protobuf/compiler/cpp/generator.cc @@ -42,6 +42,7 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "google/protobuf/compiler/cpp/file.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/descriptor.pb.h" @@ -168,7 +169,7 @@ bool CppGenerator::Generate(const FileDescriptor* file, } if (next_pos > pos) file_options.field_listener_options.forbidden_field_listener_events - .insert(value.substr(pos, next_pos - pos)); + .emplace(value.substr(pos, next_pos - pos)); pos = next_pos + 1; } while (pos < value.size()); } else if (key == "unverified_lazy_message_sets") { diff --git a/src/google/protobuf/compiler/cpp/helpers.cc b/src/google/protobuf/compiler/cpp/helpers.cc index d32d4c1a6c..2429bbcf73 100644 --- a/src/google/protobuf/compiler/cpp/helpers.cc +++ b/src/google/protobuf/compiler/cpp/helpers.cc @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -50,8 +49,6 @@ #include "google/protobuf/compiler/scc.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" @@ -66,6 +63,8 @@ #include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/strtod.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" // Must be last. @@ -404,6 +403,7 @@ std::string Namespace(const std::string& package) { return "::" + DotsToColons(package); } +std::string Namespace(const FileDescriptor* d) { return Namespace(d, {}); } std::string Namespace(const FileDescriptor* d, const Options& options) { std::string ns = Namespace(d->package()); if (IsWellKnownMessage(d) && options.opensource_runtime) { @@ -419,14 +419,17 @@ std::string Namespace(const FileDescriptor* d, const Options& options) { return ns; } +std::string Namespace(const Descriptor* d) { return Namespace(d, {}); } std::string Namespace(const Descriptor* d, const Options& options) { return Namespace(d->file(), options); } +std::string Namespace(const FieldDescriptor* d) { return Namespace(d, {}); } std::string Namespace(const FieldDescriptor* d, const Options& options) { return Namespace(d->file(), options); } +std::string Namespace(const EnumDescriptor* d) { return Namespace(d, {}); } std::string Namespace(const EnumDescriptor* d, const Options& options) { return Namespace(d->file(), options); } @@ -1254,7 +1257,9 @@ bool IsImplicitWeakField(const FieldDescriptor* field, const Options& options, } MessageAnalysis MessageSCCAnalyzer::GetSCCAnalysis(const SCC* scc) { - if (analysis_cache_.count(scc)) return analysis_cache_[scc]; + auto it = analysis_cache_.find(scc); + if (it != analysis_cache_.end()) return it->second; + MessageAnalysis result; if (UsingImplicitWeakFields(scc->GetFile(), options_)) { result.contains_weak = true; @@ -1309,7 +1314,7 @@ MessageAnalysis MessageSCCAnalyzer::GetSCCAnalysis(const SCC* scc) { // in the graph, the graph should be a DAG. Hence we shouldn't need to mark // nodes visited as we can never return to them. By inserting them here // we will go in an infinite loop if the SCC is not correct. - return analysis_cache_[scc] = result; + return analysis_cache_[scc] = std::move(result); } void ListAllFields(const Descriptor* d, diff --git a/src/google/protobuf/compiler/cpp/helpers.h b/src/google/protobuf/compiler/cpp/helpers.h index fbce6003ce..8e537f22aa 100644 --- a/src/google/protobuf/compiler/cpp/helpers.h +++ b/src/google/protobuf/compiler/cpp/helpers.h @@ -38,7 +38,6 @@ #include #include #include -#include #include #include "google/protobuf/compiler/scc.h" @@ -117,6 +116,10 @@ std::string Namespace(const FileDescriptor* d, const Options& options); std::string Namespace(const Descriptor* d, const Options& options); std::string Namespace(const FieldDescriptor* d, const Options& options); std::string Namespace(const EnumDescriptor* d, const Options& options); +std::string Namespace(const FileDescriptor* d); +std::string Namespace(const Descriptor* d); +std::string Namespace(const FieldDescriptor* d); +std::string Namespace(const EnumDescriptor* d); // Returns true if it's safe to reset "field" to zero. bool CanInitializeByZeroing(const FieldDescriptor* field); @@ -668,7 +671,7 @@ class PROTOC_EXPORT MessageSCCAnalyzer { }; SCCAnalyzer analyzer_; Options options_; - std::map analysis_cache_; + absl::flat_hash_map analysis_cache_; }; void ListAllFields(const Descriptor* d, diff --git a/src/google/protobuf/compiler/cpp/map_field.cc b/src/google/protobuf/compiler/cpp/map_field.cc index 529a54f060..dd9f0a6c47 100644 --- a/src/google/protobuf/compiler/cpp/map_field.cc +++ b/src/google/protobuf/compiler/cpp/map_field.cc @@ -32,11 +32,11 @@ #include -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/map_field.h b/src/google/protobuf/compiler/cpp/map_field.h index 06f3e0abc0..1465566d4b 100644 --- a/src/google/protobuf/compiler/cpp/map_field.h +++ b/src/google/protobuf/compiler/cpp/map_field.h @@ -31,7 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MAP_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_MAP_FIELD_H__ -#include #include #include "google/protobuf/compiler/cpp/helpers.h" diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index bf54fb4289..7be63c2af3 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -49,8 +49,8 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/generated_message_util.h" #include "google/protobuf/map_entry_lite.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" +#include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" @@ -67,6 +67,7 @@ #include "google/protobuf/compiler/cpp/parse_function_generator.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be included last. @@ -514,8 +515,8 @@ void AnnotationVar(const Descriptor* desc, const Options& options, absl::flat_hash_map& vars, absl::string_view name, absl::string_view val) { if (!HasTracker(desc, options) || - options.field_listener_options.forbidden_field_listener_events.count( - std::string(absl::StripPrefix(name, "annotate_"))) != 0) { + options.field_listener_options.forbidden_field_listener_events.contains( + absl::StripPrefix(name, "annotate_"))) { val = ""; } diff --git a/src/google/protobuf/compiler/cpp/message.h b/src/google/protobuf/compiler/cpp/message.h index 5de18734d0..7e22304152 100644 --- a/src/google/protobuf/compiler/cpp/message.h +++ b/src/google/protobuf/compiler/cpp/message.h @@ -37,9 +37,7 @@ #include #include -#include #include -#include #include #include #include diff --git a/src/google/protobuf/compiler/cpp/message_field.h b/src/google/protobuf/compiler/cpp/message_field.h index 39efe28b01..a7708c8838 100644 --- a/src/google/protobuf/compiler/cpp/message_field.h +++ b/src/google/protobuf/compiler/cpp/message_field.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__ -#include #include #include "google/protobuf/compiler/cpp/field.h" diff --git a/src/google/protobuf/compiler/cpp/move_unittest.cc b/src/google/protobuf/compiler/cpp/move_unittest.cc index e723346291..3f6f8e8f42 100644 --- a/src/google/protobuf/compiler/cpp/move_unittest.cc +++ b/src/google/protobuf/compiler/cpp/move_unittest.cc @@ -29,9 +29,9 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "google/protobuf/stubs/common.h" -#include "google/protobuf/test_util.h" #include "google/protobuf/unittest.pb.h" #include +#include "google/protobuf/test_util.h" #if LANG_CXX11 #include diff --git a/src/google/protobuf/compiler/cpp/names.h b/src/google/protobuf/compiler/cpp/names.h index d83cabbac0..f4dac4c644 100644 --- a/src/google/protobuf/compiler/cpp/names.h +++ b/src/google/protobuf/compiler/cpp/names.h @@ -43,10 +43,23 @@ class Descriptor; class EnumDescriptor; class EnumValueDescriptor; class FieldDescriptor; +class FileDescriptor; namespace compiler { namespace cpp { +// Returns the fully qualified C++ namespace. +// +// For example, if you had: +// package foo.bar; +// message Baz { message Moo {} } +// Then the qualified namespace for Moo would be: +// ::foo::bar +std::string Namespace(const FileDescriptor* d); +std::string Namespace(const Descriptor* d); +std::string Namespace(const FieldDescriptor* d); +std::string Namespace(const EnumDescriptor* d); + // Returns the unqualified C++ name. // // For example, if you had: diff --git a/src/google/protobuf/compiler/cpp/options.h b/src/google/protobuf/compiler/cpp/options.h index 7aab669131..affaca38c1 100644 --- a/src/google/protobuf/compiler/cpp/options.h +++ b/src/google/protobuf/compiler/cpp/options.h @@ -33,9 +33,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_OPTIONS_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_OPTIONS_H__ -#include #include +#include "absl/container/flat_hash_set.h" + namespace google { namespace protobuf { namespace compiler { @@ -53,7 +54,7 @@ enum class EnforceOptimizeMode { struct FieldListenerOptions { bool inject_field_listener_events = false; - std::set forbidden_field_listener_events; + absl::flat_hash_set forbidden_field_listener_events; }; // Generator options (see generator.cc for a description of each): diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc index 04db1a6ee5..ff174721fc 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -36,12 +36,12 @@ #include #include -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/generated_message_tctable_gen.h" #include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { @@ -1145,7 +1145,6 @@ void ParseFunctionGenerator::GenerateFieldBody( uint32_t tag = WireFormatLite::MakeTag(field->number(), wiretype); switch (wiretype) { case WireFormatLite::WIRETYPE_VARINT: { - std::string type = PrimitiveTypeName(options_, field->cpp_type()); if (field->type() == FieldDescriptor::TYPE_ENUM) { format.Set("enum_type", QualifiedClassName(field->enum_type(), options_)); diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.h b/src/google/protobuf/compiler/cpp/parse_function_generator.h index f3198b5f0f..3ad19240cc 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.h +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.h @@ -31,17 +31,16 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_PARSE_FUNCTION_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_PARSE_FUNCTION_GENERATOR_H__ -#include #include #include #include "google/protobuf/io/printer.h" #include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format_lite.h" #include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/generated_message_tctable_gen.h" +#include "google/protobuf/wire_format_lite.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/primitive_field.cc b/src/google/protobuf/compiler/cpp/primitive_field.cc index 5b0f97164b..52ce221314 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/primitive_field.cc @@ -37,10 +37,10 @@ #include #include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/primitive_field.h b/src/google/protobuf/compiler/cpp/primitive_field.h index b39c8464ed..78e717b417 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.h +++ b/src/google/protobuf/compiler/cpp/primitive_field.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_PRIMITIVE_FIELD_H__ -#include #include #include "google/protobuf/compiler/cpp/field.h" diff --git a/src/google/protobuf/compiler/cpp/service.h b/src/google/protobuf/compiler/cpp/service.h index b38591b62b..9e258f2391 100644 --- a/src/google/protobuf/compiler/cpp/service.h +++ b/src/google/protobuf/compiler/cpp/service.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_SERVICE_H__ -#include #include #include "google/protobuf/descriptor.h" diff --git a/src/google/protobuf/compiler/cpp/string_field.h b/src/google/protobuf/compiler/cpp/string_field.h index 02bee858f3..67cfa34c8c 100644 --- a/src/google/protobuf/compiler/cpp/string_field.h +++ b/src/google/protobuf/compiler/cpp/string_field.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_STRING_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_STRING_FIELD_H__ -#include #include #include "google/protobuf/compiler/cpp/field.h" diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index a477a8112a..b40e0bd6f3 100644 --- a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc @@ -37,11 +37,10 @@ // "generate_descriptor_proto.sh" and add the changed files under // csharp/src/ to your changelist. -#include - #include "google/protobuf/testing/file.h" #include "google/protobuf/testing/googletest.h" #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" @@ -103,7 +102,7 @@ class MockGeneratorContext : public GeneratorContext { } private: - std::map> files_; + absl::flat_hash_map> files_; }; class GenerateAndTest { diff --git a/src/google/protobuf/compiler/csharp/csharp_enum.cc b/src/google/protobuf/compiler/csharp/csharp_enum.cc index 846da9b6c9..eaeef31053 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum.cc +++ b/src/google/protobuf/compiler/csharp/csharp_enum.cc @@ -31,8 +31,10 @@ #include "google/protobuf/compiler/csharp/csharp_enum.h" #include +#include #include "google/protobuf/compiler/code_generator.h" +#include "absl/container/flat_hash_set.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h" @@ -63,8 +65,8 @@ void EnumGenerator::Generate(io::Printer* printer) { "access_level", class_access_level(), "name", descriptor_->name()); printer->Indent(); - std::set used_names; - std::set used_number; + absl::flat_hash_set used_names; + absl::flat_hash_set used_number; for (int i = 0; i < descriptor_->value_count(); i++) { WriteEnumValueDocComment(printer, descriptor_->value(i)); if (descriptor_->value(i)->options().deprecated()) { diff --git a/src/google/protobuf/compiler/importer.h b/src/google/protobuf/compiler/importer.h index 3b8dd51d58..3912f2dcb2 100644 --- a/src/google/protobuf/compiler/importer.h +++ b/src/google/protobuf/compiler/importer.h @@ -37,7 +37,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ #define GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ -#include #include #include #include diff --git a/src/google/protobuf/compiler/importer_unittest.cc b/src/google/protobuf/compiler/importer_unittest.cc index 614ef28c1e..8099ca2fa5 100644 --- a/src/google/protobuf/compiler/importer_unittest.cc +++ b/src/google/protobuf/compiler/importer_unittest.cc @@ -41,13 +41,13 @@ #include "google/protobuf/testing/file.h" #include "google/protobuf/testing/file.h" #include "google/protobuf/testing/file.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/testing/googletest.h" #include #include "absl/container/flat_hash_map.h" #include "absl/status/status.h" #include "absl/strings/substitute.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/BUILD.bazel b/src/google/protobuf/compiler/java/BUILD.bazel index 3ccc73da81..b93a423b6c 100644 --- a/src/google/protobuf/compiler/java/BUILD.bazel +++ b/src/google/protobuf/compiler/java/BUILD.bazel @@ -20,23 +20,23 @@ cc_library( cc_library( name = "names_internal", + srcs = [ + "helpers.cc", + "name_resolver.cc", + "names.cc", + ], hdrs = [ "helpers.h", "name_resolver.h", "names.h", "options.h", ], - srcs = [ - "helpers.cc", - "name_resolver.cc", - "names.cc", - ], copts = COPTS, include_prefix = "google/protobuf/compiler/java", visibility = ["//pkg:__pkg__"], deps = [ - "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf/compiler:code_generator", "@com_google_absl//absl/container:flat_hash_set", ], ) @@ -110,10 +110,11 @@ cc_library( "//src/google/protobuf/compiler:__pkg__", ], deps = [ - ":names_internal", ":names", + ":names_internal", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", ], diff --git a/src/google/protobuf/compiler/java/context.cc b/src/google/protobuf/compiler/java/context.cc index b9f0c8f15a..5d16ffb673 100644 --- a/src/google/protobuf/compiler/java/context.cc +++ b/src/google/protobuf/compiler/java/context.cc @@ -30,11 +30,11 @@ #include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/descriptor.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/field.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/doc_comment.cc b/src/google/protobuf/compiler/java/doc_comment.cc index fb5b5543f3..496d59d269 100644 --- a/src/google/protobuf/compiler/java/doc_comment.cc +++ b/src/google/protobuf/compiler/java/doc_comment.cc @@ -36,9 +36,8 @@ #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" #include "absl/strings/str_split.h" +#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/printer.h" diff --git a/src/google/protobuf/compiler/java/enum.cc b/src/google/protobuf/compiler/java/enum.cc index f290623cac..84c99e6779 100644 --- a/src/google/protobuf/compiler/java/enum.cc +++ b/src/google/protobuf/compiler/java/enum.cc @@ -36,7 +36,6 @@ #include -#include "google/protobuf/io/printer.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" @@ -44,6 +43,7 @@ #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/enum.h b/src/google/protobuf/compiler/java/enum.h index 8868e47459..ae85b0c34c 100644 --- a/src/google/protobuf/compiler/java/enum.h +++ b/src/google/protobuf/compiler/java/enum.h @@ -37,6 +37,7 @@ #include #include + #include "google/protobuf/descriptor.h" namespace google { diff --git a/src/google/protobuf/compiler/java/enum_field.cc b/src/google/protobuf/compiler/java/enum_field.cc index 022511ff71..f28fde7c7d 100644 --- a/src/google/protobuf/compiler/java/enum_field.cc +++ b/src/google/protobuf/compiler/java/enum_field.cc @@ -39,14 +39,14 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -91,22 +91,15 @@ void SetEnumVariables( if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); - (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); - // Note that these have a trailing ";". (*variables)["set_has_field_bit_message"] = GenerateSetBit(messageBitIndex) + ";"; - (*variables)["set_has_field_bit_builder"] = - GenerateSetBit(builderBitIndex) + ";"; - (*variables)["clear_has_field_bit_builder"] = - GenerateClearBit(builderBitIndex) + ";"; - + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); } else { (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_builder"] = ""; - (*variables)["clear_has_field_bit_builder"] = ""; - + (*variables)["set_has_field_bit_to_local"] = ""; variables->insert({"is_field_present_message", absl::StrCat((*variables)["name"], "_ != ", (*variables)["default"], ".getNumber()")}); @@ -117,10 +110,15 @@ void SetEnumVariables( (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); + + // Note that these have a trailing ";". + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); if (SupportUnknownEnumValue(descriptor->file())) { variables->insert( @@ -137,7 +135,10 @@ void SetEnumVariables( ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { + : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), + name_resolver_(context->GetNameResolver()) { SetEnumVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_, context); @@ -145,13 +146,19 @@ ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator( ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {} +int ImmutableEnumFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutableEnumFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutableEnumFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; } -int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { - return GetNumBitsForMessage(); -} +int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { return 1; } void ImmutableEnumFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { @@ -170,7 +177,7 @@ void ImmutableEnumFieldGenerator::GenerateInterfaceMembers( } void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const { - printer->Print(variables_, "private int $name$_;\n"); + printer->Print(variables_, "private int $name$_ = $default_number$;\n"); PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); @@ -225,8 +232,8 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$Value$}$(int value) {\n" - " $set_has_field_bit_builder$\n" " $name$_ = value;\n" + " $set_has_field_bit_builder$\n" " onChanged();\n" " return this;\n" "}\n"); @@ -321,9 +328,7 @@ void ImmutableEnumFieldGenerator::GenerateInitializationCode( void ImmutableEnumFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = $default_number$;\n" - "$clear_has_field_bit_builder$\n"); + printer->Print(variables_, "$name$_ = $default_number$;\n"); } void ImmutableEnumFieldGenerator::GenerateMergingCode( @@ -346,13 +351,13 @@ void ImmutableEnumFieldGenerator::GenerateMergingCode( void ImmutableEnumFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - if (HasHazzer(descriptor_)) { - printer->Print(variables_, - "if ($get_has_field_bit_from_local$) {\n" - " $set_has_field_bit_to_local$;\n" - "}\n"); + printer->Print(variables_, + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = $name$_;\n"); + if (GetNumBitsForMessage() > 0) { + printer->Print(variables_, " $set_has_field_bit_to_local$;\n"); } - printer->Print(variables_, "result.$name$_ = $name$_;\n"); + printer->Print("}\n"); } void ImmutableEnumFieldGenerator::GenerateBuilderParsingCode( @@ -504,6 +509,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( " return $default$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); printer->Print(variables_, @@ -518,6 +524,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ true); printer->Print( @@ -540,10 +547,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderClearCode( void ImmutableEnumOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, - "if ($has_oneof_case_message$) {\n" - " result.$oneof_name$_ = $oneof_name$_;\n" - "}\n"); + // No-Op: Handled by single statement for the oneof } void ImmutableEnumOneofFieldGenerator::GenerateMergingCode( @@ -632,11 +636,8 @@ void ImmutableEnumOneofFieldGenerator::GenerateHashCode( RepeatedImmutableEnumFieldGenerator::RepeatedImmutableEnumFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetEnumVariables(descriptor, messageBitIndex, builderBitIndex, - context->GetFieldGeneratorInfo(descriptor), name_resolver_, - &variables_, context); -} + : ImmutableEnumFieldGenerator(descriptor, messageBitIndex, builderBitIndex, + context) {} RepeatedImmutableEnumFieldGenerator::~RepeatedImmutableEnumFieldGenerator() {} diff --git a/src/google/protobuf/compiler/java/enum_field.h b/src/google/protobuf/compiler/java/enum_field.h index e0fc5c1fae..ed3d08a506 100644 --- a/src/google/protobuf/compiler/java/enum_field.h +++ b/src/google/protobuf/compiler/java/enum_field.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_H__ -#include #include #include "absl/container/flat_hash_map.h" @@ -69,6 +68,8 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { // implements ImmutableFieldGenerator // --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -91,6 +92,8 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; @@ -118,7 +121,7 @@ class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator { void GenerateHashCode(io::Printer* printer) const override; }; -class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { +class RepeatedImmutableEnumFieldGenerator : public ImmutableEnumFieldGenerator { public: explicit RepeatedImmutableEnumFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, @@ -151,11 +154,6 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { void GenerateKotlinDslMembers(io::Printer* printer) const override; std::string GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; - ClassNameResolver* name_resolver_; }; } // namespace java diff --git a/src/google/protobuf/compiler/java/enum_field_lite.cc b/src/google/protobuf/compiler/java/enum_field_lite.cc index e2a1a6e149..348d97ba4a 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/enum_field_lite.cc @@ -39,8 +39,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" @@ -48,6 +46,8 @@ #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/enum_field_lite.h b/src/google/protobuf/compiler/java/enum_field_lite.h index 17a95ac7f7..d51ef34648 100644 --- a/src/google/protobuf/compiler/java/enum_field_lite.h +++ b/src/google/protobuf/compiler/java/enum_field_lite.h @@ -36,7 +36,6 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_ENUM_FIELD_LITE_H__ #include -#include #include #include "absl/container/flat_hash_map.h" diff --git a/src/google/protobuf/compiler/java/enum_lite.cc b/src/google/protobuf/compiler/java/enum_lite.cc index dc222541b0..5d10a684bc 100644 --- a/src/google/protobuf/compiler/java/enum_lite.cc +++ b/src/google/protobuf/compiler/java/enum_lite.cc @@ -36,7 +36,6 @@ #include -#include "google/protobuf/io/printer.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" @@ -44,6 +43,7 @@ #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/enum_lite.h b/src/google/protobuf/compiler/java/enum_lite.h index 13306b1398..309d539b2e 100644 --- a/src/google/protobuf/compiler/java/enum_lite.h +++ b/src/google/protobuf/compiler/java/enum_lite.h @@ -37,6 +37,7 @@ #include #include + #include "google/protobuf/descriptor.h" namespace google { diff --git a/src/google/protobuf/compiler/java/extension.cc b/src/google/protobuf/compiler/java/extension.cc index 421465b313..b553b45ba7 100644 --- a/src/google/protobuf/compiler/java/extension.cc +++ b/src/google/protobuf/compiler/java/extension.cc @@ -34,13 +34,13 @@ #include "google/protobuf/compiler/java/extension.h" -#include "google/protobuf/io/printer.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/extension.h b/src/google/protobuf/compiler/java/extension.h index 15341b74dd..ad5709cfe9 100644 --- a/src/google/protobuf/compiler/java/extension.h +++ b/src/google/protobuf/compiler/java/extension.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_H__ -#include #include #include "absl/container/flat_hash_map.h" diff --git a/src/google/protobuf/compiler/java/extension_lite.cc b/src/google/protobuf/compiler/java/extension_lite.cc index 111e51054b..592679b4e3 100644 --- a/src/google/protobuf/compiler/java/extension_lite.cc +++ b/src/google/protobuf/compiler/java/extension_lite.cc @@ -32,12 +32,12 @@ #include -#include "google/protobuf/io/printer.h" #include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/extension_lite.h b/src/google/protobuf/compiler/java/extension_lite.h index 015f2ee856..da5612a287 100644 --- a/src/google/protobuf/compiler/java/extension_lite.h +++ b/src/google/protobuf/compiler/java/extension_lite.h @@ -31,7 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_EXTENSION_LITE_H__ -#include #include #include "google/protobuf/compiler/java/extension.h" diff --git a/src/google/protobuf/compiler/java/field.cc b/src/google/protobuf/compiler/java/field.cc index 449edf7fe4..3967ec48e3 100644 --- a/src/google/protobuf/compiler/java/field.cc +++ b/src/google/protobuf/compiler/java/field.cc @@ -39,7 +39,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -55,6 +54,7 @@ #include "google/protobuf/compiler/java/primitive_field_lite.h" #include "google/protobuf/compiler/java/string_field.h" #include "google/protobuf/compiler/java/string_field_lite.h" +#include "google/protobuf/io/printer.h" namespace google { diff --git a/src/google/protobuf/compiler/java/field.h b/src/google/protobuf/compiler/java/field.h index 7926f0821c..98ecb878c5 100644 --- a/src/google/protobuf/compiler/java/field.h +++ b/src/google/protobuf/compiler/java/field.h @@ -36,14 +36,13 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ #include -#include #include #include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.h" #include "absl/container/flat_hash_map.h" +#include "google/protobuf/descriptor.h" #include "google/protobuf/port.h" namespace google { @@ -72,6 +71,8 @@ class ImmutableFieldGenerator { ImmutableFieldGenerator& operator=(const ImmutableFieldGenerator&) = delete; virtual ~ImmutableFieldGenerator(); + virtual int GetMessageBitIndex() const = 0; + virtual int GetBuilderBitIndex() const = 0; virtual int GetNumBitsForMessage() const = 0; virtual int GetNumBitsForBuilder() const = 0; virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; diff --git a/src/google/protobuf/compiler/java/file.cc b/src/google/protobuf/compiler/java/file.cc index 4776277db2..6f61be85e8 100644 --- a/src/google/protobuf/compiler/java/file.cc +++ b/src/google/protobuf/compiler/java/file.cc @@ -35,13 +35,11 @@ #include "google/protobuf/compiler/java/file.h" #include -#include +#include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/dynamic_message.h" +#include "absl/container/btree_set.h" #include "absl/strings/str_cat.h" +#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/enum.h" #include "google/protobuf/compiler/java/enum_lite.h" @@ -53,6 +51,9 @@ #include "google/protobuf/compiler/java/service.h" #include "google/protobuf/compiler/java/shared_code_generator.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -76,8 +77,8 @@ struct FieldDescriptorCompare { } }; -typedef std::set - FieldDescriptorSet; +using FieldDescriptorSet = + absl::btree_set; // Recursively searches the given message to collect extensions. // Returns true if all the extensions can be recognized. The extensions will be @@ -456,16 +457,16 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable( FieldDescriptorSet extensions; CollectExtensions(file_proto, *file_->pool(), &extensions, file_data); - if (extensions.size() > 0) { + if (!extensions.empty()) { // Must construct an ExtensionRegistry containing all existing extensions // and use it to parse the descriptor data again to recognize extensions. printer->Print( "com.google.protobuf.ExtensionRegistry registry =\n" " com.google.protobuf.ExtensionRegistry.newInstance();\n"); FieldDescriptorSet::iterator it; - for (it = extensions.begin(); it != extensions.end(); it++) { + for (const FieldDescriptor* field : extensions) { std::unique_ptr generator( - generator_factory_->NewExtensionGenerator(*it)); + generator_factory_->NewExtensionGenerator(field)); bytecode_estimate += generator->GenerateRegistrationCode(printer); MaybeRestartJavaMethod( printer, &bytecode_estimate, &method_num, @@ -525,7 +526,7 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable( FieldDescriptorSet extensions; CollectExtensions(file_proto, *file_->pool(), &extensions, file_data); - if (extensions.size() > 0) { + if (!extensions.empty()) { // Try to load immutable messages' outer class. Its initialization code // will take care of interpreting custom options. printer->Print( @@ -546,9 +547,8 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable( "com.google.protobuf.ExtensionRegistry registry =\n" " com.google.protobuf.ExtensionRegistry.newInstance();\n" "com.google.protobuf.MessageLite defaultExtensionInstance = null;\n"); - FieldDescriptorSet::iterator it; - for (it = extensions.begin(); it != extensions.end(); it++) { - const FieldDescriptor* field = *it; + + for (const FieldDescriptor* field : extensions) { std::string scope; if (field->extension_scope() != NULL) { scope = name_resolver_->GetMutableClassName(field->extension_scope()) + @@ -689,6 +689,23 @@ std::string FileGenerator::GetKotlinClassname() { return name_resolver_->GetFileClassName(file_, immutable_api_, true); } +void FileGenerator::GenerateKotlin(io::Printer* printer) { + printer->Print( + "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" + "// source: $filename$\n" + "\n", + "filename", file_->name()); + printer->Print( + "// Generated files should ignore deprecation warnings\n" + "@file:Suppress(\"DEPRECATION\")"); + if (!java_package_.empty()) { + printer->Print( + "package $package$;\n" + "\n", + "package", EscapeKotlinKeywords(java_package_)); + } +} + void FileGenerator::GenerateKotlinSiblings( const std::string& package_dir, GeneratorContext* context, std::vector* file_list, diff --git a/src/google/protobuf/compiler/java/file.h b/src/google/protobuf/compiler/java/file.h index bf1e23ba1f..862242f44c 100644 --- a/src/google/protobuf/compiler/java/file.h +++ b/src/google/protobuf/compiler/java/file.h @@ -82,6 +82,7 @@ class FileGenerator { void Generate(io::Printer* printer); std::string GetKotlinClassname(); + void GenerateKotlin(io::Printer* printer); void GenerateKotlinSiblings(const std::string& package_dir, GeneratorContext* generator_context, std::vector* file_list, diff --git a/src/google/protobuf/compiler/java/generator.h b/src/google/protobuf/compiler/java/generator.h index fc7755c2b8..fdb4bb75c9 100644 --- a/src/google/protobuf/compiler/java/generator.h +++ b/src/google/protobuf/compiler/java/generator.h @@ -38,6 +38,7 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ #include + #include "google/protobuf/compiler/code_generator.h" // Must be included last. diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index fea72712b5..dd688dbaae 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -39,7 +39,6 @@ #include #include -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" @@ -52,6 +51,7 @@ #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/strtod.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index a3eee1a938..79f17850ba 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -38,12 +38,12 @@ #include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" #include "absl/strings/string_view.h" #include "google/protobuf/compiler/java/names.h" #include "google/protobuf/compiler/java/options.h" +#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/kotlin_generator.cc b/src/google/protobuf/compiler/java/kotlin_generator.cc index 3470ccbb2f..685b1e8cf0 100644 --- a/src/google/protobuf/compiler/java/kotlin_generator.cc +++ b/src/google/protobuf/compiler/java/kotlin_generator.cc @@ -119,6 +119,8 @@ bool KotlinGenerator::Generate(const FileDescriptor* file, output.get(), '$', file_options.annotate_code ? &annotation_collector : nullptr); + file_generator->GenerateKotlin(&printer); + file_generator->GenerateKotlinSiblings(package_dir, context, &all_files, &all_annotations); diff --git a/src/google/protobuf/compiler/java/map_field.cc b/src/google/protobuf/compiler/java/map_field.cc index 4c7715c69e..603d2b96ff 100644 --- a/src/google/protobuf/compiler/java/map_field.cc +++ b/src/google/protobuf/compiler/java/map_field.cc @@ -30,12 +30,12 @@ #include "google/protobuf/compiler/java/map_field.h" -#include "google/protobuf/io/printer.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -127,9 +127,8 @@ void SetMessageVariables( : ""; (*variables)["value_null_check"] = valueJavaType != JAVATYPE_ENUM && IsReferenceType(valueJavaType) - ? "if (value == null) {\n" - " throw new NullPointerException(\"map value\");\n" - "}\n" + ? "if (value == null) { " + "throw new NullPointerException(\"map value\"); }" : ""; if (valueJavaType == JAVATYPE_ENUM) { // We store enums as Integers internally. @@ -195,6 +194,14 @@ void SetMessageVariables( name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" + UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, "; (*variables)["ver"] = GeneratedCodeVersionSuffix(); + + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); + (*variables)["get_has_field_bit_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; } } // namespace @@ -203,6 +210,8 @@ ImmutableMapFieldGenerator::ImmutableMapFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), name_resolver_(context->GetNameResolver()), context_(context) { SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, @@ -212,6 +221,14 @@ ImmutableMapFieldGenerator::ImmutableMapFieldGenerator( ImmutableMapFieldGenerator::~ImmutableMapFieldGenerator() {} +int ImmutableMapFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutableMapFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutableMapFieldGenerator::GetNumBitsForMessage() const { return 0; } int ImmutableMapFieldGenerator::GetNumBitsForBuilder() const { return 1; } @@ -275,17 +292,16 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers( printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$\n" - "$value_type_pass_through_nullness$ " + "$deprecation$$value_type_pass_through_nullness$ " "${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type_pass_through_nullness$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$\n" - "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" - " $key_type$ key);\n"); + printer->Print( + variables_, + "$deprecation$$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" + " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); } } else { @@ -306,17 +322,16 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers( printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$\n" - "$value_type_pass_through_nullness$ " + "$deprecation$$value_type_pass_through_nullness$ " "${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type_pass_through_nullness$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$\n" - "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n" - " $key_type$ key);\n"); + printer->Print( + variables_, + "$deprecation$$value_type$ ${$get$capitalized_name$OrThrow$}$(\n" + " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); } } @@ -372,42 +387,45 @@ void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const { void ImmutableMapFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { - printer->Print(variables_, - "private com.google.protobuf.MapField<\n" - " $type_parameters$> $name$_;\n" - "private com.google.protobuf.MapField<$type_parameters$>\n" - "internalGet$capitalized_name$() {\n" - " if ($name$_ == null) {\n" - " return com.google.protobuf.MapField.emptyMapField(\n" - " $map_field_parameter$);\n" - " }\n" - " return $name$_;\n" - "}\n" - "private com.google.protobuf.MapField<$type_parameters$>\n" - "internalGetMutable$capitalized_name$() {\n" - " $on_changed$;\n" - " if ($name$_ == null) {\n" - " $name$_ = com.google.protobuf.MapField.newMapField(\n" - " $map_field_parameter$);\n" - " }\n" - " if (!$name$_.isMutable()) {\n" - " $name$_ = $name$_.copy();\n" - " }\n" - " return $name$_;\n" - "}\n"); + printer->Print( + variables_, + "private com.google.protobuf.MapField<\n" + " $type_parameters$> $name$_;\n" + "$deprecation$private com.google.protobuf.MapField<$type_parameters$>\n" + " internalGet$capitalized_name$() {\n" + " if ($name$_ == null) {\n" + " return com.google.protobuf.MapField.emptyMapField(\n" + " $map_field_parameter$);\n" + " }\n" + " return $name$_;\n" + "}\n" + "$deprecation$private com.google.protobuf.MapField<$type_parameters$>\n" + " internalGetMutable$capitalized_name$() {\n" + " if ($name$_ == null) {\n" + " $name$_ = com.google.protobuf.MapField.newMapField(\n" + " $map_field_parameter$);\n" + " }\n" + " if (!$name$_.isMutable()) {\n" + " $name$_ = $name$_.copy();\n" + " }\n" + " $set_has_field_bit_builder$\n" + " $on_changed$\n" + " return $name$_;\n" + "}\n"); GenerateMapGetters(printer); - printer->Print(variables_, - "$deprecation$\n" - "public Builder ${$clear$capitalized_name$$}$() {\n" - " internalGetMutable$capitalized_name$().getMutableMap()\n" - " .clear();\n" - " return this;\n" - "}\n"); + printer->Print( + variables_, + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" + " $clear_has_field_bit_builder$\n" + " internalGetMutable$capitalized_name$().getMutableMap()\n" + " .clear();\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$\n" - "public Builder ${$remove$capitalized_name$$}$(\n" + "$deprecation$public Builder ${$remove$capitalized_name$$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" @@ -415,6 +433,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { if (context_->options().opensource_runtime) { printer->Print( @@ -424,12 +443,14 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "${$getMutable$capitalized_name$$}$() {\n" + " ${$getMutable$capitalized_name$$}$() {\n" + " $set_has_field_bit_builder$\n" " return internalGetAdapted$capitalized_name$Map(\n" " internalGetMutable$capitalized_name$().getMutableMap());\n" "}\n"); printer->Annotate("{", "}", descriptor_); } + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public Builder ${$put$capitalized_name$$}$(\n" @@ -439,9 +460,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " $value_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .put(key, $name$ValueConverter.doBackward(value));\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -450,9 +473,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " internalGetAdapted$capitalized_name$Map(\n" " internalGetMutable$capitalized_name$().getMutableMap())\n" " .putAll(values);\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + if (SupportUnknownEnumValue(descriptor_->file())) { if (context_->options().opensource_runtime) { printer->Print( @@ -463,10 +488,12 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" "${$getMutable$capitalized_name$Value$}$() {\n" + " $set_has_field_bit_builder$\n" " return internalGetMutable$capitalized_name$().getMutableMap();\n" "}\n"); printer->Annotate("{", "}", descriptor_); } + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -477,9 +504,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " $value_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .put(key, value);\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -487,6 +516,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .putAll(values);\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); @@ -500,56 +530,61 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$type_parameters$>\n" - "${$getMutable$capitalized_name$$}$() {\n" + " ${$getMutable$capitalized_name$$}$() {\n" + " $set_has_field_bit_builder$\n" " return internalGetMutable$capitalized_name$().getMutableMap();\n" "}\n"); printer->Annotate("{", "}", descriptor_); } + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$" - "public Builder ${$put$capitalized_name$$}$(\n" + "$deprecation$public Builder ${$put$capitalized_name$$}$(\n" " $key_type$ key,\n" " $value_type$ value) {\n" " $key_null_check$\n" " $value_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .put(key, value);\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$\n" - "public Builder ${$putAll$capitalized_name$$}$(\n" - " java.util.Map<$type_parameters$> values) {\n" - " internalGetMutable$capitalized_name$().getMutableMap()\n" - " .putAll(values);\n" - " return this;\n" - "}\n"); + printer->Print( + variables_, + "$deprecation$public Builder ${$putAll$capitalized_name$$}$(\n" + " java.util.Map<$type_parameters$> values) {\n" + " internalGetMutable$capitalized_name$().getMutableMap()\n" + " .putAll(values);\n" + " $set_has_field_bit_builder$\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); } } void ImmutableMapFieldGenerator::GenerateMapGetters( io::Printer* printer) const { - printer->Print(variables_, - "$deprecation$\n" - "public int ${$get$capitalized_name$Count$}$() {\n" - " return internalGet$capitalized_name$().getMap().size();\n" - "}\n"); + printer->Print( + variables_, + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" + " return internalGet$capitalized_name$().getMap().size();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$\n" "@java.lang.Override\n" - "public boolean ${$contains$capitalized_name$$}$(\n" + "$deprecation$public boolean ${$contains$capitalized_name$$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " return internalGet$capitalized_name$().getMap().containsKey(key);\n" "}\n"); printer->Annotate("{", "}", descriptor_); + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { if (context_->options().opensource_runtime) { printer->Print( @@ -565,22 +600,23 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( "}\n"); printer->Annotate("{", "}", descriptor_); } + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "$deprecation$public java.util.Map<$boxed_key_type$, " + "$value_enum_type$>\n" "${$get$capitalized_name$Map$}$() {\n" " return internalGetAdapted$capitalized_name$Map(\n" " internalGet$capitalized_name$().getMap());" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_enum_type_pass_through_nullness$ " + "$deprecation$public $value_enum_type_pass_through_nullness$ " "${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_enum_type_pass_through_nullness$ defaultValue) {\n" @@ -592,12 +628,12 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " : defaultValue;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" + "$deprecation$public $value_enum_type$ get$capitalized_name$OrThrow(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" @@ -608,6 +644,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " return $name$ValueConverter.doForward(map.get(key));\n" "}\n"); printer->Annotate("{", "}", descriptor_); + if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, @@ -622,21 +659,19 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "${$get$capitalized_name$ValueMap$}$() {\n" - " return internalGet$capitalized_name$().getMap();\n" - "}\n"); + printer->Print(variables_, + "@java.lang.Override\n" + "$deprecation$public java.util.Map<$boxed_key_type$, " + "$boxed_value_type$>\n" + "${$get$capitalized_name$ValueMap$}$() {\n" + " return internalGet$capitalized_name$().getMap();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_type_pass_through_nullness$ " + "$deprecation$public $value_type_pass_through_nullness$ " "${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type_pass_through_nullness$ defaultValue) {\n" @@ -650,8 +685,8 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" + "$deprecation$public $value_type$ " + "${$get$capitalized_name$ValueOrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" @@ -680,8 +715,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$type_parameters$> " + "$deprecation$public java.util.Map<$type_parameters$> " "${$get$capitalized_name$Map$}$() {\n" " return internalGet$capitalized_name$().getMap();\n" "}\n"); @@ -690,8 +724,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_type_pass_through_nullness$ " + "$deprecation$public $value_type_pass_through_nullness$ " "${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type_pass_through_nullness$ defaultValue) {\n" @@ -702,19 +735,19 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "@java.lang.Override\n" - "$deprecation$\n" - "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n" - " $key_type$ key) {\n" - " $key_null_check$\n" - " java.util.Map<$type_parameters$> map =\n" - " internalGet$capitalized_name$().getMap();\n" - " if (!map.containsKey(key)) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" - " return map.get(key);\n" - "}\n"); + printer->Print( + variables_, + "@java.lang.Override\n" + "$deprecation$public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n" + " $key_type$ key) {\n" + " $key_null_check$\n" + " java.util.Map<$type_parameters$> map =\n" + " internalGet$capitalized_name$().getMap();\n" + " if (!map.containsKey(key)) {\n" + " throw new java.lang.IllegalArgumentException();\n" + " }\n" + " return map.get(key);\n" + "}\n"); printer->Annotate("{", "}", descriptor_); } } @@ -813,6 +846,7 @@ void ImmutableMapFieldGenerator::GenerateInitializationCode( void ImmutableMapFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { + // No need to clear the has-bit since we clear the bitField ints all at once. printer->Print(variables_, "internalGetMutable$capitalized_name$().clear();\n"); } @@ -821,14 +855,17 @@ void ImmutableMapFieldGenerator::GenerateMergingCode( io::Printer* printer) const { printer->Print(variables_, "internalGetMutable$capitalized_name$().mergeFrom(\n" - " other.internalGet$capitalized_name$());\n"); + " other.internalGet$capitalized_name$());\n" + "$set_has_field_bit_builder$\n"); } void ImmutableMapFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { printer->Print(variables_, - "result.$name$_ = internalGet$capitalized_name$();\n" - "result.$name$_.makeImmutable();\n"); + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = internalGet$capitalized_name$();\n" + " result.$name$_.makeImmutable();\n" + "}\n"); } void ImmutableMapFieldGenerator::GenerateBuilderParsingCode( @@ -845,6 +882,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderParsingCode( "} else {\n" " internalGetMutable$capitalized_name$().getMutableMap().put(\n" " $name$__.getKey(), $name$__.getValue());\n" + " $set_has_field_bit_builder$\n" "}\n"); } else { printer->Print( @@ -853,7 +891,8 @@ void ImmutableMapFieldGenerator::GenerateBuilderParsingCode( "$name$__ = input.readMessage(\n" " $default_entry$.getParserForType(), extensionRegistry);\n" "internalGetMutable$capitalized_name$().getMutableMap().put(\n" - " $name$__.getKey(), $name$__.getValue());\n"); + " $name$__.getKey(), $name$__.getValue());\n" + "$set_has_field_bit_builder$\n"); } } void ImmutableMapFieldGenerator::GenerateSerializationCode( diff --git a/src/google/protobuf/compiler/java/map_field.h b/src/google/protobuf/compiler/java/map_field.h index 39cdbde767..5454ea081a 100644 --- a/src/google/protobuf/compiler/java/map_field.h +++ b/src/google/protobuf/compiler/java/map_field.h @@ -46,6 +46,8 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { ~ImmutableMapFieldGenerator() override; // implements ImmutableFieldGenerator --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -68,6 +70,8 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; Context* context_; diff --git a/src/google/protobuf/compiler/java/map_field_lite.cc b/src/google/protobuf/compiler/java/map_field_lite.cc index 94d964fa38..b2b5b77906 100644 --- a/src/google/protobuf/compiler/java/map_field_lite.cc +++ b/src/google/protobuf/compiler/java/map_field_lite.cc @@ -32,11 +32,11 @@ #include -#include "google/protobuf/io/printer.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/message.cc b/src/google/protobuf/compiler/java/message.cc index 9ff8b87aa0..12d4406909 100644 --- a/src/google/protobuf/compiler/java/message.cc +++ b/src/google/protobuf/compiler/java/message.cc @@ -39,10 +39,6 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -56,7 +52,11 @@ #include "google/protobuf/compiler/java/message_builder_lite.h" #include "google/protobuf/compiler/java/message_serialization.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -84,7 +84,8 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor) : descriptor_(descriptor) { for (int i = 0; i < descriptor_->field_count(); i++) { if (IsRealOneof(descriptor_->field(i))) { - oneofs_.insert(descriptor_->field(i)->containing_oneof()); + const OneofDescriptor* oneof = descriptor_->field(i)->containing_oneof(); + GOOGLE_CHECK(oneofs_.emplace(oneof->index(), oneof).first->second == oneof); } } } @@ -294,13 +295,14 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { field_generators_.get(descriptor_->field(i)) .GenerateInterfaceMembers(printer); } - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { printer->Print( "\n" "$classname$.$oneof_capitalized_name$Case " "get$oneof_capitalized_name$Case();\n", "oneof_capitalized_name", - context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "classname", + context_->GetOneofGeneratorInfo(kv.second)->capitalized_name, + "classname", context_->GetNameResolver()->GetImmutableClassName(descriptor_)); } printer->Outdent(); @@ -426,7 +428,8 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { // oneof absl::flat_hash_map vars; - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; @@ -1033,7 +1036,8 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode( } // Compare oneofs. - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; printer->Print( "if (!get$oneof_capitalized_name$Case().equals(" "other.get$oneof_capitalized_name$Case())) return false;\n", @@ -1113,7 +1117,8 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode( } // hashCode oneofs. - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; printer->Print("switch ($oneof_name$Case_) {\n", "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); printer->Indent(); @@ -1279,7 +1284,8 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const { .GenerateKotlinDslMembers(printer); } - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; printer->Print( "public val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n" " @JvmName(\"get$oneof_capitalized_name$Case\")\n" @@ -1366,12 +1372,14 @@ void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers( GenerateKotlinOrNull(printer); } -void ImmutableMessageGenerator::GenerateKotlinOrNull(io::Printer* printer) const { +void ImmutableMessageGenerator::GenerateKotlinOrNull( + io::Printer* printer) const { for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = descriptor_->field(i); if (field->has_presence() && GetJavaType(field) == JAVATYPE_MESSAGE) { printer->Print( - "public val $full_classname$OrBuilder.$camelcase_name$OrNull: $full_name$?\n" + "public val $full_classname$OrBuilder.$camelcase_name$OrNull: " + "$full_name$?\n" " get() = if (has$name$()) get$name$() else null\n\n", "full_classname", EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)), @@ -1586,6 +1594,11 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { " defaultInstance.getDescriptorForType().getFullName());\n" "}\n" "\n" + "public boolean isSameTypeAs(com.google.protobuf.Message message) {\n" + " return getTypeNameFromTypeUrl(getTypeUrl()).equals(\n" + " message.getDescriptorForType().getFullName());\n" + "}\n" + "\n" "@SuppressWarnings(\"serial\")\n" "private volatile com.google.protobuf.Message cachedUnpackValue;\n" "\n" @@ -1611,7 +1624,30 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { " .parseFrom(getValue());\n" " cachedUnpackValue = result;\n" " return result;\n" - "}\n"); + "}\n" + "\n" + "@java.lang.SuppressWarnings(\"unchecked\")\n" + "public T unpackSameTypeAs(" + "T message)\n" + " throws com.google.protobuf.InvalidProtocolBufferException {\n"); + printer->Print( + " boolean invalidValue = false;\n" + " if (cachedUnpackValue != null) {\n" + " if (cachedUnpackValue.getClass() == message.getClass()) {\n" + " return (T) cachedUnpackValue;\n" + " }\n" + " invalidValue = true;\n" + " }\n" + " if (invalidValue || !isSameTypeAs(message)) {\n" + " throw new com.google.protobuf.InvalidProtocolBufferException(\n" + " \"Type of the Any message does not match the given " + "exemplar.\");\n" + " }\n" + " T result = (T) message.getParserForType().parseFrom(getValue());\n" + " cachedUnpackValue = result;\n" + " return result;\n" + "}\n" + "\n"); } } // namespace java diff --git a/src/google/protobuf/compiler/java/message.h b/src/google/protobuf/compiler/java/message.h index 0380eab8fa..a122c83433 100644 --- a/src/google/protobuf/compiler/java/message.h +++ b/src/google/protobuf/compiler/java/message.h @@ -35,9 +35,9 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_H__ -#include #include +#include "absl/container/btree_map.h" #include "google/protobuf/compiler/java/field.h" namespace google { @@ -94,7 +94,7 @@ class MessageGenerator { protected: const Descriptor* descriptor_; - std::set oneofs_; + absl::btree_map oneofs_; }; class ImmutableMessageGenerator : public MessageGenerator { diff --git a/src/google/protobuf/compiler/java/message_builder.cc b/src/google/protobuf/compiler/java/message_builder.cc index eb85dd4f76..dd2a1529a1 100644 --- a/src/google/protobuf/compiler/java/message_builder.cc +++ b/src/google/protobuf/compiler/java/message_builder.cc @@ -36,11 +36,9 @@ #include #include +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" @@ -53,6 +51,9 @@ #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -85,7 +86,8 @@ MessageBuilderGenerator::MessageBuilderGenerator(const Descriptor* descriptor, "generate lite messages."; for (int i = 0; i < descriptor_->field_count(); i++) { if (IsRealOneof(descriptor_->field(i))) { - oneofs_.insert(descriptor_->field(i)->containing_oneof()); + const OneofDescriptor* oneof = descriptor_->field(i)->containing_oneof(); + GOOGLE_CHECK(oneofs_.emplace(oneof->index(), oneof).first->second == oneof); } } } @@ -127,7 +129,8 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { // oneof absl::flat_hash_map vars; - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; @@ -146,12 +149,11 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { "\n" "public Builder clear$oneof_capitalized_name$() {\n" " $oneof_name$Case_ = 0;\n" - " $oneof_name$_ = null;\n"); - printer->Print(" onChanged();\n"); - printer->Print( - " return this;\n" - "}\n" - "\n"); + " $oneof_name$_ = null;\n" + " onChanged();\n" + " return this;\n" + "}\n" + "\n"); } // Integers for bit fields. @@ -358,17 +360,22 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( " super.clear();\n"); printer->Indent(); + int totalBuilderInts = (descriptor_->field_count() + 31) / 32; + for (int i = 0; i < totalBuilderInts; i++) { + printer->Print("$bit_field_name$ = 0;\n", "bit_field_name", + GetBitFieldName(i)); + } for (int i = 0; i < descriptor_->field_count(); i++) { field_generators_.get(descriptor_->field(i)) .GenerateBuilderClearCode(printer); } - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { printer->Print( "$oneof_name$Case_ = 0;\n" "$oneof_name$_ = null;\n", - "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); + "oneof_name", context_->GetOneofGeneratorInfo(kv.second)->name); } printer->Outdent(); @@ -409,63 +416,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); - printer->Print( - "@java.lang.Override\n" - "public $classname$ buildPartial() {\n" - " $classname$ result = new $classname$(this);\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Indent(); - - int totalBuilderBits = 0; - int totalMessageBits = 0; - for (int i = 0; i < descriptor_->field_count(); i++) { - const ImmutableFieldGenerator& field = - field_generators_.get(descriptor_->field(i)); - totalBuilderBits += field.GetNumBitsForBuilder(); - totalMessageBits += field.GetNumBitsForMessage(); - } - int totalBuilderInts = (totalBuilderBits + 31) / 32; - int totalMessageInts = (totalMessageBits + 31) / 32; - - // Local vars for from and to bit fields to avoid accessing the builder and - // message over and over for these fields. Seems to provide a slight - // perforamance improvement in micro benchmark and this is also what proto1 - // code does. - for (int i = 0; i < totalBuilderInts; i++) { - printer->Print("int from_$bit_field_name$ = $bit_field_name$;\n", - "bit_field_name", GetBitFieldName(i)); - } - for (int i = 0; i < totalMessageInts; i++) { - printer->Print("int to_$bit_field_name$ = 0;\n", "bit_field_name", - GetBitFieldName(i)); - } - - // Output generation code for each field. - for (int i = 0; i < descriptor_->field_count(); i++) { - field_generators_.get(descriptor_->field(i)).GenerateBuildingCode(printer); - } - - // Copy the bit field results to the generated message - for (int i = 0; i < totalMessageInts; i++) { - printer->Print("result.$bit_field_name$ = to_$bit_field_name$;\n", - "bit_field_name", GetBitFieldName(i)); - } - - for (auto oneof : oneofs_) { - printer->Print("result.$oneof_name$Case_ = $oneof_name$Case_;\n", - "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); - } - - printer->Outdent(); - - printer->Print(" onBuilt();\n"); - - printer->Print( - " return result;\n" - "}\n" - "\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); + GenerateBuildPartial(printer); if (context_->options().opensource_runtime) { // Override methods declared in GeneratedMessage to return the concrete @@ -572,7 +523,8 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( } // Merge oneof fields. - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; printer->Print("switch (other.get$oneof_capitalized_name$Case()) {\n", "oneof_capitalized_name", context_->GetOneofGeneratorInfo(oneof)->capitalized_name); @@ -615,6 +567,157 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( } } +void MessageBuilderGenerator::GenerateBuildPartial(io::Printer* printer) { + printer->Print( + "@java.lang.Override\n" + "public $classname$ buildPartial() {\n" + " $classname$ result = new $classname$(this);\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + + printer->Indent(); + + // Handle the repeated fields first so that the "mutable bits" are cleared. + bool has_repeated_fields = false; + for (int i = 0; i < descriptor_->field_count(); ++i) { + if (descriptor_->field(i)->is_repeated() && + !IsMapField(descriptor_->field(i))) { + has_repeated_fields = true; + printer->Print("buildPartialRepeatedFields(result);\n"); + break; + } + } + + // One buildPartial#() per from_bit_field + int totalBuilderInts = (descriptor_->field_count() + 31) / 32; + if (totalBuilderInts > 0) { + for (int i = 0; i < totalBuilderInts; ++i) { + printer->Print( + "if ($bit_field_name$ != 0) { buildPartial$piece$(result); }\n", + "bit_field_name", GetBitFieldName(i), "piece", absl::StrCat(i)); + } + } + + if (!oneofs_.empty()) { + printer->Print("buildPartialOneofs(result);\n"); + } + + printer->Outdent(); + printer->Print( + " onBuilt();\n" + " return result;\n" + "}\n" + "\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + + // Build Repeated Fields + if (has_repeated_fields) { + printer->Print( + "private void buildPartialRepeatedFields($classname$ result) {\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + printer->Indent(); + for (int i = 0; i < descriptor_->field_count(); ++i) { + if (descriptor_->field(i)->is_repeated() && + !IsMapField(descriptor_->field(i))) { + const ImmutableFieldGenerator& field = + field_generators_.get(descriptor_->field(i)); + field.GenerateBuildingCode(printer); + } + } + printer->Outdent(); + printer->Print("}\n\n"); + } + + // Build non-oneof fields + int start_field = 0; + for (int i = 0; i < totalBuilderInts; i++) { + start_field = GenerateBuildPartialPiece(printer, i, start_field); + } + + // Build Oneofs + if (!oneofs_.empty()) { + printer->Print("private void buildPartialOneofs($classname$ result) {\n", + "classname", + name_resolver_->GetImmutableClassName(descriptor_)); + printer->Indent(); + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; + printer->Print( + "result.$oneof_name$Case_ = $oneof_name$Case_;\n" + "result.$oneof_name$_ = this.$oneof_name$_;\n", + "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); + for (int i = 0; i < oneof->field_count(); ++i) { + if (oneof->field(i)->message_type() != nullptr) { + const ImmutableFieldGenerator& field = + field_generators_.get(oneof->field(i)); + field.GenerateBuildingCode(printer); + } + } + } + printer->Outdent(); + printer->Print("}\n\n"); + } +} + +int MessageBuilderGenerator::GenerateBuildPartialPiece(io::Printer* printer, + int piece, + int first_field) { + printer->Print( + "private void buildPartial$piece$($classname$ result) {\n" + " int from_$bit_field_name$ = $bit_field_name$;\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_), "piece", + absl::StrCat(piece), "bit_field_name", GetBitFieldName(piece)); + printer->Indent(); + std::set declared_to_bitfields; + + int bit = 0; + int next = first_field; + for (; bit < 32 && next < descriptor_->field_count(); ++next) { + const ImmutableFieldGenerator& field = + field_generators_.get(descriptor_->field(next)); + bit += field.GetNumBitsForBuilder(); + + // Skip oneof fields that are handled separately + if (IsRealOneof(descriptor_->field(next))) { + continue; + } + + // Skip repeated fields because they are currently handled + // in separate buildPartial sub-methods. + if (descriptor_->field(next)->is_repeated() && + !IsMapField(descriptor_->field(next))) { + continue; + } + // Skip fields without presence bits in the builder + if (field.GetNumBitsForBuilder() == 0) { + continue; + } + + // Track message bits if necessary + if (field.GetNumBitsForMessage() > 0) { + int to_bitfield = field.GetMessageBitIndex() / 32; + if (declared_to_bitfields.count(to_bitfield) == 0) { + printer->Print("int to_$bit_field_name$ = 0;\n", "bit_field_name", + GetBitFieldName(to_bitfield)); + declared_to_bitfields.insert(to_bitfield); + } + } + + // Copy the field from the builder to the message + field.GenerateBuildingCode(printer); + } + + // Copy the bit field results to the generated message + for (int to_bitfield : declared_to_bitfields) { + printer->Print("result.$bit_field_name$ |= to_$bit_field_name$;\n", + "bit_field_name", GetBitFieldName(to_bitfield)); + } + + printer->Outdent(); + printer->Print("}\n\n"); + + return next; +} + // =================================================================== void MessageBuilderGenerator::GenerateBuilderParsingMethods( diff --git a/src/google/protobuf/compiler/java/message_builder.h b/src/google/protobuf/compiler/java/message_builder.h index 5d37bb6f0f..efafd36bcc 100644 --- a/src/google/protobuf/compiler/java/message_builder.h +++ b/src/google/protobuf/compiler/java/message_builder.h @@ -35,9 +35,9 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_H__ -#include #include +#include "absl/container/btree_map.h" #include "google/protobuf/compiler/java/field.h" namespace google { @@ -71,6 +71,11 @@ class MessageBuilderGenerator { private: void GenerateCommonBuilderMethods(io::Printer* printer); + void GenerateBuildPartial(io::Printer* printer); + int GenerateBuildPartialPiece(io::Printer* printer, int piece, + int first_field); + int GenerateBuildPartialPieceWithoutPresence(io::Printer* printer, int piece, + int first_field); void GenerateDescriptorMethods(io::Printer* printer); void GenerateBuilderParsingMethods(io::Printer* printer); void GenerateBuilderFieldParsingCases(io::Printer* printer); @@ -84,7 +89,7 @@ class MessageBuilderGenerator { Context* context_; ClassNameResolver* name_resolver_; FieldGeneratorMap field_generators_; - std::set oneofs_; + absl::btree_map oneofs_; }; } // namespace java diff --git a/src/google/protobuf/compiler/java/message_builder_lite.cc b/src/google/protobuf/compiler/java/message_builder_lite.cc index 5f047344e2..ab4378e21d 100644 --- a/src/google/protobuf/compiler/java/message_builder_lite.cc +++ b/src/google/protobuf/compiler/java/message_builder_lite.cc @@ -39,9 +39,6 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" @@ -53,6 +50,9 @@ #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -73,7 +73,8 @@ MessageBuilderLiteGenerator::MessageBuilderLiteGenerator( "generate non-lite messages."; for (int i = 0; i < descriptor_->field_count(); i++) { if (IsRealOneof(descriptor_->field(i))) { - oneofs_.insert(descriptor_->field(i)->containing_oneof()); + const OneofDescriptor* oneof = descriptor_->field(i)->containing_oneof(); + GOOGLE_CHECK(oneofs_.emplace(oneof->index(), oneof).first->second == oneof); } } } @@ -103,7 +104,8 @@ void MessageBuilderLiteGenerator::Generate(io::Printer* printer) { GenerateCommonBuilderMethods(printer); // oneof - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; diff --git a/src/google/protobuf/compiler/java/message_builder_lite.h b/src/google/protobuf/compiler/java/message_builder_lite.h index f21aec6402..a0d0e15210 100644 --- a/src/google/protobuf/compiler/java/message_builder_lite.h +++ b/src/google/protobuf/compiler/java/message_builder_lite.h @@ -35,9 +35,9 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_BUILDER_LITE_H__ -#include #include +#include "absl/container/btree_map.h" #include "google/protobuf/compiler/java/field.h" namespace google { @@ -77,7 +77,7 @@ class MessageBuilderLiteGenerator { Context* context_; ClassNameResolver* name_resolver_; FieldGeneratorMap field_generators_; - std::set oneofs_; + absl::btree_map oneofs_; }; } // namespace java diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index c77d345e7c..7ce013f2d6 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -36,13 +36,13 @@ #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -91,22 +91,14 @@ void SetMessageVariables( if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); - (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); // Note that these have a trailing ";". - (*variables)["set_has_field_bit_message"] = - GenerateSetBit(messageBitIndex) + ";"; - (*variables)["set_has_field_bit_builder"] = - GenerateSetBit(builderBitIndex) + ";"; - (*variables)["clear_has_field_bit_builder"] = - GenerateClearBit(builderBitIndex) + ";"; + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); } else { - (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_builder"] = ""; - (*variables)["clear_has_field_bit_builder"] = ""; - + (*variables)["set_has_field_bit_to_local"] = ""; variables->insert({"is_field_present_message", absl::StrCat((*variables)["name"], "_ != null")}); } @@ -116,10 +108,13 @@ void SetMessageVariables( (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); } } // namespace @@ -130,6 +125,8 @@ ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), name_resolver_(context->GetNameResolver()), context_(context) { SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, @@ -139,13 +136,19 @@ ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator( ImmutableMessageFieldGenerator::~ImmutableMessageFieldGenerator() {} +int ImmutableMessageFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutableMessageFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutableMessageFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; } -int ImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { - return GetNumBitsForMessage(); -} +int ImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { return 1; } void ImmutableMessageFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { @@ -178,24 +181,6 @@ void ImmutableMessageFieldGenerator::GenerateMembers( " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print( - variables_, - "@java.lang.Override\n" - "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" - " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "@java.lang.Override\n" - "$deprecation$public $type$OrBuilder " - "${$get$capitalized_name$OrBuilder$}$() {\n" - " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); } else { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -205,24 +190,25 @@ void ImmutableMessageFieldGenerator::GenerateMembers( " return $name$_ != null;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print( - variables_, - "@java.lang.Override\n" - "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" - " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "@java.lang.Override\n" - "$deprecation$public $type$OrBuilder " - "${$get$capitalized_name$OrBuilder$}$() {\n" - " return get$capitalized_name$();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); + printer->Print( + variables_, + "@java.lang.Override\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" + " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); + + WriteFieldDocComment(printer, descriptor_); + printer->Print( + variables_, + "@java.lang.Override\n" + "$deprecation$public $type$OrBuilder " + "${$get$capitalized_name$OrBuilder$}$() {\n" + " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableMessageFieldGenerator::PrintNestedBuilderCondition( @@ -260,9 +246,6 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( // When using nested-builders, the code initially works just like the // non-nested builder case. It only creates a nested builder lazily on // demand and then forever delegates to it after creation. - - bool has_hasbit = HasHasbit(descriptor_); - printer->Print(variables_, "private $type$ $name$_;\n"); printer->Print(variables_, @@ -277,21 +260,11 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( // boolean hasField() WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - if (has_hasbit) { - printer->Print( - variables_, - "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" - " return $get_has_field_bit_builder$;\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } else { - printer->Print( - variables_, - "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" - " return $name$Builder_ != null || $name$_ != null;\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" + " return $get_has_field_bit_builder$;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); // Field getField() WriteFieldAccessorDocComment(printer, descriptor_, GETTER); @@ -309,12 +282,12 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( "if (value == null) {\n" " throw new NullPointerException();\n" "}\n" - "$name$_ = value;\n" - "$on_changed$\n", + "$name$_ = value;\n", "$name$Builder_.setMessage(value);\n", "$set_has_field_bit_builder$\n" + "$on_changed$\n" "return this;\n"); // Field.Builder setField(Field.Builder builderForValue) @@ -324,58 +297,48 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue)", - "$name$_ = builderForValue.build();\n" - "$on_changed$\n", + "$name$_ = builderForValue.build();\n", "$name$Builder_.setMessage(builderForValue.build());\n", "$set_has_field_bit_builder$\n" + "$on_changed$\n" "return this;\n"); - // Field.Builder mergeField(Field value) + // Message.Builder mergeField(Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$merge$capitalized_name$$}$($type$ value)", - - has_hasbit - ? "if ($get_has_field_bit_builder$ &&\n" - " $name$_ != null &&\n" - " $name$_ != $type$.getDefaultInstance()) {\n" - " $name$_ =\n" - " $type$.newBuilder($name$_).mergeFrom(value).buildPartial();\n" - "} else {\n" - " $name$_ = value;\n" - "}\n" - "$on_changed$\n" - : "if ($name$_ != null) {\n" - " $name$_ =\n" - " $type$.newBuilder($name$_).mergeFrom(value).buildPartial();\n" - "} else {\n" - " $name$_ = value;\n" - "}\n" - "$on_changed$\n", + "if ($get_has_field_bit_builder$ &&\n" + " $name$_ != null &&\n" + " $name$_ != $type$.getDefaultInstance()) {\n" + " get$capitalized_name$Builder().mergeFrom(value);\n" + "} else {\n" + " $name$_ = value;\n" + "}\n", "$name$Builder_.mergeFrom(value);\n", "$set_has_field_bit_builder$\n" + "$on_changed$\n" "return this;\n"); - // Field.Builder clearField() + // Message.Builder clearField() WriteFieldDocComment(printer, descriptor_); - PrintNestedBuilderFunction( - printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()", - - "$name$_ = null;\n" - "$on_changed$\n", - - has_hasbit ? "$name$Builder_.clear();\n" - : "$name$_ = null;\n" - "$name$Builder_ = null;\n", - - "$clear_has_field_bit_builder$\n" - "return this;\n"); + printer->Print(variables_, + "$deprecation$public Builder clear$capitalized_name$() {\n" + " $clear_has_field_bit_builder$\n" + " $name$_ = null;\n" + " if ($name$Builder_ != null) {\n" + " $name$Builder_.dispose();\n" + " $name$Builder_ = null;\n" + " }\n" + " $on_changed$\n" + " return this;\n" + "}\n"); + // Field.Builder getFieldBuilder() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$.Builder " @@ -385,6 +348,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " return get$capitalized_name$FieldBuilder().getBuilder();\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // FieldOrBuilder getFieldOrBuilder() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$OrBuilder " @@ -397,6 +362,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // SingleFieldBuilder getFieldFieldBuilder WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -455,9 +422,7 @@ void ImmutableMessageFieldGenerator::GenerateKotlinOrNull(io::Printer* printer) void ImmutableMessageFieldGenerator::GenerateFieldBuilderInitializationCode( io::Printer* printer) const { - if (HasHasbit(descriptor_)) { - printer->Print(variables_, "get$capitalized_name$FieldBuilder();\n"); - } + printer->Print(variables_, "get$capitalized_name$FieldBuilder();\n"); } void ImmutableMessageFieldGenerator::GenerateInitializationCode( @@ -465,17 +430,13 @@ void ImmutableMessageFieldGenerator::GenerateInitializationCode( void ImmutableMessageFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - if (HasHasbit(descriptor_)) { - PrintNestedBuilderCondition(printer, "$name$_ = null;\n", - - "$name$Builder_.clear();\n"); - printer->Print(variables_, "$clear_has_field_bit_builder$\n"); - } else { - PrintNestedBuilderCondition(printer, "$name$_ = null;\n", - - "$name$_ = null;\n" - "$name$Builder_ = null;\n"); - } + // No need to clear the has-bit since we clear the bitField ints all at once. + printer->Print(variables_, + "$name$_ = null;\n" + "if ($name$Builder_ != null) {\n" + " $name$Builder_.dispose();\n" + " $name$Builder_ = null;\n" + "}\n"); } void ImmutableMessageFieldGenerator::GenerateMergingCode( @@ -488,19 +449,15 @@ void ImmutableMessageFieldGenerator::GenerateMergingCode( void ImmutableMessageFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - if (HasHasbit(descriptor_)) { - printer->Print(variables_, "if ($get_has_field_bit_from_local$) {\n"); - printer->Indent(); - PrintNestedBuilderCondition(printer, "result.$name$_ = $name$_;\n", - "result.$name$_ = $name$Builder_.build();\n"); - printer->Outdent(); - printer->Print(variables_, - " $set_has_field_bit_to_local$;\n" - "}\n"); - } else { - PrintNestedBuilderCondition(printer, "result.$name$_ = $name$_;\n", - "result.$name$_ = $name$Builder_.build();\n"); + printer->Print(variables_, + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = $name$Builder_ == null\n" + " ? $name$_\n" + " : $name$Builder_.build();\n"); + if (GetNumBitsForMessage() > 0) { + printer->Print(variables_, " $set_has_field_bit_to_local$;\n"); } + printer->Print("}\n"); } void ImmutableMessageFieldGenerator::GenerateBuilderParsingCode( @@ -581,6 +538,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateMembers( " return $has_oneof_case_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "@java.lang.Override\n" @@ -764,7 +722,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( " $oneof_name$_ = null;\n" " }\n" " $set_oneof_case_message$;\n" - " $on_changed$;\n" + " $on_changed$\n" " return $name$Builder_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); @@ -781,16 +739,11 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderClearCode( void ImmutableMessageOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, "if ($has_oneof_case_message$) {\n"); - printer->Indent(); - - PrintNestedBuilderCondition( - printer, "result.$oneof_name$_ = $oneof_name$_;\n", - - "result.$oneof_name$_ = $name$Builder_.build();\n"); - - printer->Outdent(); - printer->Print("}\n"); + printer->Print(variables_, + "if ($has_oneof_case_message$ &&\n" + " $name$Builder_ != null) {\n" + " result.$oneof_name$_ = $name$Builder_.build();\n" + "}\n"); } void ImmutableMessageOneofFieldGenerator::GenerateMergingCode( @@ -840,11 +793,8 @@ void ImmutableMessageOneofFieldGenerator::GenerateSerializedSizeCode( RepeatedImmutableMessageFieldGenerator::RepeatedImmutableMessageFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); -} + : ImmutableMessageFieldGenerator(descriptor, messageBitIndex, + builderBitIndex, context) {} RepeatedImmutableMessageFieldGenerator:: ~RepeatedImmutableMessageFieldGenerator() {} @@ -898,6 +848,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_;\n" // note: unmodifiable list "}\n"); printer->Annotate("{", "}", descriptor_); + + // List getFieldOrBuilderList() WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -907,6 +859,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // int getFieldCount() WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -915,6 +869,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_.size();\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // Field getField(int index) WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -923,6 +879,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_.get(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // FieldOrBuilder getFieldOrBuilder(int index) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" @@ -1148,7 +1106,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "return this;\n"); - // Builder clearAllRepeatedField() + // Builder clearRepeatedField() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()", @@ -1175,6 +1133,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "return this;\n"); + // Field.Builder getRepeatedFieldBuilder(int index) WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -1184,6 +1143,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); + // FieldOrBuilder getRepeatedFieldOrBuilder(int index) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$OrBuilder " @@ -1197,6 +1157,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); + // List getRepeatedFieldOrBuilderList() WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -1210,6 +1171,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); + // Field.Builder addRepeatedField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$.Builder " @@ -1218,6 +1180,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " $type$.getDefaultInstance());\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // Field.Builder addRepeatedFieldBuilder(int index) WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -1227,6 +1191,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " index, $type$.getDefaultInstance());\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // List getRepeatedFieldBuilderList() WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, diff --git a/src/google/protobuf/compiler/java/message_field.h b/src/google/protobuf/compiler/java/message_field.h index 6510a16e92..acefb36691 100644 --- a/src/google/protobuf/compiler/java/message_field.h +++ b/src/google/protobuf/compiler/java/message_field.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_H__ -#include #include #include "google/protobuf/compiler/java/field.h" @@ -70,6 +69,8 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { // implements ImmutableFieldGenerator // --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -92,18 +93,20 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; Context* context_; - void PrintNestedBuilderCondition(io::Printer* printer, - const char* regular_case, - const char* nested_builder_case) const; - void PrintNestedBuilderFunction(io::Printer* printer, - const char* method_prototype, - const char* regular_case, - const char* nested_builder_case, - const char* trailing_code) const; + virtual void PrintNestedBuilderCondition( + io::Printer* printer, const char* regular_case, + const char* nested_builder_case) const; + virtual void PrintNestedBuilderFunction(io::Printer* printer, + const char* method_prototype, + const char* regular_case, + const char* nested_builder_case, + const char* trailing_code) const; private: void GenerateKotlinOrNull(io::Printer* printer) const; @@ -131,7 +134,8 @@ class ImmutableMessageOneofFieldGenerator void GenerateSerializedSizeCode(io::Printer* printer) const override; }; -class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { +class RepeatedImmutableMessageFieldGenerator + : public ImmutableMessageFieldGenerator { public: explicit RepeatedImmutableMessageFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, @@ -164,18 +168,14 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { std::string GetBoxedType() const override; protected: - const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; - ClassNameResolver* name_resolver_; - - void PrintNestedBuilderCondition(io::Printer* printer, - const char* regular_case, - const char* nested_builder_case) const; + void PrintNestedBuilderCondition( + io::Printer* printer, const char* regular_case, + const char* nested_builder_case) const override; void PrintNestedBuilderFunction(io::Printer* printer, const char* method_prototype, const char* regular_case, const char* nested_builder_case, - const char* trailing_code) const; + const char* trailing_code) const override; }; } // namespace java diff --git a/src/google/protobuf/compiler/java/message_field_lite.cc b/src/google/protobuf/compiler/java/message_field_lite.cc index 0a27635d7a..c0c2a1d21f 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.cc +++ b/src/google/protobuf/compiler/java/message_field_lite.cc @@ -37,13 +37,13 @@ #include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/message_field_lite.h b/src/google/protobuf/compiler/java/message_field_lite.h index 227d2660ad..01328d2c87 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.h +++ b/src/google/protobuf/compiler/java/message_field_lite.h @@ -36,7 +36,6 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_FIELD_LITE_H__ #include -#include #include #include "google/protobuf/compiler/java/field.h" diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index 64195ecda6..fb4106950a 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -40,9 +40,6 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" @@ -57,6 +54,9 @@ #include "google/protobuf/compiler/java/message_builder_lite.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" // Must be last. #include "google/protobuf/port_def.inc" @@ -81,7 +81,8 @@ ImmutableMessageLiteGenerator::ImmutableMessageLiteGenerator( "generate non-lite messages."; for (int i = 0; i < descriptor_->field_count(); i++) { if (IsRealOneof(descriptor_->field(i))) { - oneofs_.insert(descriptor_->field(i)->containing_oneof()); + const OneofDescriptor* oneof = descriptor_->field(i)->containing_oneof(); + GOOGLE_CHECK(oneofs_.emplace(oneof->index(), oneof).first->second == oneof); } } } @@ -152,7 +153,8 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { field_generators_.get(descriptor_->field(i)) .GenerateInterfaceMembers(printer); } - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; variables["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; variables["classname"] = @@ -245,7 +247,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { // oneof absl::flat_hash_map vars = {{"{", ""}, {"}", ""}}; - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; @@ -522,11 +525,11 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( // Record the number of oneofs. WriteIntToUtf16CharSequence(oneofs_.size(), &chars); - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { printer->Print( "\"$oneof_name$_\",\n" "\"$oneof_name$Case_\",\n", - "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); + "oneof_name", context_->GetOneofGeneratorInfo(kv.second)->name); } // Integers for bit fields. @@ -784,7 +787,8 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl( .GenerateKotlinDslMembers(printer); } - for (auto oneof : oneofs_) { + for (auto& kv : oneofs_) { + const OneofDescriptor* oneof = kv.second; printer->Print( "public val $oneof_name$Case: $message$.$oneof_capitalized_name$Case\n" " @JvmName(\"get$oneof_capitalized_name$Case\")\n" diff --git a/src/google/protobuf/compiler/java/message_serialization.cc b/src/google/protobuf/compiler/java/message_serialization.cc index d0a0fe26f4..fb258b8dc5 100644 --- a/src/google/protobuf/compiler/java/message_serialization.cc +++ b/src/google/protobuf/compiler/java/message_serialization.cc @@ -30,9 +30,9 @@ #include "google/protobuf/compiler/java/message_serialization.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" #include "absl/strings/str_cat.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/message_serialization.h b/src/google/protobuf/compiler/java/message_serialization.h index 3b11c47f6d..3b7c8461cb 100644 --- a/src/google/protobuf/compiler/java/message_serialization.h +++ b/src/google/protobuf/compiler/java/message_serialization.h @@ -35,10 +35,10 @@ #include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" #include "google/protobuf/compiler/java/field.h" #include "google/protobuf/compiler/java/helpers.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/printer.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/name_resolver.cc b/src/google/protobuf/compiler/java/name_resolver.cc index 72078bd6b8..32f35ad3a2 100644 --- a/src/google/protobuf/compiler/java/name_resolver.cc +++ b/src/google/protobuf/compiler/java/name_resolver.cc @@ -32,10 +32,10 @@ #include -#include "google/protobuf/compiler/code_generator.h" #include "absl/strings/ascii.h" #include "absl/strings/str_replace.h" #include "absl/strings/substitute.h" +#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/names.h" diff --git a/src/google/protobuf/compiler/java/name_resolver.h b/src/google/protobuf/compiler/java/name_resolver.h index d73b355702..7e8a75ce34 100644 --- a/src/google/protobuf/compiler/java/name_resolver.h +++ b/src/google/protobuf/compiler/java/name_resolver.h @@ -31,11 +31,11 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__ -#include #include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" +#include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/java/options.h" #include "google/protobuf/port.h" @@ -151,7 +151,7 @@ class ClassNameResolver { const FileDescriptor* file, bool immutable, bool kotlin); // Caches the result to provide better performance. - std::map + absl::flat_hash_map file_immutable_outer_class_names_; }; diff --git a/src/google/protobuf/compiler/java/plugin_unittest.cc b/src/google/protobuf/compiler/java/plugin_unittest.cc index 7fcfd87069..467d1fe694 100644 --- a/src/google/protobuf/compiler/java/plugin_unittest.cc +++ b/src/google/protobuf/compiler/java/plugin_unittest.cc @@ -35,13 +35,13 @@ #include "google/protobuf/testing/file.h" #include "google/protobuf/testing/file.h" -#include "google/protobuf/compiler/java/generator.h" -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/testing/googletest.h" #include #include "absl/strings/str_split.h" +#include "google/protobuf/compiler/command_line_interface.h" +#include "google/protobuf/compiler/java/generator.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/primitive_field.cc b/src/google/protobuf/compiler/java/primitive_field.cc index 36754350b3..50e063721d 100644 --- a/src/google/protobuf/compiler/java/primitive_field.cc +++ b/src/google/protobuf/compiler/java/primitive_field.cc @@ -39,13 +39,13 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { @@ -122,9 +122,7 @@ void SetPrimitiveVariables( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); if (IsReferenceType(GetJavaType(descriptor))) { (*variables)["null_check"] = - " if (value == null) {\n" - " throw new NullPointerException();\n" - " }\n"; + "if (value == null) { throw new NullPointerException(); }"; } else { (*variables)["null_check"] = ""; } @@ -146,22 +144,12 @@ void SetPrimitiveVariables( if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); - (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); - // Note that these have a trailing ";". - (*variables)["set_has_field_bit_message"] = - GenerateSetBit(messageBitIndex) + ";"; - (*variables)["set_has_field_bit_builder"] = - GenerateSetBit(builderBitIndex) + ";"; - (*variables)["clear_has_field_bit_builder"] = - GenerateClearBit(builderBitIndex) + ";"; - + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex) + ";"; (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); } else { - (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_builder"] = ""; - (*variables)["clear_has_field_bit_builder"] = ""; - + (*variables)["set_has_field_bit_to_local"] = ""; switch (descriptor->type()) { case FieldDescriptor::TYPE_BYTES: (*variables)["is_field_present_message"] = @@ -188,10 +176,15 @@ void SetPrimitiveVariables( (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); + // Always track the presence of a field explicitly in the builder, regardless + // of syntax. + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; } } // namespace @@ -201,7 +194,10 @@ void SetPrimitiveVariables( ImmutablePrimitiveFieldGenerator::ImmutablePrimitiveFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { + : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), + name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_, context); @@ -209,13 +205,19 @@ ImmutablePrimitiveFieldGenerator::ImmutablePrimitiveFieldGenerator( ImmutablePrimitiveFieldGenerator::~ImmutablePrimitiveFieldGenerator() {} +int ImmutablePrimitiveFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutablePrimitiveFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; } -int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { - return GetNumBitsForMessage(); -} +int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { return 1; } void ImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { @@ -230,7 +232,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers( void ImmutablePrimitiveFieldGenerator::GenerateMembers( io::Printer* printer) const { - printer->Print(variables_, "private $field_type$ $name$_;\n"); + printer->Print(variables_, "private $field_type$ $name$_ = $default$;\n"); PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); @@ -280,9 +282,9 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" - "$null_check$" - " $set_has_field_bit_builder$\n" + " $null_check$\n" " $name$_ = value;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" " return this;\n" "}\n"); @@ -355,9 +357,8 @@ void ImmutablePrimitiveFieldGenerator::GenerateInitializationCode( void ImmutablePrimitiveFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = $default$;\n" - "$clear_has_field_bit_builder$\n"); + // No need to clear the has-bit since we clear the bitField ints all at once. + printer->Print(variables_, "$name$_ = $default$;\n"); } void ImmutablePrimitiveFieldGenerator::GenerateMergingCode( @@ -377,23 +378,13 @@ void ImmutablePrimitiveFieldGenerator::GenerateMergingCode( void ImmutablePrimitiveFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - if (HasHazzer(descriptor_)) { - if (IsDefaultValueJavaDefault(descriptor_)) { - printer->Print(variables_, - "if ($get_has_field_bit_from_local$) {\n" - " result.$name$_ = $name$_;\n" - " $set_has_field_bit_to_local$;\n" - "}\n"); - } else { - printer->Print(variables_, - "if ($get_has_field_bit_from_local$) {\n" - " $set_has_field_bit_to_local$;\n" - "}\n" - "result.$name$_ = $name$_;\n"); - } - } else { - printer->Print(variables_, "result.$name$_ = $name$_;\n"); + printer->Print(variables_, + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = $name$_;\n"); + if (GetNumBitsForMessage() > 0) { + printer->Print(variables_, " $set_has_field_bit_to_local$\n"); } + printer->Print("}\n"); } void ImmutablePrimitiveFieldGenerator::GenerateBuilderParsingCode( @@ -582,7 +573,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" - "$null_check$" + " $null_check$\n" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" " $on_changed$\n" @@ -613,10 +604,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderClearCode( void ImmutablePrimitiveOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, - "if ($has_oneof_case_message$) {\n" - " result.$oneof_name$_ = $oneof_name$_;\n" - "}\n"); + // no-op } void ImmutablePrimitiveOneofFieldGenerator::GenerateMergingCode( @@ -674,11 +662,8 @@ RepeatedImmutablePrimitiveFieldGenerator:: int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); -} + : ImmutablePrimitiveFieldGenerator(descriptor, messageBitIndex, + builderBitIndex, context) {} RepeatedImmutablePrimitiveFieldGenerator:: ~RepeatedImmutablePrimitiveFieldGenerator() {} @@ -758,7 +743,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( " if (!$get_mutable_bit_builder$) {\n" " $name$_ = $mutable_copy_list$;\n" " $set_mutable_bit_builder$;\n" - " }\n" + " }\n" "}\n"); // Note: We return an unmodifiable list because otherwise the caller @@ -793,7 +778,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" - "$null_check$" + " $null_check$\n" " ensure$capitalized_name$IsMutable();\n" " $repeated_set$(index, value);\n" " $on_changed$\n" @@ -805,7 +790,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$$}$($type$ value) {\n" - "$null_check$" + " $null_check$\n" " ensure$capitalized_name$IsMutable();\n" " $repeated_add$(value);\n" " $on_changed$\n" @@ -943,9 +928,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateInitializationCode( void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = $empty_list$;\n" - "$clear_mutable_bit_builder$;\n"); + printer->Print(variables_, "$name$_ = $empty_list$;\n"); } void RepeatedImmutablePrimitiveFieldGenerator::GenerateMergingCode( diff --git a/src/google/protobuf/compiler/java/primitive_field.h b/src/google/protobuf/compiler/java/primitive_field.h index f81e28da18..7e9868609f 100644 --- a/src/google/protobuf/compiler/java/primitive_field.h +++ b/src/google/protobuf/compiler/java/primitive_field.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_H__ -#include #include #include "google/protobuf/compiler/java/field.h" @@ -70,6 +69,8 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { // implements ImmutableFieldGenerator // --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -92,6 +93,8 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; @@ -119,7 +122,7 @@ class ImmutablePrimitiveOneofFieldGenerator }; class RepeatedImmutablePrimitiveFieldGenerator - : public ImmutableFieldGenerator { + : public ImmutablePrimitiveFieldGenerator { public: explicit RepeatedImmutablePrimitiveFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, @@ -152,11 +155,6 @@ class RepeatedImmutablePrimitiveFieldGenerator void GenerateKotlinDslMembers(io::Printer* printer) const override; std::string GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; - ClassNameResolver* name_resolver_; }; } // namespace java diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.cc b/src/google/protobuf/compiler/java/primitive_field_lite.cc index 31fe87dfdf..badc0d8f1a 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/primitive_field_lite.cc @@ -39,13 +39,13 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/wire_format.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/primitive_field_lite.h b/src/google/protobuf/compiler/java/primitive_field_lite.h index 95b42432a9..aa8ba7611d 100644 --- a/src/google/protobuf/compiler/java/primitive_field_lite.h +++ b/src/google/protobuf/compiler/java/primitive_field_lite.h @@ -36,7 +36,6 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_PRIMITIVE_FIELD_LITE_H__ #include -#include #include #include "google/protobuf/compiler/java/field.h" diff --git a/src/google/protobuf/compiler/java/service.cc b/src/google/protobuf/compiler/java/service.cc index 25fbfe30bf..ed77ae2fd7 100644 --- a/src/google/protobuf/compiler/java/service.cc +++ b/src/google/protobuf/compiler/java/service.cc @@ -34,12 +34,12 @@ #include "google/protobuf/compiler/java/service.h" -#include "google/protobuf/io/printer.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" // Must be last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/compiler/java/service.h b/src/google/protobuf/compiler/java/service.h index 06f50ff873..98f9b235a9 100644 --- a/src/google/protobuf/compiler/java/service.h +++ b/src/google/protobuf/compiler/java/service.h @@ -35,7 +35,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ -#include #include "google/protobuf/descriptor.h" namespace google { diff --git a/src/google/protobuf/compiler/java/shared_code_generator.cc b/src/google/protobuf/compiler/java/shared_code_generator.cc index c70b61cd78..cc3ea6b8c5 100644 --- a/src/google/protobuf/compiler/java/shared_code_generator.cc +++ b/src/google/protobuf/compiler/java/shared_code_generator.cc @@ -34,15 +34,15 @@ #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/descriptor.h" #include "absl/strings/escaping.h" +#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/compiler/java/names.h" +#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/string_field.cc b/src/google/protobuf/compiler/java/string_field.cc index 4992ef2bcc..c267219ca7 100644 --- a/src/google/protobuf/compiler/java/string_field.cc +++ b/src/google/protobuf/compiler/java/string_field.cc @@ -40,14 +40,14 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { @@ -79,9 +79,7 @@ void SetPrimitiveVariables( (*variables)["tag_size"] = absl::StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["null_check"] = - " if (value == null) {\n" - " throw new NullPointerException();\n" - " }\n"; + "if (value == null) { throw new NullPointerException(); }"; (*variables)["isStringEmpty"] = "com.google.protobuf.GeneratedMessage" + GeneratedCodeVersionSuffix() + ".isStringEmpty"; @@ -106,21 +104,18 @@ void SetPrimitiveVariables( if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); - (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); // Note that these have a trailing ";". (*variables)["set_has_field_bit_message"] = GenerateSetBit(messageBitIndex) + ";"; - (*variables)["set_has_field_bit_builder"] = - GenerateSetBit(builderBitIndex) + ";"; - (*variables)["clear_has_field_bit_builder"] = - GenerateClearBit(builderBitIndex) + ";"; (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); } else { + (*variables)["get_has_field_bit_message"] = ""; + (*variables)["set_has_field_bit_to_local"] = ""; (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_builder"] = ""; - (*variables)["clear_has_field_bit_builder"] = ""; variables->insert({"is_field_present_message", absl::StrCat("!", (*variables)["isStringEmpty"], "(", @@ -132,10 +127,13 @@ void SetPrimitiveVariables( (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; } } // namespace @@ -145,7 +143,10 @@ void SetPrimitiveVariables( ImmutableStringFieldGenerator::ImmutableStringFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { + : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), + name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_, context); @@ -153,13 +154,19 @@ ImmutableStringFieldGenerator::ImmutableStringFieldGenerator( ImmutableStringFieldGenerator::~ImmutableStringFieldGenerator() {} +int ImmutableStringFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutableStringFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutableStringFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; } -int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const { - return GetNumBitsForMessage(); -} +int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const { return 1; } // A note about how strings are handled. This code used to just store a String // in the Message. This had two issues: @@ -211,8 +218,9 @@ void ImmutableStringFieldGenerator::GenerateInterfaceMembers( void ImmutableStringFieldGenerator::GenerateMembers( io::Printer* printer) const { - printer->Print(variables_, "@SuppressWarnings(\"serial\")\n" - "private volatile java.lang.Object $name$_;\n"); + printer->Print(variables_, + "@SuppressWarnings(\"serial\")\n" + "private volatile java.lang.Object $name$_ = $default$;\n"); PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { @@ -331,9 +339,9 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" - "$null_check$" - " $set_has_field_bit_builder$\n" + " $null_check$\n" " $name$_ = value;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" " return this;\n" "}\n"); @@ -342,14 +350,14 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( /* builder */ true); printer->Print( variables_, - "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" - " $clear_has_field_bit_builder$\n"); + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"); printer->Annotate("{", "}", descriptor_); // The default value is not a simple literal so we want to avoid executing // it multiple times. Instead, get the default out of the default instance. printer->Print(variables_, " $name$_ = getDefaultInstance().get$capitalized_name$();\n"); printer->Print(variables_, + " $clear_has_field_bit_builder$\n" " $on_changed$\n" " return this;\n" "}\n"); @@ -360,14 +368,14 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( variables_, "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" - "$null_check$"); + " $null_check$\n"); printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); } printer->Print(variables_, - " $set_has_field_bit_builder$\n" " $name$_ = value;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" " return this;\n" "}\n"); @@ -415,9 +423,7 @@ void ImmutableStringFieldGenerator::GenerateInitializationCode( void ImmutableStringFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = $default$;\n" - "$clear_has_field_bit_builder$\n"); + printer->Print(variables_, "$name$_ = $default$;\n"); } void ImmutableStringFieldGenerator::GenerateMergingCode( @@ -427,14 +433,15 @@ void ImmutableStringFieldGenerator::GenerateMergingCode( // all string fields to Strings when copying fields from a Message. printer->Print(variables_, "if (other.has$capitalized_name$()) {\n" - " $set_has_field_bit_builder$\n" " $name$_ = other.$name$_;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" "}\n"); } else { printer->Print(variables_, "if (!other.get$capitalized_name$().isEmpty()) {\n" " $name$_ = other.$name$_;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" "}\n"); } @@ -442,13 +449,13 @@ void ImmutableStringFieldGenerator::GenerateMergingCode( void ImmutableStringFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - if (HasHazzer(descriptor_)) { - printer->Print(variables_, - "if ($get_has_field_bit_from_local$) {\n" - " $set_has_field_bit_to_local$;\n" - "}\n"); + printer->Print(variables_, + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = $name$_;\n"); + if (GetNumBitsForMessage() > 0) { + printer->Print(variables_, " $set_has_field_bit_to_local$;\n"); } - printer->Print(variables_, "result.$name$_ = $name$_;\n"); + printer->Print("}\n"); } void ImmutableStringFieldGenerator::GenerateBuilderParsingCode( @@ -647,7 +654,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" - "$null_check$" + " $null_check$\n" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" " $on_changed$\n" @@ -674,7 +681,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( variables_, "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" - "$null_check$"); + " $null_check$\n"); printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); @@ -704,10 +711,7 @@ void ImmutableStringOneofFieldGenerator::GenerateMergingCode( void ImmutableStringOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, - "if ($has_oneof_case_message$) {\n" - " result.$oneof_name$_ = $oneof_name$_;\n" - "}\n"); + // No-Op: oneof fields are built by a single statement } void ImmutableStringOneofFieldGenerator::GenerateBuilderParsingCode( @@ -746,11 +750,8 @@ void ImmutableStringOneofFieldGenerator::GenerateSerializedSizeCode( RepeatedImmutableStringFieldGenerator::RepeatedImmutableStringFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); -} + : ImmutableStringFieldGenerator(descriptor, messageBitIndex, + builderBitIndex, context) {} RepeatedImmutableStringFieldGenerator:: ~RepeatedImmutableStringFieldGenerator() {} @@ -889,7 +890,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, java.lang.String value) {\n" - "$null_check$" + " $null_check$\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.set(index, value);\n" " $on_changed$\n" @@ -901,7 +902,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " java.lang.String value) {\n" - "$null_check$" + " $null_check$\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.add(value);\n" " $on_changed$\n" @@ -938,7 +939,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( variables_, "$deprecation$public Builder ${$add$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" - "$null_check$"); + " $null_check$\n"); printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); diff --git a/src/google/protobuf/compiler/java/string_field.h b/src/google/protobuf/compiler/java/string_field.h index bbe673a1c2..96f53b941a 100644 --- a/src/google/protobuf/compiler/java/string_field.h +++ b/src/google/protobuf/compiler/java/string_field.h @@ -36,7 +36,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_H__ -#include #include #include "google/protobuf/compiler/java/field.h" @@ -69,6 +68,8 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { // implements ImmutableFieldGenerator // --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -91,6 +92,8 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; absl::flat_hash_map variables_; ClassNameResolver* name_resolver_; }; @@ -118,7 +121,8 @@ class ImmutableStringOneofFieldGenerator void GenerateSerializedSizeCode(io::Printer* printer) const override; }; -class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { +class RepeatedImmutableStringFieldGenerator + : public ImmutableStringFieldGenerator { public: explicit RepeatedImmutableStringFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, @@ -149,11 +153,6 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { void GenerateKotlinDslMembers(io::Printer* printer) const override; std::string GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; - absl::flat_hash_map variables_; - ClassNameResolver* name_resolver_; }; } // namespace java diff --git a/src/google/protobuf/compiler/java/string_field_lite.cc b/src/google/protobuf/compiler/java/string_field_lite.cc index 9b4069a209..e2c6cb4704 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.cc +++ b/src/google/protobuf/compiler/java/string_field_lite.cc @@ -40,13 +40,13 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/wire_format.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/java/string_field_lite.h b/src/google/protobuf/compiler/java/string_field_lite.h index fb9a05abcb..6fa9636681 100644 --- a/src/google/protobuf/compiler/java/string_field_lite.h +++ b/src/google/protobuf/compiler/java/string_field_lite.h @@ -37,7 +37,6 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_STRING_FIELD_LITE_H__ #include -#include #include #include "google/protobuf/compiler/java/field.h" diff --git a/src/google/protobuf/compiler/objectivec/BUILD.bazel b/src/google/protobuf/compiler/objectivec/BUILD.bazel index 3e634caafc..e0de9eb461 100644 --- a/src/google/protobuf/compiler/objectivec/BUILD.bazel +++ b/src/google/protobuf/compiler/objectivec/BUILD.bazel @@ -19,34 +19,34 @@ cc_library( cc_library( name = "names_internal", + srcs = [ + "names.cc", + ], hdrs = [ "names.h", "nsobject_methods.h", ], - srcs = [ - "names.cc", - ], copts = COPTS, include_prefix = "google/protobuf/compiler/objectivec", visibility = ["//pkg:__pkg__"], deps = [ ":line_consumer", - "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf/compiler:code_generator", "@com_google_absl//absl/container:flat_hash_set", ], ) cc_library( name = "line_consumer", - hdrs = ["line_consumer.h"], srcs = ["line_consumer.cc"], + hdrs = ["line_consumer.h"], copts = COPTS, include_prefix = "google/protobuf/compiler/objectivec", visibility = ["//pkg:__pkg__"], deps = [ - "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf/compiler:code_generator", ], ) @@ -96,6 +96,7 @@ cc_library( ":names", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/strings", ], ) diff --git a/src/google/protobuf/compiler/objectivec/enum.cc b/src/google/protobuf/compiler/objectivec/enum.cc index 650d04d31a..3235daf453 100644 --- a/src/google/protobuf/compiler/objectivec/enum.cc +++ b/src/google/protobuf/compiler/objectivec/enum.cc @@ -32,9 +32,9 @@ #include #include -#include #include +#include "absl/container/flat_hash_set.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/helpers.h" @@ -69,7 +69,7 @@ EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor) // compile error is just fine. // The values are still tracked to support the reflection apis and // TextFormat handing since they are different there. - std::set value_names; + absl::flat_hash_set value_names; for (int i = 0; i < descriptor_->value_count(); i++) { const EnumValueDescriptor* value = descriptor_->value(i); @@ -80,11 +80,8 @@ EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor) base_values_.push_back(value); value_names.insert(EnumValueName(value)); } else { - std::string value_name(EnumValueName(value)); - if (value_names.find(value_name) != value_names.end()) { + if (!value_names.insert(EnumValueName(value)).second) { alias_values_to_skip_.insert(value); - } else { - value_names.insert(value_name); } } all_values_.push_back(value); @@ -126,7 +123,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { name_); printer->Indent(); - if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { + if (!descriptor_->is_closed()) { // Include the unknown value. printer->Print( // clang-format off diff --git a/src/google/protobuf/compiler/objectivec/enum.h b/src/google/protobuf/compiler/objectivec/enum.h index c990a85146..93b80ca12f 100644 --- a/src/google/protobuf/compiler/objectivec/enum.h +++ b/src/google/protobuf/compiler/objectivec/enum.h @@ -31,10 +31,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ENUM_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ENUM_H__ -#include #include #include +#include "absl/container/flat_hash_set.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" @@ -60,7 +60,7 @@ class EnumGenerator { const EnumDescriptor* descriptor_; std::vector base_values_; std::vector all_values_; - std::set alias_values_to_skip_; + absl::flat_hash_set alias_values_to_skip_; const std::string name_; }; diff --git a/src/google/protobuf/compiler/objectivec/enum_field.cc b/src/google/protobuf/compiler/objectivec/enum_field.cc index db4b35faed..e5e881a643 100644 --- a/src/google/protobuf/compiler/objectivec/enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/enum_field.cc @@ -30,7 +30,6 @@ #include "google/protobuf/compiler/objectivec/enum_field.h" -#include #include #include "absl/container/flat_hash_map.h" @@ -76,7 +75,7 @@ EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor) void EnumFieldGenerator::GenerateCFunctionDeclarations( io::Printer* printer) const { - if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { + if (descriptor_->enum_type()->is_closed()) { return; } @@ -100,7 +99,9 @@ void EnumFieldGenerator::GenerateCFunctionDeclarations( void EnumFieldGenerator::GenerateCFunctionImplementations( io::Printer* printer) const { - if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) return; + if (descriptor_->enum_type()->is_closed()) { + return; + } // clang-format off printer->Print( @@ -121,7 +122,8 @@ void EnumFieldGenerator::GenerateCFunctionImplementations( } void EnumFieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { + absl::btree_set* fwd_decls, + bool include_external_types) const { SingleFieldGenerator::DetermineForwardDeclarations(fwd_decls, include_external_types); // If it is an enum defined in a different file (and not a WKT), then we'll diff --git a/src/google/protobuf/compiler/objectivec/enum_field.h b/src/google/protobuf/compiler/objectivec/enum_field.h index c3fd59bab4..96dd2800f4 100644 --- a/src/google/protobuf/compiler/objectivec/enum_field.h +++ b/src/google/protobuf/compiler/objectivec/enum_field.h @@ -31,10 +31,9 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ENUM_FIELD_H__ -#include -#include #include +#include "absl/container/btree_set.h" #include "google/protobuf/compiler/objectivec/field.h" namespace google { @@ -51,7 +50,7 @@ class EnumFieldGenerator : public SingleFieldGenerator { public: void GenerateCFunctionDeclarations(io::Printer* printer) const override; void GenerateCFunctionImplementations(io::Printer* printer) const override; - void DetermineForwardDeclarations(std::set* fwd_decls, + void DetermineForwardDeclarations(absl::btree_set* fwd_decls, bool include_external_types) const override; protected: diff --git a/src/google/protobuf/compiler/objectivec/extension.cc b/src/google/protobuf/compiler/objectivec/extension.cc index d8c179b763..c16a1e55e0 100644 --- a/src/google/protobuf/compiler/objectivec/extension.cc +++ b/src/google/protobuf/compiler/objectivec/extension.cc @@ -32,10 +32,10 @@ #include #include -#include #include #include +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/objectivec/helpers.h" @@ -146,7 +146,7 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization( } void ExtensionGenerator::DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) { + absl::btree_set* fwd_decls) { std::string extended_type = ClassName(descriptor_->containing_type()); fwd_decls->insert(ObjCClassDeclaration(extended_type)); ObjectiveCType objc_type = GetObjectiveCType(descriptor_); diff --git a/src/google/protobuf/compiler/objectivec/extension.h b/src/google/protobuf/compiler/objectivec/extension.h index 34f5921a63..9975c12ec1 100644 --- a/src/google/protobuf/compiler/objectivec/extension.h +++ b/src/google/protobuf/compiler/objectivec/extension.h @@ -33,6 +33,7 @@ #include +#include "absl/container/btree_set.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" @@ -53,7 +54,8 @@ class ExtensionGenerator { void GenerateMembersHeader(io::Printer* printer); void GenerateStaticVariablesInitialization(io::Printer* printer); void GenerateRegistrationSource(io::Printer* printer); - void DetermineObjectiveCClassDefinitions(std::set* fwd_decls); + void DetermineObjectiveCClassDefinitions( + absl::btree_set* fwd_decls); private: std::string method_name_; diff --git a/src/google/protobuf/compiler/objectivec/field.cc b/src/google/protobuf/compiler/objectivec/field.cc index 63d71b3cc6..24c25c5b7b 100644 --- a/src/google/protobuf/compiler/objectivec/field.cc +++ b/src/google/protobuf/compiler/objectivec/field.cc @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -231,12 +230,13 @@ void FieldGenerator::GenerateCFunctionImplementations( } void FieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { + absl::btree_set* fwd_decls, + bool include_external_types) const { // Nothing } void FieldGenerator::DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) const { + absl::btree_set* fwd_decls) const { // Nothing } @@ -329,8 +329,7 @@ void SingleFieldGenerator::GeneratePropertyDeclaration( // clang-format off printer->Print( variables_, - "@property(nonatomic, readwrite) $property_type$ $name$$deprecated_attribute$;\n" - "\n"); + "@property(nonatomic, readwrite) $property_type$ $name$$deprecated_attribute$;\n"); // clang-format on if (WantsHasProperty()) { // clang-format off @@ -339,6 +338,7 @@ void SingleFieldGenerator::GeneratePropertyDeclaration( "@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;\n"); // clang-format on } + printer->Print("\n"); } void SingleFieldGenerator::GeneratePropertyImplementation( diff --git a/src/google/protobuf/compiler/objectivec/field.h b/src/google/protobuf/compiler/objectivec/field.h index f52e7c87f7..8cc1d5ab74 100644 --- a/src/google/protobuf/compiler/objectivec/field.h +++ b/src/google/protobuf/compiler/objectivec/field.h @@ -32,10 +32,10 @@ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__ #include -#include #include #include +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/match.h" #include "google/protobuf/descriptor.h" @@ -68,10 +68,11 @@ class FieldGenerator { virtual void GenerateCFunctionImplementations(io::Printer* printer) const; // Exposed for subclasses, should always call it on the parent class also. - virtual void DetermineForwardDeclarations(std::set* fwd_decls, - bool include_external_types) const; + virtual void DetermineForwardDeclarations( + absl::btree_set* fwd_decls, + bool include_external_types) const; virtual void DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) const; + absl::btree_set* fwd_decls) const; // Used during generation, not intended to be extended by subclasses. void GenerateFieldDescription(io::Printer* printer, diff --git a/src/google/protobuf/compiler/objectivec/file.cc b/src/google/protobuf/compiler/objectivec/file.cc index be711d57b5..02c029aa3b 100644 --- a/src/google/protobuf/compiler/objectivec/file.cc +++ b/src/google/protobuf/compiler/objectivec/file.cc @@ -33,12 +33,12 @@ #include #include #include -#include #include #include #include #include "google/protobuf/compiler/code_generator.h" +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/str_cat.h" @@ -151,7 +151,7 @@ FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( } absl::flat_hash_set min_deps_collector; - absl::flat_hash_set covered_deps_collector; + absl::flat_hash_set transitive_deps_collector; absl::flat_hash_set to_prune; for (int i = 0; i < file->dependency_count(); i++) { const FileDescriptor* dep = file->dependency(i); @@ -159,11 +159,12 @@ FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( CollectMinimalFileDepsContainingExtensionsInternal(dep); // Everything the dep covered, this file will also cover. - covered_deps_collector.insert(dep_info.covered_deps.begin(), - dep_info.covered_deps.end()); + transitive_deps_collector.insert(dep_info.transitive_deps.begin(), + dep_info.transitive_deps.end()); // Prune everything from the dep's covered list in case another dep lists it // as a min dep. - to_prune.insert(dep_info.covered_deps.begin(), dep_info.covered_deps.end()); + to_prune.insert(dep_info.transitive_deps.begin(), + dep_info.transitive_deps.end()); // Does the dep have any extensions... if (dep_info.has_extensions) { @@ -171,8 +172,8 @@ FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( // deps. min_deps_collector.insert(dep); to_prune.insert(dep_info.min_deps.begin(), dep_info.min_deps.end()); - covered_deps_collector.insert(dep_info.min_deps.begin(), - dep_info.min_deps.end()); + transitive_deps_collector.insert(dep_info.min_deps.begin(), + dep_info.min_deps.end()); } else { // No -> Just use its min_deps. min_deps_collector.insert(dep_info.min_deps.begin(), @@ -187,7 +188,8 @@ FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( if (to_prune.empty() || file->dependency_count() == 1) { return deps_info_cache .insert( - {file, {file_has_exts, min_deps_collector, covered_deps_collector}}) + {file, + {file_has_exts, min_deps_collector, transitive_deps_collector}}) .first->second; } @@ -198,7 +200,7 @@ FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( return to_prune.find(value) == to_prune.end(); }); return deps_info_cache - .insert({file, {file_has_exts, min_deps, covered_deps_collector}}) + .insert({file, {file_has_exts, min_deps, transitive_deps_collector}}) .first->second; } @@ -321,15 +323,14 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { "\n"); // clang-format on - std::set fwd_decls; + absl::btree_set fwd_decls; for (const auto& generator : message_generators_) { generator->DetermineForwardDeclarations( &fwd_decls, /* include_external_types = */ headers_use_forward_declarations); } - for (std::set::const_iterator i(fwd_decls.begin()); - i != fwd_decls.end(); ++i) { - printer->Print("$value$;\n", "value", *i); + for (const auto& fwd_decl : fwd_decls) { + printer->Print("$value$;\n", "value", fwd_decl); } if (fwd_decls.begin() != fwd_decls.end()) { printer->Print("\n"); @@ -439,14 +440,13 @@ void FileGenerator::GenerateSource(io::Printer* printer) { if (headers_use_forward_declarations) { // #import the headers for anything that a plain dependency of this proto // file (that means they were just an include, not a "public" include). - std::set public_import_names; + absl::flat_hash_set public_import_names; for (int i = 0; i < file_->public_dependency_count(); i++) { public_import_names.insert(file_->public_dependency(i)->name()); } for (int i = 0; i < file_->dependency_count(); i++) { const FileDescriptor* dep = file_->dependency(i); - bool public_import = (public_import_names.count(dep->name()) != 0); - if (!public_import) { + if (!public_import_names.contains(dep->name())) { import_writer.AddFile(dep, header_extension); } } @@ -475,7 +475,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { } } - std::set fwd_decls; + absl::btree_set fwd_decls; for (const auto& generator : message_generators_) { generator->DetermineObjectiveCClassDefinitions(&fwd_decls); } diff --git a/src/google/protobuf/compiler/objectivec/file.h b/src/google/protobuf/compiler/objectivec/file.h index abff7ea5d2..0637ed0d49 100644 --- a/src/google/protobuf/compiler/objectivec/file.h +++ b/src/google/protobuf/compiler/objectivec/file.h @@ -62,10 +62,10 @@ class FileGenerator { private: struct MinDepsEntry { bool has_extensions; + // The minimal dependencies that cover all the dependencies with + // extensions. absl::flat_hash_set min_deps; - // `covered_deps` are the transtive deps of `min_deps_w_exts` that also - // have extensions. - absl::flat_hash_set covered_deps; + absl::flat_hash_set transitive_deps; }; const MinDepsEntry& CollectMinimalFileDepsContainingExtensionsInternal( const FileDescriptor* file); diff --git a/src/google/protobuf/compiler/objectivec/helpers.h b/src/google/protobuf/compiler/objectivec/helpers.h index 56808a609d..76766b26b6 100644 --- a/src/google/protobuf/compiler/objectivec/helpers.h +++ b/src/google/protobuf/compiler/objectivec/helpers.h @@ -44,10 +44,6 @@ namespace protobuf { namespace compiler { namespace objectivec { -inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) { - return file->syntax() == FileDescriptor::SYNTAX_PROTO3; -} - // Escape C++ trigraphs by escaping question marks to "\?". std::string EscapeTrigraphs(absl::string_view to_escape); diff --git a/src/google/protobuf/compiler/objectivec/import_writer.h b/src/google/protobuf/compiler/objectivec/import_writer.h index d36fe34cb2..7ad31cacf5 100644 --- a/src/google/protobuf/compiler/objectivec/import_writer.h +++ b/src/google/protobuf/compiler/objectivec/import_writer.h @@ -31,7 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_IMPORT_WRITER_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_IMPORT_WRITER_H__ -#include #include #include diff --git a/src/google/protobuf/compiler/objectivec/map_field.cc b/src/google/protobuf/compiler/objectivec/map_field.cc index 767aa1dbca..2b8df1b709 100644 --- a/src/google/protobuf/compiler/objectivec/map_field.cc +++ b/src/google/protobuf/compiler/objectivec/map_field.cc @@ -30,10 +30,10 @@ #include "google/protobuf/compiler/objectivec/map_field.h" -#include #include #include +#include "absl/container/btree_set.h" #include "absl/strings/match.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/names.h" @@ -160,23 +160,28 @@ void MapFieldGenerator::FinishInitialization() { } void MapFieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { + absl::btree_set* fwd_decls, + bool include_external_types) const { RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls, include_external_types); + const FieldDescriptor* value_descriptor = + descriptor_->message_type()->map_value(); // NOTE: Maps with values of enums don't have to worry about adding the // forward declaration because `GPB*EnumDictionary` isn't generic to the // specific enum (like say `NSDictionary`) and thus doesn't // reference the type in the header. + if (GetObjectiveCType(value_descriptor) != OBJECTIVECTYPE_MESSAGE) { + return; + } + + const Descriptor* value_msg_descriptor = value_descriptor->message_type(); - const FieldDescriptor* value_descriptor = - descriptor_->message_type()->map_value(); // Within a file there is no requirement on the order of the messages, so // local references need a forward declaration. External files (not WKTs), // need one when requested. - if (GetObjectiveCType(value_descriptor) == OBJECTIVECTYPE_MESSAGE && - ((include_external_types && - !IsProtobufLibraryBundledProtoFile(value_descriptor->file())) || - descriptor_->file() == value_descriptor->file())) { + if ((include_external_types && + !IsProtobufLibraryBundledProtoFile(value_msg_descriptor->file())) || + descriptor_->file() == value_msg_descriptor->file()) { const std::string& value_storage_type = value_field_generator_->variable("storage_type"); fwd_decls->insert("@class " + value_storage_type); @@ -184,7 +189,7 @@ void MapFieldGenerator::DetermineForwardDeclarations( } void MapFieldGenerator::DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) const { + absl::btree_set* fwd_decls) const { // Class name is already in "storage_type". const FieldDescriptor* value_descriptor = descriptor_->message_type()->map_value(); diff --git a/src/google/protobuf/compiler/objectivec/map_field.h b/src/google/protobuf/compiler/objectivec/map_field.h index 55320803f6..ee11354a12 100644 --- a/src/google/protobuf/compiler/objectivec/map_field.h +++ b/src/google/protobuf/compiler/objectivec/map_field.h @@ -31,11 +31,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MAP_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MAP_FIELD_H__ -#include #include -#include #include +#include "absl/container/btree_set.h" #include "google/protobuf/compiler/objectivec/field.h" namespace google { @@ -57,8 +56,8 @@ class MapFieldGenerator : public RepeatedFieldGenerator { ~MapFieldGenerator() override = default; void DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) const override; - void DetermineForwardDeclarations(std::set* fwd_decls, + absl::btree_set* fwd_decls) const override; + void DetermineForwardDeclarations(absl::btree_set* fwd_decls, bool include_external_types) const override; private: diff --git a/src/google/protobuf/compiler/objectivec/message.cc b/src/google/protobuf/compiler/objectivec/message.cc index 91fd9ed0f2..84606dc75e 100644 --- a/src/google/protobuf/compiler/objectivec/message.cc +++ b/src/google/protobuf/compiler/objectivec/message.cc @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -223,7 +222,7 @@ void MessageGenerator::GenerateStaticVariablesInitialization( } void MessageGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) { + absl::btree_set* fwd_decls, bool include_external_types) { if (!IsMapEntryMessage(descriptor_)) { for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* fieldDescriptor = descriptor_->field(i); @@ -238,7 +237,7 @@ void MessageGenerator::DetermineForwardDeclarations( } void MessageGenerator::DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) { + absl::btree_set* fwd_decls) { if (!IsMapEntryMessage(descriptor_)) { for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* fieldDescriptor = descriptor_->field(i); diff --git a/src/google/protobuf/compiler/objectivec/message.h b/src/google/protobuf/compiler/objectivec/message.h index 3b181f13b5..59ccd071ba 100644 --- a/src/google/protobuf/compiler/objectivec/message.h +++ b/src/google/protobuf/compiler/objectivec/message.h @@ -32,10 +32,10 @@ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MESSAGE_H__ #include -#include #include #include +#include "absl/container/btree_set.h" #include "google/protobuf/compiler/objectivec/field.h" #include "google/protobuf/compiler/objectivec/oneof.h" #include "google/protobuf/descriptor.h" @@ -63,8 +63,9 @@ class MessageGenerator { void GenerateMessageHeader(io::Printer* printer); void GenerateSource(io::Printer* printer); void GenerateExtensionRegistrationSource(io::Printer* printer); - void DetermineObjectiveCClassDefinitions(std::set* fwd_decls); - void DetermineForwardDeclarations(std::set* fwd_decls, + void DetermineObjectiveCClassDefinitions( + absl::btree_set* fwd_decls); + void DetermineForwardDeclarations(absl::btree_set* fwd_decls, bool include_external_types); // Checks if the message or a nested message includes a oneof definition. diff --git a/src/google/protobuf/compiler/objectivec/message_field.cc b/src/google/protobuf/compiler/objectivec/message_field.cc index ddf1f19716..c4e17d753a 100644 --- a/src/google/protobuf/compiler/objectivec/message_field.cc +++ b/src/google/protobuf/compiler/objectivec/message_field.cc @@ -30,9 +30,9 @@ #include "google/protobuf/compiler/objectivec/message_field.h" -#include #include +#include "absl/container/btree_set.h" #include "absl/container/flat_hash_map.h" #include "google/protobuf/compiler/objectivec/helpers.h" #include "google/protobuf/compiler/objectivec/names.h" @@ -66,7 +66,8 @@ MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor) } void MessageFieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { + absl::btree_set* fwd_decls, + bool include_external_types) const { ObjCObjFieldGenerator::DetermineForwardDeclarations(fwd_decls, include_external_types); // Within a file there is no requirement on the order of the messages, so @@ -81,7 +82,7 @@ void MessageFieldGenerator::DetermineForwardDeclarations( } void MessageFieldGenerator::DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) const { + absl::btree_set* fwd_decls) const { fwd_decls->insert(ObjCClassDeclaration(variable("storage_type"))); } @@ -95,7 +96,8 @@ RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator( } void RepeatedMessageFieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { + absl::btree_set* fwd_decls, + bool include_external_types) const { RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls, include_external_types); // Within a file there is no requirement on the order of the messages, so @@ -110,7 +112,7 @@ void RepeatedMessageFieldGenerator::DetermineForwardDeclarations( } void RepeatedMessageFieldGenerator::DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) const { + absl::btree_set* fwd_decls) const { fwd_decls->insert(ObjCClassDeclaration(variable("storage_type"))); } diff --git a/src/google/protobuf/compiler/objectivec/message_field.h b/src/google/protobuf/compiler/objectivec/message_field.h index 164869d85f..40028a0a7f 100644 --- a/src/google/protobuf/compiler/objectivec/message_field.h +++ b/src/google/protobuf/compiler/objectivec/message_field.h @@ -31,10 +31,9 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MESSAGE_FIELD_H__ -#include -#include #include +#include "absl/container/btree_set.h" #include "google/protobuf/compiler/objectivec/field.h" namespace google { @@ -53,10 +52,10 @@ class MessageFieldGenerator : public ObjCObjFieldGenerator { MessageFieldGenerator& operator=(const MessageFieldGenerator&) = delete; public: - void DetermineForwardDeclarations(std::set* fwd_decls, + void DetermineForwardDeclarations(absl::btree_set* fwd_decls, bool include_external_types) const override; void DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) const override; + absl::btree_set* fwd_decls) const override; }; class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator { @@ -71,10 +70,10 @@ class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator { const RepeatedMessageFieldGenerator&) = delete; public: - void DetermineForwardDeclarations(std::set* fwd_decls, + void DetermineForwardDeclarations(absl::btree_set* fwd_decls, bool include_external_types) const override; void DetermineObjectiveCClassDefinitions( - std::set* fwd_decls) const override; + absl::btree_set* fwd_decls) const override; }; } // namespace objectivec diff --git a/src/google/protobuf/compiler/objectivec/oneof.h b/src/google/protobuf/compiler/objectivec/oneof.h index 27a1ecbc07..d9a23f902c 100644 --- a/src/google/protobuf/compiler/objectivec/oneof.h +++ b/src/google/protobuf/compiler/objectivec/oneof.h @@ -31,7 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__ -#include #include #include diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index 7546792408..49ae6bdeac 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -598,7 +598,7 @@ bool Parser::ValidateEnum(const EnumDescriptorProto* proto) { return false; } - std::set used_values; + absl::flat_hash_set used_values; bool has_duplicates = false; for (int i = 0; i < proto->value_size(); ++i) { const EnumValueDescriptorProto& enum_value = proto->value(i); diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index cac385551f..80cc396175 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -38,10 +38,10 @@ #define GOOGLE_PROTOBUF_COMPILER_PARSER_H__ #include -#include #include #include +#include "absl/container/flat_hash_map.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/tokenizer.h" @@ -591,12 +591,12 @@ class PROTOBUF_EXPORT SourceLocationTable { void Clear(); private: - typedef std::map< + using LocationMap = absl::flat_hash_map< std::pair, - std::pair > - LocationMap; + std::pair>; LocationMap location_map_; - std::map, std::pair > + absl::flat_hash_map, + std::pair> import_location_map_; }; diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 8260721acb..f267bb2197 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -39,19 +39,20 @@ #include #include -#include "google/protobuf/test_util2.h" -#include "google/protobuf/unittest.pb.h" #include "google/protobuf/any.pb.h" -#include "google/protobuf/unittest_custom_options.pb.h" -#include "google/protobuf/io/tokenizer.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_import.pb.h" +#include "google/protobuf/unittest_import_public.pb.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format.h" #include "google/protobuf/testing/googletest.h" #include +#include "absl/container/flat_hash_map.h" #include "absl/strings/str_join.h" #include "absl/strings/substitute.h" +#include "google/protobuf/test_util2.h" +#include "google/protobuf/unittest_custom_options.pb.h" +#include "google/protobuf/wire_format.h" namespace google { namespace protobuf { @@ -2843,7 +2844,7 @@ class SourceInfoTest : public ParserTest { typedef std::multimap SpanMap; SpanMap spans_; - std::map > markers_; + absl::flat_hash_map> markers_; std::string text_without_markers_; void ExtractMarkers(const char* text) { diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index aa1cb0b3d6..5501c98f2b 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -31,8 +31,11 @@ #include "google/protobuf/compiler/php/php_generator.h" #include +#include #include "google/protobuf/compiler/code_generator.h" +#include "absl/container/flat_hash_map.h" +#include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_replace.h" @@ -43,18 +46,18 @@ #include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream.h" -const std::string kDescriptorFile = "google/protobuf/descriptor.proto"; -const std::string kEmptyFile = "google/protobuf/empty.proto"; -const std::string kEmptyMetadataFile = "GPBMetadata/Google/Protobuf/GPBEmpty.php"; -const std::string kDescriptorMetadataFile = +constexpr absl::string_view kDescriptorFile = + "google/protobuf/descriptor.proto"; +constexpr absl::string_view kEmptyFile = "google/protobuf/empty.proto"; +constexpr absl::string_view kEmptyMetadataFile = + "GPBMetadata/Google/Protobuf/GPBEmpty.php"; +constexpr absl::string_view kDescriptorMetadataFile = "GPBMetadata/Google/Protobuf/Internal/Descriptor.php"; -const std::string kDescriptorDirName = "Google/Protobuf/Internal"; -const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal"; -const char* const kValidConstantNames[] = { - "int", "float", "bool", "string", "true", - "false", "null", "void", "iterable", "parent", - "self", "readonly" -}; +constexpr absl::string_view kDescriptorPackageName = + "Google\\Protobuf\\Internal"; +constexpr absl::string_view kValidConstantNames[] = { + "int", "float", "bool", "string", "true", "false", + "null", "void", "iterable", "parent", "self", "readonly"}; const int kValidConstantNamesSize = 12; const int kFieldSetter = 1; const int kFieldGetter = 2; @@ -69,7 +72,7 @@ struct Options { bool is_descriptor = false; bool aggregate_metadata = false; bool gen_c_wkt = false; - std::set aggregate_metadata_prefixes; + absl::flat_hash_set aggregate_metadata_prefixes; }; namespace { @@ -206,7 +209,7 @@ std::string PhpNamePrefix(const std::string& classname) { std::string PhpName(const std::string& full_name, const Options& options) { if (options.is_descriptor) { - return kDescriptorPackageName; + return std::string(kDescriptorPackageName); } std::string segment; @@ -262,17 +265,17 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file, std::string segment = ""; if (proto_file == kEmptyFile) { - return kEmptyMetadataFile; + return std::string(kEmptyMetadataFile); } if (options.is_descriptor) { - return kDescriptorMetadataFile; + return std::string(kDescriptorMetadataFile); } // Append directory name. std::string file_no_suffix; int lastindex = proto_file.find_last_of('.'); if (proto_file == kEmptyFile) { - return kEmptyMetadataFile; + return std::string(kEmptyMetadataFile); } else { file_no_suffix = proto_file.substr(0, lastindex); } @@ -991,9 +994,10 @@ void GenerateAddFileToPool(const FileDescriptor* file, const Options& options, static void AnalyzeDependencyForFile( const FileDescriptor* file, - std::set* nodes_without_dependency, - std::map>* deps, - std::map* dependency_count) { + absl::flat_hash_set* nodes_without_dependency, + absl::flat_hash_map>* deps, + absl::flat_hash_map* dependency_count) { int count = file->dependency_count(); for (int i = 0; i < file->dependency_count(); i++) { const FileDescriptor* dependency = file->dependency(i); @@ -1013,7 +1017,7 @@ static void AnalyzeDependencyForFile( continue; } if (deps->find(dependency) == deps->end()) { - (*deps)[dependency] = std::set(); + (*deps)[dependency] = {}; } (*deps)[dependency].insert(file); AnalyzeDependencyForFile( @@ -1049,9 +1053,11 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options, "}\n"); // Sort files according to dependency - std::map> deps; - std::map dependency_count; - std::set nodes_without_dependency; + absl::flat_hash_map> + deps; + absl::flat_hash_map dependency_count; + absl::flat_hash_set nodes_without_dependency; FileDescriptorSet sorted_file_set; AnalyzeDependencyForFile( diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc index b7e5c0e6f8..76f4f27193 100644 --- a/src/google/protobuf/compiler/plugin.cc +++ b/src/google/protobuf/compiler/plugin.cc @@ -33,8 +33,6 @@ #include "google/protobuf/compiler/plugin.h" #include -#include - #ifdef _WIN32 #include #else diff --git a/src/google/protobuf/compiler/python/plugin_unittest.cc b/src/google/protobuf/compiler/python/plugin_unittest.cc index b8f25cf3e5..b613f2df7e 100644 --- a/src/google/protobuf/compiler/python/plugin_unittest.cc +++ b/src/google/protobuf/compiler/python/plugin_unittest.cc @@ -37,11 +37,11 @@ #include "google/protobuf/testing/file.h" #include "google/protobuf/compiler/command_line_interface.h" #include "google/protobuf/compiler/python/generator.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/testing/googletest.h" #include #include "absl/strings/str_split.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/python/pyi_generator.cc b/src/google/protobuf/compiler/python/pyi_generator.cc index bc90a6436c..607a054534 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.cc +++ b/src/google/protobuf/compiler/python/pyi_generator.cc @@ -33,6 +33,7 @@ #include #include +#include "absl/container/flat_hash_set.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "absl/strings/str_split.h" @@ -152,7 +153,7 @@ void CheckImportModules(const Descriptor* descriptor, void PyiGenerator::PrintImportForDescriptor( const FileDescriptor& desc, - std::set* seen_aliases) const { + absl::flat_hash_set* seen_aliases) const { const std::string& filename = desc.name(); std::string module_name_owned = StrippedModuleName(filename); absl::string_view module_name(module_name_owned); @@ -179,7 +180,7 @@ void PyiGenerator::PrintImportForDescriptor( void PyiGenerator::PrintImports() const { // Prints imported dependent _pb2 files. - std::set seen_aliases; + absl::flat_hash_set seen_aliases; for (int i = 0; i < file_->dependency_count(); ++i) { const FileDescriptor* dep = file_->dependency(i); PrintImportForDescriptor(*dep, &seen_aliases); @@ -303,17 +304,26 @@ void PyiGenerator::PrintEnum(const EnumDescriptor& enum_descriptor) const { " __slots__ = []\n", "enum_name", enum_name); Annotate("enum_name", &enum_descriptor); + printer_->Indent(); + PrintEnumValues(enum_descriptor, /* is_classvar = */ true); + printer_->Outdent(); } -void PyiGenerator::PrintEnumValues( - const EnumDescriptor& enum_descriptor) const { +void PyiGenerator::PrintEnumValues(const EnumDescriptor& enum_descriptor, + bool is_classvar) const { // enum values std::string module_enum_name = ModuleLevelName(enum_descriptor); for (int j = 0; j < enum_descriptor.value_count(); ++j) { const EnumValueDescriptor* value_descriptor = enum_descriptor.value(j); - printer_->Print("$name$: $module_enum_name$\n", - "name", value_descriptor->name(), - "module_enum_name", module_enum_name); + if (is_classvar) { + printer_->Print("$name$: _ClassVar[$module_enum_name$]\n", "name", + value_descriptor->name(), "module_enum_name", + module_enum_name); + } else { + printer_->Print("$name$: $module_enum_name$\n", "name", + value_descriptor->name(), "module_enum_name", + module_enum_name); + } Annotate("name", value_descriptor); } } @@ -397,7 +407,6 @@ void PyiGenerator::PrintMessage( "class_name", class_name, "extra_base", extra_base); Annotate("class_name", &message_descriptor); printer_->Indent(); - printer_->Indent(); // Prints slots printer_->Print("__slots__ = [", "class_name", class_name); @@ -537,8 +546,6 @@ void PyiGenerator::PrintMessage( printer_->Print(", **kwargs"); } printer_->Print(") -> None: ...\n"); - - printer_->Outdent(); printer_->Outdent(); } @@ -596,8 +603,10 @@ bool PyiGenerator::Generate(const FileDescriptor* file, GeneratedCodeInfo annotations; io::AnnotationProtoCollector annotation_collector( &annotations); - io::Printer printer(output.get(), '$', - annotate_code ? &annotation_collector : nullptr); + io::Printer::Options printer_opt( + '$', annotate_code ? &annotation_collector : nullptr); + printer_opt.spaces_per_indent = 4; + io::Printer printer(output.get(), printer_opt); printer_ = &printer; PrintImports(); diff --git a/src/google/protobuf/compiler/python/pyi_generator.h b/src/google/protobuf/compiler/python/pyi_generator.h index bd7e71f90f..fca8654afd 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.h +++ b/src/google/protobuf/compiler/python/pyi_generator.h @@ -35,10 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_PYTHON_PYI_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_PYTHON_PYI_GENERATOR_H__ -#include #include #include "absl/container/flat_hash_map.h" +#include "absl/container/flat_hash_set.h" #include "absl/synchronization/mutex.h" #include "google/protobuf/compiler/code_generator.h" @@ -77,14 +77,16 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera std::string* error) const override; private: - void PrintImportForDescriptor(const FileDescriptor& desc, - std::set* seen_aliases) const; + void PrintImportForDescriptor( + const FileDescriptor& desc, + absl::flat_hash_set* seen_aliases) const; template void Annotate(const std::string& label, const DescriptorT* descriptor) const; void PrintImports() const; void PrintTopLevelEnums() const; void PrintEnum(const EnumDescriptor& enum_descriptor) const; - void PrintEnumValues(const EnumDescriptor& enum_descriptor) const; + void PrintEnumValues(const EnumDescriptor& enum_descriptor, + bool is_classvar = false) const; template void PrintExtensions(const DescriptorT& descriptor) const; void PrintMessages() const; diff --git a/src/google/protobuf/compiler/scc.h b/src/google/protobuf/compiler/scc.h index 2408dcd07b..c9a112af71 100644 --- a/src/google/protobuf/compiler/scc.h +++ b/src/google/protobuf/compiler/scc.h @@ -31,10 +31,13 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_SCC_H__ #define GOOGLE_PROTOBUF_COMPILER_SCC_H__ -#include +#include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" +#include "absl/container/flat_hash_map.h" +#include "absl/container/flat_hash_set.h" +#include "absl/memory/memory.h" #include "google/protobuf/descriptor.h" // Must be included last. @@ -68,8 +71,11 @@ class PROTOC_EXPORT SCCAnalyzer { SCCAnalyzer& operator=(const SCCAnalyzer&) = delete; const SCC* GetSCC(const Descriptor* descriptor) { - if (cache_.count(descriptor)) return cache_[descriptor].scc; - return DFS(descriptor).scc; + auto it = cache_.find(descriptor); + if (it == cache_.end()) { + return DFS(descriptor).scc; + } + return it->second->scc; } private: @@ -79,7 +85,7 @@ class PROTOC_EXPORT SCCAnalyzer { int lowlink; }; - std::map cache_; + absl::flat_hash_map> cache_; std::vector stack_; int index_; std::vector> garbage_bin_; @@ -91,24 +97,25 @@ class PROTOC_EXPORT SCCAnalyzer { // Tarjan's Strongly Connected Components algo NodeData DFS(const Descriptor* descriptor) { - // Must not have visited already. - GOOGLE_DCHECK_EQ(cache_.count(descriptor), 0); - // Mark visited by inserting in map. - NodeData& result = cache_[descriptor]; + auto ins = cache_.try_emplace(descriptor, absl::make_unique()); + // Must not have visited already. + GOOGLE_DCHECK(ins.second); + NodeData& result = *ins.first->second; // Initialize data structures. result.index = result.lowlink = index_++; stack_.push_back(descriptor); // Recurse the fields / nodes in graph - for (auto dep : DepsGenerator()(descriptor)) { + for (const auto* dep : DepsGenerator()(descriptor)) { GOOGLE_CHECK(dep); - if (cache_.count(dep) == 0) { + auto it = cache_.find(dep); + if (it == cache_.end()) { // unexplored node NodeData child_data = DFS(dep); result.lowlink = std::min(result.lowlink, child_data.lowlink); } else { - NodeData child_data = cache_[dep]; + NodeData& child_data = *it->second; if (child_data.scc == nullptr) { // Still in the stack_ so we found a back edge result.lowlink = std::min(result.lowlink, child_data.index); @@ -123,7 +130,7 @@ class PROTOC_EXPORT SCCAnalyzer { scc->descriptors.push_back(scc_desc); // Remove from stack stack_.pop_back(); - cache_[scc_desc].scc = scc; + cache_[scc_desc]->scc = scc; if (scc_desc == descriptor) break; } @@ -141,7 +148,7 @@ class PROTOC_EXPORT SCCAnalyzer { // Add the SCC's that are children of this SCC to its children. void AddChildren(SCC* scc) { - std::set seen; + absl::flat_hash_set seen; for (auto descriptor : scc->descriptors) { for (auto child_msg : DepsGenerator()(descriptor)) { GOOGLE_CHECK(child_msg); diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index cf4899dc25..14cb76db2c 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -42,13 +42,11 @@ #include "google/protobuf/compiler/importer.h" #include "google/protobuf/compiler/parser.h" #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_custom_options.pb.h" #include "google/protobuf/descriptor.pb.h" #include "absl/strings/str_format.h" +#include "google/protobuf/unittest_custom_options.pb.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/logging.h" -#include "google/protobuf/unittest_lazy_dependencies.pb.h" -#include "google/protobuf/unittest_proto3_arena.pb.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor_database.h" @@ -58,6 +56,10 @@ #include "google/protobuf/testing/googletest.h" #include #include "google/protobuf/stubs/logging.h" +#include "google/protobuf/unittest_lazy_dependencies.pb.h" +#include "google/protobuf/unittest_lazy_dependencies_custom_option.pb.h" +#include "google/protobuf/unittest_lazy_dependencies_enum.pb.h" +#include "google/protobuf/unittest_proto3_arena.pb.h" #include "absl/strings/substitute.h" diff --git a/src/google/protobuf/drop_unknown_fields_test.cc b/src/google/protobuf/drop_unknown_fields_test.cc index 747cb5b8fe..bcb7b2bef9 100644 --- a/src/google/protobuf/drop_unknown_fields_test.cc +++ b/src/google/protobuf/drop_unknown_fields_test.cc @@ -30,10 +30,10 @@ #include -#include "google/protobuf/unittest_drop_unknown_fields.pb.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/message_lite.h" #include +#include "google/protobuf/unittest_drop_unknown_fields.pb.h" using unittest_drop_unknown_fields::Foo; using unittest_drop_unknown_fields::FooWithExtraFields; diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 7c60f7f59f..79bf16cc7a 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -21,7 +21,7 @@ namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Duration::Duration( ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.seconds_)*/int64_t{0} + /*decltype(_impl_.seconds_)*/::int64_t{0} , /*decltype(_impl_.nanos_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct DurationDefaultTypeInternal { @@ -40,7 +40,7 @@ static constexpr const ::_pb::EnumDescriptor** file_level_enum_descriptors_google_2fprotobuf_2fduration_2eproto = nullptr; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2fduration_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fduration_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2fduration_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _internal_metadata_), @@ -131,7 +131,7 @@ inline void Duration::SharedCtor( (void)arena; (void)is_message_owned; new (&_impl_) Impl_{ - decltype(_impl_.seconds_){int64_t{0}} + decltype(_impl_.seconds_){::int64_t{0}} , decltype(_impl_.nanos_){0} , /*decltype(_impl_._cached_size_)*/{} }; @@ -156,11 +156,11 @@ void Duration::SetCachedSize(int size) const { void Duration::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Duration) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - ::memset(&_impl_.seconds_, 0, static_cast( + ::memset(&_impl_.seconds_, 0, static_cast<::size_t>( reinterpret_cast(&_impl_.nanos_) - reinterpret_cast(&_impl_.seconds_)) + sizeof(_impl_.nanos_)); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); @@ -170,24 +170,26 @@ const char* Duration::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // int64 seconds = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { _impl_.seconds_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // int32 nanos = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 16)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 16)) { _impl_.nanos_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -212,11 +214,11 @@ failure: #undef CHK_ } -uint8_t* Duration::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Duration::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Duration) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // int64 seconds = 1; @@ -239,12 +241,12 @@ uint8_t* Duration::_InternalSerialize( return target; } -size_t Duration::ByteSizeLong() const { +::size_t Duration::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Duration) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -274,7 +276,7 @@ void Duration::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTO // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_seconds() != 0) { diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index e347599a00..6efd4edad4 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -46,7 +46,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fduration_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fduration_2eproto; @@ -154,10 +154,10 @@ class PROTOBUF_EXPORT Duration final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -191,20 +191,20 @@ class PROTOBUF_EXPORT Duration final : }; // int64 seconds = 1; void clear_seconds(); - int64_t seconds() const; - void set_seconds(int64_t value); + ::int64_t seconds() const; + void set_seconds(::int64_t value); private: - int64_t _internal_seconds() const; - void _internal_set_seconds(int64_t value); + ::int64_t _internal_seconds() const; + void _internal_set_seconds(::int64_t value); public: // int32 nanos = 2; void clear_nanos(); - int32_t nanos() const; - void set_nanos(int32_t value); + ::int32_t nanos() const; + void set_nanos(::int32_t value); private: - int32_t _internal_nanos() const; - void _internal_set_nanos(int32_t value); + ::int32_t _internal_nanos() const; + void _internal_set_nanos(::int32_t value); public: // @@protoc_insertion_point(class_scope:google.protobuf.Duration) @@ -215,8 +215,8 @@ class PROTOBUF_EXPORT Duration final : typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { - int64_t seconds_; - int32_t nanos_; + ::int64_t seconds_; + ::int32_t nanos_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; }; union { Impl_ _impl_; }; @@ -240,20 +240,20 @@ class PROTOBUF_EXPORT Duration final : // int64 seconds = 1; inline void Duration::clear_seconds() { - _impl_.seconds_ = int64_t{0}; + _impl_.seconds_ = ::int64_t{0}; } -inline int64_t Duration::_internal_seconds() const { +inline ::int64_t Duration::_internal_seconds() const { return _impl_.seconds_; } -inline int64_t Duration::seconds() const { +inline ::int64_t Duration::seconds() const { // @@protoc_insertion_point(field_get:google.protobuf.Duration.seconds) return _internal_seconds(); } -inline void Duration::_internal_set_seconds(int64_t value) { +inline void Duration::_internal_set_seconds(::int64_t value) { _impl_.seconds_ = value; } -inline void Duration::set_seconds(int64_t value) { +inline void Duration::set_seconds(::int64_t value) { _internal_set_seconds(value); // @@protoc_insertion_point(field_set:google.protobuf.Duration.seconds) } @@ -262,18 +262,18 @@ inline void Duration::set_seconds(int64_t value) { inline void Duration::clear_nanos() { _impl_.nanos_ = 0; } -inline int32_t Duration::_internal_nanos() const { +inline ::int32_t Duration::_internal_nanos() const { return _impl_.nanos_; } -inline int32_t Duration::nanos() const { +inline ::int32_t Duration::nanos() const { // @@protoc_insertion_point(field_get:google.protobuf.Duration.nanos) return _internal_nanos(); } -inline void Duration::_internal_set_nanos(int32_t value) { +inline void Duration::_internal_set_nanos(::int32_t value) { _impl_.nanos_ = value; } -inline void Duration::set_nanos(int32_t value) { +inline void Duration::set_nanos(::int32_t value) { _internal_set_nanos(value); // @@protoc_insertion_point(field_set:google.protobuf.Duration.nanos) } diff --git a/src/google/protobuf/dynamic_message_unittest.cc b/src/google/protobuf/dynamic_message_unittest.cc index 6dd1184710..261161e2e3 100644 --- a/src/google/protobuf/dynamic_message_unittest.cc +++ b/src/google/protobuf/dynamic_message_unittest.cc @@ -47,12 +47,12 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_no_field_presence.pb.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/testing/googletest.h" #include #include "google/protobuf/test_util.h" +#include "google/protobuf/unittest_no_field_presence.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index c04ad78a68..9abd09f702 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -37,7 +37,7 @@ static constexpr const ::_pb::EnumDescriptor** file_level_enum_descriptors_google_2fprotobuf_2fempty_2eproto = nullptr; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2fempty_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fempty_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2fempty_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Empty, _internal_metadata_), diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 9f118e5db3..9c0db49fbc 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -47,7 +47,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fempty_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fempty_2eproto; diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index 791c1e3489..6cd1248ddd 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc @@ -38,12 +38,12 @@ #include #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/arena.h" #include "absl/container/flat_hash_set.h" #include "absl/hash/hash.h" #include "google/protobuf/extension_set_inl.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/message_lite.h" #include "google/protobuf/metadata_lite.h" #include "google/protobuf/parse_context.h" diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index 2ce566aec6..8be14c3381 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -49,8 +49,8 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/logging.h" #include "google/protobuf/port.h" -#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/port.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/parse_context.h" #include "google/protobuf/repeated_field.h" #include "google/protobuf/wire_format_lite.h" diff --git a/src/google/protobuf/extension_set_heavy.cc b/src/google/protobuf/extension_set_heavy.cc index 0ccce3c373..abf9e5fe76 100644 --- a/src/google/protobuf/extension_set_heavy.cc +++ b/src/google/protobuf/extension_set_heavy.cc @@ -35,13 +35,13 @@ // Contains methods defined in extension_set.h which cannot be part of the // lite library because they use descriptors or reflection. -#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" #include "absl/base/casts.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/extension_set.h" #include "google/protobuf/extension_set_inl.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/message.h" #include "google/protobuf/message_lite.h" #include "google/protobuf/parse_context.h" diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index b8b329dd4a..4bf4c7ebc9 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -45,7 +45,6 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format.h" #include "google/protobuf/testing/googletest.h" #include #include "absl/base/casts.h" @@ -53,6 +52,7 @@ #include "absl/strings/match.h" #include "google/protobuf/test_util.h" #include "google/protobuf/test_util2.h" +#include "google/protobuf/wire_format.h" // Must be included last. diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index de87758950..be8476c3fa 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -39,7 +39,7 @@ static constexpr const ::_pb::EnumDescriptor** file_level_enum_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto = nullptr; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldMask, _internal_metadata_), @@ -158,7 +158,7 @@ void FieldMask::SetCachedSize(int size) const { void FieldMask::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldMask) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -170,12 +170,12 @@ const char* FieldMask::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // repeated string paths = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { ptr -= 1; do { ptr += 1; @@ -185,8 +185,9 @@ const char* FieldMask::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.FieldMask.paths")); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -211,11 +212,11 @@ failure: #undef CHK_ } -uint8_t* FieldMask::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* FieldMask::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldMask) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // repeated string paths = 1; @@ -236,12 +237,12 @@ uint8_t* FieldMask::_InternalSerialize( return target; } -size_t FieldMask::ByteSizeLong() const { +::size_t FieldMask::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldMask) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -269,7 +270,7 @@ void FieldMask::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROT // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.paths_.MergeFrom(from._impl_.paths_); diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 94e3d77e15..5267c45f32 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -46,7 +46,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto; @@ -154,10 +154,10 @@ class PROTOBUF_EXPORT FieldMask final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -199,12 +199,12 @@ class PROTOBUF_EXPORT FieldMask final : void set_paths(int index, const std::string& value); void set_paths(int index, std::string&& value); void set_paths(int index, const char* value); - void set_paths(int index, const char* value, size_t size); + void set_paths(int index, const char* value, ::size_t size); std::string* add_paths(); void add_paths(const std::string& value); void add_paths(std::string&& value); void add_paths(const char* value); - void add_paths(const char* value, size_t size); + void add_paths(const char* value, ::size_t size); const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& paths() const; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_paths(); private: @@ -280,7 +280,7 @@ inline void FieldMask::set_paths(int index, const char* value) { GOOGLE_DCHECK(value != nullptr); _impl_.paths_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths) } -inline void FieldMask::set_paths(int index, const char* value, size_t size) { +inline void FieldMask::set_paths(int index, const char* value, ::size_t size) { _impl_.paths_.Mutable(index)->assign( reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldMask.paths) @@ -300,7 +300,7 @@ inline void FieldMask::add_paths(const char* value) { GOOGLE_DCHECK(value != nullptr); _impl_.paths_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths) } -inline void FieldMask::add_paths(const char* value, size_t size) { +inline void FieldMask::add_paths(const char* value, ::size_t size) { _impl_.paths_.Add()->assign(reinterpret_cast(value), size); // @@protoc_insertion_point(field_add_pointer:google.protobuf.FieldMask.paths) } diff --git a/src/google/protobuf/generated_message_bases.h b/src/google/protobuf/generated_message_bases.h index e8310799e4..d542ca414e 100644 --- a/src/google/protobuf/generated_message_bases.h +++ b/src/google/protobuf/generated_message_bases.h @@ -35,9 +35,9 @@ #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_BASES_H__ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_BASES_H__ -#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/arena.h" #include "google/protobuf/generated_message_util.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/message.h" #include "google/protobuf/parse_context.h" diff --git a/src/google/protobuf/generated_message_reflection_unittest.cc b/src/google/protobuf/generated_message_reflection_unittest.cc index f3e0e0eb2d..7236066426 100644 --- a/src/google/protobuf/generated_message_reflection_unittest.cc +++ b/src/google/protobuf/generated_message_reflection_unittest.cc @@ -48,7 +48,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/map_unittest.pb.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_mset.pb.h" @@ -59,6 +58,7 @@ #include #include "absl/strings/cord.h" #include "google/protobuf/map_test_util.h" +#include "google/protobuf/map_unittest.pb.h" #include "google/protobuf/test_util.h" // Must be included last. diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h index 86032ef2c8..910cc2615c 100644 --- a/src/google/protobuf/generated_message_tctable_impl.h +++ b/src/google/protobuf/generated_message_tctable_impl.h @@ -529,6 +529,18 @@ class PROTOBUF_EXPORT TcParser final { const TcParseTableBase* table, google::protobuf::internal::ParseContext* ctx); + // Test only access to verify that the right function is being called via + // MiniParse. + struct TestMiniParseResult { + TailCallParseFunc called_func; + uint32_t tag; + const TcParseTableBase::FieldEntry* found_entry; + const char* ptr; + }; + static TestMiniParseResult TestMiniParse(PROTOBUF_TC_PARAM_DECL); + template + static const char* MiniParseImpl(PROTOBUF_TC_PARAM_DECL); + template static inline const char* SingularParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL); template diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index cfa6c9371f..e146aefe42 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -254,15 +254,25 @@ absl::string_view TcParser::FieldName(const TcParseTableBase* table, field_index + 1); } -PROTOBUF_NOINLINE const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) { +template +inline PROTOBUF_ALWAYS_INLINE const char* TcParser::MiniParseImpl( + PROTOBUF_TC_PARAM_DECL) { + TestMiniParseResult* test_out; + if (export_called_function) { + test_out = reinterpret_cast( + static_cast(data.data)); + } + uint32_t tag; ptr = ReadTagInlined(ptr, &tag); if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) { + if (export_called_function) *test_out = {Error}; return Error(PROTOBUF_TC_PARAM_PASS); } auto* entry = FindFieldEntry(table, tag >> 3); if (entry == nullptr) { + if (export_called_function) *test_out = {table->fallback, tag}; data.data = tag; PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS); } @@ -324,9 +334,22 @@ PROTOBUF_NOINLINE const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) { "Invalid table order"); TailCallParseFunc parse_fn = kMiniParseTable[field_type]; + if (export_called_function) *test_out = {parse_fn, tag, entry}; + PROTOBUF_MUSTTAIL return parse_fn(PROTOBUF_TC_PARAM_PASS); } +PROTOBUF_NOINLINE const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return MiniParseImpl(PROTOBUF_TC_PARAM_PASS); +} +PROTOBUF_NOINLINE TcParser::TestMiniParseResult TcParser::TestMiniParse( + PROTOBUF_TC_PARAM_DECL) { + TestMiniParseResult result = {}; + data.data = reinterpret_cast(&result); + result.ptr = MiniParseImpl(PROTOBUF_TC_PARAM_PASS); + return result; +} + const char* TcParser::MpFallback(PROTOBUF_TC_PARAM_DECL) { PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS); } @@ -766,31 +789,99 @@ done10: return {p + 10, res1 & res2 & res3}; } +template inline PROTOBUF_ALWAYS_INLINE const char* ParseVarint(const char* p, - uint64_t* value) { + Type* value) { + static_assert(sizeof(Type) == 4 || sizeof(Type) == 8, + "Only [u]int32_t and [u]int64_t please"); int64_t byte = static_cast(*p); if (PROTOBUF_PREDICT_TRUE(byte >= 0)) { *value = byte; return p + 1; } else { auto tmp = Parse64FallbackPair(p, byte); - if (PROTOBUF_PREDICT_TRUE(tmp.first)) *value = tmp.second; + if (PROTOBUF_PREDICT_TRUE(tmp.first)) { + *value = static_cast(tmp.second); + } return tmp.first; } } +// This overload is specifically for handling bool, because bools have very +// different requirements and performance opportunities than ints. +inline PROTOBUF_ALWAYS_INLINE const char* ParseVarint(const char* p, + bool* value) { + unsigned char byte = static_cast(*p++); + if (PROTOBUF_PREDICT_TRUE(byte == 0 || byte == 1)) { + // This is the code path almost always taken, + // so we take care to make it very efficient. + if (sizeof(byte) == sizeof(*value)) { + memcpy(value, &byte, 1); + } else { + // The C++ standard does not specify that a `bool` takes only one byte + *value = byte; + } + return p; + } + // This part, we just care about code size. + // Although it's almost never used, we have to support it because we guarantee + // compatibility for users who change a field from an int32 or int64 to a bool + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + byte = (byte - 0x80) | *p++; + if (PROTOBUF_PREDICT_FALSE(byte & 0x80)) { + return nullptr; + } + } + } + } + } + } + } + } + } + } + *value = byte; + return p; +} + template -inline FieldType ZigZagDecodeHelper(uint64_t value) { +inline FieldType ZigZagDecodeHelper(FieldType value) { return static_cast(value); } template <> -inline int32_t ZigZagDecodeHelper(uint64_t value) { +inline uint32_t ZigZagDecodeHelper(uint32_t value) { return WireFormatLite::ZigZagDecode32(value); } template <> -inline int64_t ZigZagDecodeHelper(uint64_t value) { +inline int32_t ZigZagDecodeHelper(int32_t value) { + return WireFormatLite::ZigZagDecode32(value); +} + +template <> +inline uint64_t ZigZagDecodeHelper(uint64_t value) { + return WireFormatLite::ZigZagDecode64(value); +} + +template <> +inline int64_t ZigZagDecodeHelper(int64_t value) { return WireFormatLite::ZigZagDecode64(value); } @@ -845,11 +936,11 @@ PROTOBUF_NOINLINE const char* TcParser::SingularVarBigint( #if defined(__GNUC__) // This empty asm block convinces the compiler that the contents of spill may // have changed, and thus can't be cached in registers. It's similar to, but - // more optimal then, the effect of declaring it "volatile". + // more optimal than, the effect of declaring it "volatile". asm("" : "+m"(spill)); #endif - uint64_t tmp; + FieldType tmp; PROTOBUF_ASSUME(static_cast(*ptr) < 0); ptr = ParseVarint(ptr, &tmp); @@ -923,7 +1014,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedVarint( const auto expected_tag = UnalignedLoad(ptr); do { ptr += sizeof(TagType); - uint64_t tmp; + FieldType tmp; ptr = ParseVarint(ptr, &tmp); if (ptr == nullptr) { return Error(PROTOBUF_TC_PARAM_PASS); @@ -1930,6 +2021,7 @@ PROTOBUF_NOINLINE const char* TcParser::MpRepeatedVarint( field.Add(is_zigzag ? WireFormatLite::ZigZagDecode64(tmp) : tmp); if (!ctx->DataAvailable(ptr)) break; ptr2 = ReadTag(ptr, &next_tag); + if (ptr2 == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); } while (next_tag == decoded_tag); } else if (rep == field_layout::kRep32Bits) { auto& field = RefAt>(msg, entry.offset); @@ -1950,6 +2042,7 @@ PROTOBUF_NOINLINE const char* TcParser::MpRepeatedVarint( field.Add(tmp); if (!ctx->DataAvailable(ptr)) break; ptr2 = ReadTag(ptr, &next_tag); + if (ptr2 == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); } while (next_tag == decoded_tag); } else { GOOGLE_DCHECK_EQ(rep, static_cast(field_layout::kRep8Bits)); @@ -1963,6 +2056,7 @@ PROTOBUF_NOINLINE const char* TcParser::MpRepeatedVarint( field.Add(static_cast(tmp)); if (!ctx->DataAvailable(ptr)) break; ptr2 = ReadTag(ptr, &next_tag); + if (ptr2 == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); } while (next_tag == decoded_tag); } diff --git a/src/google/protobuf/generated_message_tctable_lite_test.cc b/src/google/protobuf/generated_message_tctable_lite_test.cc index 79b0d461af..56b0cea5cd 100644 --- a/src/google/protobuf/generated_message_tctable_lite_test.cc +++ b/src/google/protobuf/generated_message_tctable_lite_test.cc @@ -31,9 +31,9 @@ #include #include "google/protobuf/generated_message_tctable_impl.h" -#include "google/protobuf/wire_format_lite.h" #include #include +#include "google/protobuf/wire_format_lite.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index f9c75c64d0..4dd5ccbdb0 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -38,10 +38,10 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/arenastring.h" #include "google/protobuf/extension_set.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/message_lite.h" #include "google/protobuf/metadata_lite.h" #include "google/protobuf/repeated_field.h" diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index 1915e8cbad..979c89750c 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -33,8 +33,8 @@ #include -#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/message_lite.h" #include "google/protobuf/repeated_field.h" diff --git a/src/google/protobuf/inlined_string_field_unittest.cc b/src/google/protobuf/inlined_string_field_unittest.cc index 53552df1ca..bba2289d3d 100644 --- a/src/google/protobuf/inlined_string_field_unittest.cc +++ b/src/google/protobuf/inlined_string_field_unittest.cc @@ -40,11 +40,11 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/arenastring.h" #include #include "absl/strings/string_view.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/message.h" diff --git a/src/google/protobuf/json/internal/parser_traits.h b/src/google/protobuf/json/internal/parser_traits.h index 957354cbe4..cfe74a26cf 100644 --- a/src/google/protobuf/json/internal/parser_traits.h +++ b/src/google/protobuf/json/internal/parser_traits.h @@ -42,7 +42,6 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/message.h" -#include "google/protobuf/wire_format_lite.h" #include "absl/base/attributes.h" #include "absl/base/casts.h" #include "absl/container/flat_hash_map.h" @@ -54,6 +53,7 @@ #include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/json/internal/descriptor_traits.h" +#include "google/protobuf/wire_format_lite.h" #include "google/protobuf/stubs/status_macros.h" // Must be included last. diff --git a/src/google/protobuf/json/internal/unparser_traits.h b/src/google/protobuf/json/internal/unparser_traits.h index 9e1f3efc9b..cab762ba33 100644 --- a/src/google/protobuf/json/internal/unparser_traits.h +++ b/src/google/protobuf/json/internal/unparser_traits.h @@ -45,8 +45,6 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/message.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" #include "absl/container/flat_hash_map.h" #include "absl/status/status.h" #include "absl/strings/escaping.h" @@ -57,6 +55,8 @@ #include "absl/types/variant.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/json/internal/descriptor_traits.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" #include "google/protobuf/stubs/status_macros.h" // Must be included last. diff --git a/src/google/protobuf/json/internal/untyped_message.cc b/src/google/protobuf/json/internal/untyped_message.cc index 7341fb378a..a7d949d6db 100644 --- a/src/google/protobuf/json/internal/untyped_message.cc +++ b/src/google/protobuf/json/internal/untyped_message.cc @@ -44,8 +44,6 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/message.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" #include "absl/container/flat_hash_map.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" @@ -56,6 +54,8 @@ #include "absl/types/variant.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/util/type_resolver.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" #include "utf8_validity.h" #include "google/protobuf/stubs/status_macros.h" diff --git a/src/google/protobuf/json/internal/untyped_message.h b/src/google/protobuf/json/internal/untyped_message.h index ba549c1a2c..6b2822edc2 100644 --- a/src/google/protobuf/json/internal/untyped_message.h +++ b/src/google/protobuf/json/internal/untyped_message.h @@ -42,8 +42,6 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/message.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" #include "absl/container/flat_hash_map.h" #include "absl/status/status.h" #include "absl/strings/str_format.h" @@ -53,6 +51,8 @@ #include "absl/types/variant.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/util/type_resolver.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" #include "google/protobuf/stubs/status_macros.h" // Must be included last. diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc index 1a031717a2..d89a17d7f0 100644 --- a/src/google/protobuf/lite_unittest.cc +++ b/src/google/protobuf/lite_unittest.cc @@ -36,8 +36,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/map_lite_unittest.pb.h" -#include "google/protobuf/unittest_lite.pb.h" #include #include "absl/strings/match.h" #include "absl/strings/string_view.h" @@ -47,8 +45,10 @@ #include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/map_lite_test_util.h" +#include "google/protobuf/map_lite_unittest.pb.h" #include "google/protobuf/parse_context.h" #include "google/protobuf/test_util_lite.h" +#include "google/protobuf/unittest_lite.pb.h" #include "google/protobuf/wire_format_lite.h" namespace google { diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index be11257260..411be6e4c1 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -37,11 +37,11 @@ #include #include -#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" #include "absl/base/casts.h" #include "google/protobuf/arenastring.h" #include "google/protobuf/generated_message_util.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/map.h" #include "google/protobuf/map_type_handler.h" #include "google/protobuf/parse_context.h" diff --git a/src/google/protobuf/map_field_lite.h b/src/google/protobuf/map_field_lite.h index d8e539c0d3..0576d0d0cd 100644 --- a/src/google/protobuf/map_field_lite.h +++ b/src/google/protobuf/map_field_lite.h @@ -33,8 +33,8 @@ #include -#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/port.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/map.h" #include "google/protobuf/map_entry_lite.h" #include "google/protobuf/parse_context.h" diff --git a/src/google/protobuf/map_field_test.cc b/src/google/protobuf/map_field_test.cc index 9e834d5d58..fce6ccf2c9 100644 --- a/src/google/protobuf/map_field_test.cc +++ b/src/google/protobuf/map_field_test.cc @@ -33,7 +33,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/map_unittest.pb.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/arena.h" #include "google/protobuf/map.h" @@ -45,6 +44,7 @@ #include "absl/strings/str_format.h" #include "google/protobuf/arena_test_util.h" #include "google/protobuf/map_test_util.h" +#include "google/protobuf/map_unittest.pb.h" // Must be included last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index 9346936e63..0e5c6861ea 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -28,11 +28,12 @@ // (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 "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest_import.pb.h" +#include "absl/container/flat_hash_set.h" #include "google/protobuf/map_proto2_unittest.pb.h" #include "google/protobuf/map_unittest.pb.h" #include "google/protobuf/reflection_tester.h" -#include "absl/container/flat_hash_set.h" -#include "google/protobuf/test_util2.h" #define BRIDGE_UNITTEST ::google::protobuf::bridge_unittest diff --git a/src/google/protobuf/map_test_util.h b/src/google/protobuf/map_test_util.h index 130e494bef..d5e6acb63b 100644 --- a/src/google/protobuf/map_test_util.h +++ b/src/google/protobuf/map_test_util.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_MAP_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_MAP_TEST_UTIL_H__ +#include "google/protobuf/unittest.pb.h" #include "google/protobuf/map_unittest.pb.h" #include "google/protobuf/reflection_tester.h" diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index c092792346..8979734b0b 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -31,9 +31,9 @@ #ifndef GOOGLE_PROTOBUF_MAP_TYPE_HANDLER_H__ #define GOOGLE_PROTOBUF_MAP_TYPE_HANDLER_H__ -#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" #include "google/protobuf/arenastring.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/parse_context.h" #include "google/protobuf/wire_format_lite.h" diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 1b464365be..492e0f02fc 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -39,8 +39,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" #include "absl/base/casts.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" @@ -52,6 +50,8 @@ #include "google/protobuf/generated_message_reflection.h" #include "google/protobuf/generated_message_tctable_impl.h" #include "google/protobuf/generated_message_util.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/map_field.h" #include "google/protobuf/map_field_inl.h" #include "google/protobuf/parse_context.h" diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 335527e4e0..f08b3466c1 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -809,6 +809,7 @@ class PROTOBUF_EXPORT Reflection final { std::string value) const; void AddEnum(Message* message, const FieldDescriptor* field, const EnumValueDescriptor* value) const; + // Add an integer value to a repeated enum field rather than // EnumValueDescriptor. For proto3 this is just setting the enum field to the // value specified, for proto2 it's more complicated. If value is a known enum @@ -990,6 +991,7 @@ class PROTOBUF_EXPORT Reflection final { template RepeatedPtrField* MutableRepeatedPtrFieldInternal( Message* message, const FieldDescriptor* field) const; + // Obtain a pointer to a Repeated Field Structure and do some type checking: // on field->cpp_type(), // on field->field_option().ctype() (if ctype >= 0) diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index eea99e0e2c..161758df57 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -42,10 +42,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/arena.h" #include "absl/base/dynamic_annotations.h" #include "absl/strings/cord.h" @@ -54,6 +50,10 @@ #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "google/protobuf/generated_message_util.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/parse_context.h" #include "google/protobuf/repeated_field.h" diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 92e5b73845..38e903eb06 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -45,12 +45,12 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/logging.h" -#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" #include "google/protobuf/port.h" #include "absl/base/call_once.h" #include "absl/strings/string_view.h" #include "google/protobuf/explicitly_constructed.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/metadata_lite.h" #include "google/protobuf/port.h" diff --git a/src/google/protobuf/no_field_presence_test.cc b/src/google/protobuf/no_field_presence_test.cc index d28fb14f18..22d6ed5656 100644 --- a/src/google/protobuf/no_field_presence_test.cc +++ b/src/google/protobuf/no_field_presence_test.cc @@ -31,10 +31,10 @@ #include #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_no_field_presence.pb.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.h" #include +#include "google/protobuf/unittest_no_field_presence.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/parse_context.cc b/src/google/protobuf/parse_context.cc index af062e0546..9e591ad91d 100644 --- a/src/google/protobuf/parse_context.cc +++ b/src/google/protobuf/parse_context.cc @@ -265,12 +265,12 @@ const char* EpsCopyInputStream::InitFrom(io::ZeroCopyInputStream* zcis) { const char* ParseContext::ReadSizeAndPushLimitAndDepth(const char* ptr, int* old_limit) { int size = ReadSize(&ptr); - if (PROTOBUF_PREDICT_FALSE(!ptr)) { + if (PROTOBUF_PREDICT_FALSE(!ptr) || depth_ <= 0) { *old_limit = 0; // Make sure this isn't uninitialized even on error return return nullptr; } *old_limit = PushLimit(ptr, size); - if (--depth_ < 0) return nullptr; + --depth_; return ptr; } @@ -278,7 +278,9 @@ const char* ParseContext::ParseMessage(MessageLite* msg, const char* ptr) { int old; ptr = ReadSizeAndPushLimitAndDepth(ptr, &old); if (ptr == nullptr) return ptr; + auto old_depth = depth_; ptr = msg->_InternalParse(ptr, this); + if (ptr != nullptr) GOOGLE_DCHECK_EQ(old_depth, depth_); depth_++; if (!PopLimit(old)) return nullptr; return ptr; @@ -636,7 +638,7 @@ PROTOBUF_ALWAYS_INLINE inline V1Type ValueBarrier(V1Type value1) { PROTOBUF_ALWAYS_INLINE inline uint64_t ExtractAndMergeTwoChunks( uint64_t data, uint64_t first_byte) { - GOOGLE_DCHECK(first_byte <= 6); + GOOGLE_DCHECK_LE(first_byte, 6); uint64_t first = Ubfx7(data, first_byte * 8); uint64_t second = Ubfx7(data, (first_byte + 1) * 8); return ForceToRegister(first | (second << 7)); diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 627a0689de..e1ff16c9b5 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -36,8 +36,6 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/arena.h" #include "absl/strings/internal/resize_uninitialized.h" #include "absl/strings/string_view.h" @@ -45,6 +43,8 @@ #include "google/protobuf/endian.h" #include "google/protobuf/implicit_weak_message.h" #include "google/protobuf/inlined_string_field.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/metadata_lite.h" #include "google/protobuf/port.h" #include "google/protobuf/repeated_field.h" @@ -445,7 +445,9 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { MessageLite* msg, const char* ptr, const Table* table) { int old; ptr = ReadSizeAndPushLimitAndDepthInlined(ptr, &old); + auto old_depth = depth_; ptr = ptr ? TcParser::ParseLoop(msg, ptr, this, table) : nullptr; + if (ptr != nullptr) GOOGLE_DCHECK_EQ(old_depth, depth_); depth_++; if (!PopLimit(old)) return nullptr; return ptr; @@ -456,7 +458,13 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { T* msg, const char* ptr, uint32_t tag) { if (--depth_ < 0) return nullptr; group_depth_++; + auto old_depth = depth_; + auto old_group_depth = group_depth_; ptr = msg->_InternalParse(ptr, this); + if (ptr != nullptr) { + GOOGLE_DCHECK_EQ(old_depth, depth_); + GOOGLE_DCHECK_EQ(old_group_depth, group_depth_); + } group_depth_--; depth_++; if (PROTOBUF_PREDICT_FALSE(!ConsumeEndGroup(tag))) return nullptr; @@ -468,7 +476,13 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { MessageLite* msg, const char* ptr, uint32_t tag, const Table* table) { if (--depth_ < 0) return nullptr; group_depth_++; + auto old_depth = depth_; + auto old_group_depth = group_depth_; ptr = TcParser::ParseLoop(msg, ptr, this, table); + if (ptr != nullptr) { + GOOGLE_DCHECK_EQ(old_depth, depth_); + GOOGLE_DCHECK_EQ(old_group_depth, group_depth_); + } group_depth_--; depth_++; if (PROTOBUF_PREDICT_FALSE(!ConsumeEndGroup(tag))) return nullptr; @@ -835,7 +849,9 @@ PROTOBUF_NODISCARD const char* ParseContext::ParseMessage(T* msg, int old; ptr = ReadSizeAndPushLimitAndDepth(ptr, &old); if (ptr == nullptr) return ptr; + auto old_depth = depth_; ptr = msg->_InternalParse(ptr, this); + if (ptr != nullptr) GOOGLE_DCHECK_EQ(old_depth, depth_); depth_++; if (!PopLimit(old)) return nullptr; return ptr; diff --git a/src/google/protobuf/preserve_unknown_enum_test.cc b/src/google/protobuf/preserve_unknown_enum_test.cc index 64d8247252..22c2d46850 100644 --- a/src/google/protobuf/preserve_unknown_enum_test.cc +++ b/src/google/protobuf/preserve_unknown_enum_test.cc @@ -29,11 +29,11 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_preserve_unknown_enum.pb.h" -#include "google/protobuf/unittest_preserve_unknown_enum2.pb.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" #include +#include "google/protobuf/unittest_preserve_unknown_enum.pb.h" +#include "google/protobuf/unittest_preserve_unknown_enum2.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/proto3_arena_lite_unittest.cc b/src/google/protobuf/proto3_arena_lite_unittest.cc index 7c37f3f8ac..acff0accb0 100644 --- a/src/google/protobuf/proto3_arena_lite_unittest.cc +++ b/src/google/protobuf/proto3_arena_lite_unittest.cc @@ -32,9 +32,9 @@ #include #include -#include "google/protobuf/unittest_proto3_arena.pb.h" #include "google/protobuf/arena.h" #include +#include "google/protobuf/unittest_proto3_arena.pb.h" using proto3_arena_unittest::TestAllTypes; diff --git a/src/google/protobuf/proto3_arena_unittest.cc b/src/google/protobuf/proto3_arena_unittest.cc index 0f55865406..11cd523b6b 100644 --- a/src/google/protobuf/proto3_arena_unittest.cc +++ b/src/google/protobuf/proto3_arena_unittest.cc @@ -33,13 +33,13 @@ #include #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_proto3_arena.pb.h" -#include "google/protobuf/unittest_proto3_optional.pb.h" #include "google/protobuf/arena.h" #include "google/protobuf/text_format.h" #include #include "absl/strings/match.h" #include "google/protobuf/test_util.h" +#include "google/protobuf/unittest_proto3_arena.pb.h" +#include "google/protobuf/unittest_proto3_optional.pb.h" // Must be included last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index 3136d4f8d0..cbc33d0458 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -1699,7 +1699,8 @@ TEST(RepeatedPtrField, ExtractSubrange) { // Create an array with "sz" elements and "extra" cleared elements. // Use an arena to avoid copies from debug-build stability checks. Arena arena; - RepeatedPtrField field(&arena); + auto& field = + *Arena::CreateMessage>(&arena); for (int i = 0; i < sz + extra; ++i) { subject.push_back(new std::string()); field.AddAllocated(subject[i]); diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 706a005761..699b6c764d 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -995,10 +995,6 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { // Gets the underlying array. This pointer is possibly invalidated by // any add or remove operation. - // - // This API is deprecated. Instead of directly working with element array, - // use APIs in repeated_field_util.h; e.g. sorting, etc. - PROTOBUF_DEPRECATED_MSG("Use APIs in repeated_field_util.h") Element** mutable_data(); const Element* const* data() const; diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index ce0f339939..a4cec865e8 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -39,7 +39,7 @@ static constexpr const ::_pb::EnumDescriptor** file_level_enum_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto = nullptr; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceContext, _internal_metadata_), @@ -170,7 +170,7 @@ void SourceContext::SetCachedSize(int size) const { void SourceContext::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.SourceContext) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -182,18 +182,19 @@ const char* SourceContext::_InternalParse(const char* ptr, ::_pbi::ParseContext* #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string file_name = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_file_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.SourceContext.file_name")); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -218,11 +219,11 @@ failure: #undef CHK_ } -uint8_t* SourceContext::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* SourceContext::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceContext) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string file_name = 1; @@ -243,12 +244,12 @@ uint8_t* SourceContext::_InternalSerialize( return target; } -size_t SourceContext::ByteSizeLong() const { +::size_t SourceContext::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceContext) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -275,7 +276,7 @@ void SourceContext::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const :: // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_file_name().empty()) { diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 6794cc54a2..3bf2774962 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -46,7 +46,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto; @@ -154,10 +154,10 @@ class PROTOBUF_EXPORT SourceContext final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index eb92db0870..576f6c3971 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -79,7 +79,7 @@ static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fstruct_2eproto[4] static const ::_pb::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2fstruct_2eproto[1]; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2fstruct_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fstruct_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2fstruct_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, _has_bits_), PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, _internal_metadata_), @@ -285,7 +285,7 @@ void Struct::SetCachedSize(int size) const { void Struct::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Struct) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -297,12 +297,12 @@ const char* Struct::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // map fields = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { ptr -= 1; do { ptr += 1; @@ -310,8 +310,9 @@ const char* Struct::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -336,11 +337,11 @@ failure: #undef CHK_ } -uint8_t* Struct::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Struct::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Struct) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // map fields = 1; @@ -377,12 +378,12 @@ uint8_t* Struct::_InternalSerialize( return target; } -size_t Struct::ByteSizeLong() const { +::size_t Struct::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Struct) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -411,7 +412,7 @@ void Struct::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBU // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Struct) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.fields_.MergeFrom(from._impl_.fields_); @@ -445,7 +446,7 @@ void Struct::InternalSwap(Struct* other) { class Value::_Internal { public: - static constexpr int32_t kOneofCaseOffset = + static constexpr ::int32_t kOneofCaseOffset = PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _impl_._oneof_case_); static const ::PROTOBUF_NAMESPACE_ID::Struct& struct_value(const Value* msg); static const ::PROTOBUF_NAMESPACE_ID::ListValue& list_value(const Value* msg); @@ -612,7 +613,7 @@ void Value::clear_kind() { void Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -624,59 +625,65 @@ const char* Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // .google.protobuf.NullValue null_value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { + ::uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); _internal_set_null_value(static_cast<::PROTOBUF_NAMESPACE_ID::NullValue>(val)); - } else + } else { goto handle_unusual; + } continue; // double number_value = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 17)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 17)) { _internal_set_number_value(::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr)); ptr += sizeof(double); - } else + } else { goto handle_unusual; + } continue; // string string_value = 3; case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 26)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { auto str = _internal_mutable_string_value(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Value.string_value")); - } else + } else { goto handle_unusual; + } continue; // bool bool_value = 4; case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 32)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 32)) { _internal_set_bool_value(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr)); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.Struct struct_value = 5; case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 42)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 42)) { ptr = ctx->ParseMessage(_internal_mutable_struct_value(), ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.ListValue list_value = 6; case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 50)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 50)) { ptr = ctx->ParseMessage(_internal_mutable_list_value(), ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -701,11 +708,11 @@ failure: #undef CHK_ } -uint8_t* Value::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Value::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // .google.protobuf.NullValue null_value = 1; @@ -759,12 +766,12 @@ uint8_t* Value::_InternalSerialize( return target; } -size_t Value::ByteSizeLong() const { +::size_t Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Value) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -826,7 +833,7 @@ void Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Value) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; switch (from.kind_case()) { @@ -940,7 +947,7 @@ void ListValue::SetCachedSize(int size) const { void ListValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ListValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -952,12 +959,12 @@ const char* ListValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // repeated .google.protobuf.Value values = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { ptr -= 1; do { ptr += 1; @@ -965,8 +972,9 @@ const char* ListValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -991,11 +999,11 @@ failure: #undef CHK_ } -uint8_t* ListValue::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* ListValue::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ListValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // repeated .google.protobuf.Value values = 1; @@ -1014,12 +1022,12 @@ uint8_t* ListValue::_InternalSerialize( return target; } -size_t ListValue::ByteSizeLong() const { +::size_t ListValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ListValue) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1046,7 +1054,7 @@ void ListValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROT // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ListValue) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.values_.MergeFrom(from._impl_.values_); diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 8eead0ab2c..973221c9ab 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -50,7 +50,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fstruct_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fstruct_2eproto; @@ -81,9 +81,9 @@ PROTOBUF_NAMESPACE_OPEN enum NullValue : int { NULL_VALUE = 0, NullValue_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), + std::numeric_limits<::int32_t>::min(), NullValue_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), + std::numeric_limits<::int32_t>::max(), }; PROTOBUF_EXPORT bool NullValue_IsValid(int value); @@ -115,7 +115,7 @@ inline bool NullValue_Parse(absl::string_view name, NullValue* value) { // ------------------------------------------------------------------- -class Struct_FieldsEntry_DoNotUse : public ::PROTOBUF_NAMESPACE_ID::internal::MapEntry { @@ -229,10 +229,10 @@ class PROTOBUF_EXPORT Struct final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -401,10 +401,10 @@ class PROTOBUF_EXPORT Value final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -563,7 +563,7 @@ class PROTOBUF_EXPORT Value final : ::PROTOBUF_NAMESPACE_ID::ListValue* list_value_; } kind_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - uint32_t _oneof_case_[1]; + ::uint32_t _oneof_case_[1]; }; union { Impl_ _impl_; }; @@ -659,10 +659,10 @@ class PROTOBUF_EXPORT ListValue final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index b80ee89330..7ab3d488e7 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -46,10 +46,6 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/tokenizer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/numbers.h" @@ -60,7 +56,11 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/dynamic_message.h" +#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/strtod.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/map_field.h" #include "google/protobuf/message.h" #include "google/protobuf/repeated_field.h" @@ -273,7 +273,7 @@ const Descriptor* DefaultFinderFindAnyType(const Message& message, // =========================================================================== // Internal class for parsing an ASCII representation of a Protocol Message. // This class makes use of the Protocol Message compiler's tokenizer found -// in //net/proto2/io/public/tokenizer.h. Note that class's Parse +// in //third_party/protobuf/io/tokenizer.h. Note that class's Parse // method is *not* thread-safe and should only be used in a single thread at // a time. @@ -1383,7 +1383,7 @@ class TextFormat::Parser::ParserImpl { // =========================================================================== // Internal class for writing text to the io::ZeroCopyOutputStream. Adapted -// from the Printer found in //net/proto2/io/public/printer.h +// from the Printer found in //third_party/protobuf/io/printer.h class TextFormat::Printer::TextGenerator : public TextFormat::BaseTextGenerator { public: @@ -1770,13 +1770,7 @@ class StringBaseTextGenerator : public TextFormat::BaseTextGenerator { output_.append(text, size); } -// Some compilers do not support ref-qualifiers even in C++11 mode. -// Disable the optimization for now and revisit it later. -#if 0 // LANG_CXX11 std::string Consume() && { return std::move(output_); } -#else // !LANG_CXX11 - const std::string& Get() { return output_; } -#endif // LANG_CXX11 private: std::string output_; @@ -1790,17 +1784,10 @@ class StringBaseTextGenerator : public TextFormat::BaseTextGenerator { TextFormat::FieldValuePrinter::FieldValuePrinter() {} TextFormat::FieldValuePrinter::~FieldValuePrinter() {} -#if 0 // LANG_CXX11 #define FORWARD_IMPL(fn, ...) \ StringBaseTextGenerator generator; \ delegate_.fn(__VA_ARGS__, &generator); \ return std::move(generator).Consume() -#else // !LANG_CXX11 -#define FORWARD_IMPL(fn, ...) \ - StringBaseTextGenerator generator; \ - delegate_.fn(__VA_ARGS__, &generator); \ - return generator.Get() -#endif // LANG_CXX11 std::string TextFormat::FieldValuePrinter::PrintBool(bool val) const { FORWARD_IMPL(PrintBool, val); @@ -2584,6 +2571,15 @@ void TextFormat::Printer::PrintFieldValue(const Message& message, << "Index must be -1 for non-repeated fields"; const FastFieldValuePrinter* printer = GetFieldPrinter(field); +#ifndef PROTO2_OPENSOURCE +#ifdef SUPPORT_EXPLICIT_DEBUG_STRING + if (redact_debug_string_ && internal::ShouldRedactField(field)) { + std::string redacted_value = "go/redact-debug-string"; + generator->PrintString(redacted_value); + return; + } +#endif +#endif switch (field->cpp_type()) { #define OUTPUT_FIELD(CPPTYPE, METHOD) \ diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index 4deeec8f1f..bbf6943674 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -47,13 +47,9 @@ #include "google/protobuf/testing/file.h" #include "google/protobuf/testing/file.h" #include "google/protobuf/any.pb.h" -#include "google/protobuf/map_unittest.pb.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_mset.pb.h" #include "google/protobuf/unittest_mset_wire_format.pb.h" -#include "google/protobuf/unittest_proto3.pb.h" -#include "google/protobuf/io/tokenizer.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" #include #include "google/protobuf/testing/googletest.h" #include @@ -63,8 +59,12 @@ #include "absl/strings/str_format.h" #include "absl/strings/str_replace.h" #include "absl/strings/substitute.h" +#include "google/protobuf/io/tokenizer.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/map_unittest.pb.h" #include "google/protobuf/test_util.h" #include "google/protobuf/test_util2.h" +#include "google/protobuf/unittest_proto3.pb.h" // Must be included last. diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index a26f164d3c..a64dbc0438 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -21,7 +21,7 @@ namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Timestamp::Timestamp( ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.seconds_)*/int64_t{0} + /*decltype(_impl_.seconds_)*/::int64_t{0} , /*decltype(_impl_.nanos_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct TimestampDefaultTypeInternal { @@ -40,7 +40,7 @@ static constexpr const ::_pb::EnumDescriptor** file_level_enum_descriptors_google_2fprotobuf_2ftimestamp_2eproto = nullptr; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2ftimestamp_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2ftimestamp_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2ftimestamp_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Timestamp, _internal_metadata_), @@ -131,7 +131,7 @@ inline void Timestamp::SharedCtor( (void)arena; (void)is_message_owned; new (&_impl_) Impl_{ - decltype(_impl_.seconds_){int64_t{0}} + decltype(_impl_.seconds_){::int64_t{0}} , decltype(_impl_.nanos_){0} , /*decltype(_impl_._cached_size_)*/{} }; @@ -156,11 +156,11 @@ void Timestamp::SetCachedSize(int size) const { void Timestamp::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Timestamp) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - ::memset(&_impl_.seconds_, 0, static_cast( + ::memset(&_impl_.seconds_, 0, static_cast<::size_t>( reinterpret_cast(&_impl_.nanos_) - reinterpret_cast(&_impl_.seconds_)) + sizeof(_impl_.nanos_)); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); @@ -170,24 +170,26 @@ const char* Timestamp::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // int64 seconds = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { _impl_.seconds_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // int32 nanos = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 16)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 16)) { _impl_.nanos_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -212,11 +214,11 @@ failure: #undef CHK_ } -uint8_t* Timestamp::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Timestamp::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Timestamp) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // int64 seconds = 1; @@ -239,12 +241,12 @@ uint8_t* Timestamp::_InternalSerialize( return target; } -size_t Timestamp::ByteSizeLong() const { +::size_t Timestamp::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Timestamp) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -274,7 +276,7 @@ void Timestamp::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROT // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Timestamp) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_seconds() != 0) { diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 9b19abbeff..a2f5e03071 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -46,7 +46,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2ftimestamp_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2ftimestamp_2eproto; @@ -154,10 +154,10 @@ class PROTOBUF_EXPORT Timestamp final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -191,20 +191,20 @@ class PROTOBUF_EXPORT Timestamp final : }; // int64 seconds = 1; void clear_seconds(); - int64_t seconds() const; - void set_seconds(int64_t value); + ::int64_t seconds() const; + void set_seconds(::int64_t value); private: - int64_t _internal_seconds() const; - void _internal_set_seconds(int64_t value); + ::int64_t _internal_seconds() const; + void _internal_set_seconds(::int64_t value); public: // int32 nanos = 2; void clear_nanos(); - int32_t nanos() const; - void set_nanos(int32_t value); + ::int32_t nanos() const; + void set_nanos(::int32_t value); private: - int32_t _internal_nanos() const; - void _internal_set_nanos(int32_t value); + ::int32_t _internal_nanos() const; + void _internal_set_nanos(::int32_t value); public: // @@protoc_insertion_point(class_scope:google.protobuf.Timestamp) @@ -215,8 +215,8 @@ class PROTOBUF_EXPORT Timestamp final : typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { - int64_t seconds_; - int32_t nanos_; + ::int64_t seconds_; + ::int32_t nanos_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; }; union { Impl_ _impl_; }; @@ -240,20 +240,20 @@ class PROTOBUF_EXPORT Timestamp final : // int64 seconds = 1; inline void Timestamp::clear_seconds() { - _impl_.seconds_ = int64_t{0}; + _impl_.seconds_ = ::int64_t{0}; } -inline int64_t Timestamp::_internal_seconds() const { +inline ::int64_t Timestamp::_internal_seconds() const { return _impl_.seconds_; } -inline int64_t Timestamp::seconds() const { +inline ::int64_t Timestamp::seconds() const { // @@protoc_insertion_point(field_get:google.protobuf.Timestamp.seconds) return _internal_seconds(); } -inline void Timestamp::_internal_set_seconds(int64_t value) { +inline void Timestamp::_internal_set_seconds(::int64_t value) { _impl_.seconds_ = value; } -inline void Timestamp::set_seconds(int64_t value) { +inline void Timestamp::set_seconds(::int64_t value) { _internal_set_seconds(value); // @@protoc_insertion_point(field_set:google.protobuf.Timestamp.seconds) } @@ -262,18 +262,18 @@ inline void Timestamp::set_seconds(int64_t value) { inline void Timestamp::clear_nanos() { _impl_.nanos_ = 0; } -inline int32_t Timestamp::_internal_nanos() const { +inline ::int32_t Timestamp::_internal_nanos() const { return _impl_.nanos_; } -inline int32_t Timestamp::nanos() const { +inline ::int32_t Timestamp::nanos() const { // @@protoc_insertion_point(field_get:google.protobuf.Timestamp.nanos) return _internal_nanos(); } -inline void Timestamp::_internal_set_nanos(int32_t value) { +inline void Timestamp::_internal_set_nanos(::int32_t value) { _impl_.nanos_ = value; } -inline void Timestamp::set_nanos(int32_t value) { +inline void Timestamp::set_nanos(::int32_t value) { _internal_set_nanos(value); // @@protoc_insertion_point(field_set:google.protobuf.Timestamp.nanos) } diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 096d52ef42..d1faed97bb 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -115,7 +115,7 @@ static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2ftype_2eproto[5]; static const ::_pb::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto[3]; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2ftype_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2ftype_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2ftype_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _internal_metadata_), @@ -478,7 +478,7 @@ void Type::SetCachedSize(int size) const { void Type::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Type) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -498,22 +498,23 @@ const char* Type::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string name = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Type.name")); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Field fields = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 18)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { ptr -= 1; do { ptr += 1; @@ -521,12 +522,13 @@ const char* Type::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); - } else + } else { goto handle_unusual; + } continue; // repeated string oneofs = 3; case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 26)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { ptr -= 1; do { ptr += 1; @@ -536,12 +538,13 @@ const char* Type::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Type.oneofs")); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Option options = 4; case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 34)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 34)) { ptr -= 1; do { ptr += 1; @@ -549,25 +552,28 @@ const char* Type::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<34>(ptr)); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.SourceContext source_context = 5; case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 42)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 42)) { ptr = ctx->ParseMessage(_internal_mutable_source_context(), ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.Syntax syntax = 6; case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 48)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 48)) { + ::uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); _internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val)); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -592,11 +598,11 @@ failure: #undef CHK_ } -uint8_t* Type::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Type::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Type) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string name = 1; @@ -657,12 +663,12 @@ uint8_t* Type::_InternalSerialize( return target; } -size_t Type::ByteSizeLong() const { +::size_t Type::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Type) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -724,7 +730,7 @@ void Type::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_ // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.fields_.MergeFrom(from._impl_.fields_); @@ -842,7 +848,7 @@ Field::Field(const Field& from) _this->GetArenaForAllocation()); } ::memcpy(&_impl_.kind_, &from._impl_.kind_, - static_cast(reinterpret_cast(&_impl_.packed_) - + static_cast<::size_t>(reinterpret_cast(&_impl_.packed_) - reinterpret_cast(&_impl_.kind_)) + sizeof(_impl_.packed_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.Field) } @@ -906,7 +912,7 @@ void Field::SetCachedSize(int size) const { void Field::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Field) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -915,7 +921,7 @@ void Field::Clear() { _impl_.type_url_.ClearToEmpty(); _impl_.json_name_.ClearToEmpty(); _impl_.default_value_.ClearToEmpty(); - ::memset(&_impl_.kind_, 0, static_cast( + ::memset(&_impl_.kind_, 0, static_cast<::size_t>( reinterpret_cast(&_impl_.packed_) - reinterpret_cast(&_impl_.kind_)) + sizeof(_impl_.packed_)); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); @@ -925,74 +931,81 @@ const char* Field::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // .google.protobuf.Field.Kind kind = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { + ::uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); _internal_set_kind(static_cast<::PROTOBUF_NAMESPACE_ID::Field_Kind>(val)); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.Field.Cardinality cardinality = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 16)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 16)) { + ::uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); _internal_set_cardinality(static_cast<::PROTOBUF_NAMESPACE_ID::Field_Cardinality>(val)); - } else + } else { goto handle_unusual; + } continue; // int32 number = 3; case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 24)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 24)) { _impl_.number_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // string name = 4; case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 34)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 34)) { auto str = _internal_mutable_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Field.name")); - } else + } else { goto handle_unusual; + } continue; // string type_url = 6; case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 50)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 50)) { auto str = _internal_mutable_type_url(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Field.type_url")); - } else + } else { goto handle_unusual; + } continue; // int32 oneof_index = 7; case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 56)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 56)) { _impl_.oneof_index_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // bool packed = 8; case 8: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 64)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 64)) { _impl_.packed_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Option options = 9; case 9: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 74)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 74)) { ptr -= 1; do { ptr += 1; @@ -1000,28 +1013,31 @@ const char* Field::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<74>(ptr)); - } else + } else { goto handle_unusual; + } continue; // string json_name = 10; case 10: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 82)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 82)) { auto str = _internal_mutable_json_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Field.json_name")); - } else + } else { goto handle_unusual; + } continue; // string default_value = 11; case 11: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 90)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 90)) { auto str = _internal_mutable_default_value(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Field.default_value")); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1046,11 +1062,11 @@ failure: #undef CHK_ } -uint8_t* Field::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Field::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Field) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // .google.protobuf.Field.Kind kind = 1; @@ -1141,12 +1157,12 @@ uint8_t* Field::_InternalSerialize( return target; } -size_t Field::ByteSizeLong() const { +::size_t Field::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Field) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1228,7 +1244,7 @@ void Field::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Field) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.options_.MergeFrom(from._impl_.options_); @@ -1400,7 +1416,7 @@ void Enum::SetCachedSize(int size) const { void Enum::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Enum) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1419,22 +1435,23 @@ const char* Enum::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string name = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Enum.name")); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.EnumValue enumvalue = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 18)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { ptr -= 1; do { ptr += 1; @@ -1442,12 +1459,13 @@ const char* Enum::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Option options = 3; case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 26)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { ptr -= 1; do { ptr += 1; @@ -1455,25 +1473,28 @@ const char* Enum::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.SourceContext source_context = 4; case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 34)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 34)) { ptr = ctx->ParseMessage(_internal_mutable_source_context(), ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.Syntax syntax = 5; case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 40)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 40)) { + ::uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); _internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val)); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1498,11 +1519,11 @@ failure: #undef CHK_ } -uint8_t* Enum::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Enum::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Enum) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string name = 1; @@ -1553,12 +1574,12 @@ uint8_t* Enum::_InternalSerialize( return target; } -size_t Enum::ByteSizeLong() const { +::size_t Enum::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Enum) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1612,7 +1633,7 @@ void Enum::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_ // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.enumvalue_.MergeFrom(from._impl_.enumvalue_); @@ -1737,7 +1758,7 @@ void EnumValue::SetCachedSize(int size) const { void EnumValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1751,30 +1772,32 @@ const char* EnumValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string name = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.EnumValue.name")); - } else + } else { goto handle_unusual; + } continue; // int32 number = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 16)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 16)) { _impl_.number_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; // repeated .google.protobuf.Option options = 3; case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 26)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { ptr -= 1; do { ptr += 1; @@ -1782,8 +1805,9 @@ const char* EnumValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1808,11 +1832,11 @@ failure: #undef CHK_ } -uint8_t* EnumValue::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* EnumValue::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string name = 1; @@ -1847,12 +1871,12 @@ uint8_t* EnumValue::_InternalSerialize( return target; } -size_t EnumValue::ByteSizeLong() const { +::size_t EnumValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValue) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1891,7 +1915,7 @@ void EnumValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROT // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValue) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; _this->_impl_.options_.MergeFrom(from._impl_.options_); @@ -2016,7 +2040,7 @@ void Option::SetCachedSize(int size) const { void Option::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Option) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -2032,26 +2056,28 @@ const char* Option::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string name = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_name(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.Option.name")); - } else + } else { goto handle_unusual; + } continue; // .google.protobuf.Any value = 2; case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 18)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { ptr = ctx->ParseMessage(_internal_mutable_value(), ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -2076,11 +2102,11 @@ failure: #undef CHK_ } -uint8_t* Option::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Option::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Option) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string name = 1; @@ -2108,12 +2134,12 @@ uint8_t* Option::_InternalSerialize( return target; } -size_t Option::ByteSizeLong() const { +::size_t Option::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Option) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -2147,7 +2173,7 @@ void Option::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBU // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Option) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_name().empty()) { diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index cd31a4bf94..0dcf3eb612 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -49,7 +49,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2ftype_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2ftype_2eproto; @@ -103,9 +103,9 @@ enum Field_Kind : int { Field_Kind_TYPE_SINT32 = 17, Field_Kind_TYPE_SINT64 = 18, Field_Kind_Field_Kind_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), + std::numeric_limits<::int32_t>::min(), Field_Kind_Field_Kind_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), + std::numeric_limits<::int32_t>::max(), }; PROTOBUF_EXPORT bool Field_Kind_IsValid(int value); @@ -137,9 +137,9 @@ enum Field_Cardinality : int { Field_Cardinality_CARDINALITY_REQUIRED = 2, Field_Cardinality_CARDINALITY_REPEATED = 3, Field_Cardinality_Field_Cardinality_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), + std::numeric_limits<::int32_t>::min(), Field_Cardinality_Field_Cardinality_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), + std::numeric_limits<::int32_t>::max(), }; PROTOBUF_EXPORT bool Field_Cardinality_IsValid(int value); @@ -169,9 +169,9 @@ enum Syntax : int { SYNTAX_PROTO2 = 0, SYNTAX_PROTO3 = 1, Syntax_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), + std::numeric_limits<::int32_t>::min(), Syntax_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), + std::numeric_limits<::int32_t>::max(), }; PROTOBUF_EXPORT bool Syntax_IsValid(int value); @@ -292,10 +292,10 @@ class PROTOBUF_EXPORT Type final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -360,12 +360,12 @@ class PROTOBUF_EXPORT Type final : void set_oneofs(int index, const std::string& value); void set_oneofs(int index, std::string&& value); void set_oneofs(int index, const char* value); - void set_oneofs(int index, const char* value, size_t size); + void set_oneofs(int index, const char* value, ::size_t size); std::string* add_oneofs(); void add_oneofs(const std::string& value); void add_oneofs(std::string&& value); void add_oneofs(const char* value); - void add_oneofs(const char* value, size_t size); + void add_oneofs(const char* value, ::size_t size); const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& oneofs() const; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_oneofs(); private: @@ -541,10 +541,10 @@ class PROTOBUF_EXPORT Field final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -737,20 +737,20 @@ class PROTOBUF_EXPORT Field final : // int32 number = 3; void clear_number(); - int32_t number() const; - void set_number(int32_t value); + ::int32_t number() const; + void set_number(::int32_t value); private: - int32_t _internal_number() const; - void _internal_set_number(int32_t value); + ::int32_t _internal_number() const; + void _internal_set_number(::int32_t value); public: // int32 oneof_index = 7; void clear_oneof_index(); - int32_t oneof_index() const; - void set_oneof_index(int32_t value); + ::int32_t oneof_index() const; + void set_oneof_index(::int32_t value); private: - int32_t _internal_oneof_index() const; - void _internal_set_oneof_index(int32_t value); + ::int32_t _internal_oneof_index() const; + void _internal_set_oneof_index(::int32_t value); public: // bool packed = 8; @@ -777,8 +777,8 @@ class PROTOBUF_EXPORT Field final : ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr default_value_; int kind_; int cardinality_; - int32_t number_; - int32_t oneof_index_; + ::int32_t number_; + ::int32_t oneof_index_; bool packed_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; }; @@ -875,10 +875,10 @@ class PROTOBUF_EXPORT Enum final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -1098,10 +1098,10 @@ class PROTOBUF_EXPORT EnumValue final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -1168,11 +1168,11 @@ class PROTOBUF_EXPORT EnumValue final : // int32 number = 2; void clear_number(); - int32_t number() const; - void set_number(int32_t value); + ::int32_t number() const; + void set_number(::int32_t value); private: - int32_t _internal_number() const; - void _internal_set_number(int32_t value); + ::int32_t _internal_number() const; + void _internal_set_number(::int32_t value); public: // @@protoc_insertion_point(class_scope:google.protobuf.EnumValue) @@ -1185,7 +1185,7 @@ class PROTOBUF_EXPORT EnumValue final : struct Impl_ { ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option > options_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; - int32_t number_; + ::int32_t number_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; }; union { Impl_ _impl_; }; @@ -1281,10 +1281,10 @@ class PROTOBUF_EXPORT Option final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -1502,7 +1502,7 @@ inline void Type::set_oneofs(int index, const char* value) { GOOGLE_DCHECK(value != nullptr); _impl_.oneofs_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.Type.oneofs) } -inline void Type::set_oneofs(int index, const char* value, size_t size) { +inline void Type::set_oneofs(int index, const char* value, ::size_t size) { _impl_.oneofs_.Mutable(index)->assign( reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Type.oneofs) @@ -1522,7 +1522,7 @@ inline void Type::add_oneofs(const char* value) { GOOGLE_DCHECK(value != nullptr); _impl_.oneofs_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.Type.oneofs) } -inline void Type::add_oneofs(const char* value, size_t size) { +inline void Type::add_oneofs(const char* value, ::size_t size) { _impl_.oneofs_.Add()->assign(reinterpret_cast(value), size); // @@protoc_insertion_point(field_add_pointer:google.protobuf.Type.oneofs) } @@ -1725,18 +1725,18 @@ inline void Field::set_cardinality(::PROTOBUF_NAMESPACE_ID::Field_Cardinality va inline void Field::clear_number() { _impl_.number_ = 0; } -inline int32_t Field::_internal_number() const { +inline ::int32_t Field::_internal_number() const { return _impl_.number_; } -inline int32_t Field::number() const { +inline ::int32_t Field::number() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.number) return _internal_number(); } -inline void Field::_internal_set_number(int32_t value) { +inline void Field::_internal_set_number(::int32_t value) { _impl_.number_ = value; } -inline void Field::set_number(int32_t value) { +inline void Field::set_number(::int32_t value) { _internal_set_number(value); // @@protoc_insertion_point(field_set:google.protobuf.Field.number) } @@ -1835,18 +1835,18 @@ inline void Field::set_allocated_type_url(std::string* type_url) { inline void Field::clear_oneof_index() { _impl_.oneof_index_ = 0; } -inline int32_t Field::_internal_oneof_index() const { +inline ::int32_t Field::_internal_oneof_index() const { return _impl_.oneof_index_; } -inline int32_t Field::oneof_index() const { +inline ::int32_t Field::oneof_index() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.oneof_index) return _internal_oneof_index(); } -inline void Field::_internal_set_oneof_index(int32_t value) { +inline void Field::_internal_set_oneof_index(::int32_t value) { _impl_.oneof_index_ = value; } -inline void Field::set_oneof_index(int32_t value) { +inline void Field::set_oneof_index(::int32_t value) { _internal_set_oneof_index(value); // @@protoc_insertion_point(field_set:google.protobuf.Field.oneof_index) } @@ -2283,18 +2283,18 @@ inline void EnumValue::set_allocated_name(std::string* name) { inline void EnumValue::clear_number() { _impl_.number_ = 0; } -inline int32_t EnumValue::_internal_number() const { +inline ::int32_t EnumValue::_internal_number() const { return _impl_.number_; } -inline int32_t EnumValue::number() const { +inline ::int32_t EnumValue::number() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumValue.number) return _internal_number(); } -inline void EnumValue::_internal_set_number(int32_t value) { +inline void EnumValue::_internal_set_number(::int32_t value) { _impl_.number_ = value; } -inline void EnumValue::set_number(int32_t value) { +inline void EnumValue::set_number(::int32_t value) { _internal_set_number(value); // @@protoc_insertion_point(field_set:google.protobuf.EnumValue.number) } diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto index b7a1b2d145..2ee1acf2ee 100644 --- a/src/google/protobuf/unittest.proto +++ b/src/google/protobuf/unittest.proto @@ -1570,3 +1570,8 @@ message StringParseTester { repeated string repeated_string_midfield = 1002; repeated string repeated_string_hifield = 1000002; }; + +message BadFieldNames{ + optional int32 OptionalInt32 = 1; + optional int32 for = 2; +} diff --git a/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto b/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto index 52ec8e4cc4..466948ea56 100644 --- a/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto +++ b/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto @@ -36,8 +36,8 @@ syntax = "proto2"; -import "google/protobuf/unittest_lazy_dependencies_enum.proto"; import "google/protobuf/descriptor.proto"; +import "google/protobuf/unittest_lazy_dependencies_enum.proto"; // Some generic_services option(s) added automatically. // See: http://go/proto2-generic-services-default diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc index 7eecd300eb..8b104f7e4c 100644 --- a/src/google/protobuf/unknown_field_set.cc +++ b/src/google/protobuf/unknown_field_set.cc @@ -36,15 +36,15 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "absl/strings/cord.h" #include "absl/strings/internal/resize_uninitialized.h" #include "google/protobuf/extension_set.h" #include "google/protobuf/generated_message_tctable_decl.h" #include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/parse_context.h" #include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format_lite.h" diff --git a/src/google/protobuf/unknown_field_set.h b/src/google/protobuf/unknown_field_set.h index 04b630ebbd..85e51a577f 100644 --- a/src/google/protobuf/unknown_field_set.h +++ b/src/google/protobuf/unknown_field_set.h @@ -46,9 +46,9 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/logging.h" +#include "google/protobuf/port.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/port.h" #include "google/protobuf/message_lite.h" #include "google/protobuf/parse_context.h" #include "google/protobuf/port.h" diff --git a/src/google/protobuf/unknown_field_set_unittest.cc b/src/google/protobuf/unknown_field_set_unittest.cc index 41df3f3e65..ac84b60ef7 100644 --- a/src/google/protobuf/unknown_field_set_unittest.cc +++ b/src/google/protobuf/unknown_field_set_unittest.cc @@ -44,12 +44,10 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/logging.h" #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_lite.pb.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format.h" #include #include "google/protobuf/testing/googletest.h" #include @@ -59,6 +57,8 @@ #include "absl/time/clock.h" #include "absl/time/time.h" #include "google/protobuf/test_util.h" +#include "google/protobuf/unittest_lite.pb.h" +#include "google/protobuf/wire_format.h" namespace google { diff --git a/src/google/protobuf/util/delimited_message_util.cc b/src/google/protobuf/util/delimited_message_util.cc index 36b51e9576..1dcd943e6f 100644 --- a/src/google/protobuf/util/delimited_message_util.cc +++ b/src/google/protobuf/util/delimited_message_util.cc @@ -32,6 +32,7 @@ // See https://github.com/protocolbuffers/protobuf/pull/710 for details. #include "google/protobuf/util/delimited_message_util.h" + #include "google/protobuf/io/coded_stream.h" namespace google { diff --git a/src/google/protobuf/util/delimited_message_util_test.cc b/src/google/protobuf/util/delimited_message_util_test.cc index 954afb2f5e..4817c2f103 100644 --- a/src/google/protobuf/util/delimited_message_util_test.cc +++ b/src/google/protobuf/util/delimited_message_util_test.cc @@ -35,10 +35,10 @@ #include -#include "google/protobuf/test_util.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/testing/googletest.h" #include +#include "google/protobuf/test_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/field_mask_util_test.cc b/src/google/protobuf/util/field_mask_util_test.cc index a67a0254f9..fbdebf7f0f 100644 --- a/src/google/protobuf/util/field_mask_util_test.cc +++ b/src/google/protobuf/util/field_mask_util_test.cc @@ -35,11 +35,11 @@ #include #include "google/protobuf/field_mask.pb.h" -#include "google/protobuf/test_util.h" #include "google/protobuf/unittest.pb.h" #include #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" +#include "google/protobuf/test_util.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index 3c990c939f..6843a3e813 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -44,9 +44,6 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" @@ -59,6 +56,9 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/util/field_comparator.h" // Always include as last one, otherwise it can break compilation diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index 4f8c5784a7..f848d8b787 100644 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -34,29 +34,29 @@ // // TODO(ksroka): Move some of these tests to field_comparator_test.cc. +#include "google/protobuf/util/message_differencer.h" + #include #include #include #include #include "google/protobuf/stubs/common.h" - -#include #include "google/protobuf/stubs/logging.h" +#include "google/protobuf/unittest.pb.h" +#include +#include "google/protobuf/testing/googletest.h" +#include +#include "absl/functional/bind_front.h" +#include "absl/strings/str_split.h" #include "google/protobuf/any_test.pb.h" #include "google/protobuf/map_test_util.h" #include "google/protobuf/map_unittest.pb.h" #include "google/protobuf/test_util.h" -#include "google/protobuf/unittest.pb.h" #include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format.h" #include "google/protobuf/util/field_comparator.h" -#include "google/protobuf/util/message_differencer.h" -#include "google/protobuf/testing/googletest.h" -#include -#include "absl/functional/bind_front.h" -#include "absl/strings/str_split.h" #include "google/protobuf/util/message_differencer_unittest.pb.h" +#include "google/protobuf/wire_format.h" namespace google { diff --git a/src/google/protobuf/util/type_resolver_util_test.cc b/src/google/protobuf/util/type_resolver_util_test.cc index d926541980..7da6de21c7 100644 --- a/src/google/protobuf/util/type_resolver_util_test.cc +++ b/src/google/protobuf/util/type_resolver_util_test.cc @@ -38,14 +38,14 @@ #include "google/protobuf/type.pb.h" #include "google/protobuf/wrappers.pb.h" -#include "google/protobuf/map_unittest.pb.h" -#include "google/protobuf/test_util.h" #include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_custom_options.pb.h" #include "google/protobuf/util/type_resolver.h" #include "google/protobuf/testing/googletest.h" #include #include "google/protobuf/util/json_format_proto3.pb.h" +#include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/test_util.h" +#include "google/protobuf/unittest_custom_options.pb.h" namespace google { namespace protobuf { diff --git a/src/google/protobuf/wire_format.cc b/src/google/protobuf/wire_format.cc index e65dad0ca5..ff542b734d 100644 --- a/src/google/protobuf/wire_format.cc +++ b/src/google/protobuf/wire_format.cc @@ -40,13 +40,13 @@ #include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" #include "absl/strings/cord.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/dynamic_message.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/map_field.h" #include "google/protobuf/map_field_inl.h" #include "google/protobuf/message.h" diff --git a/src/google/protobuf/wire_format_unittest.inc b/src/google/protobuf/wire_format_unittest.inc index 81a577e5d4..28ead5b3c5 100644 --- a/src/google/protobuf/wire_format_unittest.inc +++ b/src/google/protobuf/wire_format_unittest.inc @@ -38,8 +38,6 @@ #include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" #include #include "google/protobuf/testing/googletest.h" #include @@ -49,6 +47,8 @@ #include "absl/strings/match.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/test_util2.h" +#include "google/protobuf/wire_format.h" +#include "google/protobuf/wire_format_lite.h" // clang-format off #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index 9bc739752e..a09a6a27c2 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -49,7 +49,7 @@ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FloatValueDefaultTypeInternal _FloatValue_default_instance_; PROTOBUF_CONSTEXPR Int64Value::Int64Value( ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.value_)*/int64_t{0} + /*decltype(_impl_.value_)*/::int64_t{0} , /*decltype(_impl_._cached_size_)*/{}} {} struct Int64ValueDefaultTypeInternal { PROTOBUF_CONSTEXPR Int64ValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} @@ -63,7 +63,7 @@ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Int64ValueDefaultTypeInternal _Int64Value_default_instance_; PROTOBUF_CONSTEXPR UInt64Value::UInt64Value( ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.value_)*/uint64_t{0u} + /*decltype(_impl_.value_)*/::uint64_t{0u} , /*decltype(_impl_._cached_size_)*/{}} {} struct UInt64ValueDefaultTypeInternal { PROTOBUF_CONSTEXPR UInt64ValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} @@ -151,7 +151,7 @@ static constexpr const ::_pb::EnumDescriptor** file_level_enum_descriptors_google_2fprotobuf_2fwrappers_2eproto = nullptr; static constexpr const ::_pb::ServiceDescriptor** file_level_service_descriptors_google_2fprotobuf_2fwrappers_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fwrappers_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( +const ::uint32_t TableStruct_google_2fprotobuf_2fwrappers_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( protodesc_cold) = { ~0u, // no _has_bits_ PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DoubleValue, _internal_metadata_), @@ -359,7 +359,7 @@ void DoubleValue::SetCachedSize(int size) const { void DoubleValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DoubleValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -371,16 +371,17 @@ const char* DoubleValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* c #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // double value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 9)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 9)) { _impl_.value_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); ptr += sizeof(double); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -405,17 +406,17 @@ failure: #undef CHK_ } -uint8_t* DoubleValue::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* DoubleValue::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DoubleValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // double value = 1; - static_assert(sizeof(uint64_t) == sizeof(double), "Code assumes uint64_t and double are the same size."); + static_assert(sizeof(::uint64_t) == sizeof(double), "Code assumes ::uint64_t and double are the same size."); double tmp_value = this->_internal_value(); - uint64_t raw_value; + ::uint64_t raw_value; memcpy(&raw_value, &tmp_value, sizeof(tmp_value)); if (raw_value != 0) { target = stream->EnsureSpace(target); @@ -430,19 +431,19 @@ uint8_t* DoubleValue::_InternalSerialize( return target; } -size_t DoubleValue::ByteSizeLong() const { +::size_t DoubleValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DoubleValue) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; // double value = 1; - static_assert(sizeof(uint64_t) == sizeof(double), "Code assumes uint64_t and double are the same size."); + static_assert(sizeof(::uint64_t) == sizeof(double), "Code assumes ::uint64_t and double are the same size."); double tmp_value = this->_internal_value(); - uint64_t raw_value; + ::uint64_t raw_value; memcpy(&raw_value, &tmp_value, sizeof(tmp_value)); if (raw_value != 0) { total_size += 1 + 8; @@ -464,12 +465,12 @@ void DoubleValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PR // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DoubleValue) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; - static_assert(sizeof(uint64_t) == sizeof(double), "Code assumes uint64_t and double are the same size."); + static_assert(sizeof(::uint64_t) == sizeof(double), "Code assumes ::uint64_t and double are the same size."); double tmp_value = from._internal_value(); - uint64_t raw_value; + ::uint64_t raw_value; memcpy(&raw_value, &tmp_value, sizeof(tmp_value)); if (raw_value != 0) { _this->_internal_set_value(from._internal_value()); @@ -548,7 +549,7 @@ void FloatValue::SetCachedSize(int size) const { void FloatValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FloatValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -560,16 +561,17 @@ const char* FloatValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ct #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // float value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 13)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 13)) { _impl_.value_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr); ptr += sizeof(float); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -594,17 +596,17 @@ failure: #undef CHK_ } -uint8_t* FloatValue::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* FloatValue::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FloatValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // float value = 1; - static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + static_assert(sizeof(::uint32_t) == sizeof(float), "Code assumes ::uint32_t and float are the same size."); float tmp_value = this->_internal_value(); - uint32_t raw_value; + ::uint32_t raw_value; memcpy(&raw_value, &tmp_value, sizeof(tmp_value)); if (raw_value != 0) { target = stream->EnsureSpace(target); @@ -619,19 +621,19 @@ uint8_t* FloatValue::_InternalSerialize( return target; } -size_t FloatValue::ByteSizeLong() const { +::size_t FloatValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FloatValue) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; // float value = 1; - static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + static_assert(sizeof(::uint32_t) == sizeof(float), "Code assumes ::uint32_t and float are the same size."); float tmp_value = this->_internal_value(); - uint32_t raw_value; + ::uint32_t raw_value; memcpy(&raw_value, &tmp_value, sizeof(tmp_value)); if (raw_value != 0) { total_size += 1 + 4; @@ -653,12 +655,12 @@ void FloatValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PRO // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FloatValue) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; - static_assert(sizeof(uint32_t) == sizeof(float), "Code assumes uint32_t and float are the same size."); + static_assert(sizeof(::uint32_t) == sizeof(float), "Code assumes ::uint32_t and float are the same size."); float tmp_value = from._internal_value(); - uint32_t raw_value; + ::uint32_t raw_value; memcpy(&raw_value, &tmp_value, sizeof(tmp_value)); if (raw_value != 0) { _this->_internal_set_value(from._internal_value()); @@ -713,7 +715,7 @@ inline void Int64Value::SharedCtor( (void)arena; (void)is_message_owned; new (&_impl_) Impl_{ - decltype(_impl_.value_){int64_t{0}} + decltype(_impl_.value_){::int64_t{0}} , /*decltype(_impl_._cached_size_)*/{} }; } @@ -737,11 +739,11 @@ void Int64Value::SetCachedSize(int size) const { void Int64Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Int64Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - _impl_.value_ = int64_t{0}; + _impl_.value_ = ::int64_t{0}; _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); } @@ -749,16 +751,17 @@ const char* Int64Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ct #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // int64 value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { _impl_.value_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -783,11 +786,11 @@ failure: #undef CHK_ } -uint8_t* Int64Value::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Int64Value::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int64Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // int64 value = 1; @@ -804,12 +807,12 @@ uint8_t* Int64Value::_InternalSerialize( return target; } -size_t Int64Value::ByteSizeLong() const { +::size_t Int64Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int64Value) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -834,7 +837,7 @@ void Int64Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PRO // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int64Value) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_value() != 0) { @@ -890,7 +893,7 @@ inline void UInt64Value::SharedCtor( (void)arena; (void)is_message_owned; new (&_impl_) Impl_{ - decltype(_impl_.value_){uint64_t{0u}} + decltype(_impl_.value_){::uint64_t{0u}} , /*decltype(_impl_._cached_size_)*/{} }; } @@ -914,11 +917,11 @@ void UInt64Value::SetCachedSize(int size) const { void UInt64Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UInt64Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - _impl_.value_ = uint64_t{0u}; + _impl_.value_ = ::uint64_t{0u}; _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); } @@ -926,16 +929,17 @@ const char* UInt64Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* c #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // uint64 value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { _impl_.value_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -960,11 +964,11 @@ failure: #undef CHK_ } -uint8_t* UInt64Value::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* UInt64Value::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt64Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // uint64 value = 1; @@ -981,12 +985,12 @@ uint8_t* UInt64Value::_InternalSerialize( return target; } -size_t UInt64Value::ByteSizeLong() const { +::size_t UInt64Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt64Value) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1011,7 +1015,7 @@ void UInt64Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PR // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt64Value) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_value() != 0) { @@ -1091,7 +1095,7 @@ void Int32Value::SetCachedSize(int size) const { void Int32Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Int32Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1103,16 +1107,17 @@ const char* Int32Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ct #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // int32 value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { _impl_.value_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1137,11 +1142,11 @@ failure: #undef CHK_ } -uint8_t* Int32Value::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* Int32Value::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int32Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // int32 value = 1; @@ -1158,12 +1163,12 @@ uint8_t* Int32Value::_InternalSerialize( return target; } -size_t Int32Value::ByteSizeLong() const { +::size_t Int32Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int32Value) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1188,7 +1193,7 @@ void Int32Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PRO // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int32Value) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_value() != 0) { @@ -1268,7 +1273,7 @@ void UInt32Value::SetCachedSize(int size) const { void UInt32Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UInt32Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1280,16 +1285,17 @@ const char* UInt32Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* c #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // uint32 value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { _impl_.value_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1314,11 +1320,11 @@ failure: #undef CHK_ } -uint8_t* UInt32Value::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* UInt32Value::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt32Value) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // uint32 value = 1; @@ -1335,12 +1341,12 @@ uint8_t* UInt32Value::_InternalSerialize( return target; } -size_t UInt32Value::ByteSizeLong() const { +::size_t UInt32Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt32Value) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1365,7 +1371,7 @@ void UInt32Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PR // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt32Value) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_value() != 0) { @@ -1445,7 +1451,7 @@ void BoolValue::SetCachedSize(int size) const { void BoolValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.BoolValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1457,16 +1463,17 @@ const char* BoolValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // bool value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { _impl_.value_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1491,11 +1498,11 @@ failure: #undef CHK_ } -uint8_t* BoolValue::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* BoolValue::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BoolValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // bool value = 1; @@ -1512,12 +1519,12 @@ uint8_t* BoolValue::_InternalSerialize( return target; } -size_t BoolValue::ByteSizeLong() const { +::size_t BoolValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.BoolValue) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1542,7 +1549,7 @@ void BoolValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROT // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BoolValue) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (from._internal_value() != 0) { @@ -1639,7 +1646,7 @@ void StringValue::SetCachedSize(int size) const { void StringValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.StringValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1651,18 +1658,19 @@ const char* StringValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* c #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // string value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_value(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); CHK_(::_pbi::VerifyUTF8(str, "google.protobuf.StringValue.value")); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1687,11 +1695,11 @@ failure: #undef CHK_ } -uint8_t* StringValue::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* StringValue::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.StringValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // string value = 1; @@ -1712,12 +1720,12 @@ uint8_t* StringValue::_InternalSerialize( return target; } -size_t StringValue::ByteSizeLong() const { +::size_t StringValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.StringValue) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1744,7 +1752,7 @@ void StringValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PR // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.StringValue) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_value().empty()) { @@ -1846,7 +1854,7 @@ void BytesValue::SetCachedSize(int size) const { void BytesValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.BytesValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1858,17 +1866,18 @@ const char* BytesValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ct #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { - uint32_t tag; + ::uint32_t tag; ptr = ::_pbi::ReadTag(ptr, &tag); switch (tag >> 3) { // bytes value = 1; case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { auto str = _internal_mutable_value(); ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); - } else + } else { goto handle_unusual; + } continue; default: goto handle_unusual; @@ -1893,11 +1902,11 @@ failure: #undef CHK_ } -uint8_t* BytesValue::_InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { +::uint8_t* BytesValue::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BytesValue) - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; // bytes value = 1; @@ -1914,12 +1923,12 @@ uint8_t* BytesValue::_InternalSerialize( return target; } -size_t BytesValue::ByteSizeLong() const { +::size_t BytesValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.BytesValue) - size_t total_size = 0; + ::size_t total_size = 0; - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -1946,7 +1955,7 @@ void BytesValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PRO // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BytesValue) GOOGLE_DCHECK_NE(&from, _this); - uint32_t cached_has_bits = 0; + ::uint32_t cached_has_bits = 0; (void) cached_has_bits; if (!from._internal_value().empty()) { diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 1f0ac0f74b..8c4838d67c 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -46,7 +46,7 @@ PROTOBUF_NAMESPACE_CLOSE // Internal implementation detail -- do not use these members. struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fwrappers_2eproto { - static const uint32_t offsets[]; + static const ::uint32_t offsets[]; }; PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fwrappers_2eproto; @@ -194,10 +194,10 @@ class PROTOBUF_EXPORT DoubleValue final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -341,10 +341,10 @@ class PROTOBUF_EXPORT FloatValue final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -488,10 +488,10 @@ class PROTOBUF_EXPORT Int64Value final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -524,11 +524,11 @@ class PROTOBUF_EXPORT Int64Value final : }; // int64 value = 1; void clear_value(); - int64_t value() const; - void set_value(int64_t value); + ::int64_t value() const; + void set_value(::int64_t value); private: - int64_t _internal_value() const; - void _internal_set_value(int64_t value); + ::int64_t _internal_value() const; + void _internal_set_value(::int64_t value); public: // @@protoc_insertion_point(class_scope:google.protobuf.Int64Value) @@ -539,7 +539,7 @@ class PROTOBUF_EXPORT Int64Value final : typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { - int64_t value_; + ::int64_t value_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; }; union { Impl_ _impl_; }; @@ -635,10 +635,10 @@ class PROTOBUF_EXPORT UInt64Value final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -671,11 +671,11 @@ class PROTOBUF_EXPORT UInt64Value final : }; // uint64 value = 1; void clear_value(); - uint64_t value() const; - void set_value(uint64_t value); + ::uint64_t value() const; + void set_value(::uint64_t value); private: - uint64_t _internal_value() const; - void _internal_set_value(uint64_t value); + ::uint64_t _internal_value() const; + void _internal_set_value(::uint64_t value); public: // @@protoc_insertion_point(class_scope:google.protobuf.UInt64Value) @@ -686,7 +686,7 @@ class PROTOBUF_EXPORT UInt64Value final : typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { - uint64_t value_; + ::uint64_t value_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; }; union { Impl_ _impl_; }; @@ -782,10 +782,10 @@ class PROTOBUF_EXPORT Int32Value final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -818,11 +818,11 @@ class PROTOBUF_EXPORT Int32Value final : }; // int32 value = 1; void clear_value(); - int32_t value() const; - void set_value(int32_t value); + ::int32_t value() const; + void set_value(::int32_t value); private: - int32_t _internal_value() const; - void _internal_set_value(int32_t value); + ::int32_t _internal_value() const; + void _internal_set_value(::int32_t value); public: // @@protoc_insertion_point(class_scope:google.protobuf.Int32Value) @@ -833,7 +833,7 @@ class PROTOBUF_EXPORT Int32Value final : typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { - int32_t value_; + ::int32_t value_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; }; union { Impl_ _impl_; }; @@ -929,10 +929,10 @@ class PROTOBUF_EXPORT UInt32Value final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -965,11 +965,11 @@ class PROTOBUF_EXPORT UInt32Value final : }; // uint32 value = 1; void clear_value(); - uint32_t value() const; - void set_value(uint32_t value); + ::uint32_t value() const; + void set_value(::uint32_t value); private: - uint32_t _internal_value() const; - void _internal_set_value(uint32_t value); + ::uint32_t _internal_value() const; + void _internal_set_value(::uint32_t value); public: // @@protoc_insertion_point(class_scope:google.protobuf.UInt32Value) @@ -980,7 +980,7 @@ class PROTOBUF_EXPORT UInt32Value final : typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { - uint32_t value_; + ::uint32_t value_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; }; union { Impl_ _impl_; }; @@ -1076,10 +1076,10 @@ class PROTOBUF_EXPORT BoolValue final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -1223,10 +1223,10 @@ class PROTOBUF_EXPORT StringValue final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -1375,10 +1375,10 @@ class PROTOBUF_EXPORT BytesValue final : PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; bool IsInitialized() const final; - size_t ByteSizeLong() const final; + ::size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - uint8_t* _InternalSerialize( - uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _impl_._cached_size_.Get(); } private: @@ -1503,20 +1503,20 @@ inline void FloatValue::set_value(float value) { // int64 value = 1; inline void Int64Value::clear_value() { - _impl_.value_ = int64_t{0}; + _impl_.value_ = ::int64_t{0}; } -inline int64_t Int64Value::_internal_value() const { +inline ::int64_t Int64Value::_internal_value() const { return _impl_.value_; } -inline int64_t Int64Value::value() const { +inline ::int64_t Int64Value::value() const { // @@protoc_insertion_point(field_get:google.protobuf.Int64Value.value) return _internal_value(); } -inline void Int64Value::_internal_set_value(int64_t value) { +inline void Int64Value::_internal_set_value(::int64_t value) { _impl_.value_ = value; } -inline void Int64Value::set_value(int64_t value) { +inline void Int64Value::set_value(::int64_t value) { _internal_set_value(value); // @@protoc_insertion_point(field_set:google.protobuf.Int64Value.value) } @@ -1527,20 +1527,20 @@ inline void Int64Value::set_value(int64_t value) { // uint64 value = 1; inline void UInt64Value::clear_value() { - _impl_.value_ = uint64_t{0u}; + _impl_.value_ = ::uint64_t{0u}; } -inline uint64_t UInt64Value::_internal_value() const { +inline ::uint64_t UInt64Value::_internal_value() const { return _impl_.value_; } -inline uint64_t UInt64Value::value() const { +inline ::uint64_t UInt64Value::value() const { // @@protoc_insertion_point(field_get:google.protobuf.UInt64Value.value) return _internal_value(); } -inline void UInt64Value::_internal_set_value(uint64_t value) { +inline void UInt64Value::_internal_set_value(::uint64_t value) { _impl_.value_ = value; } -inline void UInt64Value::set_value(uint64_t value) { +inline void UInt64Value::set_value(::uint64_t value) { _internal_set_value(value); // @@protoc_insertion_point(field_set:google.protobuf.UInt64Value.value) } @@ -1553,18 +1553,18 @@ inline void UInt64Value::set_value(uint64_t value) { inline void Int32Value::clear_value() { _impl_.value_ = 0; } -inline int32_t Int32Value::_internal_value() const { +inline ::int32_t Int32Value::_internal_value() const { return _impl_.value_; } -inline int32_t Int32Value::value() const { +inline ::int32_t Int32Value::value() const { // @@protoc_insertion_point(field_get:google.protobuf.Int32Value.value) return _internal_value(); } -inline void Int32Value::_internal_set_value(int32_t value) { +inline void Int32Value::_internal_set_value(::int32_t value) { _impl_.value_ = value; } -inline void Int32Value::set_value(int32_t value) { +inline void Int32Value::set_value(::int32_t value) { _internal_set_value(value); // @@protoc_insertion_point(field_set:google.protobuf.Int32Value.value) } @@ -1577,18 +1577,18 @@ inline void Int32Value::set_value(int32_t value) { inline void UInt32Value::clear_value() { _impl_.value_ = 0u; } -inline uint32_t UInt32Value::_internal_value() const { +inline ::uint32_t UInt32Value::_internal_value() const { return _impl_.value_; } -inline uint32_t UInt32Value::value() const { +inline ::uint32_t UInt32Value::value() const { // @@protoc_insertion_point(field_get:google.protobuf.UInt32Value.value) return _internal_value(); } -inline void UInt32Value::_internal_set_value(uint32_t value) { +inline void UInt32Value::_internal_set_value(::uint32_t value) { _impl_.value_ = value; } -inline void UInt32Value::set_value(uint32_t value) { +inline void UInt32Value::set_value(::uint32_t value) { _internal_set_value(value); // @@protoc_insertion_point(field_set:google.protobuf.UInt32Value.value) } diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 2599477778..b610a8ee9d 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -29,193 +29,193 @@ all_compile_actions = [ ] def _impl(ctx): - if "mingw" in ctx.attr.target_full_name: - artifact_name_patterns = [ - artifact_name_pattern( - category_name = "executable", - prefix = "", - extension = ".exe", - ), - ] - else: - artifact_name_patterns = [] + if "mingw" in ctx.attr.target_full_name: + artifact_name_patterns = [ + artifact_name_pattern( + category_name = "executable", + prefix = "", + extension = ".exe", + ), + ] + else: + artifact_name_patterns = [] - tool_paths = [ - tool_path( - name = "gcc", - path = "/usr/local/bin/clang", - ), - tool_path( - name = "ld", - path = ctx.attr.linker_path, - ), - tool_path( - name = "ar", - path = "/usr/local/bin/llvm-ar", - ), - tool_path( - name = "compat-ld", - path = ctx.attr.linker_path, - ), - tool_path( - name = "cpp", - path = "/bin/false", - ), - tool_path( - name = "dwp", - path = "/bin/false", - ), - tool_path( - name = "gcov", - path = "/bin/false", - ), - tool_path( - name = "nm", - path = "/bin/false", - ), - tool_path( - name = "objcopy", - path = "/bin/false", - ), - tool_path( - name = "objdump", - path = "/bin/false", - ), - tool_path( - name = "strip", - path = "/bin/false", - ), - ] + tool_paths = [ + tool_path( + name = "gcc", + path = "/usr/local/bin/clang", + ), + tool_path( + name = "ld", + path = ctx.attr.linker_path, + ), + tool_path( + name = "ar", + path = "/usr/local/bin/llvm-ar", + ), + tool_path( + name = "compat-ld", + path = ctx.attr.linker_path, + ), + tool_path( + name = "cpp", + path = "/bin/false", + ), + tool_path( + name = "dwp", + path = "/bin/false", + ), + tool_path( + name = "gcov", + path = "/bin/false", + ), + tool_path( + name = "nm", + path = "/bin/false", + ), + tool_path( + name = "objcopy", + path = "/bin/false", + ), + tool_path( + name = "objdump", + path = "/bin/false", + ), + tool_path( + name = "strip", + path = "/bin/false", + ), + ] - linker_flags = feature( - name = "default_linker_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = [ - "-B" + ctx.attr.linker_path, - "-lstdc++", - "--target=" + ctx.attr.target_full_name, - ] + ctx.attr.extra_linker_flags, - ), - ], - ), - ], - ) + linker_flags = feature( + name = "default_linker_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + flags = [ + "-B" + ctx.attr.linker_path, + "-lstdc++", + "--target=" + ctx.attr.target_full_name, + ] + ctx.attr.extra_linker_flags, + ), + ], + ), + ], + ) - if "osx" in ctx.attr.target_full_name: - sysroot_action_set = all_link_actions - else: - sysroot_action_set = all_link_actions + all_compile_actions + if "osx" in ctx.attr.target_full_name: + sysroot_action_set = all_link_actions + else: + sysroot_action_set = all_link_actions + all_compile_actions - sysroot_flags = feature( - name = "sysroot_flags", - #Only enable this if a sysroot was specified - enabled = (ctx.attr.sysroot != ""), - flag_sets = [ - flag_set( - actions = sysroot_action_set, - flag_groups = [ - flag_group( - flags = [ - "--sysroot", - ctx.attr.sysroot, - ], - ), - ], - ), - ], - ) + sysroot_flags = feature( + name = "sysroot_flags", + #Only enable this if a sysroot was specified + enabled = (ctx.attr.sysroot != ""), + flag_sets = [ + flag_set( + actions = sysroot_action_set, + flag_groups = [ + flag_group( + flags = [ + "--sysroot", + ctx.attr.sysroot, + ], + ), + ], + ), + ], + ) - if ctx.attr.target_cpu == "x86_32": - bit_flag = "-m32" - else: - bit_flag = "-m64" - compiler_flags = feature( - name = "default_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = [ - bit_flag, - "-Wall", - "-no-canonical-prefixes", - "--target=" + ctx.attr.target_full_name, - "-fvisibility=hidden", - ] + ctx.attr.extra_compiler_flags + [ - "-isystem", - ctx.attr.sysroot, - ], - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [flag_group(flags = ["-DNDEBUG", "-O3"])], - with_features = [with_feature_set(features = ["opt"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [flag_group(flags = ["-g"])], - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [flag_group(flags = ["-O1"])], - with_features = [with_feature_set(features = ["fastbuild"])], - ), - ], - ) + if ctx.attr.target_cpu == "x86_32": + bit_flag = "-m32" + else: + bit_flag = "-m64" + compiler_flags = feature( + name = "default_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = [ + bit_flag, + "-Wall", + "-no-canonical-prefixes", + "--target=" + ctx.attr.target_full_name, + "-fvisibility=hidden", + ] + ctx.attr.extra_compiler_flags + [ + "-isystem", + ctx.attr.sysroot, + ], + ), + ], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [flag_group(flags = ["-DNDEBUG", "-O3"])], + with_features = [with_feature_set(features = ["opt"])], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [flag_group(flags = ["-g"])], + with_features = [with_feature_set(features = ["dbg"])], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [flag_group(flags = ["-O1"])], + with_features = [with_feature_set(features = ["fastbuild"])], + ), + ], + ) - features = [ - linker_flags, - compiler_flags, - sysroot_flags, - feature(name = "dbg"), - feature(name = "opt"), - ] + features = [ + linker_flags, + compiler_flags, + sysroot_flags, + feature(name = "dbg"), + feature(name = "opt"), + ] - if "mingw" in ctx.attr.target_full_name: - features.append( - feature( - name = "targets_windows", - enabled = True, - ) - ) - else: - features.append( - feature( - name = "supports_pic", - enabled = True - ) - ) + if "mingw" in ctx.attr.target_full_name: + features.append( + feature( + name = "targets_windows", + enabled = True, + ), + ) + else: + features.append( + feature( + name = "supports_pic", + enabled = True, + ), + ) - return cc_common.create_cc_toolchain_config_info( - abi_libc_version = ctx.attr.abi_version, - abi_version = ctx.attr.abi_version, - artifact_name_patterns = artifact_name_patterns, - ctx = ctx, - compiler = "clang", - cxx_builtin_include_directories = [ - ctx.attr.sysroot, - ctx.attr.extra_include, - "/usr/local/include", - "/usr/local/lib/clang", - ], - features = features, - host_system_name = "local", - target_cpu = ctx.attr.target_cpu, - target_libc = ctx.attr.target_cpu, - target_system_name = ctx.attr.target_full_name, - toolchain_identifier = ctx.attr.target_full_name, - tool_paths = tool_paths, - ) + return cc_common.create_cc_toolchain_config_info( + abi_libc_version = ctx.attr.abi_version, + abi_version = ctx.attr.abi_version, + artifact_name_patterns = artifact_name_patterns, + ctx = ctx, + compiler = "clang", + cxx_builtin_include_directories = [ + ctx.attr.sysroot, + ctx.attr.extra_include, + "/usr/local/include", + "/usr/local/lib/clang", + ], + features = features, + host_system_name = "local", + target_cpu = ctx.attr.target_cpu, + target_libc = ctx.attr.target_cpu, + target_system_name = ctx.attr.target_full_name, + toolchain_identifier = ctx.attr.target_full_name, + tool_paths = tool_paths, + ) cc_toolchain_config = rule( implementation = _impl,