diff --git a/.github/workflows/cmake-android.yml b/.github/workflows/cmake-android.yml index 0652b01fa4..2f3a8157a9 100644 --- a/.github/workflows/cmake-android.yml +++ b/.github/workflows/cmake-android.yml @@ -45,7 +45,7 @@ jobs: run: sudo apt-get update && sudo apt-get install -y ninja-build - name: configure - run: cmake --preset with-sccache -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_WPILIB=OFF -DWITH_GUI=OFF -DWITH_CSCORE=OFF -DWITH_TESTS=OFF -DWITH_SIMULATION_MODULES=OFF -DWITH_PROTOBUF=OFF -DWITH_JAVA=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=${{ steps.setup-ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake -DANDROID_ABI="${{ matrix.abi }}" -DANDROID_PLATFORM=android-24 + run: cmake --preset with-sccache -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_WPILIB=OFF -DWITH_GUI=OFF -DWITH_CSCORE=OFF -DWITH_TESTS=OFF -DWITH_SIMULATION_MODULES=OFF -DWITH_JAVA=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=${{ steps.setup-ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake -DANDROID_ABI="${{ matrix.abi }}" -DANDROID_PLATFORM=android-24 - name: build run: cmake --build build-cmake --parallel $(nproc) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index d55c42c3d9..19f9b9546e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -23,7 +23,6 @@ jobs: - os: macOS-14 name: macOS container: "" - env: "" flags: "--preset with-sccache -DCMAKE_BUILD_TYPE=Release -DWITH_EXAMPLES=ON" - os: windows-2022 name: Windows @@ -36,11 +35,11 @@ jobs: steps: - name: Install dependencies (Linux) if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y libopencv-dev libopencv-java libprotobuf-dev protobuf-compiler ninja-build + run: sudo apt-get update && sudo apt-get install -y libopencv-dev libopencv-java ninja-build - name: Install dependencies (macOS) if: runner.os == 'macOS' - run: brew install opencv protobuf@29 ninja + run: brew install opencv ninja - uses: ilammy/msvc-dev-cmd@v1.13.0 if: runner.os == 'Windows' diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index 7c2b404fcf..f4e5f00b10 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -33,7 +33,7 @@ jobs: container: wpilib/roborio-cross-ubuntu:2025-24.04 steps: - name: Install Dependencies - run: sudo apt-get update && sudo apt-get install -y libopencv-dev libopencv-java clang-18 libprotobuf-dev protobuf-compiler ninja-build + run: sudo apt-get update && sudo apt-get install -y libopencv-dev libopencv-java clang-18 ninja-build - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 diff --git a/.github/workflows/upstream-utils.yml b/.github/workflows/upstream-utils.yml index dbad7c1e7e..3cb0135e1e 100644 --- a/.github/workflows/upstream-utils.yml +++ b/.github/workflows/upstream-utils.yml @@ -120,12 +120,6 @@ jobs: ./mpack.py clone ./mpack.py copy-src ./mpack.py format-patch - - name: Run protobuf.py - run: | - cd upstream_utils - ./protobuf.py clone - ./protobuf.py copy-src - ./protobuf.py format-patch - name: Run sleipnir.py run: | cd upstream_utils @@ -138,6 +132,12 @@ jobs: ./stb.py clone ./stb.py copy-src ./stb.py format-patch + - name: Run upb.py + run: | + cd upstream_utils + ./upb.py clone + ./upb.py copy-src + ./upb.py format-patch - name: Add untracked files to index so they count as changes run: git add -A - name: Check output diff --git a/.styleguide b/.styleguide index a23842e2f5..b4cebdb3d0 100644 --- a/.styleguide +++ b/.styleguide @@ -35,7 +35,6 @@ includeOtherLibs { ^cscore ^fmt/ ^glass/ - ^google/ ^gtest/ ^hal/ ^imgui @@ -47,6 +46,7 @@ includeOtherLibs { ^support/ ^units/ ^unsupported/ + ^upb/ ^vision/ ^wpi/ ^wpigui diff --git a/CMakeLists.txt b/CMakeLists.txt index accb155171..affa07e55c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,7 +90,6 @@ option(WITH_EXAMPLES "Build examples" OFF) option(WITH_TESTS "Build unit tests (requires internet connection)" ON) option(WITH_GUI "Build GUI items" ON) option(WITH_SIMULATION_MODULES "Build simulation modules" ON) -option(WITH_PROTOBUF "Build protobuf support" ON) option(WITH_BENCHMARK "Build the benchmark project" ON) # Options for using a package manager (e.g., vcpkg) for certain dependencies. @@ -151,14 +150,6 @@ endif() find_package(LIBSSH CONFIG 0.7.1) -set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) -if(WITH_PROTOBUF) - set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "" FORCE) - find_package(Protobuf REQUIRED) - find_program(PROTOC_COMPILER protoc REQUIRED) -endif() -set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF) - get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(isMultiConfig) diff --git a/README-CMake.md b/README-CMake.md index f9f6c568ba..eaa954d2d1 100644 --- a/README-CMake.md +++ b/README-CMake.md @@ -31,8 +31,6 @@ By default, all libraries get built with a default CMake setup. The libraries ar ## Prerequisites -The protobuf library and compiler are needed for protobuf generation. - OpenCV needs to be findable by CMake. On systems like the Jetson, this is installed by default. Otherwise, you will need to build OpenCV from source and install it. If you want JNI and Java, you will need a JDK of at least version 21 installed. In addition, you need a `JAVA_HOME` environment variable set properly and set to the JDK directory. @@ -65,8 +63,6 @@ The following build options are available: * This option will build the HAL and wpilibc/j during the build. The HAL is the simulation HAL, unless the external HAL options are used. The CMake build has no capability to build for the roboRIO. * `WITH_WPIMATH` (ON Default) * This option will build the wpimath library. This option must be on to build wpilib. -* `WITH_PROTOBUF` (ON Default) - * This option will build with the protobuf library. * `WITH_WPIUNITS` (`WITH_JAVA` Default) * This option will build the wpiunits library. This option must be on to build the Java wpimath library and requires `WITH_JAVA` to also be on. * `OPENCV_JAVA_INSTALL_DIR` @@ -90,8 +86,6 @@ If you want to change any of the options, add `-DOPTIONHERE=VALUE` to the `cmake If you want, you can also use `ccmake` in order to visually set these properties as well. [Here](https://cmake.org/cmake/help/v3.0/manual/ccmake.1.html) is the link to the documentation for that program. On Windows, you can use `cmake-gui` instead. -Note that if you are cross-compiling, you will need to override the protobuf options manually to point to the libraries for the target platform. Leave the protoc binary location as the path to the binary for the host platform, since protoc needs to execute on the host platform. - ## Presets The WPILib CMake setup has a variety of presets for common configurations and options used. The default sets the generator to Ninja and build directory to `build-cmake`. The other presets are `with-java` (sets `WITH_JAVA=ON`), `sccache` (sets the C/C++ compiler launcher to sccache), and `with-java-sccache` (a comibination of `with-java` and `sccache`. @@ -118,7 +112,7 @@ sudo cmake --build . --target install ## Preparing to use the installed libraries -On Windows, make sure the directories for the libraries you built are on PATH. For wpilib, the default install location is `C:\Program Files (x86)\allwpilib`. If you built other libraries like OpenCV and protobuf from source, install them, and add the install directories to PATH. This ensures CMake can locate the libraries. +On Windows, make sure the directories for the libraries you built are on PATH. For wpilib, the default install location is `C:\Program Files (x86)\allwpilib`. If you built other libraries like OpenCV from source, install them, and add the install directories to PATH. This ensures CMake can locate the libraries. You will also want to add the directories where the DLLs are located (usually the `bin` subdirectory of the install directory) to PATH so they can be loaded by your program. If you are using OpenCV and Java, the `opencv_java` DLL is located in either the `lib` subdirectory if you built but didn't install OpenCV, or the `java` subdirectory if you did install OpenCV. @@ -234,6 +228,6 @@ Last Load Error: C:\Program Files (x86)\allwpilib\bin\wpiHaljni.dll: Can't find dependent libraries ``` -If you get this error, that's usually an indication that not all your libraries are in your PATH. The two libraries that should be in your PATH are OpenCV and protobuf. If the error is coming from cscore, it's likely you're missing OpenCV. Otherwise, it's likely you're missing protobuf. +If you get this error, that's usually an indication that not all your libraries are in your PATH. If the error is coming from cscore specifically, it's likely you're missing OpenCV. Otherwise, it's likely the wpilib libraries are not in a directory on PATH. Note that Linux will not have this specific type of error, as it will usually tell you the dependent library you are missing. In that case, you most likely need to add the library to `LD_LIBRARY_PATH`. diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt index f927bf85ae..2654e20852 100644 --- a/ThirdPartyNotices.txt +++ b/ThirdPartyNotices.txt @@ -49,7 +49,7 @@ glfw thirdparty/imgui_suite/glfw Dear ImGui thirdparty/imgui_suite/imgui implot thirdparty/imgui_suite/implot nanopb wpiutil/src/main/native/thirdparty/nanopb -protobuf wpiutil/src/main/native/thirdparty/protobuf +upb wpiutil/src/main/native/thirdparty/upb mrcal wpical/src/main/native/thirdparty/mrcal libdogleg wpical/src/main/native/thirdparty/libdogleg Simd hal/src/main/native/athena/simd @@ -1355,7 +1355,7 @@ redistribute it freely, subject to the following restrictions: distribution. ================ -protobuf License +upb License ================ Copyright 2008 Google Inc. All rights reserved. diff --git a/cmake/modules/AddDoxygenDocs.cmake b/cmake/modules/AddDoxygenDocs.cmake index c307587b43..1df4f4d99d 100644 --- a/cmake/modules/AddDoxygenDocs.cmake +++ b/cmake/modules/AddDoxygenDocs.cmake @@ -17,7 +17,7 @@ macro(add_doxygen_docs) foreach(dir ${dirs}) list(APPEND docs_dirs ${dir}/src/main/native/include) file(GLOB dirs ${dir}/src/main/native/thirdparty/*/include) - list(FILTER dirs EXCLUDE REGEX eigen|protobuf) + list(FILTER dirs EXCLUDE REGEX eigen) set(DOXYGEN_EXCLUDE_PATTERNS "*.pb.h" "**/.clang-tidy" "**/.clang-format") if(DOCS_WARNINGS_AS_ERRORS) diff --git a/cmake/modules/AddTest.cmake b/cmake/modules/AddTest.cmake index b916f6f2cc..224cffa3b2 100644 --- a/cmake/modules/AddTest.cmake +++ b/cmake/modules/AddTest.cmake @@ -2,9 +2,6 @@ include(CompileWarnings) macro(wpilib_add_test name srcdir) file(GLOB_RECURSE test_src ${srcdir}/*.cpp) - if(NOT WITH_PROTOBUF) - list(FILTER test_src EXCLUDE REGEX "/proto/") - endif() add_executable(${name}_test ${test_src}) set_property(TARGET ${name}_test PROPERTY FOLDER "tests") wpilib_target_warnings(${name}_test) diff --git a/datalog/.styleguide b/datalog/.styleguide index c2a7b00037..718d2404f4 100644 --- a/datalog/.styleguide +++ b/datalog/.styleguide @@ -21,5 +21,6 @@ repoRootNameOverride { includeOtherLibs { ^fmt/ ^gtest/ + ^upb/ ^wpi/(?!datalog) } diff --git a/datalog/src/main/native/cpp/DataLogReaderThread.cpp b/datalog/src/main/native/cpp/DataLogReaderThread.cpp index 95f9a53921..c7b948204f 100644 --- a/datalog/src/main/native/cpp/DataLogReaderThread.cpp +++ b/datalog/src/main/native/cpp/DataLogReaderThread.cpp @@ -110,13 +110,18 @@ void DataLogReaderThread::ReadMain() { schema, err); } } else if (auto filename = wpi::remove_prefix(name, "/.schema/proto:")) { -#ifndef NO_PROTOBUF // protobuf descriptor handling - if (!m_protoDb.Add(*filename, data)) { + upb_Status status; + status.ok = true; + upb_DefPool_AddFile( + m_protoPool, + google_protobuf_FileDescriptorProto_parse( + reinterpret_cast(data.data()), data.size(), m_arena), + &status); + if (!status.ok) { wpi::print("could not decode protobuf '{}' filename '{}'\n", name, *filename); } -#endif } } diff --git a/datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h b/datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h index e94e4187f2..b9408fea3c 100644 --- a/datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h @@ -13,6 +13,8 @@ #include #include +#include +#include #include #include #include @@ -20,10 +22,6 @@ #include "wpi/datalog/DataLogReader.h" -#ifndef NO_PROTOBUF -#include -#endif - namespace wpi::log { class DataLogReaderRange { @@ -88,9 +86,8 @@ class DataLogReaderThread { } wpi::StructDescriptorDatabase& GetStructDatabase() { return m_structDb; } -#ifndef NO_PROTOBUF - wpi::ProtobufMessageDatabase& GetProtobufDatabase() { return m_protoDb; } -#endif + upb_DefPool* GetProtobufDatabase() { return m_protoPool; } + upb_Arena* GetProtobufArena() { return m_arena; } const wpi::log::DataLogReader& GetReader() const { return m_reader; } @@ -109,9 +106,8 @@ class DataLogReaderThread { std::map> m_entriesByName; wpi::DenseMap m_entriesById; wpi::StructDescriptorDatabase m_structDb; -#ifndef NO_PROTOBUF - wpi::ProtobufMessageDatabase m_protoDb; -#endif + upb_DefPool* m_protoPool = upb_DefPool_New(); + upb_Arena* m_arena = upb_Arena_New(); std::thread m_thread; }; diff --git a/docs/build.gradle b/docs/build.gradle index a97c8c33f4..1e634ca649 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -145,10 +145,9 @@ doxygen.sourceSets.main { exclude '*.pb.h' - // Save space by excluding protobuf and eigen + // Save space by excluding eigen exclude 'Eigen/**' exclude 'unsupported/**' - exclude 'google/protobuf/**' exclude '**/.clang-tidy' exclude '**/.clang-format' diff --git a/glass/.styleguide b/glass/.styleguide index e1943a80e7..c72e55d59c 100644 --- a/glass/.styleguide +++ b/glass/.styleguide @@ -24,12 +24,12 @@ includeOtherLibs { ^fmt/ ^fields/ ^frc/ - ^google/ ^imgui portable-file-dialogs.h ^networktables/ ^ntcore ^units + ^upb/ ^wpi/ ^wpigui ^wpimath/ diff --git a/glass/src/libnt/native/cpp/NetworkTables.cpp b/glass/src/libnt/native/cpp/NetworkTables.cpp index 8d3959f4b6..fb7c9b0c82 100644 --- a/glass/src/libnt/native/cpp/NetworkTables.cpp +++ b/glass/src/libnt/native/cpp/NetworkTables.cpp @@ -25,6 +25,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -33,11 +39,6 @@ #include #include -#ifndef NO_PROTOBUF -#include -#include -#endif - #include "glass/Context.h" #include "glass/DataSource.h" #include "glass/Storage.h" @@ -353,172 +354,218 @@ static void UpdateStructValueSource(NetworkTablesModel& model, } } -#ifndef NO_PROTOBUF static void UpdateProtobufValueSource(NetworkTablesModel& model, NetworkTablesModel::ValueSource* out, - const google::protobuf::Message& msg, + const upb_Message* msg, + const upb_MessageDef* msgDef, std::string_view name, int64_t time) { - auto desc = msg.GetDescriptor(); - out->typeStr = fmt::format("proto:{}", desc->full_name()); + out->typeStr = fmt::format("proto:{}", upb_MessageDef_FullName(msgDef)); + int fieldCount = upb_MessageDef_FieldCount(msgDef); if (!out->valueChildrenMap || - desc->field_count() != static_cast(out->valueChildren.size())) { + fieldCount != static_cast(out->valueChildren.size())) { out->valueChildren.clear(); out->valueChildrenMap = true; - out->valueChildren.reserve(desc->field_count()); - for (int i = 0, end = desc->field_count(); i < end; ++i) { + out->valueChildren.reserve(fieldCount); + for (int i = 0, end = fieldCount; i < end; ++i) { out->valueChildren.emplace_back(); auto& child = out->valueChildren.back(); - child.name = desc->field(i)->name(); + child.name = upb_FieldDef_Name(upb_MessageDef_Field(msgDef, i)); child.path = fmt::format("{}/{}", name, child.name); } } - auto refl = msg.GetReflection(); auto outIt = out->valueChildren.begin(); - for (int fieldNum = 0, end = desc->field_count(); fieldNum < end; - ++fieldNum) { - auto field = desc->field(fieldNum); + for (int fieldNum = 0, end = fieldCount; fieldNum < end; ++fieldNum) { + const upb_FieldDef* field = upb_MessageDef_Field(msgDef, fieldNum); auto& child = *outIt++; - switch (field->cpp_type()) { - case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); + switch (upb_FieldDef_CType(field)) { + case kUpb_CType_Bool: { + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); std::vector v; v.reserve(size); for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedBool(msg, field, i)); + v.emplace_back(upb_Array_Get(arr, i).bool_val); } child.value = nt::Value::MakeBooleanArray(std::move(v), time); } else { - child.value = nt::Value::MakeBoolean(refl->GetBool(msg, field), time); - } - child.UpdateFromValue(model, child.path, ""); - break; - case google::protobuf::FieldDescriptor::CPPTYPE_STRING: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); - std::vector v; - v.reserve(size); - for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedString(msg, field, i)); - } - child.value = nt::Value::MakeStringArray(std::move(v), time); - } else { - child.value = - nt::Value::MakeString(refl->GetString(msg, field), time); + child.value = nt::Value::MakeBoolean( + upb_Message_GetFieldByDef(msg, field).bool_val, time); child.UpdateFromValue(model, child.path, ""); } break; - case google::protobuf::FieldDescriptor::CPPTYPE_INT32: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); - std::vector v; - v.reserve(size); - for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedInt32(msg, field, i)); - } - child.value = nt::Value::MakeIntegerArray(std::move(v), time); - } else { - child.value = - nt::Value::MakeInteger(refl->GetInt32(msg, field), time); - } - child.UpdateFromValue(model, child.path, ""); - break; - case google::protobuf::FieldDescriptor::CPPTYPE_INT64: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); - std::vector v; - v.reserve(size); - for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedInt64(msg, field, i)); - } - child.value = nt::Value::MakeIntegerArray(std::move(v), time); - } else { - child.value = - nt::Value::MakeInteger(refl->GetInt64(msg, field), time); - } - child.UpdateFromValue(model, child.path, ""); - break; - case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); - std::vector v; - v.reserve(size); - for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedUInt32(msg, field, i)); - } - child.value = nt::Value::MakeIntegerArray(std::move(v), time); - } else { - child.value = - nt::Value::MakeInteger(refl->GetUInt32(msg, field), time); - } - child.UpdateFromValue(model, child.path, ""); - break; - case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); - std::vector v; - v.reserve(size); - for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedUInt64(msg, field, i)); - } - child.value = nt::Value::MakeIntegerArray(std::move(v), time); - } else { - child.value = - nt::Value::MakeInteger(refl->GetUInt64(msg, field), time); - } - child.UpdateFromValue(model, child.path, ""); - break; - case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); - std::vector v; - v.reserve(size); - for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedFloat(msg, field, i)); - } - child.value = nt::Value::MakeFloatArray(std::move(v), time); - } else { - child.value = nt::Value::MakeFloat(refl->GetFloat(msg, field), time); - } - child.UpdateFromValue(model, child.path, ""); - break; - case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); - std::vector v; - v.reserve(size); - for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedDouble(msg, field, i)); - } - child.value = nt::Value::MakeDoubleArray(std::move(v), time); - } else { - child.value = - nt::Value::MakeDouble(refl->GetDouble(msg, field), time); - } - child.UpdateFromValue(model, child.path, ""); - break; - case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: - if (field->is_repeated()) { - size_t size = refl->FieldSize(msg, field); + } + case kUpb_CType_String: { + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); std::vector v; v.reserve(size); for (size_t i = 0; i < size; ++i) { - v.emplace_back(refl->GetRepeatedEnum(msg, field, i)->name()); + upb_StringView sv = upb_Array_Get(arr, i).str_val; + v.emplace_back(sv.data, sv.size); } child.value = nt::Value::MakeStringArray(std::move(v), time); } else { - child.value = - nt::Value::MakeString(refl->GetEnum(msg, field)->name(), time); + upb_StringView sv = upb_Message_GetFieldByDef(msg, field).str_val; + child.value = nt::Value::MakeString({sv.data, sv.size}, time); + child.UpdateFromValue(model, child.path, ""); + } + break; + } + case kUpb_CType_Int32: { + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); + std::vector v; + v.reserve(size); + for (size_t i = 0; i < size; ++i) { + v.emplace_back(upb_Array_Get(arr, i).int32_val); + } + child.value = nt::Value::MakeIntegerArray(std::move(v), time); + } else { + child.value = nt::Value::MakeInteger( + upb_Message_GetFieldByDef(msg, field).int32_val, time); } child.UpdateFromValue(model, child.path, ""); break; - case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: - if (field->is_repeated()) { + } + case kUpb_CType_Int64: { + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); + std::vector v; + v.reserve(size); + for (size_t i = 0; i < size; ++i) { + v.emplace_back(upb_Array_Get(arr, i).int64_val); + } + child.value = nt::Value::MakeIntegerArray(std::move(v), time); + } else { + child.value = nt::Value::MakeInteger( + upb_Message_GetFieldByDef(msg, field).int64_val, time); + } + child.UpdateFromValue(model, child.path, ""); + break; + } + case kUpb_CType_UInt32: { + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); + std::vector v; + v.reserve(size); + for (size_t i = 0; i < size; ++i) { + v.emplace_back(upb_Array_Get(arr, i).uint32_val); + } + child.value = nt::Value::MakeIntegerArray(std::move(v), time); + } else { + child.value = nt::Value::MakeInteger( + upb_Message_GetFieldByDef(msg, field).uint32_val, time); + } + child.UpdateFromValue(model, child.path, ""); + break; + } + case kUpb_CType_UInt64: { + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); + std::vector v; + v.reserve(size); + for (size_t i = 0; i < size; ++i) { + v.emplace_back(upb_Array_Get(arr, i).uint64_val); + } + child.value = nt::Value::MakeIntegerArray(std::move(v), time); + } else { + child.value = nt::Value::MakeInteger( + upb_Message_GetFieldByDef(msg, field).uint64_val, time); + } + child.UpdateFromValue(model, child.path, ""); + break; + } + case kUpb_CType_Float: { + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); + std::vector v; + v.reserve(size); + for (size_t i = 0; i < size; ++i) { + v.emplace_back(upb_Array_Get(arr, i).float_val); + } + child.value = nt::Value::MakeFloatArray(std::move(v), time); + } else { + child.value = nt::Value::MakeFloat( + upb_Message_GetFieldByDef(msg, field).float_val, time); + } + child.UpdateFromValue(model, child.path, ""); + break; + } + case kUpb_CType_Double: { + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); + std::vector v; + v.reserve(size); + for (size_t i = 0; i < size; ++i) { + v.emplace_back(upb_Array_Get(arr, i).double_val); + } + child.value = nt::Value::MakeDoubleArray(std::move(v), time); + } else { + child.value = nt::Value::MakeDouble( + upb_Message_GetFieldByDef(msg, field).double_val, time); + } + child.UpdateFromValue(model, child.path, ""); + break; + } + case kUpb_CType_Enum: { + const upb_EnumDef* enumDef = upb_FieldDef_EnumSubDef(field); + if (upb_FieldDef_IsRepeated(field)) { + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); + std::vector v; + v.reserve(size); + for (size_t i = 0; i < size; ++i) { + int32_t value = upb_Message_GetFieldByDef(msg, field).int32_val; + const upb_EnumValueDef* enumValueDef = + upb_EnumDef_FindValueByNumber(enumDef, value); + if (enumValueDef) { + const char* name = upb_EnumValueDef_Name(enumValueDef); + v.emplace_back(name); + } else { + v.emplace_back(fmt::format("{}", value)); + } + } + child.value = nt::Value::MakeStringArray(std::move(v), time); + } else { + int32_t value = upb_Message_GetFieldByDef(msg, field).int32_val; + const upb_EnumValueDef* enumValueDef = + upb_EnumDef_FindValueByNumber(enumDef, value); + if (enumValueDef) { + const char* name = upb_EnumValueDef_Name(enumValueDef); + child.value = nt::Value::MakeString(name, time); + } else { + child.value = nt::Value::MakeString(fmt::format("{}", value), time); + } + } + child.UpdateFromValue(model, child.path, ""); + break; + } + case kUpb_CType_Message: { + if (upb_FieldDef_IsRepeated(field)) { if (child.valueChildrenMap) { child.valueChildren.clear(); child.valueChildrenMap = false; } - size_t size = refl->FieldSize(msg, field); + const upb_Array* arr = + upb_Message_GetFieldByDef(msg, field).array_val; + size_t size = upb_Array_Size(arr); child.valueChildren.resize(size); unsigned int i = 0; for (auto&& child2 : child.valueChildren) { @@ -526,23 +573,24 @@ static void UpdateProtobufValueSource(NetworkTablesModel& model, child2.name = fmt::format("[{}]", i); child2.path = fmt::format("{}{}", name, child.name); } - UpdateProtobufValueSource(model, &child2, - refl->GetRepeatedMessage(msg, field, i), + const upb_Message* submsg = upb_Array_Get(arr, i).msg_val; + const upb_MessageDef* submsgDef = upb_FieldDef_MessageSubDef(field); + UpdateProtobufValueSource(model, &child2, submsg, submsgDef, child2.path, time); // recurse ++i; } } else { UpdateProtobufValueSource( - model, &child, - refl->GetMessage(msg, field, - model.GetProtobufDatabase().GetMessageFactory()), - child.path, time); // recurse + model, &child, upb_Message_GetFieldByDef(msg, field).msg_val, + upb_FieldDef_MessageSubDef(field), child.path, time); // recurse } break; + } + case kUpb_CType_Bytes: + break; } } } -#endif static void UpdateJsonValueSource(NetworkTablesModel& model, NetworkTablesModel::ValueSource* out, @@ -817,13 +865,19 @@ void NetworkTablesModel::ValueSource::UpdateFromValue( valueChildren.clear(); } } else if (auto filename = wpi::remove_prefix(typeStr, "proto:")) { -#ifndef NO_PROTOBUF - auto msg = model.m_protoDb.Find(*filename); - if (msg) { - msg->Clear(); + const upb_MessageDef* messageDef = upb_DefPool_FindMessageByName( + model.GetProtobufDatabase(), filename->data()); + if (messageDef) { auto raw = value.GetRaw(); - if (msg->ParseFromArray(raw.data(), raw.size())) { - UpdateProtobufValueSource(model, this, *msg, name, + const upb_MiniTable* miniTable = upb_MessageDef_MiniTable(messageDef); + + upb_Message* message = + upb_Message_New(miniTable, model.GetProtobufArena()); + upb_DecodeStatus status = upb_Decode( + reinterpret_cast(raw.data()), raw.size(), message, + miniTable, nullptr, 0, model.GetProtobufArena()); + if (status == kUpb_DecodeStatus_Ok) { + UpdateProtobufValueSource(model, this, message, messageDef, name, value.last_change()); } else { valueChildren.clear(); @@ -831,9 +885,6 @@ void NetworkTablesModel::ValueSource::UpdateFromValue( } else { valueChildren.clear(); } -#else - valueChildren.clear(); -#endif } else { valueChildren.clear(); } @@ -959,9 +1010,17 @@ void NetworkTablesModel::Update() { wpi::remove_prefix(entry->info.name, "/.schema/proto:"); entry->value.IsRaw() && filename && entry->info.type_str == "proto:FileDescriptorProto") { -#ifndef NO_PROTOBUF // protobuf descriptor handling - if (!m_protoDb.Add(*filename, entry->value.GetRaw())) { + upb_Status status; + status.ok = true; + auto descriptor = entry->value.GetRaw(); + upb_DefPool_AddFile( + m_protoPool, + google_protobuf_FileDescriptorProto_parse( + reinterpret_cast(descriptor.data()), + descriptor.size(), m_arena), + &status); + if (!status.ok) { wpi::print("could not decode protobuf '{}' filename '{}'\n", entry->info.name, *filename); } else { @@ -976,7 +1035,6 @@ void NetworkTablesModel::Update() { } } } -#endif } } } diff --git a/glass/src/libnt/native/include/glass/networktables/NetworkTables.h b/glass/src/libnt/native/include/glass/networktables/NetworkTables.h index 65a6c20363..27cb6d4f0f 100644 --- a/glass/src/libnt/native/include/glass/networktables/NetworkTables.h +++ b/glass/src/libnt/native/include/glass/networktables/NetworkTables.h @@ -16,14 +16,12 @@ #include #include #include +#include +#include #include #include #include -#ifndef NO_PROTOBUF -#include -#endif - #include "glass/Model.h" #include "glass/View.h" @@ -174,9 +172,8 @@ class NetworkTablesModel : public Model { Entry* AddEntry(NT_Topic topic); wpi::StructDescriptorDatabase& GetStructDatabase() { return m_structDb; } -#ifndef NO_PROTOBUF - wpi::ProtobufMessageDatabase& GetProtobufDatabase() { return m_protoDb; } -#endif + upb_DefPool* GetProtobufDatabase() { return m_protoPool; } + upb_Arena* GetProtobufArena() { return m_arena; } private: void RebuildTree(); @@ -199,9 +196,8 @@ class NetworkTablesModel : public Model { Client m_server; wpi::StructDescriptorDatabase m_structDb; -#ifndef NO_PROTOBUF - wpi::ProtobufMessageDatabase m_protoDb; -#endif + upb_DefPool* m_protoPool = upb_DefPool_New(); + upb_Arena* m_arena = upb_Arena_New(); }; using NetworkTablesFlags = int; diff --git a/upstream_utils/protobuf.py b/upstream_utils/protobuf.py deleted file mode 100755 index 9882c735b1..0000000000 --- a/upstream_utils/protobuf.py +++ /dev/null @@ -1,269 +0,0 @@ -#!/usr/bin/env python3 - -import os -import shutil -from pathlib import Path - -from upstream_utils import Lib, walk_cwd_and_copy_if - -protobuf_lite_sources = { - Path("any_lite.cc"), - Path("arena.cc"), - Path("arenastring.cc"), - Path("arenaz_sampler.cc"), - Path("extension_set.cc"), - Path("generated_enum_util.cc"), - Path("generated_message_tctable_lite.cc"), - Path("generated_message_util.cc"), - Path("implicit_weak_message.cc"), - Path("inlined_string_field.cc"), - Path("io/coded_stream.cc"), - Path("io/io_win32.cc"), - Path("io/strtod.cc"), - Path("io/zero_copy_stream.cc"), - Path("io/zero_copy_stream_impl.cc"), - Path("io/zero_copy_stream_impl_lite.cc"), - Path("map.cc"), - Path("message_lite.cc"), - Path("parse_context.cc"), - Path("repeated_field.cc"), - Path("repeated_ptr_field.cc"), - Path("stubs/bytestream.cc"), - Path("stubs/common.cc"), - Path("stubs/int128.cc"), - Path("stubs/status.cc"), - Path("stubs/statusor.cc"), - Path("stubs/stringpiece.cc"), - Path("stubs/stringprintf.cc"), - Path("stubs/structurally_valid.cc"), - Path("stubs/strutil.cc"), - Path("stubs/time.cc"), - Path("wire_format_lite.cc"), -} - -protobuf_lite_includes = { - Path("google/protobuf/any.h"), - Path("google/protobuf/arena.h"), - Path("google/protobuf/arena_impl.h"), - Path("google/protobuf/arenastring.h"), - Path("google/protobuf/arenaz_sampler.h"), - Path("google/protobuf/endian.h"), - Path("google/protobuf/explicitly_constructed.h"), - Path("google/protobuf/extension_set.h"), - Path("google/protobuf/extension_set_inl.h"), - Path("google/protobuf/generated_enum_util.h"), - Path("google/protobuf/generated_message_tctable_decl.h"), - Path("google/protobuf/generated_message_tctable_impl.h"), - Path("google/protobuf/generated_message_util.h"), - Path("google/protobuf/has_bits.h"), - Path("google/protobuf/implicit_weak_message.h"), - Path("google/protobuf/inlined_string_field.h"), - Path("google/protobuf/io/coded_stream.h"), - Path("google/protobuf/io/io_win32.h"), - Path("google/protobuf/io/strtod.h"), - Path("google/protobuf/io/zero_copy_stream.h"), - Path("google/protobuf/io/zero_copy_stream_impl.h"), - Path("google/protobuf/io/zero_copy_stream_impl_lite.h"), - Path("google/protobuf/map.h"), - Path("google/protobuf/map_entry_lite.h"), - Path("google/protobuf/map_field_lite.h"), - Path("google/protobuf/map_type_handler.h"), - Path("google/protobuf/message_lite.h"), - Path("google/protobuf/metadata_lite.h"), - Path("google/protobuf/parse_context.h"), - Path("google/protobuf/port.h"), - Path("google/protobuf/repeated_field.h"), - Path("google/protobuf/repeated_ptr_field.h"), - Path("google/protobuf/stubs/bytestream.h"), - Path("google/protobuf/stubs/callback.h"), - Path("google/protobuf/stubs/casts.h"), - Path("google/protobuf/stubs/common.h"), - Path("google/protobuf/stubs/hash.h"), - Path("google/protobuf/stubs/logging.h"), - Path("google/protobuf/stubs/macros.h"), - Path("google/protobuf/stubs/map_util.h"), - Path("google/protobuf/stubs/mutex.h"), - Path("google/protobuf/stubs/once.h"), - Path("google/protobuf/stubs/platform_macros.h"), - Path("google/protobuf/stubs/port.h"), - Path("google/protobuf/stubs/status.h"), - Path("google/protobuf/stubs/stl_util.h"), - Path("google/protobuf/stubs/stringpiece.h"), - Path("google/protobuf/stubs/strutil.h"), - Path("google/protobuf/stubs/template_util.h"), - Path("google/protobuf/wire_format_lite.h"), -} -protobuf_sources = { - Path("any.cc"), - Path("any.pb.cc"), - Path("api.pb.cc"), - Path("compiler/importer.cc"), - Path("compiler/parser.cc"), - Path("descriptor.cc"), - Path("descriptor.pb.cc"), - Path("descriptor_database.cc"), - Path("duration.pb.cc"), - Path("dynamic_message.cc"), - Path("empty.pb.cc"), - Path("extension_set_heavy.cc"), - Path("field_mask.pb.cc"), - Path("generated_message_bases.cc"), - Path("generated_message_reflection.cc"), - Path("generated_message_tctable_full.cc"), - Path("io/gzip_stream.cc"), - Path("io/printer.cc"), - Path("io/tokenizer.cc"), - Path("map_field.cc"), - Path("message.cc"), - Path("reflection_ops.cc"), - Path("service.cc"), - Path("source_context.pb.cc"), - Path("struct.pb.cc"), - Path("stubs/substitute.cc"), - Path("text_format.cc"), - Path("timestamp.pb.cc"), - Path("type.pb.cc"), - Path("unknown_field_set.cc"), - Path("util/delimited_message_util.cc"), - Path("util/field_comparator.cc"), - Path("util/field_mask_util.cc"), - Path("util/internal/datapiece.cc"), - Path("util/internal/default_value_objectwriter.cc"), - Path("util/internal/error_listener.cc"), - Path("util/internal/field_mask_utility.cc"), - Path("util/internal/json_escaping.cc"), - Path("util/internal/json_objectwriter.cc"), - Path("util/internal/json_stream_parser.cc"), - Path("util/internal/object_writer.cc"), - Path("util/internal/proto_writer.cc"), - Path("util/internal/protostream_objectsource.cc"), - Path("util/internal/protostream_objectwriter.cc"), - Path("util/internal/type_info.cc"), - Path("util/internal/utility.cc"), - Path("util/json_util.cc"), - Path("util/message_differencer.cc"), - Path("util/time_util.cc"), - Path("util/type_resolver_util.cc"), - Path("wire_format.cc"), - Path("wrappers.pb.cc"), -} - -protobuf_includes = { - Path("google/protobuf/any.pb.h"), - Path("google/protobuf/api.pb.h"), - Path("google/protobuf/compiler/importer.h"), - Path("google/protobuf/compiler/parser.h"), - Path("google/protobuf/descriptor.h"), - Path("google/protobuf/descriptor.pb.h"), - Path("google/protobuf/descriptor_database.h"), - Path("google/protobuf/duration.pb.h"), - Path("google/protobuf/dynamic_message.h"), - Path("google/protobuf/empty.pb.h"), - Path("google/protobuf/field_access_listener.h"), - Path("google/protobuf/field_mask.pb.h"), - Path("google/protobuf/generated_enum_reflection.h"), - Path("google/protobuf/generated_message_bases.h"), - Path("google/protobuf/generated_message_reflection.h"), - Path("google/protobuf/io/gzip_stream.h"), - Path("google/protobuf/io/printer.h"), - Path("google/protobuf/io/tokenizer.h"), - Path("google/protobuf/map_entry.h"), - Path("google/protobuf/map_field.h"), - Path("google/protobuf/map_field_inl.h"), - Path("google/protobuf/message.h"), - Path("google/protobuf/metadata.h"), - Path("google/protobuf/reflection.h"), - Path("google/protobuf/reflection_internal.h"), - Path("google/protobuf/reflection_ops.h"), - Path("google/protobuf/service.h"), - Path("google/protobuf/source_context.pb.h"), - Path("google/protobuf/struct.pb.h"), - Path("google/protobuf/text_format.h"), - Path("google/protobuf/timestamp.pb.h"), - Path("google/protobuf/type.pb.h"), - Path("google/protobuf/unknown_field_set.h"), - Path("google/protobuf/util/delimited_message_util.h"), - Path("google/protobuf/util/field_comparator.h"), - Path("google/protobuf/util/field_mask_util.h"), - Path("google/protobuf/util/json_util.h"), - Path("google/protobuf/util/message_differencer.h"), - Path("google/protobuf/util/time_util.h"), - Path("google/protobuf/util/type_resolver.h"), - Path("google/protobuf/util/type_resolver_util.h"), - Path("google/protobuf/wire_format.h"), - Path("google/protobuf/wrappers.pb.h"), -} - -protobuf_internal_includes = { - Path("google/protobuf/port_def.inc"), - Path("google/protobuf/port_undef.inc"), - Path("google/protobuf/stubs/int128.h"), - Path("google/protobuf/stubs/mathutil.h"), - Path("google/protobuf/stubs/statusor.h"), - Path("google/protobuf/stubs/status_macros.h"), - Path("google/protobuf/stubs/stringprintf.h"), - Path("google/protobuf/stubs/substitute.h"), - Path("google/protobuf/stubs/time.h"), - Path("google/protobuf/util/internal/constants.h"), - Path("google/protobuf/util/internal/datapiece.h"), - Path("google/protobuf/util/internal/default_value_objectwriter.h"), - Path("google/protobuf/util/internal/error_listener.h"), - Path("google/protobuf/util/internal/field_mask_utility.h"), - Path("google/protobuf/util/internal/json_escaping.h"), - Path("google/protobuf/util/internal/json_objectwriter.h"), - Path("google/protobuf/util/internal/json_stream_parser.h"), - Path("google/protobuf/util/internal/location_tracker.h"), - Path("google/protobuf/util/internal/object_location_tracker.h"), - Path("google/protobuf/util/internal/object_source.h"), - Path("google/protobuf/util/internal/object_writer.h"), - Path("google/protobuf/util/internal/proto_writer.h"), - Path("google/protobuf/util/internal/protostream_objectsource.h"), - Path("google/protobuf/util/internal/protostream_objectwriter.h"), - Path("google/protobuf/util/internal/structured_objectwriter.h"), - Path("google/protobuf/util/internal/type_info.h"), - Path("google/protobuf/util/internal/utility.h"), -} - -use_src_files = protobuf_lite_sources | protobuf_sources -use_include_files = ( - protobuf_lite_includes | protobuf_includes | protobuf_internal_includes -) - - -def copy_upstream_src(wpilib_root: Path): - upstream_root = Path(".").absolute() - wpiutil = wpilib_root / "wpiutil" - - # Delete old install - for d in [ - "src/main/native/thirdparty/protobuf/src", - "src/main/native/thirdparty/protobuf/include", - ]: - shutil.rmtree(wpiutil / d, ignore_errors=True) - - # Copy protobuf source files into allwpilib - os.chdir(upstream_root / "src/google/protobuf") - walk_cwd_and_copy_if( - lambda dp, f: dp / f in use_src_files, - wpiutil / "src/main/native/thirdparty/protobuf/src", - ) - - # Copy protobuf header files into allwpilib - os.chdir(upstream_root / "src") - walk_cwd_and_copy_if( - lambda dp, f: dp / f in use_include_files, - wpiutil / "src/main/native/thirdparty/protobuf/include", - ) - - -def main(): - name = "protobuf" - url = "https://github.com/protocolbuffers/protobuf" - tag = "v3.21.12" - - protobuf = Lib(name, url, tag, copy_upstream_src) - protobuf.main() - - -if __name__ == "__main__": - main() diff --git a/upstream_utils/protobuf_patches/0001-Fix-sign-compare-warnings.patch b/upstream_utils/protobuf_patches/0001-Fix-sign-compare-warnings.patch deleted file mode 100644 index 2432a96916..0000000000 --- a/upstream_utils/protobuf_patches/0001-Fix-sign-compare-warnings.patch +++ /dev/null @@ -1,325 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Sat, 10 Jun 2023 14:13:07 -0700 -Subject: [PATCH 01/15] Fix sign-compare warnings - ---- - src/google/protobuf/compiler/importer.cc | 2 +- - src/google/protobuf/compiler/parser.cc | 4 ++-- - src/google/protobuf/io/io_win32.cc | 2 +- - src/google/protobuf/stubs/stringprintf.cc | 4 ++-- - src/google/protobuf/stubs/strutil.cc | 2 +- - src/google/protobuf/stubs/substitute.cc | 2 +- - src/google/protobuf/util/field_mask_util.cc | 2 +- - src/google/protobuf/util/internal/datapiece.cc | 7 +++++++ - .../protobuf/util/internal/default_value_objectwriter.cc | 4 ++-- - .../protobuf/util/internal/default_value_objectwriter.h | 2 +- - src/google/protobuf/util/internal/json_escaping.cc | 6 +++--- - src/google/protobuf/util/internal/json_objectwriter.h | 2 +- - src/google/protobuf/util/internal/json_stream_parser.cc | 8 ++++---- - src/google/protobuf/util/internal/proto_writer.cc | 2 +- - .../protobuf/util/internal/protostream_objectwriter.cc | 2 +- - src/google/protobuf/util/internal/utility.cc | 2 +- - src/google/protobuf/util/json_util.cc | 2 +- - 17 files changed, 31 insertions(+), 24 deletions(-) - -diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc -index f1e26f8bdd1d3619acd8827f9a2a0e6b2acdd124..678e87eb03cc3959a1890327cd1e918cb1896fa3 100644 ---- a/src/google/protobuf/compiler/importer.cc -+++ b/src/google/protobuf/compiler/importer.cc -@@ -398,7 +398,7 @@ DiskSourceTree::DiskFileToVirtualFile(const std::string& disk_file, - int mapping_index = -1; - std::string canonical_disk_file = CanonicalizePath(disk_file); - -- for (int i = 0; i < mappings_.size(); i++) { -+ for (size_t i = 0; i < mappings_.size(); i++) { - // Apply the mapping in reverse. - if (ApplyMapping(canonical_disk_file, mappings_[i].disk_path, - mappings_[i].virtual_path, virtual_file)) { -diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc -index 5bd37d147bc449444f875f89367a208a32a9146e..e36a4a74359fcace20c017f241d58930660b9381 100644 ---- a/src/google/protobuf/compiler/parser.cc -+++ b/src/google/protobuf/compiler/parser.cc -@@ -159,7 +159,7 @@ bool IsLowerUnderscore(const std::string& name) { - } - - bool IsNumberFollowUnderscore(const std::string& name) { -- for (int i = 1; i < name.length(); i++) { -+ for (size_t i = 1; i < name.length(); i++) { - const char c = name[i]; - if (IsNumber(c) && name[i - 1] == '_') { - return true; -@@ -500,7 +500,7 @@ void Parser::LocationRecorder::AttachComments( - if (!trailing->empty()) { - location_->mutable_trailing_comments()->swap(*trailing); - } -- for (int i = 0; i < detached_comments->size(); ++i) { -+ for (size_t i = 0; i < detached_comments->size(); ++i) { - location_->add_leading_detached_comments()->swap((*detached_comments)[i]); - } - detached_comments->clear(); -diff --git a/src/google/protobuf/io/io_win32.cc b/src/google/protobuf/io/io_win32.cc -index 4e8190880918f1ba155d75db76d6c1ee0b003247..78c07d0d771b9c227c6cd930fc91d272fd67500f 100644 ---- a/src/google/protobuf/io/io_win32.cc -+++ b/src/google/protobuf/io/io_win32.cc -@@ -198,7 +198,7 @@ wstring normalize(wstring path) { - // Join all segments. - bool first = true; - std::wstringstream result; -- for (int i = 0; i < segments.size(); ++i) { -+ for (size_t i = 0; i < segments.size(); ++i) { - if (!first) { - result << L'\\'; - } -diff --git a/src/google/protobuf/stubs/stringprintf.cc b/src/google/protobuf/stubs/stringprintf.cc -index a6ad4c0da4080f5241c26176046a3add5247e25c..8b890f47c386f0d6b0ab9fd9928fae03edd076eb 100644 ---- a/src/google/protobuf/stubs/stringprintf.cc -+++ b/src/google/protobuf/stubs/stringprintf.cc -@@ -149,10 +149,10 @@ std::string StringPrintfVector(const char* format, - // or displaying random chunks of memory to users. - - const char* cstr[kStringPrintfVectorMaxArgs]; -- for (int i = 0; i < v.size(); ++i) { -+ for (size_t i = 0; i < v.size(); ++i) { - cstr[i] = v[i].c_str(); - } -- for (int i = v.size(); i < GOOGLE_ARRAYSIZE(cstr); ++i) { -+ for (size_t i = v.size(); i < GOOGLE_ARRAYSIZE(cstr); ++i) { - cstr[i] = &string_printf_empty_block[0]; - } - -diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc -index 594c8eac6a6ebff6d8bc8cc8518e3fd521f24da1..3462e91ff273dc071628f06b91698a0f166514fc 100644 ---- a/src/google/protobuf/stubs/strutil.cc -+++ b/src/google/protobuf/stubs/strutil.cc -@@ -697,7 +697,7 @@ bool safe_parse_positive_int(std::string text, IntType *value_p) { - IntType value = 0; - const IntType vmax = std::numeric_limits::max(); - assert(vmax > 0); -- assert(vmax >= base); -+ assert(static_cast(vmax) >= base); - const IntType vmax_over_base = vmax / base; - const char* start = text.data(); - const char* end = start + text.size(); -diff --git a/src/google/protobuf/stubs/substitute.cc b/src/google/protobuf/stubs/substitute.cc -index d301682ee3377760430839bc5d6530621333e48d..8c75b2562e43d9d4ade3ef187d38e2e81b43e2c7 100644 ---- a/src/google/protobuf/stubs/substitute.cc -+++ b/src/google/protobuf/stubs/substitute.cc -@@ -128,7 +128,7 @@ void SubstituteAndAppend(std::string* output, const char* format, - } - } - -- GOOGLE_DCHECK_EQ(target - output->data(), output->size()); -+ GOOGLE_DCHECK_EQ(target - output->data(), static_cast(output->size())); - } - - } // namespace strings -diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc -index 700e59004a083c731477bcc0bb4d5c36d06f306c..9a40b851a9e51d30b286ff5d89707bf9f279d0c0 100644 ---- a/src/google/protobuf/util/field_mask_util.cc -+++ b/src/google/protobuf/util/field_mask_util.cc -@@ -366,7 +366,7 @@ void FieldMaskTree::RemovePath(const std::string& path, - Node* node = &root_; - const Descriptor* current_descriptor = descriptor; - Node* new_branch_node = nullptr; -- for (int i = 0; i < parts.size(); ++i) { -+ for (size_t i = 0; i < parts.size(); ++i) { - nodes[i] = node; - const FieldDescriptor* field_descriptor = - current_descriptor->FindFieldByName(parts[i]); -diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc -index 3e7aa84da7181e2ab270e181b9f63deb1905542f..56f4a18fa4afc64708938fa5352937cdd17b5747 100644 ---- a/src/google/protobuf/util/internal/datapiece.cc -+++ b/src/google/protobuf/util/internal/datapiece.cc -@@ -53,6 +53,10 @@ namespace { - - template - util::StatusOr ValidateNumberConversion(To after, From before) { -+#ifdef __GNUC__ -+#pragma GCC diagnostic push -+#pragma GCC diagnostic ignored "-Wsign-compare" -+#endif - if (after == before && - MathUtil::Sign(before) == MathUtil::Sign(after)) { - return after; -@@ -62,6 +66,9 @@ util::StatusOr ValidateNumberConversion(To after, From before) { - : std::is_same::value ? DoubleAsString(before) - : FloatAsString(before)); - } -+#ifdef __GNUC__ -+#pragma GCC diagnostic pop -+#endif - } - - // For general conversion between -diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.cc b/src/google/protobuf/util/internal/default_value_objectwriter.cc -index 7f61cdafa7c771a69364c5e9c49667535b16d957..a7d4ce78bd47e0250def474df8937927be9ef116 100644 ---- a/src/google/protobuf/util/internal/default_value_objectwriter.cc -+++ b/src/google/protobuf/util/internal/default_value_objectwriter.cc -@@ -312,7 +312,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren( - std::unordered_map orig_children_map; - - // Creates a map of child nodes to speed up lookup. -- for (int i = 0; i < children_.size(); ++i) { -+ for (size_t i = 0; i < children_.size(); ++i) { - InsertIfNotPresent(&orig_children_map, children_[i]->name_, i); - } - -@@ -389,7 +389,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren( - new_children.push_back(child.release()); - } - // Adds all leftover nodes in children_ to the beginning of new_child. -- for (int i = 0; i < children_.size(); ++i) { -+ for (size_t i = 0; i < children_.size(); ++i) { - if (children_[i] == nullptr) { - continue; - } -diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h -index a9e1673fa1e4ed35ab6890a44eed1d362265d914..1a151ab25951f8b0e1c9c724253b16524b88530a 100644 ---- a/src/google/protobuf/util/internal/default_value_objectwriter.h -+++ b/src/google/protobuf/util/internal/default_value_objectwriter.h -@@ -154,7 +154,7 @@ class PROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { - bool preserve_proto_field_names, bool use_ints_for_enums, - FieldScrubCallBack field_scrub_callback); - virtual ~Node() { -- for (int i = 0; i < children_.size(); ++i) { -+ for (size_t i = 0; i < children_.size(); ++i) { - delete children_[i]; - } - } -diff --git a/src/google/protobuf/util/internal/json_escaping.cc b/src/google/protobuf/util/internal/json_escaping.cc -index e4fa8cf788642e4a9d9c0460c287b1c24891b9fa..c192ddca7aff3984ffcbf82e13585bdf34ad8aae 100644 ---- a/src/google/protobuf/util/internal/json_escaping.cc -+++ b/src/google/protobuf/util/internal/json_escaping.cc -@@ -179,7 +179,7 @@ bool ReadCodePoint(StringPiece str, int index, uint32_t* cp, - // the last unicode code point. - *num_read = 0; - } -- while (*num_left > 0 && index < str.size()) { -+ while (*num_left > 0 && index < static_cast(str.size())) { - uint32_t ch = static_cast(str[index++]); - --(*num_left); - ++(*num_read); -@@ -309,7 +309,7 @@ void JsonEscaping::Escape(strings::ByteSource* input, - while (input->Available() > 0) { - StringPiece str = input->Peek(); - StringPiece escaped; -- int i = 0; -+ size_t i = 0; - int num_read; - bool ok; - bool cp_was_split = num_left > 0; -@@ -349,7 +349,7 @@ void JsonEscaping::Escape(StringPiece input, strings::ByteSink* output) { - const char* p = input.data(); - - bool can_skip_escaping = true; -- for (int i = 0; i < len; i++) { -+ for (size_t i = 0; i < len; i++) { - char c = p[i]; - if (c < 0x20 || c >= 0x7F || c == '"' || c == '<' || c == '>' || - c == '\\') { -diff --git a/src/google/protobuf/util/internal/json_objectwriter.h b/src/google/protobuf/util/internal/json_objectwriter.h -index cb7dff6e9fe79858a73b2c7501106fe8d05ccac5..92348da3b5c3f07e6146136352f976c94fe54340 100644 ---- a/src/google/protobuf/util/internal/json_objectwriter.h -+++ b/src/google/protobuf/util/internal/json_objectwriter.h -@@ -102,7 +102,7 @@ class PROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter { - if (!indent_string.empty()) { - indent_char_ = indent_string[0]; - indent_count_ = indent_string.length(); -- for (int i = 1; i < indent_string.length(); i++) { -+ for (size_t i = 1; i < indent_string.length(); i++) { - if (indent_char_ != indent_string_[i]) { - indent_char_ = '\0'; - indent_count_ = 0; -diff --git a/src/google/protobuf/util/internal/json_stream_parser.cc b/src/google/protobuf/util/internal/json_stream_parser.cc -index 5c34dbccafb9f40249ba3c0b7318b2e897f203dc..e786781f6de23c8a7ea282d061df6032111f6d21 100644 ---- a/src/google/protobuf/util/internal/json_stream_parser.cc -+++ b/src/google/protobuf/util/internal/json_stream_parser.cc -@@ -80,7 +80,7 @@ inline void ReplaceInvalidCodePoints(StringPiece str, - const std::string& replacement, - std::string* dst) { - while (!str.empty()) { -- int n_valid_bytes = internal::UTF8SpnStructurallyValid(str); -+ size_t n_valid_bytes = internal::UTF8SpnStructurallyValid(str); - StringPiece valid_part = str.substr(0, n_valid_bytes); - StrAppend(dst, valid_part); - -@@ -98,7 +98,7 @@ inline void ReplaceInvalidCodePoints(StringPiece str, - - static bool ConsumeKey(StringPiece* input, StringPiece* key) { - if (input->empty() || !IsLetter((*input)[0])) return false; -- int len = 1; -+ size_t len = 1; - for (; len < input->size(); ++len) { - if (!IsAlphanumeric((*input)[len])) { - break; -@@ -113,7 +113,7 @@ static bool ConsumeKey(StringPiece* input, StringPiece* key) { - static bool ConsumeKeyPermissive(StringPiece* input, - StringPiece* key) { - if (input->empty() || !IsLetter((*input)[0])) return false; -- int len = 1; -+ size_t len = 1; - for (; len < input->size(); ++len) { - if (IsKeySeparator((*input)[len])) { - break; -@@ -946,7 +946,7 @@ util::Status JsonStreamParser::ParseKey() { - JsonStreamParser::TokenType JsonStreamParser::GetNextTokenType() { - SkipWhitespace(); - -- int size = p_.size(); -+ size_t size = p_.size(); - if (size == 0) { - // If we ran out of data, report unknown and we'll place the previous parse - // type onto the stack and try again when we have more data. -diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc -index afa5e2e474b6960b8826a40b73615d5dffd971de..11b6df13d8f4f9506e828c39d6e74bc8acceb23d 100644 ---- a/src/google/protobuf/util/internal/proto_writer.cc -+++ b/src/google/protobuf/util/internal/proto_writer.cc -@@ -408,7 +408,7 @@ std::string ProtoWriter::ProtoElement::ToString() const { - if (!ow_->IsRepeated(*(now->parent_field_)) || - now->parent()->parent_field_ != now->parent_field_) { - std::string name = now->parent_field_->name(); -- int i = 0; -+ size_t i = 0; - while (i < name.size() && - (ascii_isalnum(name[i]) || name[i] == '_')) - ++i; -diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc -index ecb219e06e514b1a6ba0e3e343126a75852d0a1d..ce94cfcefb417203f80142c54003efea283f6a1c 100644 ---- a/src/google/protobuf/util/internal/protostream_objectwriter.cc -+++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc -@@ -378,7 +378,7 @@ void ProtoStreamObjectWriter::AnyWriter::StartAny(const DataPiece& value) { - - // Now we know the proto type and can interpret all data fields we gathered - // before the "@type" field. -- for (int i = 0; i < uninterpreted_events_.size(); ++i) { -+ for (size_t i = 0; i < uninterpreted_events_.size(); ++i) { - uninterpreted_events_[i].Replay(this); - } - } -diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc -index 918ee17d9b040ae1bf9d98e3f46f75770c471393..3c4ac086d594d67b334cbc1dc046c281cd59a374 100644 ---- a/src/google/protobuf/util/internal/utility.cc -+++ b/src/google/protobuf/util/internal/utility.cc -@@ -345,7 +345,7 @@ void DeleteWellKnownTypes() { delete well_known_types_; } - - void InitWellKnownTypes() { - well_known_types_ = new std::set; -- for (int i = 0; i < GOOGLE_ARRAYSIZE(well_known_types_name_array_); ++i) { -+ for (size_t i = 0; i < GOOGLE_ARRAYSIZE(well_known_types_name_array_); ++i) { - well_known_types_->insert(well_known_types_name_array_[i]); - } - google::protobuf::internal::OnShutdown(&DeleteWellKnownTypes); -diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc -index c39c10d87b7d8bf6fc18cae1ce459257c45945d6..a9b1c52a73c86d3e3655ba0748f2a82c68bd40ce 100644 ---- a/src/google/protobuf/util/json_util.cc -+++ b/src/google/protobuf/util/json_util.cc -@@ -64,7 +64,7 @@ ZeroCopyStreamByteSink::~ZeroCopyStreamByteSink() { - - void ZeroCopyStreamByteSink::Append(const char* bytes, size_t len) { - while (true) { -- if (len <= buffer_size_) { // NOLINT -+ if (static_cast(len) <= buffer_size_) { // NOLINT - memcpy(buffer_, bytes, len); - buffer_ = static_cast(buffer_) + len; - buffer_size_ -= len; diff --git a/upstream_utils/protobuf_patches/0002-Remove-redundant-move.patch b/upstream_utils/protobuf_patches/0002-Remove-redundant-move.patch deleted file mode 100644 index 527983530e..0000000000 --- a/upstream_utils/protobuf_patches/0002-Remove-redundant-move.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Sat, 10 Jun 2023 14:41:39 -0700 -Subject: [PATCH 02/15] Remove redundant move - ---- - src/google/protobuf/extension_set.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h -index 0e6d0521104d7f721bdbad1dd593233b035c5b85..b5343689ef7c16442995746439bbe8928022c593 100644 ---- a/src/google/protobuf/extension_set.h -+++ b/src/google/protobuf/extension_set.h -@@ -714,7 +714,7 @@ class PROTOBUF_EXPORT ExtensionSet { - static KeyValueFunctor ForEach(Iterator begin, Iterator end, - KeyValueFunctor func) { - for (Iterator it = begin; it != end; ++it) func(it->first, it->second); -- return std::move(func); -+ return func; - } - - // Applies a functor to the pairs in sorted order. diff --git a/upstream_utils/protobuf_patches/0003-Fix-maybe-uninitialized-warnings.patch b/upstream_utils/protobuf_patches/0003-Fix-maybe-uninitialized-warnings.patch deleted file mode 100644 index e7af7b502a..0000000000 --- a/upstream_utils/protobuf_patches/0003-Fix-maybe-uninitialized-warnings.patch +++ /dev/null @@ -1,168 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Sat, 10 Jun 2023 15:00:20 -0700 -Subject: [PATCH 03/15] Fix maybe-uninitialized warnings - ---- - src/google/protobuf/arena.cc | 6 +++--- - src/google/protobuf/arena_impl.h | 4 ++-- - src/google/protobuf/extension_set_inl.h | 2 +- - .../protobuf/generated_message_tctable_lite.cc | 16 ++++++++-------- - src/google/protobuf/io/coded_stream.cc | 2 +- - 5 files changed, 15 insertions(+), 15 deletions(-) - -diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc -index 6ba508a5f0f3436d52ccc326cc932ceed3cd79fa..194404213ee5f6ad05b1e01f2bff23859d60dc56 100644 ---- a/src/google/protobuf/arena.cc -+++ b/src/google/protobuf/arena.cc -@@ -411,7 +411,7 @@ uint64_t ThreadSafeArena::Reset() { - std::pair - ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, - const std::type_info* type) { -- SerialArena* arena; -+ SerialArena* arena = nullptr; - if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && - GetSerialArenaFast(&arena))) { - return arena->AllocateAlignedWithCleanup(n, alloc_policy_.get()); -@@ -421,7 +421,7 @@ ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, - } - - void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) { -- SerialArena* arena; -+ SerialArena* arena = nullptr; - if (PROTOBUF_PREDICT_FALSE(!GetSerialArenaFast(&arena))) { - arena = GetSerialArenaFallback(&thread_cache()); - } -@@ -433,7 +433,7 @@ void* ThreadSafeArena::AllocateAlignedFallback(size_t n, - const std::type_info* type) { - if (alloc_policy_.should_record_allocs()) { - alloc_policy_.RecordAlloc(type, n); -- SerialArena* arena; -+ SerialArena* arena = nullptr; - if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { - return arena->AllocateAligned(n, alloc_policy_.get()); - } -diff --git a/src/google/protobuf/arena_impl.h b/src/google/protobuf/arena_impl.h -index 76727688b558354be18f0c6576db1d4619348ef4..8af70c48f13feece7cf8580e71845ec267ddaddb 100644 ---- a/src/google/protobuf/arena_impl.h -+++ b/src/google/protobuf/arena_impl.h -@@ -482,7 +482,7 @@ class PROTOBUF_EXPORT ThreadSafeArena { - - template - void* AllocateAligned(size_t n, const std::type_info* type) { -- SerialArena* arena; -+ SerialArena* arena = nullptr; - if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && - GetSerialArenaFast(&arena))) { - return arena->AllocateAligned(n, AllocPolicy()); -@@ -492,7 +492,7 @@ class PROTOBUF_EXPORT ThreadSafeArena { - } - - void ReturnArrayMemory(void* p, size_t size) { -- SerialArena* arena; -+ SerialArena* arena = nullptr; - if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { - arena->ReturnArrayMemory(p, size); - } -diff --git a/src/google/protobuf/extension_set_inl.h b/src/google/protobuf/extension_set_inl.h -index e4e711721d4d8690e1e87fc8e31df1b5836d4fd7..50c04cd41feccf6cb5fda2740d6d4adb874645d7 100644 ---- a/src/google/protobuf/extension_set_inl.h -+++ b/src/google/protobuf/extension_set_inl.h -@@ -206,7 +206,7 @@ const char* ExtensionSet::ParseMessageSetItemTmpl( - const char* ptr, const Msg* extendee, internal::InternalMetadata* metadata, - internal::ParseContext* ctx) { - std::string payload; -- uint32_t type_id; -+ uint32_t type_id = 0; - enum class State { kNoTag, kHasType, kHasPayload, kDone }; - State state = State::kNoTag; - -diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc -index 9993811dca3229edc766061c4a8d54933bcb0eba..2268b2be4d4c60c545765469549d73c6a468dac8 100644 ---- a/src/google/protobuf/generated_message_tctable_lite.cc -+++ b/src/google/protobuf/generated_message_tctable_lite.cc -@@ -770,7 +770,7 @@ PROTOBUF_NOINLINE const char* TcParser::SingularVarBigint( - }; - volatile Spill spill = {data.data, msg, table, hasbits}; - -- uint64_t tmp; -+ uint64_t tmp = 0; - PROTOBUF_ASSUME(static_cast(*ptr) < 0); - ptr = ParseVarint(ptr, &tmp); - -@@ -845,7 +845,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedVarint( - auto expected_tag = UnalignedLoad(ptr); - do { - ptr += sizeof(TagType); -- uint64_t tmp; -+ uint64_t tmp = 0; - ptr = ParseVarint(ptr, &tmp); - if (ptr == nullptr) { - return Error(PROTOBUF_TC_PARAM_PASS); -@@ -1001,7 +1001,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularEnum( - } - const char* ptr2 = ptr; // Save for unknown enum case - ptr += sizeof(TagType); // Consume tag -- uint64_t tmp; -+ uint64_t tmp = 0; - ptr = ParseVarint(ptr, &tmp); - if (ptr == nullptr) { - return Error(PROTOBUF_TC_PARAM_PASS); -@@ -1052,7 +1052,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedEnum( - do { - const char* ptr2 = ptr; // save for unknown enum case - ptr += sizeof(TagType); -- uint64_t tmp; -+ uint64_t tmp = 0; - ptr = ParseVarint(ptr, &tmp); - if (ptr == nullptr) { - return Error(PROTOBUF_TC_PARAM_PASS); -@@ -1477,7 +1477,7 @@ const char* TcParser::MpVarint(PROTOBUF_TC_PARAM_DECL) { - - // Parse the value: - const char* ptr2 = ptr; // save for unknown enum case -- uint64_t tmp; -+ uint64_t tmp = 0; - ptr = ParseVarint(ptr, &tmp); - if (ptr == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); - -@@ -1542,7 +1542,7 @@ const char* TcParser::MpRepeatedVarint(PROTOBUF_TC_PARAM_DECL) { - const char* ptr2 = ptr; - uint32_t next_tag; - do { -- uint64_t tmp; -+ uint64_t tmp = 0; - ptr = ParseVarint(ptr2, &tmp); - if (ptr == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); - field.Add(is_zigzag ? WireFormatLite::ZigZagDecode64(tmp) : tmp); -@@ -1554,7 +1554,7 @@ const char* TcParser::MpRepeatedVarint(PROTOBUF_TC_PARAM_DECL) { - const char* ptr2 = ptr; - uint32_t next_tag; - do { -- uint64_t tmp; -+ uint64_t tmp = 0; - ptr = ParseVarint(ptr2, &tmp); - if (ptr == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); - if (is_validated_enum) { -@@ -1575,7 +1575,7 @@ const char* TcParser::MpRepeatedVarint(PROTOBUF_TC_PARAM_DECL) { - const char* ptr2 = ptr; - uint32_t next_tag; - do { -- uint64_t tmp; -+ uint64_t tmp = 0; - ptr = ParseVarint(ptr2, &tmp); - if (ptr == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); - field.Add(static_cast(tmp)); -diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc -index 487e1b8a379b86bfa3097d68a64ee0a727d36cab..53997901f333292f71ac52e7f9c876bd918f7bf6 100644 ---- a/src/google/protobuf/io/coded_stream.cc -+++ b/src/google/protobuf/io/coded_stream.cc -@@ -462,7 +462,7 @@ int64_t CodedInputStream::ReadVarint32Fallback(uint32_t first_byte_or_zero) { - (buffer_end_ > buffer_ && !(buffer_end_[-1] & 0x80))) { - GOOGLE_DCHECK_NE(first_byte_or_zero, 0) - << "Caller should provide us with *buffer_ when buffer is non-empty"; -- uint32_t temp; -+ uint32_t temp = 0; - ::std::pair p = - ReadVarint32FromArray(first_byte_or_zero, buffer_, &temp); - if (!p.first) return -1; diff --git a/upstream_utils/protobuf_patches/0004-Fix-coded_stream-WriteRaw.patch b/upstream_utils/protobuf_patches/0004-Fix-coded_stream-WriteRaw.patch deleted file mode 100644 index 0532b078b0..0000000000 --- a/upstream_utils/protobuf_patches/0004-Fix-coded_stream-WriteRaw.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Sat, 10 Jun 2023 15:03:38 -0700 -Subject: [PATCH 04/15] Fix coded_stream WriteRaw - ---- - src/google/protobuf/implicit_weak_message.h | 2 +- - src/google/protobuf/io/coded_stream.h | 4 ++-- - 2 files changed, 3 insertions(+), 3 deletions(-) - -diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h -index b894ab4809090011f381828857d1674a6b7bff9b..c358c14c06f773d87f5089c75566a5a6fcba13e6 100644 ---- a/src/google/protobuf/implicit_weak_message.h -+++ b/src/google/protobuf/implicit_weak_message.h -@@ -100,7 +100,7 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { - if (data_ == nullptr) { - return target; - } -- return stream->WriteRaw(data_->data(), static_cast(data_->size()), -+ return stream->WriteRaw(data_->data(), data_->size(), - target); - } - -diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h -index c8fc994f916d047c0a7b176e53c9e946ebd752de..6c0dd4ab4099d1d748957af8bfc5f8c59c2aa3d6 100644 ---- a/src/google/protobuf/io/coded_stream.h -+++ b/src/google/protobuf/io/coded_stream.h -@@ -677,8 +677,8 @@ class PROTOBUF_EXPORT EpsCopyOutputStream { - return ptr; - } - -- uint8_t* WriteRaw(const void* data, int size, uint8_t* ptr) { -- if (PROTOBUF_PREDICT_FALSE(end_ - ptr < size)) { -+ uint8_t* WriteRaw(const void* data, size_t size, uint8_t* ptr) { -+ if (PROTOBUF_PREDICT_FALSE(end_ - ptr < static_cast(size))) { - return WriteRawFallback(data, size, ptr); - } - std::memcpy(ptr, data, size); diff --git a/upstream_utils/protobuf_patches/0005-Suppress-enum-enum-conversion-warning.patch b/upstream_utils/protobuf_patches/0005-Suppress-enum-enum-conversion-warning.patch deleted file mode 100644 index 10e0c0d92c..0000000000 --- a/upstream_utils/protobuf_patches/0005-Suppress-enum-enum-conversion-warning.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Sat, 10 Jun 2023 15:13:45 -0700 -Subject: [PATCH 05/15] Suppress enum-enum conversion warning - ---- - src/google/protobuf/generated_message_tctable_impl.h | 9 +++++++++ - 1 file changed, 9 insertions(+) - -diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h -index 21fa5332d39b24e0bdb6432f27183df743d512c6..5aceeb39ae24866e7258d62cf5b025df0ba20fc5 100644 ---- a/src/google/protobuf/generated_message_tctable_impl.h -+++ b/src/google/protobuf/generated_message_tctable_impl.h -@@ -180,6 +180,12 @@ static_assert(kFmtShift + kFmtBits == 12, "number of bits changed"); - // This assertion should not change unless the storage width changes: - static_assert(kFmtShift + kFmtBits <= 16, "too many bits"); - -+#ifdef __GNUC__ -+#pragma GCC diagnostic push -+#if __GNUC__ >= 12 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1) -+#pragma GCC diagnostic ignored "-Wdeprecated-enum-enum-conversion" -+#endif -+#endif - // Convenience aliases (16 bits, with format): - enum FieldType : uint16_t { - // Numeric types: -@@ -232,6 +238,9 @@ enum FieldType : uint16_t { - // Map types: - kMap = kFkMap, - }; -+#ifdef __GNUC__ -+#pragma GCC diagnostic pop -+#endif - - // clang-format on - } // namespace field_layout diff --git a/upstream_utils/protobuf_patches/0006-Fix-noreturn-function-returning.patch b/upstream_utils/protobuf_patches/0006-Fix-noreturn-function-returning.patch deleted file mode 100644 index 7d5f8a6837..0000000000 --- a/upstream_utils/protobuf_patches/0006-Fix-noreturn-function-returning.patch +++ /dev/null @@ -1,23 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Sat, 10 Jun 2023 15:16:46 -0700 -Subject: [PATCH 06/15] Fix noreturn function returning - ---- - src/google/protobuf/generated_message_tctable_impl.h | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h -index 5aceeb39ae24866e7258d62cf5b025df0ba20fc5..c80ac0cd299c126398329c780534156bb1536e15 100644 ---- a/src/google/protobuf/generated_message_tctable_impl.h -+++ b/src/google/protobuf/generated_message_tctable_impl.h -@@ -262,6 +262,9 @@ template - #endif - void AlignFail(uintptr_t address) { - GOOGLE_LOG(FATAL) << "Unaligned (" << align << ") access at " << address; -+#ifdef __GNUC__ -+ __builtin_unreachable(); -+#endif - } - - extern template void AlignFail<4>(uintptr_t); diff --git a/upstream_utils/protobuf_patches/0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch b/upstream_utils/protobuf_patches/0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch deleted file mode 100644 index 54dc40ce3e..0000000000 --- a/upstream_utils/protobuf_patches/0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Sat, 10 Jun 2023 15:59:45 -0700 -Subject: [PATCH 07/15] Work around GCC 12 restrict warning compiler bug - -https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329 ---- - src/google/protobuf/io/tokenizer.cc | 7 +++++++ - 1 file changed, 7 insertions(+) - -diff --git a/src/google/protobuf/io/tokenizer.cc b/src/google/protobuf/io/tokenizer.cc -index f9e07763e7362bd37267619336db841d0ae9df25..30d62ac9647b897c2e7c8ad43cd27ff0e08922a2 100644 ---- a/src/google/protobuf/io/tokenizer.cc -+++ b/src/google/protobuf/io/tokenizer.cc -@@ -585,7 +585,14 @@ Tokenizer::NextCommentStatus Tokenizer::TryConsumeCommentStart() { - } else { - // Oops, it was just a slash. Return it. - current_.type = TYPE_SYMBOL; -+#if defined(__GNUC__) && !defined(__clang__) -+#pragma GCC diagnostic push -+#pragma GCC diagnostic ignored "-Wrestrict" -+#endif - current_.text = "/"; -+#if defined(__GNUC__) && !defined(__clang__) -+#pragma GCC diagnostic pop -+#endif - current_.line = line_; - current_.column = column_ - 1; - current_.end_column = column_; diff --git a/upstream_utils/protobuf_patches/0008-Disable-MSVC-switch-warning.patch b/upstream_utils/protobuf_patches/0008-Disable-MSVC-switch-warning.patch deleted file mode 100644 index 4d2b2e1d34..0000000000 --- a/upstream_utils/protobuf_patches/0008-Disable-MSVC-switch-warning.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Tue, 13 Jun 2023 23:56:15 -0700 -Subject: [PATCH 08/15] Disable MSVC switch warning - ---- - src/google/protobuf/generated_message_reflection.cc | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc -index 2a807e066bb748f214e008971309ef15473344b5..599dde80b671085d87ff1812929cafe8d2aecf75 100644 ---- a/src/google/protobuf/generated_message_reflection.cc -+++ b/src/google/protobuf/generated_message_reflection.cc -@@ -75,6 +75,10 @@ using google::protobuf::internal::RepeatedPtrFieldBase; - using google::protobuf::internal::StringSpaceUsedExcludingSelfLong; - using google::protobuf::internal::WrappedMutex; - -+#ifdef _MSC_VER -+#pragma warning(disable : 4065) -+#endif -+ - namespace google { - namespace protobuf { - diff --git a/upstream_utils/protobuf_patches/0009-Disable-unused-function-warning.patch b/upstream_utils/protobuf_patches/0009-Disable-unused-function-warning.patch deleted file mode 100644 index ffe8ac62e6..0000000000 --- a/upstream_utils/protobuf_patches/0009-Disable-unused-function-warning.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Tue, 13 Jun 2023 23:58:50 -0700 -Subject: [PATCH 09/15] Disable unused function warning - ---- - src/google/protobuf/generated_message_tctable_lite.cc | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc -index 2268b2be4d4c60c545765469549d73c6a468dac8..23557a614752a9f0c93d8bd56724f3bc0f962185 100644 ---- a/src/google/protobuf/generated_message_tctable_lite.cc -+++ b/src/google/protobuf/generated_message_tctable_lite.cc -@@ -43,6 +43,10 @@ - #include - // clang-format on - -+#ifdef __GNUC__ -+#pragma GCC diagnostic ignored "-Wunused-function" -+#endif -+ - namespace google { - namespace protobuf { - namespace internal { diff --git a/upstream_utils/protobuf_patches/0010-Disable-pedantic-warning.patch b/upstream_utils/protobuf_patches/0010-Disable-pedantic-warning.patch deleted file mode 100644 index 5247e190b6..0000000000 --- a/upstream_utils/protobuf_patches/0010-Disable-pedantic-warning.patch +++ /dev/null @@ -1,95 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Wed, 14 Jun 2023 00:02:26 -0700 -Subject: [PATCH 10/15] Disable pedantic warning - ---- - src/google/protobuf/descriptor.h | 8 ++++++++ - src/google/protobuf/generated_message_reflection.cc | 2 ++ - src/google/protobuf/parse_context.h | 8 ++++++++ - src/google/protobuf/stubs/common.cc | 4 ++-- - 4 files changed, 20 insertions(+), 2 deletions(-) - -diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h -index 6e536e5705f8df4f7c13638d50c114cbfb92fb4a..bee3e32b9f1d5ba47b83d1e388716a3c3b6e82c6 100644 ---- a/src/google/protobuf/descriptor.h -+++ b/src/google/protobuf/descriptor.h -@@ -80,6 +80,10 @@ - #define PROTOBUF_EXPORT - #endif - -+#ifdef __GNUC__ -+#pragma GCC diagnostic push -+#pragma GCC diagnostic ignored "-Wpedantic" -+#endif - - namespace google { - namespace protobuf { -@@ -2434,6 +2438,10 @@ inline FileDescriptor::Syntax FileDescriptor::syntax() const { - } // namespace protobuf - } // namespace google - -+#ifdef __GNUC__ -+#pragma GCC diagnostic pop -+#endif -+ - #undef PROTOBUF_INTERNAL_CHECK_CLASS_SIZE - #include - -diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc -index 599dde80b671085d87ff1812929cafe8d2aecf75..aaed21920908b329e22c2e0d92f69397996a9f93 100644 ---- a/src/google/protobuf/generated_message_reflection.cc -+++ b/src/google/protobuf/generated_message_reflection.cc -@@ -77,6 +77,8 @@ using google::protobuf::internal::WrappedMutex; - - #ifdef _MSC_VER - #pragma warning(disable : 4065) -+#elif defined(__GNUC__) -+#pragma GCC diagnostic ignored "-Wpedantic" - #endif - - namespace google { -diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h -index 7aea50cdc385f0ed01b3989e12276494bf574939..97daae09cbff11fd3b4b99cee935aeb542c42eb4 100644 ---- a/src/google/protobuf/parse_context.h -+++ b/src/google/protobuf/parse_context.h -@@ -52,6 +52,10 @@ - // Must be included last. - #include - -+#ifdef __GNUC__ -+#pragma GCC diagnostic push -+#pragma GCC diagnostic ignored "-Wpedantic" -+#endif - - namespace google { - namespace protobuf { -@@ -1020,6 +1024,10 @@ PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* UnknownFieldParse( - } // namespace protobuf - } // namespace google - -+#ifdef __GNUC__ -+#pragma GCC diagnostic pop -+#endif -+ - #include - - #endif // GOOGLE_PROTOBUF_PARSE_CONTEXT_H__ -diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc -index e0a807ffbbc94d07176e20db230204384170607b..1423021b846966eb02d36c10df488f8aa0082a64 100644 ---- a/src/google/protobuf/stubs/common.cc -+++ b/src/google/protobuf/stubs/common.cc -@@ -277,11 +277,11 @@ LogHandler* SetLogHandler(LogHandler* new_func) { - - LogSilencer::LogSilencer() { - ++internal::log_silencer_count_; --}; -+} - - LogSilencer::~LogSilencer() { - --internal::log_silencer_count_; --}; -+} - - // =================================================================== - // emulates google3/base/callback.cc diff --git a/upstream_utils/protobuf_patches/0011-Avoid-use-of-sprintf.patch b/upstream_utils/protobuf_patches/0011-Avoid-use-of-sprintf.patch deleted file mode 100644 index 9d1252eb5c..0000000000 --- a/upstream_utils/protobuf_patches/0011-Avoid-use-of-sprintf.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Johnson -Date: Mon, 9 Oct 2023 19:28:08 -0700 -Subject: [PATCH 11/15] Avoid use of sprintf - ---- - src/google/protobuf/stubs/strutil.cc | 14 +++++++++++--- - 1 file changed, 11 insertions(+), 3 deletions(-) - -diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc -index 3462e91ff273dc071628f06b91698a0f166514fc..58e03d0c4aa7c1b0337b5f650283f00117c12baa 100644 ---- a/src/google/protobuf/stubs/strutil.cc -+++ b/src/google/protobuf/stubs/strutil.cc -@@ -503,10 +503,18 @@ int CEscapeInternal(const char* src, int src_len, char* dest, - (last_hex_escape && isxdigit(*src)))) { - if (dest_len - used < 4) // need space for 4 letter escape - return -1; -- sprintf(dest + used, (use_hex ? "\\x%02x" : "\\%03o"), -- static_cast(*src)); -+ dest[used++] = '\\'; -+ if (use_hex) { -+ constexpr char hexdigits[] = "0123456789abcdef"; -+ dest[used++] = 'x'; -+ dest[used++] = hexdigits[(static_cast(*src) >> 4) & 0xf]; -+ dest[used++] = hexdigits[static_cast(*src) & 0xf]; -+ } else { -+ dest[used++] = '0' + ((static_cast(*src) >> 6) & 0x3); -+ dest[used++] = '0' + ((static_cast(*src) >> 3) & 0x7); -+ dest[used++] = '0' + (static_cast(*src) & 0x7); -+ } - is_hex_escape = use_hex; -- used += 4; - } else { - dest[used++] = *src; break; - } diff --git a/upstream_utils/protobuf_patches/0012-Suppress-stringop-overflow-warning-false-positives.patch b/upstream_utils/protobuf_patches/0012-Suppress-stringop-overflow-warning-false-positives.patch deleted file mode 100644 index 5fc426a621..0000000000 --- a/upstream_utils/protobuf_patches/0012-Suppress-stringop-overflow-warning-false-positives.patch +++ /dev/null @@ -1,50 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Tyler Veness -Date: Fri, 10 Nov 2023 14:17:53 -0800 -Subject: [PATCH 12/15] Suppress stringop-overflow warning false positives - ---- - src/google/protobuf/io/coded_stream.h | 7 +++++++ - src/google/protobuf/unknown_field_set.cc | 7 +++++++ - 2 files changed, 14 insertions(+) - -diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h -index 6c0dd4ab4099d1d748957af8bfc5f8c59c2aa3d6..f43b7ee044673b33410a3ebec6a501ff434d061d 100644 ---- a/src/google/protobuf/io/coded_stream.h -+++ b/src/google/protobuf/io/coded_stream.h -@@ -681,7 +681,14 @@ class PROTOBUF_EXPORT EpsCopyOutputStream { - if (PROTOBUF_PREDICT_FALSE(end_ - ptr < static_cast(size))) { - return WriteRawFallback(data, size, ptr); - } -+#if __GNUC__ >= 12 -+#pragma GCC diagnostic push -+#pragma GCC diagnostic ignored "-Wstringop-overflow=" -+#endif // __GNUC__ >= 12 - std::memcpy(ptr, data, size); -+#if __GNUC__ >= 12 -+#pragma GCC diagnostic pop -+#endif // __GNUC__ >= 12 - return ptr + size; - } - // Writes the buffer specified by data, size to the stream. Possibly by -diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc -index 74c358e9a22c5475bfaef6c5ac63b05fc61b7074..5f6f7a1a298321e562112fed576a7086bd57643c 100644 ---- a/src/google/protobuf/unknown_field_set.cc -+++ b/src/google/protobuf/unknown_field_set.cc -@@ -96,9 +96,16 @@ void UnknownFieldSet::MergeFromAndDestroy(UnknownFieldSet* other) { - if (fields_.empty()) { - fields_ = std::move(other->fields_); - } else { -+#if __GNUC__ >= 12 -+#pragma GCC diagnostic push -+#pragma GCC diagnostic ignored "-Wstringop-overflow=" -+#endif // __GNUC__ >= 12 - fields_.insert(fields_.end(), - std::make_move_iterator(other->fields_.begin()), - std::make_move_iterator(other->fields_.end())); -+#if __GNUC__ >= 12 -+#pragma GCC diagnostic pop -+#endif // __GNUC__ >= 12 - } - other->fields_.clear(); - } diff --git a/upstream_utils/protobuf_patches/0013-Switch-descriptor-to-not-use-globals-from-header-inl.patch b/upstream_utils/protobuf_patches/0013-Switch-descriptor-to-not-use-globals-from-header-inl.patch deleted file mode 100644 index 02833955c8..0000000000 --- a/upstream_utils/protobuf_patches/0013-Switch-descriptor-to-not-use-globals-from-header-inl.patch +++ /dev/null @@ -1,167 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Thad House -Date: Sun, 18 Aug 2024 22:43:37 -0700 -Subject: [PATCH 13/15] Switch descriptor to not use globals from header inline - functions - ---- - src/google/protobuf/descriptor.cc | 66 +++++++++++++++++++------------ - src/google/protobuf/descriptor.h | 20 +++++----- - 2 files changed, 51 insertions(+), 35 deletions(-) - -diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc -index 5f3427dc72497b618c4dea3ec6985eeb39139349..5be05da4fb1c21fb1068ae7341cabef9dcf598a5 100644 ---- a/src/google/protobuf/descriptor.cc -+++ b/src/google/protobuf/descriptor.cc -@@ -791,31 +791,31 @@ class Symbol { - const internal::SymbolBase* ptr_; - }; - --const FieldDescriptor::CppType -- FieldDescriptor::kTypeToCppTypeMap[MAX_TYPE + 1] = { -- static_cast(0), // 0 is reserved for errors -- -- CPPTYPE_DOUBLE, // TYPE_DOUBLE -- CPPTYPE_FLOAT, // TYPE_FLOAT -- CPPTYPE_INT64, // TYPE_INT64 -- CPPTYPE_UINT64, // TYPE_UINT64 -- CPPTYPE_INT32, // TYPE_INT32 -- CPPTYPE_UINT64, // TYPE_FIXED64 -- CPPTYPE_UINT32, // TYPE_FIXED32 -- CPPTYPE_BOOL, // TYPE_BOOL -- CPPTYPE_STRING, // TYPE_STRING -- CPPTYPE_MESSAGE, // TYPE_GROUP -- CPPTYPE_MESSAGE, // TYPE_MESSAGE -- CPPTYPE_STRING, // TYPE_BYTES -- CPPTYPE_UINT32, // TYPE_UINT32 -- CPPTYPE_ENUM, // TYPE_ENUM -- CPPTYPE_INT32, // TYPE_SFIXED32 -- CPPTYPE_INT64, // TYPE_SFIXED64 -- CPPTYPE_INT32, // TYPE_SINT32 -- CPPTYPE_INT64, // TYPE_SINT64 -+static const FieldDescriptor::CppType -+ kTypeToCppTypeMap[FieldDescriptor::MAX_TYPE + 1] = { -+ static_cast(0), // 0 is reserved for errors -+ -+ FieldDescriptor::CPPTYPE_DOUBLE, // TYPE_DOUBLE -+ FieldDescriptor::CPPTYPE_FLOAT, // TYPE_FLOAT -+ FieldDescriptor::CPPTYPE_INT64, // TYPE_INT64 -+ FieldDescriptor::CPPTYPE_UINT64, // TYPE_UINT64 -+ FieldDescriptor::CPPTYPE_INT32, // TYPE_INT32 -+ FieldDescriptor::CPPTYPE_UINT64, // TYPE_FIXED64 -+ FieldDescriptor::CPPTYPE_UINT32, // TYPE_FIXED32 -+ FieldDescriptor::CPPTYPE_BOOL, // TYPE_BOOL -+ FieldDescriptor::CPPTYPE_STRING, // TYPE_STRING -+ FieldDescriptor::CPPTYPE_MESSAGE, // TYPE_GROUP -+ FieldDescriptor::CPPTYPE_MESSAGE, // TYPE_MESSAGE -+ FieldDescriptor::CPPTYPE_STRING, // TYPE_BYTES -+ FieldDescriptor::CPPTYPE_UINT32, // TYPE_UINT32 -+ FieldDescriptor::CPPTYPE_ENUM, // TYPE_ENUM -+ FieldDescriptor::CPPTYPE_INT32, // TYPE_SFIXED32 -+ FieldDescriptor::CPPTYPE_INT64, // TYPE_SFIXED64 -+ FieldDescriptor::CPPTYPE_INT32, // TYPE_SINT32 -+ FieldDescriptor::CPPTYPE_INT64, // TYPE_SINT64 - }; - --const char* const FieldDescriptor::kTypeToName[MAX_TYPE + 1] = { -+static const char* const kTypeToName[FieldDescriptor::MAX_TYPE + 1] = { - "ERROR", // 0 is reserved for errors - - "double", // TYPE_DOUBLE -@@ -838,7 +838,7 @@ const char* const FieldDescriptor::kTypeToName[MAX_TYPE + 1] = { - "sint64", // TYPE_SINT64 - }; - --const char* const FieldDescriptor::kCppTypeToName[MAX_CPPTYPE + 1] = { -+static const char* const kCppTypeToName[FieldDescriptor::MAX_CPPTYPE + 1] = { - "ERROR", // 0 is reserved for errors - - "int32", // CPPTYPE_INT32 -@@ -853,7 +853,7 @@ const char* const FieldDescriptor::kCppTypeToName[MAX_CPPTYPE + 1] = { - "message", // CPPTYPE_MESSAGE - }; - --const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = { -+static const char* const kLabelToName[FieldDescriptor::MAX_LABEL + 1] = { - "ERROR", // 0 is reserved for errors - - "optional", // LABEL_OPTIONAL -@@ -861,6 +861,22 @@ const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = { - "repeated", // LABEL_REPEATED - }; - -+const FieldDescriptor::CppType *FieldDescriptor::GetTypeToCppTypeMap() { -+ return kTypeToCppTypeMap; -+} -+ -+const char* const *FieldDescriptor::GetTypeToName() { -+ return kTypeToName; -+} -+ -+const char* const *FieldDescriptor::GetCppTypeToName() { -+ return kCppTypeToName; -+} -+ -+const char* const *FieldDescriptor::GetLabelToName() { -+ return kLabelToName; -+} -+ - const char* FileDescriptor::SyntaxName(FileDescriptor::Syntax syntax) { - switch (syntax) { - case SYNTAX_PROTO2: -diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h -index bee3e32b9f1d5ba47b83d1e388716a3c3b6e82c6..1cb2421b5362a757abe3735e15321e630b1cab3e 100644 ---- a/src/google/protobuf/descriptor.h -+++ b/src/google/protobuf/descriptor.h -@@ -976,13 +976,13 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { - mutable std::atomic default_generated_instance_; - }; - -- static const CppType kTypeToCppTypeMap[MAX_TYPE + 1]; -+ static const CppType *GetTypeToCppTypeMap(); - -- static const char* const kTypeToName[MAX_TYPE + 1]; -+ static const char* const *GetTypeToName(); - -- static const char* const kCppTypeToName[MAX_CPPTYPE + 1]; -+ static const char* const *GetCppTypeToName(); - -- static const char* const kLabelToName[MAX_LABEL + 1]; -+ static const char* const *GetLabelToName(); - - // Must be constructed using DescriptorPool. - FieldDescriptor() {} -@@ -2392,27 +2392,27 @@ inline int MethodDescriptor::index() const { - } - - inline const char* FieldDescriptor::type_name() const { -- return kTypeToName[type()]; -+ return GetTypeToName()[type()]; - } - - inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const { -- return kTypeToCppTypeMap[type()]; -+ return GetTypeToCppTypeMap()[type()]; - } - - inline const char* FieldDescriptor::cpp_type_name() const { -- return kCppTypeToName[kTypeToCppTypeMap[type()]]; -+ return GetCppTypeToName()[GetTypeToCppTypeMap()[type()]]; - } - - inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) { -- return kTypeToCppTypeMap[type]; -+ return GetTypeToCppTypeMap()[type]; - } - - inline const char* FieldDescriptor::TypeName(Type type) { -- return kTypeToName[type]; -+ return GetTypeToName()[type]; - } - - inline const char* FieldDescriptor::CppTypeName(CppType cpp_type) { -- return kCppTypeToName[cpp_type]; -+ return GetCppTypeToName()[cpp_type]; - } - - inline bool FieldDescriptor::IsTypePackable(Type field_type) { diff --git a/upstream_utils/protobuf_patches/0014-Remove-deprecated-ATOMIC_VAR_INIT.patch b/upstream_utils/protobuf_patches/0014-Remove-deprecated-ATOMIC_VAR_INIT.patch deleted file mode 100644 index cb77aad115..0000000000 --- a/upstream_utils/protobuf_patches/0014-Remove-deprecated-ATOMIC_VAR_INIT.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: braykoff <99614905+Braykoff@users.noreply.github.com> -Date: Mon, 23 Dec 2024 15:12:02 -0500 -Subject: [PATCH 14/15] Remove deprecated ATOMIC_VAR_INIT - ---- - src/google/protobuf/stubs/common.cc | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc -index 1423021b846966eb02d36c10df488f8aa0082a64..a16668a5964398c85c0268d82f652cf3c6aa668e 100644 ---- a/src/google/protobuf/stubs/common.cc -+++ b/src/google/protobuf/stubs/common.cc -@@ -178,7 +178,7 @@ void NullLogHandler(LogLevel /* level */, const char* /* filename */, - } - - static LogHandler* log_handler_ = &DefaultLogHandler; --static std::atomic log_silencer_count_ = ATOMIC_VAR_INIT(0); -+static std::atomic log_silencer_count_{0}; - - LogMessage& LogMessage::operator<<(const std::string& value) { - message_ += value; diff --git a/upstream_utils/upb.py b/upstream_utils/upb.py new file mode 100755 index 0000000000..8d7b73ecee --- /dev/null +++ b/upstream_utils/upb.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 + +import os +import shutil +from pathlib import Path + +from upstream_utils import ( + Lib, + comment_out_invalid_includes, + copy_to, + walk_cwd_and_copy_if, +) + + +def copy_upstream_src(wpilib_root: Path): + upstream_root = Path(".").absolute() + wpiutil = wpilib_root / "wpiutil" + + # Delete old install + for d in [ + "src/main/native/thirdparty/upb/include", + "src/main/native/thirdparty/upb/src", + ]: + shutil.rmtree(wpiutil / d, ignore_errors=True) + + os.chdir(upstream_root / "third_party/utf8_range") + copy_to( + [Path("utf8_range.h")], + wpiutil / "src/main/native/thirdparty/upb/include", + ) + copy_to( + [ + Path("utf8_range.c"), + Path("utf8_range_sse.inc"), + Path("utf8_range_neon.inc"), + ], + wpiutil / "src/main/native/thirdparty/upb/src", + ) + # Change directory to upb to minimize the number of files to walk + os.chdir(upstream_root / "upb") + include_files = walk_cwd_and_copy_if( + lambda dp, f: ( + len(dp.parts) >= 1 + and ( + dp.parts[0] == "base" + or dp.parts[0] == "hash" + or dp.parts[0] == "mem" + or ( + dp.parts[0] == "message" + and "compare" not in f + and "promote" not in f + and "accessors_split64" not in f + ) + or dp.parts[0] == "mini_descriptor" + or (dp.parts[0] == "mini_table" and "compat" not in f) + or dp.parts[0] == "port" + or dp.parts[0] == "reflection" + or ( + dp.parts[0] == "wire" + and "byte_size" not in f + and "decode_fast" not in dp.parts + and "test_util" not in dp.parts + ) + ) + and "cmake" not in dp.parts + ) + and (f.endswith(".h") or f.endswith(".inc")) + or f == "generated_code_support.h", + wpiutil / "src/main/native/thirdparty/upb/include/upb", + ) + for f in include_files: + comment_out_invalid_includes( + f, [wpiutil / "src/main/native/thirdparty/upb/include"] + ) + + walk_cwd_and_copy_if( + lambda dp, f: ( + len(dp.parts) >= 1 + and ( + dp.parts[0] == "base" + or dp.parts[0] == "hash" + or dp.parts[0] == "mem" + or ( + dp.parts[0] == "message" + and "compare" not in f + and "promote" not in f + ) + or dp.parts[0] == "mini_descriptor" + or (dp.parts[0] == "mini_table" and "compat" not in f) + or dp.parts[0] == "port" + or dp.parts[0] == "reflection" + or ( + dp.parts[0] == "wire" + and "byte_size" not in f + and "decode_fast" not in dp.parts + ) + ) + ) + and f.endswith(".c") + and not f == "descriptor.upb_minitable.c", + wpiutil / "src/main/native/thirdparty/upb/src", + ) + + +def main(): + name = "upb" + url = "https://github.com/protocolbuffers/protobuf" + tag = "v32.0" + + upb = Lib(name, url, tag, copy_upstream_src) + upb.main() + + +if __name__ == "__main__": + main() diff --git a/upstream_utils/upb_patches/0001-Remove-patches-as-they-interfere-with-upstream_utils.patch b/upstream_utils/upb_patches/0001-Remove-patches-as-they-interfere-with-upstream_utils.patch new file mode 100644 index 0000000000..47e197d984 --- /dev/null +++ b/upstream_utils/upb_patches/0001-Remove-patches-as-they-interfere-with-upstream_utils.patch @@ -0,0 +1,77 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Sat, 24 May 2025 23:32:48 -0400 +Subject: [PATCH 1/5] Remove patches as they interfere with upstream_utils + +--- + Disable_bundle_install.patch | 37 ------------------------------------ + Neverlink_jruby_jars.patch | 16 ---------------- + 2 files changed, 53 deletions(-) + delete mode 100644 Disable_bundle_install.patch + delete mode 100644 Neverlink_jruby_jars.patch + +diff --git a/Disable_bundle_install.patch b/Disable_bundle_install.patch +deleted file mode 100644 +index baa83832f51813161ab98115a54583bc9dbea741..0000000000000000000000000000000000000000 +--- a/Disable_bundle_install.patch ++++ /dev/null +@@ -1,37 +0,0 @@ +-Subject: [PATCH] Disable bundle install +---- +-Index: ruby/private/bundle_fetch.bzl +-IDEA additional info: +-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +-<+>UTF-8 +-=================================================================== +-diff --git a/ruby/private/bundle_fetch.bzl b/ruby/private/bundle_fetch.bzl +---- a/ruby/private/bundle_fetch.bzl (revision 075937d3f2e22d4657f5c4693e7405d8952ab209) +-+++ b/ruby/private/bundle_fetch.bzl (date 1740971614385) +-@@ -168,16 +168,16 @@ +- ) +- +- # Fetch Bundler and define an `rb_gem_install()` target for it. +-- _download_gem(repository_ctx, gemfile_lock.bundler, cache_path, gemfile_lock.bundler.sha256) +-- gem_full_names.append(":%s" % gemfile_lock.bundler.full_name) +-- gem_install_fragments.append( +-- _GEM_INSTALL_BUILD_FRAGMENT.format( +-- name = gemfile_lock.bundler.full_name, +-- gem = gemfile_lock.bundler.filename, +-- cache_path = cache_path, +-- ruby = ruby_toolchain_attr, +-- ), +-- ) +-+# _download_gem(repository_ctx, gemfile_lock.bundler, cache_path, gemfile_lock.bundler.sha256) +-+# gem_full_names.append(":%s" % gemfile_lock.bundler.full_name) +-+# gem_install_fragments.append( +-+# _GEM_INSTALL_BUILD_FRAGMENT.format( +-+# name = gemfile_lock.bundler.full_name, +-+# gem = gemfile_lock.bundler.filename, +-+# cache_path = cache_path, +-+# ruby = ruby_toolchain_attr, +-+# ), +-+# ) +- +- # Create `bin` package with shims for gem executables. +- # This allows targets to depend on `@bundle//bin:rake` +diff --git a/Neverlink_jruby_jars.patch b/Neverlink_jruby_jars.patch +deleted file mode 100644 +index 48ccca6c7cd656312620b912ff6f465059b63a53..0000000000000000000000000000000000000000 +--- a/Neverlink_jruby_jars.patch ++++ /dev/null +@@ -1,16 +0,0 @@ +-Index: ruby/private/download/BUILD.tpl +-IDEA additional info: +-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +-<+>UTF-8 +-=================================================================== +-diff --git a/ruby/private/download/BUILD.tpl b/ruby/private/download/BUILD.tpl +---- a/ruby/private/download/BUILD.tpl (revision 26e0ba621cb82933f28a59373cb6a7afe54fae95) +-+++ b/ruby/private/download/BUILD.tpl (date 1745340325192) +-@@ -33,6 +33,7 @@ +- ["dist/lib/**/*.jar"], +- allow_empty = True, +- ), +-+ neverlink = True, +- ) +- +- rb_toolchain( diff --git a/upstream_utils/upb_patches/0002-Set-bootstrap-stage-to-0.patch b/upstream_utils/upb_patches/0002-Set-bootstrap-stage-to-0.patch new file mode 100644 index 0000000000..7c48711dd0 --- /dev/null +++ b/upstream_utils/upb_patches/0002-Set-bootstrap-stage-to-0.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Fri, 23 May 2025 23:57:11 -0400 +Subject: [PATCH 2/5] Set bootstrap stage to 0 + +--- + upb/port/def.inc | 2 ++ + upb/reflection/descriptor_bootstrap.h | 2 +- + 2 files changed, 3 insertions(+), 1 deletion(-) + +diff --git a/upb/port/def.inc b/upb/port/def.inc +index d8ccc7b8ffe36d263a1f14731223ca8500ecb376..237aa87648661b05ce9a47fce00561bd2f262b13 100644 +--- a/upb/port/def.inc ++++ b/upb/port/def.inc +@@ -33,6 +33,8 @@ + #error upb requires C99 or C++17 or MSVC >= 2015. + #endif + ++#define UPB_BOOTSTRAP_STAGE 0 ++ + // Portable check for GCC minimum version: + // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html + #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +diff --git a/upb/reflection/descriptor_bootstrap.h b/upb/reflection/descriptor_bootstrap.h +index 8c501447e7ce4f7f404e075cb6be9301470ed0f9..ffb30ea949836dc0c9d1d3f73d0dfccc509e7d0d 100644 +--- a/upb/reflection/descriptor_bootstrap.h ++++ b/upb/reflection/descriptor_bootstrap.h +@@ -2,7 +2,7 @@ + #define GOOGLE_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H__ + + // IWYU pragma: begin_exports +- ++#define UPB_BOOTSTRAP_STAGE 0 + #if defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0 + // This header is checked in. + #include "upb/reflection/stage0/google/protobuf/descriptor.upb.h" diff --git a/upstream_utils/upb_patches/0003-Replace-global-alloc-struct-with-function.patch b/upstream_utils/upb_patches/0003-Replace-global-alloc-struct-with-function.patch new file mode 100644 index 0000000000..d01e2ff9f8 --- /dev/null +++ b/upstream_utils/upb_patches/0003-Replace-global-alloc-struct-with-function.patch @@ -0,0 +1,73 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Sat, 24 May 2025 23:17:42 -0400 +Subject: [PATCH 3/5] Replace global alloc struct with function + +--- + upb/mem/alloc.c | 5 ++++- + upb/mem/alloc.h | 8 ++++---- + upb/mem/arena.h | 4 ++-- + 3 files changed, 10 insertions(+), 7 deletions(-) + +diff --git a/upb/mem/alloc.c b/upb/mem/alloc.c +index 3d70ee768c2473f84129e32c24c6cf3a7f78abef..bb1a635d2926fafa3b4f7dad677dbea482cea2ed 100644 +--- a/upb/mem/alloc.c ++++ b/upb/mem/alloc.c +@@ -25,4 +25,7 @@ static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, + } + } + +-upb_alloc upb_alloc_global = {&upb_global_allocfunc}; ++upb_alloc alloc = {&upb_global_allocfunc}; ++upb_alloc* upb_alloc_global(void) { ++ return &alloc; ++} +diff --git a/upb/mem/alloc.h b/upb/mem/alloc.h +index 04da2337b498cd204b6d196e8b3ddc6ec9e66a7a..d4d7142569469868fd9a241bb0f0169b9918129f 100644 +--- a/upb/mem/alloc.h ++++ b/upb/mem/alloc.h +@@ -76,7 +76,7 @@ UPB_INLINE void upb_free_sized(upb_alloc* alloc, void* ptr, size_t size) { + + // The global allocator used by upb. Uses the standard malloc()/free(). + +-extern upb_alloc upb_alloc_global; ++upb_alloc* upb_alloc_global(void); + + /* Functions that hard-code the global malloc. + * +@@ -84,14 +84,14 @@ extern upb_alloc upb_alloc_global; + * allocator, like injecting out-of-memory faults in debug/testing builds. */ + + UPB_INLINE void* upb_gmalloc(size_t size) { +- return upb_malloc(&upb_alloc_global, size); ++ return upb_malloc(upb_alloc_global(), size); + } + + UPB_INLINE void* upb_grealloc(void* ptr, size_t oldsize, size_t size) { +- return upb_realloc(&upb_alloc_global, ptr, oldsize, size); ++ return upb_realloc(upb_alloc_global(), ptr, oldsize, size); + } + +-UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } ++UPB_INLINE void upb_gfree(void* ptr) { upb_free(upb_alloc_global(), ptr); } + + #ifdef __cplusplus + } /* extern "C" */ +diff --git a/upb/mem/arena.h b/upb/mem/arena.h +index 614ac2e043296a8993f0ac055040ea821c130fd9..24dd3830c2b0b6d403df132062e7a78903c201af 100644 +--- a/upb/mem/arena.h ++++ b/upb/mem/arena.h +@@ -78,11 +78,11 @@ uintptr_t upb_Arena_SpaceAllocated(const upb_Arena* a, size_t* fused_count); + uint32_t upb_Arena_DebugRefCount(const upb_Arena* a); + + UPB_API_INLINE upb_Arena* upb_Arena_New(void) { +- return upb_Arena_Init(NULL, 0, &upb_alloc_global); ++ return upb_Arena_Init(NULL, 0, upb_alloc_global()); + } + + UPB_API_INLINE upb_Arena* upb_Arena_NewSized(size_t size_hint) { +- return upb_Arena_Init(NULL, size_hint, &upb_alloc_global); ++ return upb_Arena_Init(NULL, size_hint, upb_alloc_global()); + } + + UPB_API_INLINE void* upb_Arena_Malloc(struct upb_Arena* a, size_t size); diff --git a/upstream_utils/upb_patches/0004-Cast-key-to-uint64_t-before-doing-a-bit-shift-This-f.patch b/upstream_utils/upb_patches/0004-Cast-key-to-uint64_t-before-doing-a-bit-shift-This-f.patch new file mode 100644 index 0000000000..65b93e3029 --- /dev/null +++ b/upstream_utils/upb_patches/0004-Cast-key-to-uint64_t-before-doing-a-bit-shift-This-f.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Mon, 26 May 2025 01:34:57 -0400 +Subject: [PATCH 4/5] Cast key to uint64_t before doing a bit shift This fixes + compilation on Win32 + +--- + upb/hash/common.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/upb/hash/common.c b/upb/hash/common.c +index ca0e488689e9cc54d143f505484497654d0f8c03..26c731764ce08f4e3f12900821fd1ebd1798da27 100644 +--- a/upb/hash/common.c ++++ b/upb/hash/common.c +@@ -95,7 +95,7 @@ typedef bool eqlfunc_t(upb_key k1, lookupkey_t k2); + + static uint32_t upb_inthash(uintptr_t key) { + if (sizeof(uintptr_t) == 8) { +- return (uint32_t)key ^ (uint32_t)(key >> 32); ++ return (uint32_t)key ^ (uint32_t)((uint64_t)(key) >> 32); + } else { + UPB_ASSERT(sizeof(uintptr_t) == 4); + return (uint32_t)key; diff --git a/upstream_utils/upb_patches/0005-Suppress-warnings.patch b/upstream_utils/upb_patches/0005-Suppress-warnings.patch new file mode 100644 index 0000000000..046d670c52 --- /dev/null +++ b/upstream_utils/upb_patches/0005-Suppress-warnings.patch @@ -0,0 +1,113 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Gold856 <117957790+Gold856@users.noreply.github.com> +Date: Mon, 26 May 2025 01:35:06 -0400 +Subject: [PATCH 5/5] Suppress warnings + +--- + third_party/utf8_range/utf8_range.c | 2 +- + upb/port/def.inc | 24 +++++++++++++++++++ + upb/port/undef.inc | 7 ++++++ + .../stage0/google/protobuf/descriptor.upb.c | 6 ++++- + upb/wire/internal/decoder.h | 2 +- + 5 files changed, 38 insertions(+), 3 deletions(-) + +diff --git a/third_party/utf8_range/utf8_range.c b/third_party/utf8_range/utf8_range.c +index 049e2e21508cf368dab6cd49727ed2e413542f71..3eb4bd7c95df0ea2346987d78d8933872719b230 100644 +--- a/third_party/utf8_range/utf8_range.c ++++ b/third_party/utf8_range/utf8_range.c +@@ -20,11 +20,11 @@ + #include + #include + #include +- + #if defined(__GNUC__) + #define FORCE_INLINE_ATTR __attribute__((always_inline)) inline + #elif defined(_MSC_VER) + #define FORCE_INLINE_ATTR __forceinline ++#pragma warning (disable : 4141) + #else + #define FORCE_INLINE_ATTR inline + #endif +diff --git a/upb/port/def.inc b/upb/port/def.inc +index 237aa87648661b05ce9a47fce00561bd2f262b13..50350e60cbbed1dfab186e7bf30ae821c378f027 100644 +--- a/upb/port/def.inc ++++ b/upb/port/def.inc +@@ -34,6 +34,30 @@ + #endif + + #define UPB_BOOTSTRAP_STAGE 0 ++#if _WIN32 ++#pragma warning(push) ++#pragma warning(disable : 4018 4047 4116 4146 4200 4244 4267 4334 4646 4789) ++#elif defined(__clang__) ++#pragma clang diagnostic push ++#ifdef __cplusplus ++#pragma clang diagnostic ignored "-Wc99-extensions" ++#endif ++#pragma clang diagnostic ignored "-Wsign-compare" ++#pragma clang diagnostic ignored "-Wflexible-array-extensions" ++#elif defined(__GNUC__) ++#pragma GCC diagnostic push ++#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" ++#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" ++#pragma GCC diagnostic ignored "-Wpedantic" ++#ifndef __cplusplus ++#pragma GCC diagnostic ignored "-Wpointer-to-int-cast" ++#endif ++#pragma GCC diagnostic ignored "-Wclobbered" ++#pragma GCC diagnostic ignored "-Wsign-compare" ++#pragma GCC diagnostic ignored "-Wstringop-overflow" ++#pragma GCC diagnostic ignored "-Wstringop-overread" ++#pragma GCC diagnostic ignored "-Wtype-limits" ++#endif + + // Portable check for GCC minimum version: + // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html +diff --git a/upb/port/undef.inc b/upb/port/undef.inc +index 764c81ce69fe63b956c97d337ba6d448c6ac70f9..b1cf7202b51dd350d49987e4e282461f9fa26399 100644 +--- a/upb/port/undef.inc ++++ b/upb/port/undef.inc +@@ -7,6 +7,13 @@ + + // This should #undef all macros #defined in def.inc + ++#if _WIN32 ++#pragma warning(pop) ++#elif defined(__clang__) ++#pragma clang diagnostic pop ++#elif defined(__GNUC__) ++#pragma GCC diagnostic pop ++#endif + #undef UPB_SIZE + #undef UPB_PTR_AT + #undef UPB_SIZEOF_FLEX +diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.c b/upb/reflection/stage0/google/protobuf/descriptor.upb.c +index 9595ce30983144322fc3616a674fce158abeb8a9..e2f59e7702a9bb1d36cfc6bba66bd350006c138f 100644 +--- a/upb/reflection/stage0/google/protobuf/descriptor.upb.c ++++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.c +@@ -1,7 +1,11 @@ + #include + #include "upb/generated_code_support.h" + #include "upb/reflection/descriptor_bootstrap.h" +- ++#ifdef __clang__ ++#pragma clang diagnostic ignored "-Wstrict-prototypes" ++#elif defined(__GNUC__) ++#pragma GCC diagnostic ignored "-Wstrict-prototypes" ++#endif + static upb_Arena* upb_BootstrapArena() { + static upb_Arena* arena = NULL; + if (!arena) arena = upb_Arena_New(); +diff --git a/upb/wire/internal/decoder.h b/upb/wire/internal/decoder.h +index 8f5299d97323760a77d72247b6d1c90034b71194..3c59c6ee69caad2c280b6823079ed0e5ab122c48 100644 +--- a/upb/wire/internal/decoder.h ++++ b/upb/wire/internal/decoder.h +@@ -110,7 +110,7 @@ UPB_INLINE void _upb_Decoder_Trace(upb_Decoder* d, char event) { + d->trace_ptr[1] = '\0'; + d->trace_ptr++; + #endif +-}; ++} + + UPB_INLINE + bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { diff --git a/vcpkg.json b/vcpkg.json index ea1d2a9b5b..fa346b3c59 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -5,7 +5,6 @@ "opencv", "fmt", "libuv", - "protobuf", "libssh" ], "builtin-baseline": "37c3e63a1306562f7f59c4c3c8892ddd50fdf992" diff --git a/wpimath/.styleguide b/wpimath/.styleguide index 91d68ae2b2..80b4f407dd 100644 --- a/wpimath/.styleguide +++ b/wpimath/.styleguide @@ -39,7 +39,6 @@ includeOtherLibs { ^Eigen/ ^fmt/ ^gcem/ - ^google/ ^gtest/ ^unsupported/ ^wpi/ diff --git a/wpimath/src/test/native/cpp/kinematics/proto/DifferentialDriveKinematicsProtoTest.cpp b/wpimath/src/test/native/cpp/kinematics/proto/DifferentialDriveKinematicsProtoTest.cpp index 38323b16f1..247d220fb3 100644 --- a/wpimath/src/test/native/cpp/kinematics/proto/DifferentialDriveKinematicsProtoTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/proto/DifferentialDriveKinematicsProtoTest.cpp @@ -2,7 +2,6 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include #include #include diff --git a/wpimath/src/test/native/cpp/kinematics/proto/SwerveDriveKinematicsProtoTest.cpp b/wpimath/src/test/native/cpp/kinematics/proto/SwerveDriveKinematicsProtoTest.cpp index 776d2b4756..80af48935f 100644 --- a/wpimath/src/test/native/cpp/kinematics/proto/SwerveDriveKinematicsProtoTest.cpp +++ b/wpimath/src/test/native/cpp/kinematics/proto/SwerveDriveKinematicsProtoTest.cpp @@ -2,7 +2,6 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include #include #include "../../ProtoTestBase.h" diff --git a/wpiutil/.styleguide b/wpiutil/.styleguide index 5b2fd08555..6abd1ec7f2 100644 --- a/wpiutil/.styleguide +++ b/wpiutil/.styleguide @@ -43,9 +43,9 @@ repoRootNameOverride { includeOtherLibs { ^fmt/ - ^google/ ^gmock/ ^gtest/ + ^upb/ } includeGuardRoots { diff --git a/wpiutil/BUILD.bazel b/wpiutil/BUILD.bazel index 856b45806e..00dbbb62e6 100644 --- a/wpiutil/BUILD.bazel +++ b/wpiutil/BUILD.bazel @@ -116,12 +116,6 @@ third_party_cc_lib_helper( src_root = "src/main/native/thirdparty/mpack/src", ) -third_party_cc_lib_helper( - name = "protobuf", - include_root = "src/main/native/thirdparty/protobuf/include", - src_root = "src/main/native/thirdparty/protobuf/src", -) - third_party_cc_lib_helper( name = "nanopb", include_root = "src/main/native/thirdparty/nanopb/include", @@ -133,6 +127,12 @@ third_party_cc_lib_helper( include_root = "src/main/native/thirdparty/sigslot/include", ) +third_party_cc_lib_helper( + name = "upb", + include_root = "src/main/native/thirdparty/upb/include", + src_root = "src/main/native/thirdparty/upb/src", +) + generate_resources( name = "generate-resources", namespace = "wpi", @@ -173,7 +173,7 @@ wpilib_cc_library( ":llvm", ":mpack", ":nanopb", - ":protobuf", + ":upb", ], visibility = ["//visibility:public"], deps = select({ diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index d48214e516..e864f541c5 100644 --- a/wpiutil/CMakeLists.txt +++ b/wpiutil/CMakeLists.txt @@ -117,13 +117,9 @@ file( src/main/native/thirdparty/llvm/cpp/*.cpp src/main/native/thirdparty/mpack/src/*.cpp src/main/native/thirdparty/nanopb/src/*.cpp + src/main/native/thirdparty/upb/src/*.c ) list(REMOVE_ITEM wpiutil_native_src ${wpiutil_jni_src}) -if(NOT WITH_PROTOBUF) - list(FILTER wpiutil_native_src EXCLUDE REGEX "/protobuf/") - # Don't filter out protobuf cpp file, it only uses nanopb - list(APPEND wpiutil_native_src src/main/native/cpp/protobuf/Protobuf.cpp) -endif() file(GLOB_RECURSE wpiutil_unix_src src/main/native/unix/*.cpp) file(GLOB_RECURSE wpiutil_linux_src src/main/native/linux/*.cpp) file(GLOB_RECURSE wpiutil_macos_src src/main/native/macOS/*.cpp) @@ -145,12 +141,7 @@ if(MSVC) target_compile_definitions(wpiutil PRIVATE -D_CRT_SECURE_NO_WARNINGS) endif() wpilib_target_warnings(wpiutil) -if(WITH_PROTOBUF) - target_link_libraries(wpiutil protobuf::libprotobuf Threads::Threads ${CMAKE_DL_LIBS}) -else() - target_link_libraries(wpiutil Threads::Threads ${CMAKE_DL_LIBS}) - target_compile_definitions(wpiutil PUBLIC NO_PROTOBUF) -endif() +target_link_libraries(wpiutil Threads::Threads ${CMAKE_DL_LIBS}) if(ATOMIC) target_link_libraries(wpiutil ${ATOMIC}) @@ -201,6 +192,7 @@ install( src/main/native/thirdparty/mpack/include/ src/main/native/thirdparty/nanopb/include/ src/main/native/thirdparty/sigslot/include/ + src/main/native/thirdparty/upb/include/ DESTINATION "${include_dest}/wpiutil" ) target_include_directories( @@ -215,6 +207,7 @@ target_include_directories( $ $ $ + $ $ ) diff --git a/wpiutil/build.gradle b/wpiutil/build.gradle index 8cbf887b0c..af74c02088 100644 --- a/wpiutil/build.gradle +++ b/wpiutil/build.gradle @@ -1,5 +1,6 @@ apply from: "${rootDir}/shared/resources.gradle" +apply plugin: 'c' ext { noWpiutil = true skipJniSymbols = [ @@ -80,15 +81,6 @@ ext { srcDirs 'src/main/native/thirdparty/sigslot/include' } } - protobufCpp(CppSourceSet) { - source { - srcDirs 'src/main/native/thirdparty/protobuf/src' - include '**/*.cpp' - } - exportedHeaders { - srcDirs 'src/main/native/thirdparty/protobuf/include' - } - } resourcesCpp(CppSourceSet) { source { srcDirs "$buildDir/generated/main/cpp", "$rootDir/shared/singlelib" @@ -98,6 +90,15 @@ ext { srcDirs 'src/main/native/include' } } + upbCpp(CSourceSet) { + source { + srcDirs 'src/main/native/thirdparty/upb/src' + include '**/*.c' + } + exportedHeaders { + srcDirs 'src/main/native/thirdparty/upb/include' + } + } } if (!it.targetPlatform.operatingSystem.isWindows()) { it.cppCompiler.define '_GNU_SOURCE' @@ -181,7 +182,7 @@ cppHeadersZip { 'src/main/native/thirdparty/mpack/include', 'src/main/native/thirdparty/nanopb/include', 'src/main/native/thirdparty/sigslot/include', - 'src/main/native/thirdparty/protobuf/include' + 'src/main/native/thirdparty/upb/include' ] thirdpartyIncDirs.each { @@ -211,10 +212,10 @@ cppSourcesZip { from('src/main/native/thirdparty/nanopb/src') { into '/' } - from('src/main/native/thirdparty/protobuf/src') { + from('src/main/native/thirdparty/sigslot/src') { into '/' } - from('src/main/native/thirdparty/sigslot/src') { + from('src/main/native/thirdparty/upb/src') { into '/' } } @@ -224,7 +225,7 @@ model { all { it.sources.each { it.exportedHeaders { - srcDirs 'src/main/native/include', 'src/main/native/thirdparty/argparse/include/', 'src/main/native/thirdparty/debugging/include', 'src/main/native/thirdparty/expected/include', 'src/main/native/thirdparty/fmtlib/include', 'src/main/native/thirdparty/llvm/include', 'src/main/native/thirdparty/sigslot/include', 'src/main/native/thirdparty/json/include', 'src/main/native/thirdparty/mpack/include', 'src/main/native/thirdparty/protobuf/include', 'src/main/native/thirdparty/nanopb/include' + srcDirs 'src/main/native/include', 'src/main/native/thirdparty/argparse/include/', 'src/main/native/thirdparty/debugging/include', 'src/main/native/thirdparty/expected/include', 'src/main/native/thirdparty/fmtlib/include', 'src/main/native/thirdparty/llvm/include', 'src/main/native/thirdparty/sigslot/include', 'src/main/native/thirdparty/json/include', 'src/main/native/thirdparty/mpack/include', 'src/main/native/thirdparty/nanopb/include', 'src/main/native/thirdparty/upb/include' } } } diff --git a/wpiutil/src/main/native/cpp/protobuf/ProtobufMessageDatabase.cpp b/wpiutil/src/main/native/cpp/protobuf/ProtobufMessageDatabase.cpp deleted file mode 100644 index 17a22db809..0000000000 --- a/wpiutil/src/main/native/cpp/protobuf/ProtobufMessageDatabase.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "wpi/protobuf/ProtobufMessageDatabase.h" - -#include -#include - -#include - -#include "wpi/ProtoHelper.h" - -using namespace wpi; - -using google::protobuf::Arena; -using google::protobuf::FileDescriptorProto; -using google::protobuf::Message; - -bool ProtobufMessageDatabase::Add(std::string_view filename, - std::span data) { - auto& file = m_files[filename]; - bool needsRebuild = false; - if (file.complete) { - file.complete = false; - - m_msgs.clear(); - m_factory.reset(); - - // rebuild the pool EXCEPT for this descriptor - m_pool = std::make_unique(); - - for (auto&& p : m_files) { - p.second.inPool = false; - } - - needsRebuild = true; - } - - if (!file.proto) { - file.proto = std::unique_ptr{ - wpi::CreateMessage(nullptr)}; - } else { - // replacing an existing one; remove any previously existing refs - for (auto&& dep : file.proto->dependency()) { - auto& depFile = m_files[dep]; - std::erase(depFile.uses, filename); - } - file.proto->Clear(); - } - - // parse data - if (!file.proto->ParseFromArray(data.data(), data.size())) { - return false; - } - - // rebuild if necessary; we do this after the parse due to dependencies - if (needsRebuild) { - for (auto&& p : m_files) { - if (p.second.complete && !p.second.inPool) { - Rebuild(p.second); - } - } - - // clear messages and reset factory; Find() will recreate as needed - m_factory = std::make_unique(); - } - - // build this one - Build(filename, file); - return true; -} - -Message* ProtobufMessageDatabase::Find(std::string_view name) const { - // cached - auto& msg = m_msgs[name]; - if (msg) { - return msg.get(); - } - - // need to create it - auto desc = m_pool->FindMessageTypeByName(std::string{name}); - if (!desc) { - return nullptr; - } - msg = std::unique_ptr{m_factory->GetPrototype(desc)->New(nullptr)}; - return msg.get(); -} - -void ProtobufMessageDatabase::Build(std::string_view filename, - ProtoFile& file) { - if (file.complete) { - return; - } - // are all of the dependencies complete? - bool complete = true; - for (auto&& dep : file.proto->dependency()) { - auto& depFile = m_files[dep]; - if (!depFile.complete) { - complete = false; - } - depFile.uses.emplace_back(filename); - } - if (!complete) { - return; - } - - // add to pool - if (!m_pool->BuildFile(*file.proto)) { - return; - } - file.inPool = true; - file.complete = true; - - // recursively validate all uses - for (auto&& use : file.uses) { - Build(use, m_files[use]); - } -} - -bool ProtobufMessageDatabase::Rebuild(ProtoFile& file) { - for (auto&& dep : file.proto->dependency()) { - auto& depFile = m_files[dep]; - if (!depFile.inPool) { - if (!Rebuild(depFile)) { - return false; - } - } - } - if (!m_pool->BuildFile(*file.proto)) { - return false; - } - file.inPool = true; - file.complete = true; - return true; -} diff --git a/wpiutil/src/main/native/include/wpi/ProtoHelper.h b/wpiutil/src/main/native/include/wpi/ProtoHelper.h deleted file mode 100644 index 898d7512b9..0000000000 --- a/wpiutil/src/main/native/include/wpi/ProtoHelper.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -namespace wpi { -template -inline T* CreateMessage(google::protobuf::Arena* arena) { -#if GOOGLE_PROTOBUF_VERSION < 4000000 - return google::protobuf::Arena::CreateMessage(arena); -#else - return google::protobuf::Arena::Create(arena); -#endif -} -} // namespace wpi diff --git a/wpiutil/src/main/native/include/wpi/protobuf/ProtobufMessageDatabase.h b/wpiutil/src/main/native/include/wpi/protobuf/ProtobufMessageDatabase.h deleted file mode 100644 index f1ab105abe..0000000000 --- a/wpiutil/src/main/native/include/wpi/protobuf/ProtobufMessageDatabase.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "wpi/StringMap.h" - -namespace wpi { - -/** - * Database of protobuf dynamic messages. Unlike the protobuf descriptor pools - * and databases, this gracefully handles adding descriptors out of order and - * descriptors being replaced. - */ -class ProtobufMessageDatabase { - public: - /** - * Adds a file descriptor to the database. If the file references other - * files that have not yet been added, no messages in that file will be - * available until those files are added. Replaces any existing file with - * the same name. - * - * @param filename filename - * @param data FileDescriptorProto serialized data - * @return False if could not parse data - */ - bool Add(std::string_view filename, std::span data); - - /** - * Finds a message in the database by name. - * - * @param name type name - * @return protobuf message, or nullptr if not found - */ - google::protobuf::Message* Find(std::string_view name) const; - - /** - * Gets message factory. - * - * @return message factory - */ - google::protobuf::MessageFactory* GetMessageFactory() { - return m_factory.get(); - } - - private: - struct ProtoFile { - std::unique_ptr proto; - std::vector uses; - bool complete = false; - bool inPool = false; - }; - - void Build(std::string_view filename, ProtoFile& file); - bool Rebuild(ProtoFile& file); - - std::unique_ptr m_pool = - std::make_unique(); - std::unique_ptr m_factory = - std::make_unique(); - wpi::StringMap m_files; // indexed by filename - // indexed by type string - mutable wpi::StringMap> m_msgs; -}; - -} // namespace wpi diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/any.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/any.h deleted file mode 100644 index 92ea2bb2c7..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/any.h +++ /dev/null @@ -1,157 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_ANY_H__ -#define GOOGLE_PROTOBUF_ANY_H__ - -#include - -#include -#include -#include - -// Must be included last. -#include - -namespace google { -namespace protobuf { - -class FieldDescriptor; -class Message; - -namespace internal { - -extern const char kAnyFullTypeName[]; // "google.protobuf.Any". -extern const char kTypeGoogleApisComPrefix[]; // "type.googleapis.com/". -extern const char kTypeGoogleProdComPrefix[]; // "type.googleprod.com/". - -std::string GetTypeUrl(StringPiece message_name, - StringPiece type_url_prefix); - -// Helper class used to implement google::protobuf::Any. -class PROTOBUF_EXPORT AnyMetadata { - typedef ArenaStringPtr UrlType; - typedef ArenaStringPtr ValueType; - public: - // AnyMetadata does not take ownership of "type_url" and "value". - constexpr AnyMetadata(UrlType* type_url, ValueType* value) - : type_url_(type_url), value_(value) {} - - // Packs a message using the default type URL prefix: "type.googleapis.com". - // The resulted type URL will be "type.googleapis.com/". - // Returns false if serializing the message failed. - template - bool PackFrom(Arena* arena, const T& message) { - return InternalPackFrom(arena, message, kTypeGoogleApisComPrefix, - T::FullMessageName()); - } - - bool PackFrom(Arena* arena, const Message& message); - - // Packs a message using the given type URL prefix. The type URL will be - // constructed by concatenating the message type's full name to the prefix - // with an optional "/" separator if the prefix doesn't already end with "/". - // For example, both PackFrom(message, "type.googleapis.com") and - // PackFrom(message, "type.googleapis.com/") yield the same result type - // URL: "type.googleapis.com/". - // Returns false if serializing the message failed. - template - bool PackFrom(Arena* arena, const T& message, - StringPiece type_url_prefix) { - return InternalPackFrom(arena, message, type_url_prefix, - T::FullMessageName()); - } - - bool PackFrom(Arena* arena, const Message& message, - StringPiece type_url_prefix); - - // Unpacks the payload into the given message. Returns false if the message's - // type doesn't match the type specified in the type URL (i.e., the full - // name after the last "/" of the type URL doesn't match the message's actual - // full name) or parsing the payload has failed. - template - bool UnpackTo(T* message) const { - return InternalUnpackTo(T::FullMessageName(), message); - } - - bool UnpackTo(Message* message) const; - - // Checks whether the type specified in the type URL matches the given type. - // A type is considered matching if its full name matches the full name after - // the last "/" in the type URL. - template - bool Is() const { - return InternalIs(T::FullMessageName()); - } - - private: - bool InternalPackFrom(Arena* arena, const MessageLite& message, - StringPiece type_url_prefix, - StringPiece type_name); - bool InternalUnpackTo(StringPiece type_name, - MessageLite* message) const; - bool InternalIs(StringPiece type_name) const; - - UrlType* type_url_; - ValueType* value_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AnyMetadata); -}; - -// Get the proto type name from Any::type_url value. For example, passing -// "type.googleapis.com/rpc.QueryOrigin" will return "rpc.QueryOrigin" in -// *full_type_name. Returns false if the type_url does not have a "/" -// in the type url separating the full type name. -// -// NOTE: this function is available publicly as a static method on the -// generated message type: google::protobuf::Any::ParseAnyTypeUrl() -bool ParseAnyTypeUrl(StringPiece type_url, std::string* full_type_name); - -// Get the proto type name and prefix from Any::type_url value. For example, -// passing "type.googleapis.com/rpc.QueryOrigin" will return -// "type.googleapis.com/" in *url_prefix and "rpc.QueryOrigin" in -// *full_type_name. Returns false if the type_url does not have a "/" in the -// type url separating the full type name. -bool ParseAnyTypeUrl(StringPiece type_url, std::string* url_prefix, - std::string* full_type_name); - -// See if message is of type google.protobuf.Any, if so, return the descriptors -// for "type_url" and "value" fields. -bool GetAnyFieldDescriptors(const Message& message, - const FieldDescriptor** type_url_field, - const FieldDescriptor** value_field); - -} // namespace internal -} // namespace protobuf -} // namespace google - -#include - -#endif // GOOGLE_PROTOBUF_ANY_H__ diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/any.pb.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/any.pb.h deleted file mode 100644 index 2c0605267c..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/any.pb.h +++ /dev/null @@ -1,384 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/any.proto - -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto - -#include -#include - -#include -#if PROTOBUF_VERSION < 3021000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -// @@protoc_insertion_point(includes) -#include -#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fany_2eproto PROTOBUF_EXPORT -PROTOBUF_NAMESPACE_OPEN -namespace internal { -class AnyMetadata; -} // namespace internal -PROTOBUF_NAMESPACE_CLOSE - -// Internal implementation detail -- do not use these members. -struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fany_2eproto { - static const uint32_t offsets[]; -}; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto; -PROTOBUF_NAMESPACE_OPEN -class Any; -struct AnyDefaultTypeInternal; -PROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_; -PROTOBUF_NAMESPACE_CLOSE -PROTOBUF_NAMESPACE_OPEN -template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Any* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Any>(Arena*); -PROTOBUF_NAMESPACE_CLOSE -PROTOBUF_NAMESPACE_OPEN - -// =================================================================== - -class PROTOBUF_EXPORT Any final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ { - public: - inline Any() : Any(nullptr) {} - ~Any() override; - explicit PROTOBUF_CONSTEXPR Any(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - Any(const Any& from); - Any(Any&& from) noexcept - : Any() { - *this = ::std::move(from); - } - - inline Any& operator=(const Any& from) { - CopyFrom(from); - return *this; - } - inline Any& operator=(Any&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const Any& default_instance() { - return *internal_default_instance(); - } - static inline const Any* internal_default_instance() { - return reinterpret_cast( - &_Any_default_instance_); - } - static constexpr int kIndexInFileMessages = - 0; - - // implements Any ----------------------------------------------- - - bool PackFrom(const ::PROTOBUF_NAMESPACE_ID::Message& message) { - GOOGLE_DCHECK_NE(&message, this); - return _impl_._any_metadata_.PackFrom(GetArena(), message); - } - bool PackFrom(const ::PROTOBUF_NAMESPACE_ID::Message& message, - ::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url_prefix) { - GOOGLE_DCHECK_NE(&message, this); - return _impl_._any_metadata_.PackFrom(GetArena(), message, type_url_prefix); - } - bool UnpackTo(::PROTOBUF_NAMESPACE_ID::Message* message) const { - return _impl_._any_metadata_.UnpackTo(message); - } - static bool GetAnyFieldDescriptors( - const ::PROTOBUF_NAMESPACE_ID::Message& message, - const ::PROTOBUF_NAMESPACE_ID::FieldDescriptor** type_url_field, - const ::PROTOBUF_NAMESPACE_ID::FieldDescriptor** value_field); - template ::value>::type> - bool PackFrom(const T& message) { - return _impl_._any_metadata_.PackFrom(GetArena(), message); - } - template ::value>::type> - bool PackFrom(const T& message, - ::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url_prefix) { - return _impl_._any_metadata_.PackFrom(GetArena(), message, type_url_prefix);} - template ::value>::type> - bool UnpackTo(T* message) const { - return _impl_._any_metadata_.UnpackTo(message); - } - template bool Is() const { - return _impl_._any_metadata_.Is(); - } - static bool ParseAnyTypeUrl(::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url, - std::string* full_type_name); - friend void swap(Any& a, Any& b) { - a.Swap(&b); - } - inline void Swap(Any* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(Any* other) { - if (other == this) return; - GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - Any* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const Any& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const Any& from) { - Any::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() 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; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(Any* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "google.protobuf.Any"; - } - protected: - explicit Any(::PROTOBUF_NAMESPACE_ID::Arena* arena, - bool is_message_owned = false); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kTypeUrlFieldNumber = 1, - kValueFieldNumber = 2, - }; - // string type_url = 1; - void clear_type_url(); - const std::string& type_url() const; - template - void set_type_url(ArgT0&& arg0, ArgT... args); - std::string* mutable_type_url(); - PROTOBUF_NODISCARD std::string* release_type_url(); - void set_allocated_type_url(std::string* type_url); - private: - const std::string& _internal_type_url() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_type_url(const std::string& value); - std::string* _internal_mutable_type_url(); - public: - - // bytes value = 2; - void clear_value(); - const std::string& value() const; - template - void set_value(ArgT0&& arg0, ArgT... args); - std::string* mutable_value(); - PROTOBUF_NODISCARD std::string* release_value(); - void set_allocated_value(std::string* value); - private: - const std::string& _internal_value() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_value(const std::string& value); - std::string* _internal_mutable_value(); - public: - - // @@protoc_insertion_point(class_scope:google.protobuf.Any) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr type_url_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr value_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata _any_metadata_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_google_2fprotobuf_2fany_2eproto; -}; -// =================================================================== - - -// =================================================================== - -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif // __GNUC__ -// Any - -// string type_url = 1; -inline void Any::clear_type_url() { - _impl_.type_url_.ClearToEmpty(); -} -inline const std::string& Any::type_url() const { - // @@protoc_insertion_point(field_get:google.protobuf.Any.type_url) - return _internal_type_url(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Any::set_type_url(ArgT0&& arg0, ArgT... args) { - - _impl_.type_url_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Any.type_url) -} -inline std::string* Any::mutable_type_url() { - std::string* _s = _internal_mutable_type_url(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Any.type_url) - return _s; -} -inline const std::string& Any::_internal_type_url() const { - return _impl_.type_url_.Get(); -} -inline void Any::_internal_set_type_url(const std::string& value) { - - _impl_.type_url_.Set(value, GetArenaForAllocation()); -} -inline std::string* Any::_internal_mutable_type_url() { - - return _impl_.type_url_.Mutable(GetArenaForAllocation()); -} -inline std::string* Any::release_type_url() { - // @@protoc_insertion_point(field_release:google.protobuf.Any.type_url) - return _impl_.type_url_.Release(); -} -inline void Any::set_allocated_type_url(std::string* type_url) { - if (type_url != nullptr) { - - } else { - - } - _impl_.type_url_.SetAllocated(type_url, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.type_url_.IsDefault()) { - _impl_.type_url_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url) -} - -// bytes value = 2; -inline void Any::clear_value() { - _impl_.value_.ClearToEmpty(); -} -inline const std::string& Any::value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Any.value) - return _internal_value(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Any::set_value(ArgT0&& arg0, ArgT... args) { - - _impl_.value_.SetBytes(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Any.value) -} -inline std::string* Any::mutable_value() { - std::string* _s = _internal_mutable_value(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Any.value) - return _s; -} -inline const std::string& Any::_internal_value() const { - return _impl_.value_.Get(); -} -inline void Any::_internal_set_value(const std::string& value) { - - _impl_.value_.Set(value, GetArenaForAllocation()); -} -inline std::string* Any::_internal_mutable_value() { - - return _impl_.value_.Mutable(GetArenaForAllocation()); -} -inline std::string* Any::release_value() { - // @@protoc_insertion_point(field_release:google.protobuf.Any.value) - return _impl_.value_.Release(); -} -inline void Any::set_allocated_value(std::string* value) { - if (value != nullptr) { - - } else { - - } - _impl_.value_.SetAllocated(value, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.value_.IsDefault()) { - _impl_.value_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value) -} - -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif // __GNUC__ - -// @@protoc_insertion_point(namespace_scope) - -PROTOBUF_NAMESPACE_CLOSE - -// @@protoc_insertion_point(global_scope) - -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/api.pb.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/api.pb.h deleted file mode 100644 index 2c4548920b..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/api.pb.h +++ /dev/null @@ -1,1437 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/api.proto - -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto - -#include -#include - -#include -#if PROTOBUF_VERSION < 3021000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -#include -#include -// @@protoc_insertion_point(includes) -#include -#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fapi_2eproto PROTOBUF_EXPORT -PROTOBUF_NAMESPACE_OPEN -namespace internal { -class AnyMetadata; -} // namespace internal -PROTOBUF_NAMESPACE_CLOSE - -// Internal implementation detail -- do not use these members. -struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fapi_2eproto { - static const uint32_t offsets[]; -}; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto; -PROTOBUF_NAMESPACE_OPEN -class Api; -struct ApiDefaultTypeInternal; -PROTOBUF_EXPORT extern ApiDefaultTypeInternal _Api_default_instance_; -class Method; -struct MethodDefaultTypeInternal; -PROTOBUF_EXPORT extern MethodDefaultTypeInternal _Method_default_instance_; -class Mixin; -struct MixinDefaultTypeInternal; -PROTOBUF_EXPORT extern MixinDefaultTypeInternal _Mixin_default_instance_; -PROTOBUF_NAMESPACE_CLOSE -PROTOBUF_NAMESPACE_OPEN -template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Api* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Api>(Arena*); -template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Method* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Method>(Arena*); -template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Mixin* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Mixin>(Arena*); -PROTOBUF_NAMESPACE_CLOSE -PROTOBUF_NAMESPACE_OPEN - -// =================================================================== - -class PROTOBUF_EXPORT Api final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ { - public: - inline Api() : Api(nullptr) {} - ~Api() override; - explicit PROTOBUF_CONSTEXPR Api(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - Api(const Api& from); - Api(Api&& from) noexcept - : Api() { - *this = ::std::move(from); - } - - inline Api& operator=(const Api& from) { - CopyFrom(from); - return *this; - } - inline Api& operator=(Api&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const Api& default_instance() { - return *internal_default_instance(); - } - static inline const Api* internal_default_instance() { - return reinterpret_cast( - &_Api_default_instance_); - } - static constexpr int kIndexInFileMessages = - 0; - - friend void swap(Api& a, Api& b) { - a.Swap(&b); - } - inline void Swap(Api* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(Api* other) { - if (other == this) return; - GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - Api* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const Api& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const Api& from) { - Api::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() 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; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(Api* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "google.protobuf.Api"; - } - protected: - explicit Api(::PROTOBUF_NAMESPACE_ID::Arena* arena, - bool is_message_owned = false); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kMethodsFieldNumber = 2, - kOptionsFieldNumber = 3, - kMixinsFieldNumber = 6, - kNameFieldNumber = 1, - kVersionFieldNumber = 4, - kSourceContextFieldNumber = 5, - kSyntaxFieldNumber = 7, - }; - // repeated .google.protobuf.Method methods = 2; - int methods_size() const; - private: - int _internal_methods_size() const; - public: - void clear_methods(); - ::PROTOBUF_NAMESPACE_ID::Method* mutable_methods(int index); - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Method >* - mutable_methods(); - private: - const ::PROTOBUF_NAMESPACE_ID::Method& _internal_methods(int index) const; - ::PROTOBUF_NAMESPACE_ID::Method* _internal_add_methods(); - public: - const ::PROTOBUF_NAMESPACE_ID::Method& methods(int index) const; - ::PROTOBUF_NAMESPACE_ID::Method* add_methods(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Method >& - methods() const; - - // repeated .google.protobuf.Option options = 3; - int options_size() const; - private: - int _internal_options_size() const; - public: - void clear_options(); - ::PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index); - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >* - mutable_options(); - private: - const ::PROTOBUF_NAMESPACE_ID::Option& _internal_options(int index) const; - ::PROTOBUF_NAMESPACE_ID::Option* _internal_add_options(); - public: - const ::PROTOBUF_NAMESPACE_ID::Option& options(int index) const; - ::PROTOBUF_NAMESPACE_ID::Option* add_options(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >& - options() const; - - // repeated .google.protobuf.Mixin mixins = 6; - int mixins_size() const; - private: - int _internal_mixins_size() const; - public: - void clear_mixins(); - ::PROTOBUF_NAMESPACE_ID::Mixin* mutable_mixins(int index); - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Mixin >* - mutable_mixins(); - private: - const ::PROTOBUF_NAMESPACE_ID::Mixin& _internal_mixins(int index) const; - ::PROTOBUF_NAMESPACE_ID::Mixin* _internal_add_mixins(); - public: - const ::PROTOBUF_NAMESPACE_ID::Mixin& mixins(int index) const; - ::PROTOBUF_NAMESPACE_ID::Mixin* add_mixins(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Mixin >& - mixins() const; - - // string name = 1; - void clear_name(); - const std::string& name() const; - template - void set_name(ArgT0&& arg0, ArgT... args); - std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); - void set_allocated_name(std::string* name); - private: - const std::string& _internal_name() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_name(const std::string& value); - std::string* _internal_mutable_name(); - public: - - // string version = 4; - void clear_version(); - const std::string& version() const; - template - void set_version(ArgT0&& arg0, ArgT... args); - std::string* mutable_version(); - PROTOBUF_NODISCARD std::string* release_version(); - void set_allocated_version(std::string* version); - private: - const std::string& _internal_version() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_version(const std::string& value); - std::string* _internal_mutable_version(); - public: - - // .google.protobuf.SourceContext source_context = 5; - bool has_source_context() const; - private: - bool _internal_has_source_context() const; - public: - void clear_source_context(); - const ::PROTOBUF_NAMESPACE_ID::SourceContext& source_context() const; - PROTOBUF_NODISCARD ::PROTOBUF_NAMESPACE_ID::SourceContext* release_source_context(); - ::PROTOBUF_NAMESPACE_ID::SourceContext* mutable_source_context(); - void set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceContext* source_context); - private: - const ::PROTOBUF_NAMESPACE_ID::SourceContext& _internal_source_context() const; - ::PROTOBUF_NAMESPACE_ID::SourceContext* _internal_mutable_source_context(); - public: - void unsafe_arena_set_allocated_source_context( - ::PROTOBUF_NAMESPACE_ID::SourceContext* source_context); - ::PROTOBUF_NAMESPACE_ID::SourceContext* unsafe_arena_release_source_context(); - - // .google.protobuf.Syntax syntax = 7; - void clear_syntax(); - ::PROTOBUF_NAMESPACE_ID::Syntax syntax() const; - void set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value); - private: - ::PROTOBUF_NAMESPACE_ID::Syntax _internal_syntax() const; - void _internal_set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value); - public: - - // @@protoc_insertion_point(class_scope:google.protobuf.Api) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Method > methods_; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option > options_; - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Mixin > mixins_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr version_; - ::PROTOBUF_NAMESPACE_ID::SourceContext* source_context_; - int syntax_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_google_2fprotobuf_2fapi_2eproto; -}; -// ------------------------------------------------------------------- - -class PROTOBUF_EXPORT Method final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ { - public: - inline Method() : Method(nullptr) {} - ~Method() override; - explicit PROTOBUF_CONSTEXPR Method(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - Method(const Method& from); - Method(Method&& from) noexcept - : Method() { - *this = ::std::move(from); - } - - inline Method& operator=(const Method& from) { - CopyFrom(from); - return *this; - } - inline Method& operator=(Method&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const Method& default_instance() { - return *internal_default_instance(); - } - static inline const Method* internal_default_instance() { - return reinterpret_cast( - &_Method_default_instance_); - } - static constexpr int kIndexInFileMessages = - 1; - - friend void swap(Method& a, Method& b) { - a.Swap(&b); - } - inline void Swap(Method* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(Method* other) { - if (other == this) return; - GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - Method* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const Method& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const Method& from) { - Method::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() 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; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(Method* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "google.protobuf.Method"; - } - protected: - explicit Method(::PROTOBUF_NAMESPACE_ID::Arena* arena, - bool is_message_owned = false); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kOptionsFieldNumber = 6, - kNameFieldNumber = 1, - kRequestTypeUrlFieldNumber = 2, - kResponseTypeUrlFieldNumber = 4, - kRequestStreamingFieldNumber = 3, - kResponseStreamingFieldNumber = 5, - kSyntaxFieldNumber = 7, - }; - // repeated .google.protobuf.Option options = 6; - int options_size() const; - private: - int _internal_options_size() const; - public: - void clear_options(); - ::PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index); - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >* - mutable_options(); - private: - const ::PROTOBUF_NAMESPACE_ID::Option& _internal_options(int index) const; - ::PROTOBUF_NAMESPACE_ID::Option* _internal_add_options(); - public: - const ::PROTOBUF_NAMESPACE_ID::Option& options(int index) const; - ::PROTOBUF_NAMESPACE_ID::Option* add_options(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >& - options() const; - - // string name = 1; - void clear_name(); - const std::string& name() const; - template - void set_name(ArgT0&& arg0, ArgT... args); - std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); - void set_allocated_name(std::string* name); - private: - const std::string& _internal_name() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_name(const std::string& value); - std::string* _internal_mutable_name(); - public: - - // string request_type_url = 2; - void clear_request_type_url(); - const std::string& request_type_url() const; - template - void set_request_type_url(ArgT0&& arg0, ArgT... args); - std::string* mutable_request_type_url(); - PROTOBUF_NODISCARD std::string* release_request_type_url(); - void set_allocated_request_type_url(std::string* request_type_url); - private: - const std::string& _internal_request_type_url() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_request_type_url(const std::string& value); - std::string* _internal_mutable_request_type_url(); - public: - - // string response_type_url = 4; - void clear_response_type_url(); - const std::string& response_type_url() const; - template - void set_response_type_url(ArgT0&& arg0, ArgT... args); - std::string* mutable_response_type_url(); - PROTOBUF_NODISCARD std::string* release_response_type_url(); - void set_allocated_response_type_url(std::string* response_type_url); - private: - const std::string& _internal_response_type_url() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_response_type_url(const std::string& value); - std::string* _internal_mutable_response_type_url(); - public: - - // bool request_streaming = 3; - void clear_request_streaming(); - bool request_streaming() const; - void set_request_streaming(bool value); - private: - bool _internal_request_streaming() const; - void _internal_set_request_streaming(bool value); - public: - - // bool response_streaming = 5; - void clear_response_streaming(); - bool response_streaming() const; - void set_response_streaming(bool value); - private: - bool _internal_response_streaming() const; - void _internal_set_response_streaming(bool value); - public: - - // .google.protobuf.Syntax syntax = 7; - void clear_syntax(); - ::PROTOBUF_NAMESPACE_ID::Syntax syntax() const; - void set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value); - private: - ::PROTOBUF_NAMESPACE_ID::Syntax _internal_syntax() const; - void _internal_set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value); - public: - - // @@protoc_insertion_point(class_scope:google.protobuf.Method) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option > options_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_type_url_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr response_type_url_; - bool request_streaming_; - bool response_streaming_; - int syntax_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_google_2fprotobuf_2fapi_2eproto; -}; -// ------------------------------------------------------------------- - -class PROTOBUF_EXPORT Mixin final : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ { - public: - inline Mixin() : Mixin(nullptr) {} - ~Mixin() override; - explicit PROTOBUF_CONSTEXPR Mixin(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); - - Mixin(const Mixin& from); - Mixin(Mixin&& from) noexcept - : Mixin() { - *this = ::std::move(from); - } - - inline Mixin& operator=(const Mixin& from) { - CopyFrom(from); - return *this; - } - inline Mixin& operator=(Mixin&& from) noexcept { - if (this == &from) return *this; - if (GetOwningArena() == from.GetOwningArena() - #ifdef PROTOBUF_FORCE_COPY_IN_MOVE - && GetOwningArena() != nullptr - #endif // !PROTOBUF_FORCE_COPY_IN_MOVE - ) { - InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return default_instance().GetMetadata().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return default_instance().GetMetadata().reflection; - } - static const Mixin& default_instance() { - return *internal_default_instance(); - } - static inline const Mixin* internal_default_instance() { - return reinterpret_cast( - &_Mixin_default_instance_); - } - static constexpr int kIndexInFileMessages = - 2; - - friend void swap(Mixin& a, Mixin& b) { - a.Swap(&b); - } - inline void Swap(Mixin* other) { - if (other == this) return; - #ifdef PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() != nullptr && - GetOwningArena() == other->GetOwningArena()) { - #else // PROTOBUF_FORCE_COPY_IN_SWAP - if (GetOwningArena() == other->GetOwningArena()) { - #endif // !PROTOBUF_FORCE_COPY_IN_SWAP - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(Mixin* other) { - if (other == this) return; - GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - Mixin* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); - } - using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; - void CopyFrom(const Mixin& from); - using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; - void MergeFrom( const Mixin& from) { - Mixin::MergeImpl(*this, from); - } - private: - static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); - public: - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() 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; - int GetCachedSize() const final { return _impl_._cached_size_.Get(); } - - private: - void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); - void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(Mixin* other); - - private: - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "google.protobuf.Mixin"; - } - protected: - explicit Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena, - bool is_message_owned = false); - public: - - static const ClassData _class_data_; - const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kNameFieldNumber = 1, - kRootFieldNumber = 2, - }; - // string name = 1; - void clear_name(); - const std::string& name() const; - template - void set_name(ArgT0&& arg0, ArgT... args); - std::string* mutable_name(); - PROTOBUF_NODISCARD std::string* release_name(); - void set_allocated_name(std::string* name); - private: - const std::string& _internal_name() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_name(const std::string& value); - std::string* _internal_mutable_name(); - public: - - // string root = 2; - void clear_root(); - const std::string& root() const; - template - void set_root(ArgT0&& arg0, ArgT... args); - std::string* mutable_root(); - PROTOBUF_NODISCARD std::string* release_root(); - void set_allocated_root(std::string* root); - private: - const std::string& _internal_root() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_root(const std::string& value); - std::string* _internal_mutable_root(); - public: - - // @@protoc_insertion_point(class_scope:google.protobuf.Mixin) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr root_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - }; - union { Impl_ _impl_; }; - friend struct ::TableStruct_google_2fprotobuf_2fapi_2eproto; -}; -// =================================================================== - - -// =================================================================== - -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif // __GNUC__ -// Api - -// string name = 1; -inline void Api::clear_name() { - _impl_.name_.ClearToEmpty(); -} -inline const std::string& Api::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.name) - return _internal_name(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Api::set_name(ArgT0&& arg0, ArgT... args) { - - _impl_.name_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Api.name) -} -inline std::string* Api::mutable_name() { - std::string* _s = _internal_mutable_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.name) - return _s; -} -inline const std::string& Api::_internal_name() const { - return _impl_.name_.Get(); -} -inline void Api::_internal_set_name(const std::string& value) { - - _impl_.name_.Set(value, GetArenaForAllocation()); -} -inline std::string* Api::_internal_mutable_name() { - - return _impl_.name_.Mutable(GetArenaForAllocation()); -} -inline std::string* Api::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.Api.name) - return _impl_.name_.Release(); -} -inline void Api::set_allocated_name(std::string* name) { - if (name != nullptr) { - - } else { - - } - _impl_.name_.SetAllocated(name, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.name_.IsDefault()) { - _impl_.name_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name) -} - -// repeated .google.protobuf.Method methods = 2; -inline int Api::_internal_methods_size() const { - return _impl_.methods_.size(); -} -inline int Api::methods_size() const { - return _internal_methods_size(); -} -inline void Api::clear_methods() { - _impl_.methods_.Clear(); -} -inline ::PROTOBUF_NAMESPACE_ID::Method* Api::mutable_methods(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.methods) - return _impl_.methods_.Mutable(index); -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Method >* -Api::mutable_methods() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.methods) - return &_impl_.methods_; -} -inline const ::PROTOBUF_NAMESPACE_ID::Method& Api::_internal_methods(int index) const { - return _impl_.methods_.Get(index); -} -inline const ::PROTOBUF_NAMESPACE_ID::Method& Api::methods(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.methods) - return _internal_methods(index); -} -inline ::PROTOBUF_NAMESPACE_ID::Method* Api::_internal_add_methods() { - return _impl_.methods_.Add(); -} -inline ::PROTOBUF_NAMESPACE_ID::Method* Api::add_methods() { - ::PROTOBUF_NAMESPACE_ID::Method* _add = _internal_add_methods(); - // @@protoc_insertion_point(field_add:google.protobuf.Api.methods) - return _add; -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Method >& -Api::methods() const { - // @@protoc_insertion_point(field_list:google.protobuf.Api.methods) - return _impl_.methods_; -} - -// repeated .google.protobuf.Option options = 3; -inline int Api::_internal_options_size() const { - return _impl_.options_.size(); -} -inline int Api::options_size() const { - return _internal_options_size(); -} -inline ::PROTOBUF_NAMESPACE_ID::Option* Api::mutable_options(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.options) - return _impl_.options_.Mutable(index); -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >* -Api::mutable_options() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.options) - return &_impl_.options_; -} -inline const ::PROTOBUF_NAMESPACE_ID::Option& Api::_internal_options(int index) const { - return _impl_.options_.Get(index); -} -inline const ::PROTOBUF_NAMESPACE_ID::Option& Api::options(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.options) - return _internal_options(index); -} -inline ::PROTOBUF_NAMESPACE_ID::Option* Api::_internal_add_options() { - return _impl_.options_.Add(); -} -inline ::PROTOBUF_NAMESPACE_ID::Option* Api::add_options() { - ::PROTOBUF_NAMESPACE_ID::Option* _add = _internal_add_options(); - // @@protoc_insertion_point(field_add:google.protobuf.Api.options) - return _add; -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >& -Api::options() const { - // @@protoc_insertion_point(field_list:google.protobuf.Api.options) - return _impl_.options_; -} - -// string version = 4; -inline void Api::clear_version() { - _impl_.version_.ClearToEmpty(); -} -inline const std::string& Api::version() const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.version) - return _internal_version(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Api::set_version(ArgT0&& arg0, ArgT... args) { - - _impl_.version_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Api.version) -} -inline std::string* Api::mutable_version() { - std::string* _s = _internal_mutable_version(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.version) - return _s; -} -inline const std::string& Api::_internal_version() const { - return _impl_.version_.Get(); -} -inline void Api::_internal_set_version(const std::string& value) { - - _impl_.version_.Set(value, GetArenaForAllocation()); -} -inline std::string* Api::_internal_mutable_version() { - - return _impl_.version_.Mutable(GetArenaForAllocation()); -} -inline std::string* Api::release_version() { - // @@protoc_insertion_point(field_release:google.protobuf.Api.version) - return _impl_.version_.Release(); -} -inline void Api::set_allocated_version(std::string* version) { - if (version != nullptr) { - - } else { - - } - _impl_.version_.SetAllocated(version, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.version_.IsDefault()) { - _impl_.version_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version) -} - -// .google.protobuf.SourceContext source_context = 5; -inline bool Api::_internal_has_source_context() const { - return this != internal_default_instance() && _impl_.source_context_ != nullptr; -} -inline bool Api::has_source_context() const { - return _internal_has_source_context(); -} -inline const ::PROTOBUF_NAMESPACE_ID::SourceContext& Api::_internal_source_context() const { - const ::PROTOBUF_NAMESPACE_ID::SourceContext* p = _impl_.source_context_; - return p != nullptr ? *p : reinterpret_cast( - ::PROTOBUF_NAMESPACE_ID::_SourceContext_default_instance_); -} -inline const ::PROTOBUF_NAMESPACE_ID::SourceContext& Api::source_context() const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.source_context) - return _internal_source_context(); -} -inline void Api::unsafe_arena_set_allocated_source_context( - ::PROTOBUF_NAMESPACE_ID::SourceContext* source_context) { - if (GetArenaForAllocation() == nullptr) { - delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_); - } - _impl_.source_context_ = source_context; - if (source_context) { - - } else { - - } - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.source_context) -} -inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() { - - ::PROTOBUF_NAMESPACE_ID::SourceContext* temp = _impl_.source_context_; - _impl_.source_context_ = nullptr; -#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE - auto* old = reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(temp); - temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); - if (GetArenaForAllocation() == nullptr) { delete old; } -#else // PROTOBUF_FORCE_COPY_IN_RELEASE - if (GetArenaForAllocation() != nullptr) { - temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); - } -#endif // !PROTOBUF_FORCE_COPY_IN_RELEASE - return temp; -} -inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::unsafe_arena_release_source_context() { - // @@protoc_insertion_point(field_release:google.protobuf.Api.source_context) - - ::PROTOBUF_NAMESPACE_ID::SourceContext* temp = _impl_.source_context_; - _impl_.source_context_ = nullptr; - return temp; -} -inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::_internal_mutable_source_context() { - - if (_impl_.source_context_ == nullptr) { - auto* p = CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceContext>(GetArenaForAllocation()); - _impl_.source_context_ = p; - } - return _impl_.source_context_; -} -inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::mutable_source_context() { - ::PROTOBUF_NAMESPACE_ID::SourceContext* _msg = _internal_mutable_source_context(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.source_context) - return _msg; -} -inline void Api::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceContext* source_context) { - ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaForAllocation(); - if (message_arena == nullptr) { - delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_); - } - if (source_context) { - ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = - ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena( - reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context)); - if (message_arena != submessage_arena) { - source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( - message_arena, source_context, submessage_arena); - } - - } else { - - } - _impl_.source_context_ = source_context; - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.source_context) -} - -// repeated .google.protobuf.Mixin mixins = 6; -inline int Api::_internal_mixins_size() const { - return _impl_.mixins_.size(); -} -inline int Api::mixins_size() const { - return _internal_mixins_size(); -} -inline void Api::clear_mixins() { - _impl_.mixins_.Clear(); -} -inline ::PROTOBUF_NAMESPACE_ID::Mixin* Api::mutable_mixins(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.mixins) - return _impl_.mixins_.Mutable(index); -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Mixin >* -Api::mutable_mixins() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.mixins) - return &_impl_.mixins_; -} -inline const ::PROTOBUF_NAMESPACE_ID::Mixin& Api::_internal_mixins(int index) const { - return _impl_.mixins_.Get(index); -} -inline const ::PROTOBUF_NAMESPACE_ID::Mixin& Api::mixins(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.mixins) - return _internal_mixins(index); -} -inline ::PROTOBUF_NAMESPACE_ID::Mixin* Api::_internal_add_mixins() { - return _impl_.mixins_.Add(); -} -inline ::PROTOBUF_NAMESPACE_ID::Mixin* Api::add_mixins() { - ::PROTOBUF_NAMESPACE_ID::Mixin* _add = _internal_add_mixins(); - // @@protoc_insertion_point(field_add:google.protobuf.Api.mixins) - return _add; -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Mixin >& -Api::mixins() const { - // @@protoc_insertion_point(field_list:google.protobuf.Api.mixins) - return _impl_.mixins_; -} - -// .google.protobuf.Syntax syntax = 7; -inline void Api::clear_syntax() { - _impl_.syntax_ = 0; -} -inline ::PROTOBUF_NAMESPACE_ID::Syntax Api::_internal_syntax() const { - return static_cast< ::PROTOBUF_NAMESPACE_ID::Syntax >(_impl_.syntax_); -} -inline ::PROTOBUF_NAMESPACE_ID::Syntax Api::syntax() const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.syntax) - return _internal_syntax(); -} -inline void Api::_internal_set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) { - - _impl_.syntax_ = value; -} -inline void Api::set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) { - _internal_set_syntax(value); - // @@protoc_insertion_point(field_set:google.protobuf.Api.syntax) -} - -// ------------------------------------------------------------------- - -// Method - -// string name = 1; -inline void Method::clear_name() { - _impl_.name_.ClearToEmpty(); -} -inline const std::string& Method::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.name) - return _internal_name(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Method::set_name(ArgT0&& arg0, ArgT... args) { - - _impl_.name_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Method.name) -} -inline std::string* Method::mutable_name() { - std::string* _s = _internal_mutable_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Method.name) - return _s; -} -inline const std::string& Method::_internal_name() const { - return _impl_.name_.Get(); -} -inline void Method::_internal_set_name(const std::string& value) { - - _impl_.name_.Set(value, GetArenaForAllocation()); -} -inline std::string* Method::_internal_mutable_name() { - - return _impl_.name_.Mutable(GetArenaForAllocation()); -} -inline std::string* Method::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.Method.name) - return _impl_.name_.Release(); -} -inline void Method::set_allocated_name(std::string* name) { - if (name != nullptr) { - - } else { - - } - _impl_.name_.SetAllocated(name, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.name_.IsDefault()) { - _impl_.name_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name) -} - -// string request_type_url = 2; -inline void Method::clear_request_type_url() { - _impl_.request_type_url_.ClearToEmpty(); -} -inline const std::string& Method::request_type_url() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url) - return _internal_request_type_url(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Method::set_request_type_url(ArgT0&& arg0, ArgT... args) { - - _impl_.request_type_url_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Method.request_type_url) -} -inline std::string* Method::mutable_request_type_url() { - std::string* _s = _internal_mutable_request_type_url(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Method.request_type_url) - return _s; -} -inline const std::string& Method::_internal_request_type_url() const { - return _impl_.request_type_url_.Get(); -} -inline void Method::_internal_set_request_type_url(const std::string& value) { - - _impl_.request_type_url_.Set(value, GetArenaForAllocation()); -} -inline std::string* Method::_internal_mutable_request_type_url() { - - return _impl_.request_type_url_.Mutable(GetArenaForAllocation()); -} -inline std::string* Method::release_request_type_url() { - // @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url) - return _impl_.request_type_url_.Release(); -} -inline void Method::set_allocated_request_type_url(std::string* request_type_url) { - if (request_type_url != nullptr) { - - } else { - - } - _impl_.request_type_url_.SetAllocated(request_type_url, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.request_type_url_.IsDefault()) { - _impl_.request_type_url_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url) -} - -// bool request_streaming = 3; -inline void Method::clear_request_streaming() { - _impl_.request_streaming_ = false; -} -inline bool Method::_internal_request_streaming() const { - return _impl_.request_streaming_; -} -inline bool Method::request_streaming() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.request_streaming) - return _internal_request_streaming(); -} -inline void Method::_internal_set_request_streaming(bool value) { - - _impl_.request_streaming_ = value; -} -inline void Method::set_request_streaming(bool value) { - _internal_set_request_streaming(value); - // @@protoc_insertion_point(field_set:google.protobuf.Method.request_streaming) -} - -// string response_type_url = 4; -inline void Method::clear_response_type_url() { - _impl_.response_type_url_.ClearToEmpty(); -} -inline const std::string& Method::response_type_url() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url) - return _internal_response_type_url(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Method::set_response_type_url(ArgT0&& arg0, ArgT... args) { - - _impl_.response_type_url_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Method.response_type_url) -} -inline std::string* Method::mutable_response_type_url() { - std::string* _s = _internal_mutable_response_type_url(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Method.response_type_url) - return _s; -} -inline const std::string& Method::_internal_response_type_url() const { - return _impl_.response_type_url_.Get(); -} -inline void Method::_internal_set_response_type_url(const std::string& value) { - - _impl_.response_type_url_.Set(value, GetArenaForAllocation()); -} -inline std::string* Method::_internal_mutable_response_type_url() { - - return _impl_.response_type_url_.Mutable(GetArenaForAllocation()); -} -inline std::string* Method::release_response_type_url() { - // @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url) - return _impl_.response_type_url_.Release(); -} -inline void Method::set_allocated_response_type_url(std::string* response_type_url) { - if (response_type_url != nullptr) { - - } else { - - } - _impl_.response_type_url_.SetAllocated(response_type_url, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.response_type_url_.IsDefault()) { - _impl_.response_type_url_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url) -} - -// bool response_streaming = 5; -inline void Method::clear_response_streaming() { - _impl_.response_streaming_ = false; -} -inline bool Method::_internal_response_streaming() const { - return _impl_.response_streaming_; -} -inline bool Method::response_streaming() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.response_streaming) - return _internal_response_streaming(); -} -inline void Method::_internal_set_response_streaming(bool value) { - - _impl_.response_streaming_ = value; -} -inline void Method::set_response_streaming(bool value) { - _internal_set_response_streaming(value); - // @@protoc_insertion_point(field_set:google.protobuf.Method.response_streaming) -} - -// repeated .google.protobuf.Option options = 6; -inline int Method::_internal_options_size() const { - return _impl_.options_.size(); -} -inline int Method::options_size() const { - return _internal_options_size(); -} -inline ::PROTOBUF_NAMESPACE_ID::Option* Method::mutable_options(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.Method.options) - return _impl_.options_.Mutable(index); -} -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >* -Method::mutable_options() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.Method.options) - return &_impl_.options_; -} -inline const ::PROTOBUF_NAMESPACE_ID::Option& Method::_internal_options(int index) const { - return _impl_.options_.Get(index); -} -inline const ::PROTOBUF_NAMESPACE_ID::Option& Method::options(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.options) - return _internal_options(index); -} -inline ::PROTOBUF_NAMESPACE_ID::Option* Method::_internal_add_options() { - return _impl_.options_.Add(); -} -inline ::PROTOBUF_NAMESPACE_ID::Option* Method::add_options() { - ::PROTOBUF_NAMESPACE_ID::Option* _add = _internal_add_options(); - // @@protoc_insertion_point(field_add:google.protobuf.Method.options) - return _add; -} -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Option >& -Method::options() const { - // @@protoc_insertion_point(field_list:google.protobuf.Method.options) - return _impl_.options_; -} - -// .google.protobuf.Syntax syntax = 7; -inline void Method::clear_syntax() { - _impl_.syntax_ = 0; -} -inline ::PROTOBUF_NAMESPACE_ID::Syntax Method::_internal_syntax() const { - return static_cast< ::PROTOBUF_NAMESPACE_ID::Syntax >(_impl_.syntax_); -} -inline ::PROTOBUF_NAMESPACE_ID::Syntax Method::syntax() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.syntax) - return _internal_syntax(); -} -inline void Method::_internal_set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) { - - _impl_.syntax_ = value; -} -inline void Method::set_syntax(::PROTOBUF_NAMESPACE_ID::Syntax value) { - _internal_set_syntax(value); - // @@protoc_insertion_point(field_set:google.protobuf.Method.syntax) -} - -// ------------------------------------------------------------------- - -// Mixin - -// string name = 1; -inline void Mixin::clear_name() { - _impl_.name_.ClearToEmpty(); -} -inline const std::string& Mixin::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.Mixin.name) - return _internal_name(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Mixin::set_name(ArgT0&& arg0, ArgT... args) { - - _impl_.name_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Mixin.name) -} -inline std::string* Mixin::mutable_name() { - std::string* _s = _internal_mutable_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Mixin.name) - return _s; -} -inline const std::string& Mixin::_internal_name() const { - return _impl_.name_.Get(); -} -inline void Mixin::_internal_set_name(const std::string& value) { - - _impl_.name_.Set(value, GetArenaForAllocation()); -} -inline std::string* Mixin::_internal_mutable_name() { - - return _impl_.name_.Mutable(GetArenaForAllocation()); -} -inline std::string* Mixin::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.Mixin.name) - return _impl_.name_.Release(); -} -inline void Mixin::set_allocated_name(std::string* name) { - if (name != nullptr) { - - } else { - - } - _impl_.name_.SetAllocated(name, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.name_.IsDefault()) { - _impl_.name_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name) -} - -// string root = 2; -inline void Mixin::clear_root() { - _impl_.root_.ClearToEmpty(); -} -inline const std::string& Mixin::root() const { - // @@protoc_insertion_point(field_get:google.protobuf.Mixin.root) - return _internal_root(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void Mixin::set_root(ArgT0&& arg0, ArgT... args) { - - _impl_.root_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.Mixin.root) -} -inline std::string* Mixin::mutable_root() { - std::string* _s = _internal_mutable_root(); - // @@protoc_insertion_point(field_mutable:google.protobuf.Mixin.root) - return _s; -} -inline const std::string& Mixin::_internal_root() const { - return _impl_.root_.Get(); -} -inline void Mixin::_internal_set_root(const std::string& value) { - - _impl_.root_.Set(value, GetArenaForAllocation()); -} -inline std::string* Mixin::_internal_mutable_root() { - - return _impl_.root_.Mutable(GetArenaForAllocation()); -} -inline std::string* Mixin::release_root() { - // @@protoc_insertion_point(field_release:google.protobuf.Mixin.root) - return _impl_.root_.Release(); -} -inline void Mixin::set_allocated_root(std::string* root) { - if (root != nullptr) { - - } else { - - } - _impl_.root_.SetAllocated(root, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.root_.IsDefault()) { - _impl_.root_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root) -} - -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif // __GNUC__ -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -PROTOBUF_NAMESPACE_CLOSE - -// @@protoc_insertion_point(global_scope) - -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arena.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arena.h deleted file mode 100644 index 3b5f16c389..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arena.h +++ /dev/null @@ -1,851 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file defines an Arena allocator for better allocation performance. - -#ifndef GOOGLE_PROTOBUF_ARENA_H__ -#define GOOGLE_PROTOBUF_ARENA_H__ - - -#include -#include -#include -#if defined(_MSC_VER) && !defined(_LIBCPP_STD_VER) && !_HAS_EXCEPTIONS -// Work around bugs in MSVC header when _HAS_EXCEPTIONS=0. -#include -#include -namespace std { -using type_info = ::type_info; -} -#else -#include -#endif - -#include -#include -#include - -// Must be included last. -#include - -#ifdef SWIG -#error "You cannot SWIG proto headers" -#endif - -namespace google { -namespace protobuf { - -struct ArenaOptions; // defined below -class Arena; // defined below -class Message; // defined in message.h -class MessageLite; -template -class Map; - -namespace arena_metrics { - -void EnableArenaMetrics(ArenaOptions* options); - -} // namespace arena_metrics - -namespace TestUtil { -class ReflectionTester; // defined in test_util.h -} // namespace TestUtil - -namespace internal { - -struct ArenaTestPeer; // defined in arena_test_util.h -class InternalMetadata; // defined in metadata_lite.h -class LazyField; // defined in lazy_field.h -class EpsCopyInputStream; // defined in parse_context.h -class RepeatedPtrFieldBase; // defined in repeated_ptr_field.h - -template -class GenericTypeHandler; // defined in repeated_field.h - -inline PROTOBUF_ALWAYS_INLINE -void* AlignTo(void* ptr, size_t align) { - return reinterpret_cast( - (reinterpret_cast(ptr) + align - 1) & (~align + 1)); -} - -// Templated cleanup methods. -template -void arena_destruct_object(void* object) { - reinterpret_cast(object)->~T(); -} - -template -struct ObjectDestructor { - constexpr static void (*destructor)(void*) = &arena_destruct_object; -}; - -template -struct ObjectDestructor { - constexpr static void (*destructor)(void*) = nullptr; -}; - -template -void arena_delete_object(void* object) { - delete reinterpret_cast(object); -} -} // namespace internal - -// ArenaOptions provides optional additional parameters to arena construction -// that control its block-allocation behavior. -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; - - // 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; - - // An initial block of memory for the arena to use, or NULL 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; - - // The size of the initial block, if provided. - size_t initial_block_size; - - // 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); - // 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::AllocationPolicy::kDefaultMaxBlockSize), - initial_block(NULL), - initial_block_size(0), - block_alloc(nullptr), - block_dealloc(nullptr), - make_metrics_collector(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; - res.max_block_size = max_block_size; - res.block_alloc = block_alloc; - res.block_dealloc = block_dealloc; - res.metrics_collector = MetricsCollector(); - return res; - } - - friend void arena_metrics::EnableArenaMetrics(ArenaOptions*); - - friend class Arena; - friend class ArenaOptionsTestFriend; -}; - -// Support for non-RTTI environments. (The metrics hooks API uses type -// information.) -#if PROTOBUF_RTTI -#define RTTI_TYPE_ID(type) (&typeid(type)) -#else -#define RTTI_TYPE_ID(type) (NULL) -#endif - -// Arena allocator. Arena allocation replaces ordinary (heap-based) allocation -// with new/delete, and improves performance by aggregating allocations into -// larger blocks and freeing allocations all at once. Protocol messages are -// allocated on an arena by using Arena::CreateMessage(Arena*), below, and -// are automatically freed when the arena is destroyed. -// -// This is a thread-safe implementation: multiple threads may allocate from the -// arena concurrently. Destruction is not thread-safe and the destructing -// thread must synchronize with users of the arena first. -// -// An arena provides two allocation interfaces: CreateMessage, which works -// for arena-enabled proto2 message types as well as other types that satisfy -// the appropriate protocol (described below), and Create, which works for -// any arbitrary type T. CreateMessage is better when the type T supports it, -// because this interface (i) passes the arena pointer to the created object so -// that its sub-objects and internal allocations can use the arena too, and (ii) -// elides the object's destructor call when possible. Create does not place -// any special requirements on the type T, and will invoke the object's -// destructor when the arena is destroyed. -// -// The arena message allocation protocol, required by -// CreateMessage(Arena* arena, Args&&... args), is as follows: -// -// - The type T must have (at least) two constructors: a constructor callable -// with `args` (without `arena`), called when a T is allocated on the heap; -// and a constructor callable with `Arena* arena, Args&&... args`, called when -// a T is allocated on an arena. If the second constructor is called with a -// NULL arena pointer, it must be equivalent to invoking the first -// (`args`-only) constructor. -// -// - The type T must have a particular type trait: a nested type -// |InternalArenaConstructable_|. This is usually a typedef to |void|. If no -// such type trait exists, then the instantiation CreateMessage will fail -// to compile. -// -// - The type T *may* have the type trait |DestructorSkippable_|. If this type -// trait is present in the type, then its destructor will not be called if and -// only if it was passed a non-NULL arena pointer. If this type trait is not -// present on the type, then its destructor is always called when the -// containing arena is destroyed. -// -// This protocol is implemented by all arena-enabled proto2 message classes as -// well as protobuf container types like RepeatedPtrField and Map. The protocol -// is internal to protobuf and is not guaranteed to be stable. Non-proto types -// should not rely on this protocol. -class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { - public: - // Default constructor with sensible default options, tuned for average - // use-cases. - inline Arena() : impl_() {} - - // Construct an arena with default options, except for the supplied - // initial block. It is more efficient to use this constructor - // instead of passing ArenaOptions if the only configuration needed - // by the caller is supplying an initial block. - inline Arena(char* initial_block, size_t initial_block_size) - : impl_(initial_block, initial_block_size) {} - - // Arena constructor taking custom options. See ArenaOptions above for - // descriptions of the options available. - explicit Arena(const ArenaOptions& options) - : impl_(options.initial_block, options.initial_block_size, - options.AllocationPolicy()) {} - - // Block overhead. Use this as a guide for how much to over-allocate the - // initial block if you want an allocation of size N to fit inside it. - // - // WARNING: if you allocate multiple objects, it is difficult to guarantee - // that a series of allocations will fit in the initial block, especially if - // Arena changes its alignment guarantees in the future! - static const size_t kBlockOverhead = - internal::ThreadSafeArena::kBlockHeaderSize + - internal::ThreadSafeArena::kSerialArenaSize; - - inline ~Arena() {} - - // TODO(protobuf-team): Fix callers to use constructor and delete this method. - void Init(const ArenaOptions&) {} - - // API to create proto2 message objects on the arena. If the arena passed in - // is NULL, then a heap allocated object is returned. Type T must be a message - // defined in a .proto file with cc_enable_arenas set to true, otherwise a - // compilation error will occur. - // - // RepeatedField and RepeatedPtrField may also be instantiated directly on an - // arena with this method. - // - // This function also accepts any type T that satisfies the arena message - // allocation protocol, documented above. - template - PROTOBUF_ALWAYS_INLINE static T* CreateMessage(Arena* arena, Args&&... args) { - static_assert( - InternalHelper::is_arena_constructable::value, - "CreateMessage can only construct types that are ArenaConstructable"); - // We must delegate to CreateMaybeMessage() and NOT CreateMessageInternal() - // because protobuf generated classes specialize CreateMaybeMessage() and we - // need to use that specialization for code size reasons. - return Arena::CreateMaybeMessage(arena, static_cast(args)...); - } - - // API to create any objects on the arena. Note that only the object will - // be created on the arena; the underlying ptrs (in case of a proto2 message) - // will be still heap allocated. Proto messages should usually be allocated - // with CreateMessage() instead. - // - // Note that even if T satisfies the arena message construction protocol - // (InternalArenaConstructable_ trait and optional DestructorSkippable_ - // trait), as described above, this function does not follow the protocol; - // instead, it treats T as a black-box type, just as if it did not have these - // traits. Specifically, T's constructor arguments will always be only those - // passed to Create() -- no additional arena pointer is implicitly added. - // Furthermore, the destructor will always be called at arena destruction time - // (unless the destructor is trivial). Hence, from T's point of view, it is as - // if the object were allocated on the heap (except that the underlying memory - // is obtained from the arena). - template - PROTOBUF_NDEBUG_INLINE static T* Create(Arena* arena, Args&&... args) { - return CreateInternal(arena, std::is_convertible(), - static_cast(args)...); - } - - // Allocates memory with the specific size and alignment. - void* AllocateAligned(size_t size, size_t align = 8) { - if (align <= 8) { - return AllocateAlignedNoHook(internal::AlignUpTo8(size)); - } else { - // We are wasting space by over allocating align - 8 bytes. Compared - // to a dedicated function that takes current alignment in consideration. - // Such a scheme would only waste (align - 8)/2 bytes on average, but - // requires a dedicated function in the outline arena allocation - // functions. Possibly re-evaluate tradeoffs later. - return internal::AlignTo(AllocateAlignedNoHook(size + align - 8), align); - } - } - - // Create an array of object type T on the arena *without* invoking the - // constructor of T. If `arena` is null, then the return value should be freed - // with `delete[] x;` (or `::operator delete[](x);`). - // To ensure safe uses, this function checks at compile time - // (when compiled as C++11) that T is trivially default-constructible and - // trivially destructible. - template - PROTOBUF_NDEBUG_INLINE static T* CreateArray(Arena* arena, - size_t num_elements) { - static_assert(std::is_trivial::value, - "CreateArray requires a trivially constructible type"); - static_assert(std::is_trivially_destructible::value, - "CreateArray requires a trivially destructible type"); - GOOGLE_CHECK_LE(num_elements, std::numeric_limits::max() / sizeof(T)) - << "Requested size is too large to fit into size_t."; - if (arena == NULL) { - return static_cast(::operator new[](num_elements * sizeof(T))); - } else { - return arena->CreateInternalRawArray(num_elements); - } - } - - // The following are routines are for monitoring. They will approximate the - // total sum allocated and used memory, but the exact value is an - // implementation deal. For instance allocated space depends on growth - // policies. Do not use these in unit tests. - // Returns the total space allocated by the arena, which is the sum of the - // sizes of the underlying blocks. - uint64_t SpaceAllocated() const { return impl_.SpaceAllocated(); } - // Returns the total space used by the arena. Similar to SpaceAllocated but - // does not include free space and block overhead. The total space returned - // may not include space used by other threads executing concurrently with - // the call to this method. - uint64_t SpaceUsed() const { return impl_.SpaceUsed(); } - - // Frees all storage allocated by this arena after calling destructors - // registered with OwnDestructor() and freeing objects registered with Own(). - // Any objects allocated on this arena are unusable after this call. It also - // returns the total space used by the arena which is the sums of the sizes - // of the allocated blocks. This method is not thread-safe. - uint64_t Reset() { return impl_.Reset(); } - - // Adds |object| to a list of heap-allocated objects to be freed with |delete| - // when the arena is destroyed or reset. - template - PROTOBUF_ALWAYS_INLINE void Own(T* object) { - OwnInternal(object, std::is_convertible()); - } - - // Adds |object| to a list of objects whose destructors will be manually - // called when the arena is destroyed or reset. This differs from Own() in - // that it does not free the underlying memory with |delete|; hence, it is - // normally only used for objects that are placement-newed into - // arena-allocated memory. - template - PROTOBUF_ALWAYS_INLINE void OwnDestructor(T* object) { - if (object != NULL) { - impl_.AddCleanup(object, &internal::arena_destruct_object); - } - } - - // Adds a custom member function on an object to the list of destructors that - // will be manually called when the arena is destroyed or reset. This differs - // from OwnDestructor() in that any member function may be specified, not only - // the class destructor. - PROTOBUF_ALWAYS_INLINE void OwnCustomDestructor(void* object, - void (*destruct)(void*)) { - impl_.AddCleanup(object, destruct); - } - - // Retrieves the arena associated with |value| if |value| is an arena-capable - // message, or NULL otherwise. If possible, the call resolves at compile time. - // Note that we can often devirtualize calls to `value->GetArena()` so usually - // calling this method is unnecessary. - template - PROTOBUF_ALWAYS_INLINE static Arena* GetArena(const T* value) { - return GetArenaInternal(value); - } - - template - class InternalHelper { - private: - // Provides access to protected GetOwningArena to generated messages. - static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); } - - static void InternalSwap(T* a, T* b) { a->InternalSwap(b); } - - static Arena* GetArenaForAllocationInternal( - const T* p, std::true_type /*is_derived_from*/) { - return p->GetArenaForAllocation(); - } - - static Arena* GetArenaForAllocationInternal( - const T* p, std::false_type /*is_derived_from*/) { - return GetArenaForAllocationForNonMessage( - p, typename is_arena_constructable::type()); - } - - static Arena* GetArenaForAllocationForNonMessage( - const T* p, std::true_type /*is_arena_constructible*/) { - return p->GetArena(); - } - - static Arena* GetArenaForAllocationForNonMessage( - const T* p, std::false_type /*is_arena_constructible*/) { - return GetArenaForAllocationForNonMessageNonArenaConstructible( - p, typename has_get_arena::type()); - } - - static Arena* GetArenaForAllocationForNonMessageNonArenaConstructible( - const T* p, std::true_type /*has_get_arena*/) { - return p->GetArena(); - } - - static Arena* GetArenaForAllocationForNonMessageNonArenaConstructible( - const T* /* p */, std::false_type /*has_get_arena*/) { - return nullptr; - } - - template - static char DestructorSkippable(const typename U::DestructorSkippable_*); - template - static double DestructorSkippable(...); - - typedef std::integral_constant< - bool, sizeof(DestructorSkippable(static_cast(0))) == - sizeof(char) || - std::is_trivially_destructible::value> - is_destructor_skippable; - - template - static char ArenaConstructable( - const typename U::InternalArenaConstructable_*); - template - static double ArenaConstructable(...); - - typedef std::integral_constant( - static_cast(0))) == - sizeof(char)> - is_arena_constructable; - - template () - .GetArena())>::value, - int>::type = 0> - static char HasGetArena(decltype(&U::GetArena)); - template - static double HasGetArena(...); - - typedef std::integral_constant(nullptr)) == - sizeof(char)> - has_get_arena; - - template - static T* Construct(void* ptr, Args&&... args) { - return new (ptr) T(static_cast(args)...); - } - - static inline PROTOBUF_ALWAYS_INLINE T* New() { - return new T(nullptr); - } - - static Arena* GetArena(const T* p) { return p->GetArena(); } - - friend class Arena; - friend class TestUtil::ReflectionTester; - }; - - // Provides access to protected GetOwningArena to generated messages. For - // internal use only. - template - static Arena* InternalGetOwningArena(const T* p) { - return InternalHelper::GetOwningArena(p); - } - - // Provides access to protected GetArenaForAllocation to generated messages. - // For internal use only. - template - static Arena* InternalGetArenaForAllocation(const T* p) { - return InternalHelper::GetArenaForAllocationInternal( - p, std::is_convertible()); - } - - // Creates message-owned arena. For internal use only. - static Arena* InternalCreateMessageOwnedArena() { - return new Arena(internal::MessageOwned{}); - } - - // Checks whether this arena is message-owned. For internal use only. - bool InternalIsMessageOwnedArena() { return IsMessageOwned(); } - - // Helper typetraits that indicates support for arenas in a type T at compile - // time. This is public only to allow construction of higher-level templated - // utilities. - // - // is_arena_constructable::value is true if the message type T has arena - // support enabled, and false otherwise. - // - // is_destructor_skippable::value is true if the message type T has told - // the arena that it is safe to skip the destructor, and false otherwise. - // - // This is inside Arena because only Arena has the friend relationships - // necessary to see the underlying generated code traits. - template - struct is_arena_constructable : InternalHelper::is_arena_constructable {}; - template - struct is_destructor_skippable : InternalHelper::is_destructor_skippable { - }; - - private: - internal::ThreadSafeArena impl_; - - template - struct has_get_arena : InternalHelper::has_get_arena {}; - - // Constructor solely used by message-owned arena. - inline Arena(internal::MessageOwned) : impl_(internal::MessageOwned{}) {} - - // Checks whether this arena is message-owned. - PROTOBUF_ALWAYS_INLINE bool IsMessageOwned() const { - return impl_.IsMessageOwned(); - } - - void ReturnArrayMemory(void* p, size_t size) { - impl_.ReturnArrayMemory(p, size); - } - - template - PROTOBUF_NDEBUG_INLINE static T* CreateMessageInternal(Arena* arena, - Args&&... args) { - static_assert( - InternalHelper::is_arena_constructable::value, - "CreateMessage can only construct types that are ArenaConstructable"); - if (arena == NULL) { - return new T(nullptr, static_cast(args)...); - } else { - return arena->DoCreateMessage(static_cast(args)...); - } - } - - // This specialization for no arguments is necessary, because its behavior is - // slightly different. When the arena pointer is nullptr, it calls T() - // instead of T(nullptr). - template - PROTOBUF_NDEBUG_INLINE static T* CreateMessageInternal(Arena* arena) { - static_assert( - InternalHelper::is_arena_constructable::value, - "CreateMessage can only construct types that are ArenaConstructable"); - if (arena == NULL) { - // Generated arena constructor T(Arena*) is protected. Call via - // InternalHelper. - return InternalHelper::New(); - } else { - return arena->DoCreateMessage(); - } - } - - // Allocate and also optionally call collector with the allocated type info - // when allocation recording is enabled. - PROTOBUF_NDEBUG_INLINE void* AllocateInternal(size_t size, size_t align, - void (*destructor)(void*), - const std::type_info* type) { - // Monitor allocation if needed. - if (destructor == nullptr) { - return AllocateAlignedWithHook(size, align, type); - } else { - if (align <= 8) { - auto res = AllocateAlignedWithCleanup(internal::AlignUpTo8(size), type); - res.second->elem = res.first; - res.second->cleanup = destructor; - return res.first; - } else { - auto res = AllocateAlignedWithCleanup(size + align - 8, type); - auto ptr = internal::AlignTo(res.first, align); - res.second->elem = ptr; - res.second->cleanup = destructor; - return ptr; - } - } - } - - // CreateMessage requires that T supports arenas, but this private method - // works whether or not T supports arenas. These are not exposed to user code - // as it can cause confusing API usages, and end up having double free in - // user code. These are used only internally from LazyField and Repeated - // fields, since they are designed to work in all mode combinations. - template - PROTOBUF_ALWAYS_INLINE static Msg* DoCreateMaybeMessage(Arena* arena, - std::true_type, - Args&&... args) { - return CreateMessageInternal(arena, std::forward(args)...); - } - - template - PROTOBUF_ALWAYS_INLINE static T* DoCreateMaybeMessage(Arena* arena, - std::false_type, - Args&&... args) { - return Create(arena, std::forward(args)...); - } - - template - PROTOBUF_ALWAYS_INLINE static T* CreateMaybeMessage(Arena* arena, - Args&&... args) { - return DoCreateMaybeMessage(arena, is_arena_constructable(), - std::forward(args)...); - } - - // Just allocate the required size for the given type assuming the - // type has a trivial constructor. - template - PROTOBUF_NDEBUG_INLINE T* CreateInternalRawArray(size_t num_elements) { - GOOGLE_CHECK_LE(num_elements, std::numeric_limits::max() / sizeof(T)) - << "Requested size is too large to fit into size_t."; - // We count on compiler to realize that if sizeof(T) is a multiple of - // 8 AlignUpTo can be elided. - const size_t n = sizeof(T) * num_elements; - return static_cast( - AllocateAlignedWithHookForArray(n, alignof(T), RTTI_TYPE_ID(T))); - } - - template - PROTOBUF_NDEBUG_INLINE T* DoCreateMessage(Args&&... args) { - return InternalHelper::Construct( - AllocateInternal(sizeof(T), alignof(T), - internal::ObjectDestructor< - InternalHelper::is_destructor_skippable::value, - T>::destructor, - RTTI_TYPE_ID(T)), - this, std::forward(args)...); - } - - // CreateInArenaStorage is used to implement map field. Without it, - // Map need to call generated message's protected arena constructor, - // which needs to declare Map as friend of generated message. - template - static void CreateInArenaStorage(T* ptr, Arena* arena, Args&&... args) { - CreateInArenaStorageInternal(ptr, arena, - typename is_arena_constructable::type(), - std::forward(args)...); - if (arena != nullptr) { - RegisterDestructorInternal( - ptr, arena, - typename InternalHelper::is_destructor_skippable::type()); - } - } - - template - static void CreateInArenaStorageInternal(T* ptr, Arena* arena, - std::true_type, Args&&... args) { - InternalHelper::Construct(ptr, arena, std::forward(args)...); - } - template - static void CreateInArenaStorageInternal(T* ptr, Arena* /* arena */, - std::false_type, Args&&... args) { - new (ptr) T(std::forward(args)...); - } - - template - static void RegisterDestructorInternal(T* /* ptr */, Arena* /* arena */, - std::true_type) {} - template - static void RegisterDestructorInternal(T* ptr, Arena* arena, - std::false_type) { - arena->OwnDestructor(ptr); - } - - // These implement Create(). The second parameter has type 'true_type' if T is - // a subtype of Message and 'false_type' otherwise. - template - PROTOBUF_ALWAYS_INLINE static T* CreateInternal(Arena* arena, std::true_type, - Args&&... args) { - if (arena == nullptr) { - return new T(std::forward(args)...); - } else { - auto destructor = - internal::ObjectDestructor::value, - T>::destructor; - T* result = - new (arena->AllocateInternal(sizeof(T), alignof(T), destructor, - RTTI_TYPE_ID(T))) - T(std::forward(args)...); - return result; - } - } - template - PROTOBUF_ALWAYS_INLINE static T* CreateInternal(Arena* arena, std::false_type, - Args&&... args) { - if (arena == nullptr) { - return new T(std::forward(args)...); - } else { - auto destructor = - internal::ObjectDestructor::value, - T>::destructor; - return new (arena->AllocateInternal(sizeof(T), alignof(T), destructor, - RTTI_TYPE_ID(T))) - T(std::forward(args)...); - } - } - - // These implement Own(), which registers an object for deletion (destructor - // call and operator delete()). The second parameter has type 'true_type' if T - // is a subtype of Message and 'false_type' otherwise. Collapsing - // all template instantiations to one for generic Message reduces code size, - // using the virtual destructor instead. - template - PROTOBUF_ALWAYS_INLINE void OwnInternal(T* object, std::true_type) { - if (object != NULL) { - impl_.AddCleanup(object, &internal::arena_delete_object); - } - } - template - PROTOBUF_ALWAYS_INLINE void OwnInternal(T* object, std::false_type) { - if (object != NULL) { - impl_.AddCleanup(object, &internal::arena_delete_object); - } - } - - // Implementation for GetArena(). Only message objects with - // InternalArenaConstructable_ tags can be associated with an arena, and such - // objects must implement a GetArena() method. - template ::value, int>::type = 0> - PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) { - return InternalHelper::GetArena(value); - } - template ::value && - has_get_arena::value, - int>::type = 0> - PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) { - return value->GetArena(); - } - template ::value && - !has_get_arena::value, - int>::type = 0> - PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) { - (void)value; - return nullptr; - } - - template - PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArena(const T* value) { - return GetOwningArenaInternal( - value, std::is_convertible()); - } - - // Implementation for GetOwningArena(). All and only message objects have - // GetOwningArena() method. - template - PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArenaInternal( - const T* value, std::true_type) { - return InternalHelper::GetOwningArena(value); - } - template - PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArenaInternal( - const T* /* value */, std::false_type) { - return nullptr; - } - - void* AllocateAlignedWithHookForArray(size_t n, size_t align, - const std::type_info* type) { - if (align <= 8) { - return AllocateAlignedWithHookForArray(internal::AlignUpTo8(n), type); - } else { - // We are wasting space by over allocating align - 8 bytes. Compared - // to a dedicated function that takes current alignment in consideration. - // Such a scheme would only waste (align - 8)/2 bytes on average, but - // requires a dedicated function in the outline arena allocation - // functions. Possibly re-evaluate tradeoffs later. - return internal::AlignTo( - AllocateAlignedWithHookForArray(n + align - 8, type), align); - } - } - - void* AllocateAlignedWithHook(size_t n, size_t align, - const std::type_info* type) { - if (align <= 8) { - return AllocateAlignedWithHook(internal::AlignUpTo8(n), type); - } else { - // We are wasting space by over allocating align - 8 bytes. Compared - // to a dedicated function that takes current alignment in consideration. - // Such a scheme would only waste (align - 8)/2 bytes on average, but - // requires a dedicated function in the outline arena allocation - // functions. Possibly re-evaluate tradeoffs later. - return internal::AlignTo(AllocateAlignedWithHook(n + align - 8, type), - align); - } - } - - void* AllocateAlignedNoHook(size_t n); - void* AllocateAlignedWithHook(size_t n, const std::type_info* type); - void* AllocateAlignedWithHookForArray(size_t n, const std::type_info* type); - std::pair - AllocateAlignedWithCleanup(size_t n, const std::type_info* type); - - template - friend class internal::GenericTypeHandler; - friend class internal::InternalMetadata; // For user_arena(). - friend class internal::LazyField; // For CreateMaybeMessage. - friend class internal::EpsCopyInputStream; // For parser performance - friend class MessageLite; - template - friend class Map; - template - friend class RepeatedField; // For ReturnArrayMemory - friend class internal::RepeatedPtrFieldBase; // For ReturnArrayMemory - friend struct internal::ArenaTestPeer; -}; - -// Defined above for supporting environments without RTTI. -#undef RTTI_TYPE_ID - -} // namespace protobuf -} // namespace google - -#include - -#endif // GOOGLE_PROTOBUF_ARENA_H__ diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arena_impl.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arena_impl.h deleted file mode 100644 index 8af70c48f1..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arena_impl.h +++ /dev/null @@ -1,686 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file defines an Arena allocator for better allocation performance. - -#ifndef GOOGLE_PROTOBUF_ARENA_IMPL_H__ -#define GOOGLE_PROTOBUF_ARENA_IMPL_H__ - -#include -#include -#include - -#include -#include -#include - -#ifdef ADDRESS_SANITIZER -#include -#endif // ADDRESS_SANITIZER - -#include - -// Must be included last. -#include - - -namespace google { -namespace protobuf { -namespace internal { - -// To prevent sharing cache lines between threads -#ifdef __cpp_aligned_new -enum { kCacheAlignment = 64 }; -#else -enum { kCacheAlignment = alignof(max_align_t) }; // do the best we can -#endif - -inline constexpr size_t AlignUpTo8(size_t n) { - // Align n to next multiple of 8 (from Hacker's Delight, Chapter 3.) - return (n + 7) & static_cast(-8); -} - -using LifecycleIdAtomic = uint64_t; - -// MetricsCollector collects stats for a particular arena. -class PROTOBUF_EXPORT ArenaMetricsCollector { - public: - ArenaMetricsCollector(bool record_allocs) : record_allocs_(record_allocs) {} - - // Invoked when the arena is about to be destroyed. This method will - // typically finalize any metric collection and delete the collector. - // space_allocated is the space used by the arena. - virtual void OnDestroy(uint64_t space_allocated) = 0; - - // OnReset() is called when the associated arena is reset. - // space_allocated is the space used by the arena just before the reset. - virtual void OnReset(uint64_t space_allocated) = 0; - - // OnAlloc is called when an allocation happens. - // type_info is promised to be static - its lifetime extends to - // match program's lifetime (It is given by typeid operator). - // Note: typeid(void) will be passed as allocated_type every time we - // intentionally want to avoid monitoring an allocation. (i.e. internal - // allocations for managing the arena) - virtual void OnAlloc(const std::type_info* allocated_type, - uint64_t alloc_size) = 0; - - // Does OnAlloc() need to be called? If false, metric collection overhead - // will be reduced since we will not do extra work per allocation. - bool RecordAllocs() { return record_allocs_; } - - protected: - // This class is destructed by the call to OnDestroy(). - ~ArenaMetricsCollector() = default; - const bool record_allocs_; -}; - -struct AllocationPolicy { - static constexpr size_t kDefaultStartBlockSize = 256; - static constexpr size_t kDefaultMaxBlockSize = 8192; - - size_t start_block_size = kDefaultStartBlockSize; - size_t max_block_size = kDefaultMaxBlockSize; - void* (*block_alloc)(size_t) = nullptr; - void (*block_dealloc)(void*, size_t) = nullptr; - ArenaMetricsCollector* metrics_collector = nullptr; - - bool IsDefault() const { - return start_block_size == kDefaultMaxBlockSize && - max_block_size == kDefaultMaxBlockSize && block_alloc == nullptr && - block_dealloc == nullptr && metrics_collector == nullptr; - } -}; - -// Tagged pointer to an AllocationPolicy. -class TaggedAllocationPolicyPtr { - public: - constexpr TaggedAllocationPolicyPtr() : policy_(0) {} - - explicit TaggedAllocationPolicyPtr(AllocationPolicy* policy) - : policy_(reinterpret_cast(policy)) {} - - void set_policy(AllocationPolicy* policy) { - auto bits = policy_ & kTagsMask; - policy_ = reinterpret_cast(policy) | bits; - } - - AllocationPolicy* get() { - return reinterpret_cast(policy_ & kPtrMask); - } - const AllocationPolicy* get() const { - return reinterpret_cast(policy_ & kPtrMask); - } - - AllocationPolicy& operator*() { return *get(); } - const AllocationPolicy& operator*() const { return *get(); } - - AllocationPolicy* operator->() { return get(); } - const AllocationPolicy* operator->() const { return get(); } - - bool is_user_owned_initial_block() const { - return static_cast(get_mask()); - } - void set_is_user_owned_initial_block(bool v) { - set_mask(v); - } - - bool should_record_allocs() const { - return static_cast(get_mask()); - } - void set_should_record_allocs(bool v) { set_mask(v); } - - uintptr_t get_raw() const { return policy_; } - - inline void RecordAlloc(const std::type_info* allocated_type, - size_t n) const { - get()->metrics_collector->OnAlloc(allocated_type, n); - } - - private: - enum : uintptr_t { - kUserOwnedInitialBlock = 1, - kRecordAllocs = 2, - }; - - static constexpr uintptr_t kTagsMask = 7; - static constexpr uintptr_t kPtrMask = ~kTagsMask; - - template - uintptr_t get_mask() const { - return policy_ & kMask; - } - template - void set_mask(bool v) { - if (v) { - policy_ |= kMask; - } else { - policy_ &= ~kMask; - } - } - uintptr_t policy_; -}; - -enum class AllocationClient { kDefault, kArray }; - -// A simple arena allocator. Calls to allocate functions must be properly -// serialized by the caller, hence this class cannot be used as a general -// purpose allocator in a multi-threaded program. It serves as a building block -// for ThreadSafeArena, which provides a thread-safe arena allocator. -// -// This class manages -// 1) Arena bump allocation + owning memory blocks. -// 2) Maintaining a cleanup list. -// It delagetes the actual memory allocation back to ThreadSafeArena, which -// contains the information on block growth policy and backing memory allocation -// used. -class PROTOBUF_EXPORT SerialArena { - public: - struct Memory { - void* ptr; - size_t size; - }; - - // Node contains the ptr of the object to be cleaned up and the associated - // cleanup function ptr. - struct CleanupNode { - void* elem; // Pointer to the object to be cleaned up. - void (*cleanup)(void*); // Function pointer to the destructor or deleter. - }; - - void CleanupList(); - uint64_t SpaceAllocated() const { - return space_allocated_.load(std::memory_order_relaxed); - } - uint64_t SpaceUsed() const; - - bool HasSpace(size_t n) const { - return n <= static_cast(limit_ - ptr_); - } - - // See comments on `cached_blocks_` member for details. - PROTOBUF_ALWAYS_INLINE void* TryAllocateFromCachedBlock(size_t size) { - if (PROTOBUF_PREDICT_FALSE(size < 16)) return nullptr; - // We round up to the next larger block in case the memory doesn't match - // the pattern we are looking for. - const size_t index = Bits::Log2FloorNonZero64(size - 1) - 3; - - if (index >= cached_block_length_) return nullptr; - auto& cached_head = cached_blocks_[index]; - if (cached_head == nullptr) return nullptr; - - void* ret = cached_head; -#ifdef ADDRESS_SANITIZER - ASAN_UNPOISON_MEMORY_REGION(ret, size); -#endif // ADDRESS_SANITIZER - cached_head = cached_head->next; - return ret; - } - - // In kArray mode we look through cached blocks. - // We do not do this by default because most non-array allocations will not - // have the right size and will fail to find an appropriate cached block. - // - // TODO(sbenza): Evaluate if we should use cached blocks for message types of - // the right size. We can statically know if the allocation size can benefit - // from it. - template - void* AllocateAligned(size_t n, const AllocationPolicy* policy) { - GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. - GOOGLE_DCHECK_GE(limit_, ptr_); - - if (alloc_client == AllocationClient::kArray) { - if (void* res = TryAllocateFromCachedBlock(n)) { - return res; - } - } - - if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) { - return AllocateAlignedFallback(n, policy); - } - return AllocateFromExisting(n); - } - - private: - void* AllocateFromExisting(size_t n) { - void* ret = ptr_; - ptr_ += n; -#ifdef ADDRESS_SANITIZER - ASAN_UNPOISON_MEMORY_REGION(ret, n); -#endif // ADDRESS_SANITIZER - return ret; - } - - // See comments on `cached_blocks_` member for details. - void ReturnArrayMemory(void* p, size_t size) { - // We only need to check for 32-bit platforms. - // In 64-bit platforms the minimum allocation size from Repeated*Field will - // be 16 guaranteed. - if (sizeof(void*) < 8) { - if (PROTOBUF_PREDICT_FALSE(size < 16)) return; - } else { - GOOGLE_DCHECK(size >= 16); - } - - // We round down to the next smaller block in case the memory doesn't match - // the pattern we are looking for. eg, someone might have called Reserve() - // on the repeated field. - const size_t index = Bits::Log2FloorNonZero64(size) - 4; - - if (PROTOBUF_PREDICT_FALSE(index >= cached_block_length_)) { - // We can't put this object on the freelist so make this object the - // freelist. It is guaranteed it is larger than the one we have, and - // large enough to hold another allocation of `size`. - CachedBlock** new_list = static_cast(p); - size_t new_size = size / sizeof(CachedBlock*); - - std::copy(cached_blocks_, cached_blocks_ + cached_block_length_, - new_list); - std::fill(new_list + cached_block_length_, new_list + new_size, nullptr); - cached_blocks_ = new_list; - // Make the size fit in uint8_t. This is the power of two, so we don't - // need anything larger. - cached_block_length_ = - static_cast(std::min(size_t{64}, new_size)); - - return; - } - - auto& cached_head = cached_blocks_[index]; - auto* new_node = static_cast(p); - new_node->next = cached_head; - cached_head = new_node; -#ifdef ADDRESS_SANITIZER - ASAN_POISON_MEMORY_REGION(p, size); -#endif // ADDRESS_SANITIZER - } - - public: - // Allocate space if the current region provides enough space. - bool MaybeAllocateAligned(size_t n, void** out) { - GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. - GOOGLE_DCHECK_GE(limit_, ptr_); - if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) return false; - *out = AllocateFromExisting(n); - return true; - } - - std::pair AllocateAlignedWithCleanup( - size_t n, const AllocationPolicy* policy) { - GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. - if (PROTOBUF_PREDICT_FALSE(!HasSpace(n + kCleanupSize))) { - return AllocateAlignedWithCleanupFallback(n, policy); - } - return AllocateFromExistingWithCleanupFallback(n); - } - - private: - std::pair AllocateFromExistingWithCleanupFallback( - size_t n) { - void* ret = ptr_; - ptr_ += n; - limit_ -= kCleanupSize; -#ifdef ADDRESS_SANITIZER - ASAN_UNPOISON_MEMORY_REGION(ret, n); - ASAN_UNPOISON_MEMORY_REGION(limit_, kCleanupSize); -#endif // ADDRESS_SANITIZER - return CreatePair(ret, reinterpret_cast(limit_)); - } - - public: - void AddCleanup(void* elem, void (*cleanup)(void*), - const AllocationPolicy* policy) { - auto res = AllocateAlignedWithCleanup(0, policy); - res.second->elem = elem; - res.second->cleanup = cleanup; - } - - void* owner() const { return owner_; } - SerialArena* next() const { return next_; } - void set_next(SerialArena* next) { next_ = next; } - - private: - friend class ThreadSafeArena; - friend class ArenaBenchmark; - - // Creates a new SerialArena inside mem using the remaining memory as for - // future allocations. - static SerialArena* New(SerialArena::Memory mem, void* owner, - ThreadSafeArenaStats* stats); - // Free SerialArena returning the memory passed in to New - template - Memory Free(Deallocator deallocator); - - // Blocks are variable length malloc-ed objects. The following structure - // describes the common header for all blocks. - struct Block { - Block(Block* next, size_t size) : next(next), size(size), start(nullptr) {} - - char* Pointer(size_t n) { - GOOGLE_DCHECK(n <= size); - return reinterpret_cast(this) + n; - } - - Block* const next; - const size_t size; - CleanupNode* start; - // data follows - }; - - void* owner_; // &ThreadCache of this thread; - Block* head_; // Head of linked list of blocks. - SerialArena* next_; // Next SerialArena in this linked list. - size_t space_used_ = 0; // Necessary for metrics. - std::atomic space_allocated_; - - // Next pointer to allocate from. Always 8-byte aligned. Points inside - // head_ (and head_->pos will always be non-canonical). We keep these - // here to reduce indirection. - char* ptr_; - // Limiting address up to which memory can be allocated from the head block. - char* limit_; - // For holding sampling information. The pointer is owned by the - // ThreadSafeArena that holds this serial arena. - ThreadSafeArenaStats* arena_stats_; - - // Repeated*Field and Arena play together to reduce memory consumption by - // reusing blocks. Currently, natural growth of the repeated field types makes - // them allocate blocks of size `8 + 2^N, N>=3`. - // When the repeated field grows returns the previous block and we put it in - // this free list. - // `cached_blocks_[i]` points to the free list for blocks of size `8+2^(i+3)`. - // The array of freelists is grown when needed in `ReturnArrayMemory()`. - struct CachedBlock { - // Simple linked list. - CachedBlock* next; - }; - uint8_t cached_block_length_ = 0; - CachedBlock** cached_blocks_ = nullptr; - - // Constructor is private as only New() should be used. - inline SerialArena(Block* b, void* owner, ThreadSafeArenaStats* stats); - void* AllocateAlignedFallback(size_t n, const AllocationPolicy* policy); - std::pair AllocateAlignedWithCleanupFallback( - size_t n, const AllocationPolicy* policy); - void AllocateNewBlock(size_t n, const AllocationPolicy* policy); - - std::pair CreatePair(void* ptr, CleanupNode* node) { - return {ptr, node}; - } - - public: - static constexpr size_t kBlockHeaderSize = AlignUpTo8(sizeof(Block)); - static constexpr size_t kCleanupSize = AlignUpTo8(sizeof(CleanupNode)); -}; - -// Tag type used to invoke the constructor of message-owned arena. -// Only message-owned arenas use this constructor for creation. -// Such constructors are internal implementation details of the library. -struct MessageOwned { - explicit MessageOwned() = default; -}; - -// This class provides the core Arena memory allocation library. Different -// implementations only need to implement the public interface below. -// Arena is not a template type as that would only be useful if all protos -// in turn would be templates, which will/cannot happen. However separating -// the memory allocation part from the cruft of the API users expect we can -// use #ifdef the select the best implementation based on hardware / OS. -class PROTOBUF_EXPORT ThreadSafeArena { - public: - ThreadSafeArena() { Init(); } - - // Constructor solely used by message-owned arena. - ThreadSafeArena(internal::MessageOwned) : tag_and_id_(kMessageOwnedArena) { - Init(); - } - - ThreadSafeArena(char* mem, size_t size) { InitializeFrom(mem, size); } - - explicit ThreadSafeArena(void* mem, size_t size, - const AllocationPolicy& policy) { - InitializeWithPolicy(mem, size, policy); - } - - // Destructor deletes all owned heap allocated objects, and destructs objects - // that have non-trivial destructors, except for proto2 message objects whose - // destructors can be skipped. Also, frees all blocks except the initial block - // if it was passed in. - ~ThreadSafeArena(); - - uint64_t Reset(); - - uint64_t SpaceAllocated() const; - uint64_t SpaceUsed() const; - - template - void* AllocateAligned(size_t n, const std::type_info* type) { - SerialArena* arena = nullptr; - if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && - GetSerialArenaFast(&arena))) { - return arena->AllocateAligned(n, AllocPolicy()); - } else { - return AllocateAlignedFallback(n, type); - } - } - - void ReturnArrayMemory(void* p, size_t size) { - SerialArena* arena = nullptr; - if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { - arena->ReturnArrayMemory(p, size); - } - } - - // This function allocates n bytes if the common happy case is true and - // returns true. Otherwise does nothing and returns false. This strange - // semantics is necessary to allow callers to program functions that only - // have fallback function calls in tail position. This substantially improves - // code for the happy path. - PROTOBUF_NDEBUG_INLINE bool MaybeAllocateAligned(size_t n, void** out) { - SerialArena* arena; - if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && - GetSerialArenaFromThreadCache(&arena))) { - return arena->MaybeAllocateAligned(n, out); - } - return false; - } - - std::pair AllocateAlignedWithCleanup( - size_t n, const std::type_info* type); - - // Add object pointer and cleanup function pointer to the list. - void AddCleanup(void* elem, void (*cleanup)(void*)); - - // Checks whether this arena is message-owned. - PROTOBUF_ALWAYS_INLINE bool IsMessageOwned() const { - return tag_and_id_ & kMessageOwnedArena; - } - - private: - // Unique for each arena. Changes on Reset(). - uint64_t tag_and_id_ = 0; - // The LSB of tag_and_id_ indicates if the arena is message-owned. - enum : uint64_t { kMessageOwnedArena = 1 }; - - TaggedAllocationPolicyPtr alloc_policy_; // Tagged pointer to AllocPolicy. - - static_assert(std::is_trivially_destructible{}, - "SerialArena needs to be trivially destructible."); - // Pointer to a linked list of SerialArena. - std::atomic threads_; - std::atomic hint_; // Fast thread-local block access - - const AllocationPolicy* AllocPolicy() const { return alloc_policy_.get(); } - void InitializeFrom(void* mem, size_t size); - void InitializeWithPolicy(void* mem, size_t size, AllocationPolicy policy); - void* AllocateAlignedFallback(size_t n, const std::type_info* type); - std::pair - AllocateAlignedWithCleanupFallback(size_t n, const std::type_info* type); - - void Init(); - void SetInitialBlock(void* mem, size_t size); - - // Delete or Destruct all objects owned by the arena. - void CleanupList(); - - inline uint64_t LifeCycleId() const { - return tag_and_id_ & ~kMessageOwnedArena; - } - - inline void CacheSerialArena(SerialArena* serial) { - thread_cache().last_serial_arena = serial; - thread_cache().last_lifecycle_id_seen = tag_and_id_; - // TODO(haberman): evaluate whether we would gain efficiency by getting rid - // of hint_. It's the only write we do to ThreadSafeArena in the allocation - // path, which will dirty the cache line. - - hint_.store(serial, std::memory_order_release); - } - - PROTOBUF_NDEBUG_INLINE bool GetSerialArenaFast(SerialArena** arena) { - if (GetSerialArenaFromThreadCache(arena)) return true; - - // Check whether we own the last accessed SerialArena on this arena. This - // fast path optimizes the case where a single thread uses multiple arenas. - ThreadCache* tc = &thread_cache(); - SerialArena* serial = hint_.load(std::memory_order_acquire); - if (PROTOBUF_PREDICT_TRUE(serial != nullptr && serial->owner() == tc)) { - *arena = serial; - return true; - } - return false; - } - - PROTOBUF_NDEBUG_INLINE bool GetSerialArenaFromThreadCache( - SerialArena** arena) { - // If this thread already owns a block in this arena then try to use that. - // This fast path optimizes the case where multiple threads allocate from - // the same arena. - ThreadCache* tc = &thread_cache(); - if (PROTOBUF_PREDICT_TRUE(tc->last_lifecycle_id_seen == tag_and_id_)) { - *arena = tc->last_serial_arena; - return true; - } - return false; - } - SerialArena* GetSerialArenaFallback(void* me); - - template - void PerSerialArena(Functor fn) { - // By omitting an Acquire barrier we ensure that any user code that doesn't - // properly synchronize Reset() or the destructor will throw a TSAN warning. - SerialArena* serial = threads_.load(std::memory_order_relaxed); - - for (; serial; serial = serial->next()) fn(serial); - } - - // Releases all memory except the first block which it returns. The first - // block might be owned by the user and thus need some extra checks before - // deleting. - SerialArena::Memory Free(size_t* space_allocated); - -#ifdef _MSC_VER -#pragma warning(disable : 4324) -#endif - struct alignas(kCacheAlignment) ThreadCache { -#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) - // If we are using the ThreadLocalStorage class to store the ThreadCache, - // then the ThreadCache's default constructor has to be responsible for - // initializing it. - ThreadCache() - : next_lifecycle_id(0), - last_lifecycle_id_seen(-1), - last_serial_arena(nullptr) {} -#endif - - // Number of per-thread lifecycle IDs to reserve. Must be power of two. - // To reduce contention on a global atomic, each thread reserves a batch of - // IDs. The following number is calculated based on a stress test with - // ~6500 threads all frequently allocating a new arena. - static constexpr size_t kPerThreadIds = 256; - // Next lifecycle ID available to this thread. We need to reserve a new - // batch, if `next_lifecycle_id & (kPerThreadIds - 1) == 0`. - uint64_t next_lifecycle_id; - // The ThreadCache is considered valid as long as this matches the - // lifecycle_id of the arena being used. - uint64_t last_lifecycle_id_seen; - SerialArena* last_serial_arena; - }; - - // Lifecycle_id can be highly contended variable in a situation of lots of - // arena creation. Make sure that other global variables are not sharing the - // cacheline. -#ifdef _MSC_VER -#pragma warning(disable : 4324) -#endif - struct alignas(kCacheAlignment) CacheAlignedLifecycleIdGenerator { - std::atomic id; - }; - static CacheAlignedLifecycleIdGenerator lifecycle_id_generator_; -#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) - // iOS does not support __thread keyword so we use a custom thread local - // storage class we implemented. - static ThreadCache& thread_cache(); -#elif defined(PROTOBUF_USE_DLLS) - // Thread local variables cannot be exposed through DLL interface but we can - // wrap them in static functions. - static ThreadCache& thread_cache(); -#else - static PROTOBUF_THREAD_LOCAL ThreadCache thread_cache_; - static ThreadCache& thread_cache() { return thread_cache_; } -#endif - - ThreadSafeArenaStatsHandle arena_stats_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ThreadSafeArena); - // All protos have pointers back to the arena hence Arena must have - // pointer stability. - ThreadSafeArena(ThreadSafeArena&&) = delete; - ThreadSafeArena& operator=(ThreadSafeArena&&) = delete; - - public: - // kBlockHeaderSize is sizeof(Block), aligned up to the nearest multiple of 8 - // to protect the invariant that pos is always at a multiple of 8. - static constexpr size_t kBlockHeaderSize = SerialArena::kBlockHeaderSize; - static constexpr size_t kSerialArenaSize = - (sizeof(SerialArena) + 7) & static_cast(-8); - static_assert(kBlockHeaderSize % 8 == 0, - "kBlockHeaderSize must be a multiple of 8."); - static_assert(kSerialArenaSize % 8 == 0, - "kSerialArenaSize must be a multiple of 8."); -}; - -} // namespace internal -} // namespace protobuf -} // namespace google - -#include - -#endif // GOOGLE_PROTOBUF_ARENA_IMPL_H__ diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arenastring.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arenastring.h deleted file mode 100644 index 6bc8395f23..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arenastring.h +++ /dev/null @@ -1,480 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_ARENASTRING_H__ -#define GOOGLE_PROTOBUF_ARENASTRING_H__ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -// must be last: -#include - -#ifdef SWIG -#error "You cannot SWIG proto headers" -#endif - - -namespace google { -namespace protobuf { -namespace internal { -class EpsCopyInputStream; - -class SwapFieldHelper; - -// Declared in message_lite.h -PROTOBUF_EXPORT extern ExplicitlyConstructedArenaString - fixed_address_empty_string; - -// Lazy string instance to support string fields with non-empty default. -// These are initialized on the first call to .get(). -class PROTOBUF_EXPORT LazyString { - public: - // We explicitly make LazyString an aggregate so that MSVC can do constant - // initialization on it without marking it `constexpr`. - // We do not want to use `constexpr` because it makes it harder to have extern - // storage for it and causes library bloat. - struct InitValue { - const char* ptr; - size_t size; - }; - // We keep a union of the initialization value and the std::string to save on - // space. We don't need the string array after Init() is done. - union { - mutable InitValue init_value_; - alignas(std::string) mutable char string_buf_[sizeof(std::string)]; - }; - mutable std::atomic inited_; - - const std::string& get() const { - // This check generates less code than a call-once invocation. - auto* res = inited_.load(std::memory_order_acquire); - if (PROTOBUF_PREDICT_FALSE(res == nullptr)) return Init(); - return *res; - } - - private: - // Initialize the string in `string_buf_`, update `inited_` and return it. - // We return it here to avoid having to read it again in the inlined code. - const std::string& Init() const; -}; - -class TaggedStringPtr { - public: - // Bit flags qualifying string properties. We can use 2 bits as - // ptr_ is guaranteed and enforced to be aligned on 4 byte boundaries. - enum Flags { - kArenaBit = 0x1, // ptr is arena allocated - kMutableBit = 0x2, // ptr contents are fully mutable - kMask = 0x3 // Bit mask - }; - - // Composed logical types - enum Type { - // Default strings are immutable and never owned. - kDefault = 0, - - // Allocated strings are mutable and (as the name implies) owned. - // A heap allocated string must be deleted. - kAllocated = kMutableBit, - - // Mutable arena strings are strings where the string instance is owned - // by the arena, but the string contents itself are owned by the string - // instance. Mutable arena string instances need to be destroyed which is - // typically done through a cleanup action added to the arena owning it. - kMutableArena = kArenaBit | kMutableBit, - - // Fixed size arena strings are strings where both the string instance and - // the string contents are fully owned by the arena. Fixed size arena - // strings are a platform and c++ library specific customization. Fixed - // size arena strings are immutable, with the exception of custom internal - // updates to the content that fit inside the existing capacity. - // Fixed size arena strings must never be deleted or destroyed. - kFixedSizeArena = kArenaBit, - }; - - TaggedStringPtr() = default; - explicit constexpr TaggedStringPtr(ExplicitlyConstructedArenaString* ptr) - : ptr_(ptr) {} - - // Sets the value to `p`, tagging the value as being a 'default' value. - // See documentation for kDefault for more info. - inline const std::string* SetDefault(const std::string* p) { - return TagAs(kDefault, const_cast(p)); - } - - // Sets the value to `p`, tagging the value as a heap allocated value. - // Allocated strings are mutable and (as the name implies) owned. - // `p` must not be null - inline std::string* SetAllocated(std::string* p) { - return TagAs(kAllocated, p); - } - - // Sets the value to `p`, tagging the value as a fixed size arena string. - // See documentation for kFixedSizeArena for more info. - // `p` must not be null - inline std::string* SetFixedSizeArena(std::string* p) { - return TagAs(kFixedSizeArena, p); - } - - // Sets the value to `p`, tagging the value as a mutable arena string. - // See documentation for kMutableArena for more info. - // `p` must not be null - inline std::string* SetMutableArena(std::string* p) { - return TagAs(kMutableArena, p); - } - - // Returns true if the contents of the current string are fully mutable. - inline bool IsMutable() const { return as_int() & kMutableBit; } - - // Returns true if the current string is an immutable default value. - inline bool IsDefault() const { return (as_int() & kMask) == kDefault; } - - // If the current string is a heap-allocated mutable value, returns a pointer - // to it. Returns nullptr otherwise. - inline std::string *GetIfAllocated() const { - auto allocated = as_int() ^ kAllocated; - if (allocated & kMask) return nullptr; - - auto ptr = reinterpret_cast(allocated); - PROTOBUF_ASSUME(ptr != nullptr); - return ptr; - } - - // Returns true if the current string is an arena allocated value. - // This means it's either a mutable or fixed size arena string. - inline bool IsArena() const { return as_int() & kArenaBit; } - - // Returns true if the current string is a fixed size arena allocated value. - inline bool IsFixedSizeArena() const { - return (as_int() & kMask) == kFixedSizeArena; - } - - // Returns the contained string pointer. - inline std::string* Get() const { - return reinterpret_cast(as_int() & ~kMask); - } - - // Returns true if the contained pointer is null, indicating some error. - // The Null value is only used during parsing for temporary values. - // A persisted ArenaStringPtr value is never null. - inline bool IsNull() { return ptr_ == nullptr; } - - private: - static inline void assert_aligned(const void* p) { - GOOGLE_DCHECK_EQ(reinterpret_cast(p) & kMask, 0UL); - } - - inline std::string* TagAs(Type type, std::string* p) { - GOOGLE_DCHECK(p != nullptr); - assert_aligned(p); - ptr_ = reinterpret_cast(reinterpret_cast(p) | type); - return p; - } - - uintptr_t as_int() const { return reinterpret_cast(ptr_); } - void* ptr_; -}; - -static_assert(std::is_trivial::value, - "TaggedStringPtr must be trivial"); - -// This class encapsulates a pointer to a std::string with or without arena -// owned contents, tagged by the bottom bits of the string pointer. It is a -// high-level wrapper that almost directly corresponds to the interface required -// by string fields in generated code. It replaces the old std::string* pointer -// in such cases. -// -// The string pointer is tagged to be either a default, externally owned value, -// a mutable heap allocated value, or an arena allocated value. The object uses -// a single global instance of an empty string that is used as the initial -// default value. Fields that have empty default values directly use this global -// default. Fields that have non empty default values are supported through -// lazily initialized default values managed by the LazyString class. -// -// Generated code and reflection code both ensure that ptr_ is never null. -// Because ArenaStringPtr is used in oneof unions, its constructor is a NOP and -// the field is always manually initialized via method calls. -// -// See TaggedStringPtr for more information about the types of string values -// being held, and the mutable and ownership invariants for each type. -struct PROTOBUF_EXPORT ArenaStringPtr { - ArenaStringPtr() = default; - constexpr ArenaStringPtr(ExplicitlyConstructedArenaString* default_value, - ConstantInitialized) - : tagged_ptr_(default_value) {} - - // Called from generated code / reflection runtime only. Resets value to point - // to a default string pointer, with the semantics that this ArenaStringPtr - // does not own the pointed-to memory. Disregards initial value of ptr_ (so - // this is the *ONLY* safe method to call after construction or when - // reinitializing after becoming the active field in a oneof union). - inline void InitDefault(); - - // Similar to `InitDefault` except that it allows the default value to be - // initialized to an externally owned string. This method is called from - // parsing code. `str` must not be null and outlive this instance. - inline void InitExternal(const std::string* str); - - // Called from generated code / reflection runtime only. Resets the value of - // this instances to the heap allocated value in `str`. `str` must not be - // null. Invokes `arena->Own(str)` to transfer ownership into the arena if - // `arena` is not null, else, `str` will be owned by ArenaStringPtr. This - // function should only be used to initialize a ArenaStringPtr or on an - // instance known to not carry any heap allocated value. - inline void InitAllocated(std::string* str, Arena* arena); - - void Set(ConstStringParam value, Arena* arena); - void Set(std::string&& value, Arena* arena); - void Set(const char* s, Arena* arena); - void Set(const char* s, size_t n, Arena* arena); - - void SetBytes(ConstStringParam value, Arena* arena); - void SetBytes(std::string&& value, Arena* arena); - void SetBytes(const char* s, Arena* arena); - void SetBytes(const void* p, size_t n, Arena* arena); - - template - void Set(std::reference_wrapper const_string_ref, - ::google::protobuf::Arena* arena) { - Set(const_string_ref.get(), arena); - } - - // Returns a mutable std::string reference. - // The version accepting a `LazyString` value is used in the generated code to - // initialize mutable copies for fields with a non-empty default where the - // default value is lazily initialized. - std::string* Mutable(Arena* arena); - std::string* Mutable(const LazyString& default_value, Arena* arena); - - // Gets a mutable pointer with unspecified contents. - // This function is identical to Mutable(), except it is optimized for the - // case where the caller is not interested in the current contents. For - // example, if the current field is not mutable, it will re-initialize the - // value with an empty string rather than a (non-empty) default value. - // Likewise, if the current value is a fixed size arena string with contents, - // it will be initialized into an empty mutable arena string. - std::string* MutableNoCopy(Arena* arena); - - // Basic accessors. - PROTOBUF_NDEBUG_INLINE const std::string& Get() const { - // Unconditionally mask away the tag. - return *tagged_ptr_.Get(); - } - - // Returns a pointer to the stored contents for this instance. - // This method is for internal debugging and tracking purposes only. - PROTOBUF_NDEBUG_INLINE const std::string* UnsafeGetPointer() const - PROTOBUF_RETURNS_NONNULL { - return tagged_ptr_.Get(); - } - - // Release returns a std::string* instance that is heap-allocated and is not - // Own()'d by any arena. If the field is not set, this returns nullptr. The - // caller retains ownership. Clears this field back to the default state. - // Used to implement release_() methods on generated classes. - PROTOBUF_NODISCARD std::string* Release(); - - // Takes a std::string that is heap-allocated, and takes ownership. The - // std::string's destructor is registered with the arena. Used to implement - // set_allocated_ in generated classes. - void SetAllocated(std::string* value, Arena* arena); - - // Frees storage (if not on an arena). - void Destroy(); - - // Clears content, but keeps allocated std::string, to avoid the overhead of - // heap operations. After this returns, the content (as seen by the user) will - // always be the empty std::string. Assumes that |default_value| is an empty - // std::string. - void ClearToEmpty(); - - // Clears content, assuming that the current value is not the empty - // string default. - void ClearNonDefaultToEmpty(); - - // Clears content, but keeps allocated std::string if arena != nullptr, to - // avoid the overhead of heap operations. After this returns, the content - // (as seen by the user) will always be equal to |default_value|. - void ClearToDefault(const LazyString& default_value, ::google::protobuf::Arena* arena); - - // Swaps internal pointers. Arena-safety semantics: this is guarded by the - // logic in Swap()/UnsafeArenaSwap() at the message level, so this method is - // 'unsafe' if called directly. - inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(ArenaStringPtr* rhs, - Arena* rhs_arena, - ArenaStringPtr* lhs, - Arena* lhs_arena); - - // Internal setter used only at parse time to directly set a donated string - // value. - void UnsafeSetTaggedPointer(TaggedStringPtr value) { tagged_ptr_ = value; } - // Generated code only! An optimization, in certain cases the generated - // code is certain we can obtain a std::string with no default checks and - // tag tests. - std::string* UnsafeMutablePointer() PROTOBUF_RETURNS_NONNULL; - - // Returns true if this instances holds an immutable default value. - inline bool IsDefault() const { return tagged_ptr_.IsDefault(); } - - private: - template - inline std::string* NewString(Arena* arena, Args&&... args) { - if (arena == nullptr) { - auto* s = new std::string(std::forward(args)...); - return tagged_ptr_.SetAllocated(s); - } else { - auto* s = Arena::Create(arena, std::forward(args)...); - return tagged_ptr_.SetMutableArena(s); - } - } - - TaggedStringPtr tagged_ptr_; - - bool IsFixedSizeArena() const { return false; } - - // Swaps tagged pointer without debug hardening. This is to allow python - // protobuf to maintain pointer stability even in DEBUG builds. - inline PROTOBUF_NDEBUG_INLINE static void UnsafeShallowSwap( - ArenaStringPtr* rhs, ArenaStringPtr* lhs) { - std::swap(lhs->tagged_ptr_, rhs->tagged_ptr_); - } - - friend class ::google::protobuf::internal::SwapFieldHelper; - friend class TcParser; - - // Slow paths. - - // MutableSlow requires that !IsString() || IsDefault - // Variadic to support 0 args for empty default and 1 arg for LazyString. - template - std::string* MutableSlow(::google::protobuf::Arena* arena, const Lazy&... lazy_default); - - friend class EpsCopyInputStream; -}; - -inline void ArenaStringPtr::InitDefault() { - tagged_ptr_ = TaggedStringPtr(&fixed_address_empty_string); -} - -inline void ArenaStringPtr::InitExternal(const std::string* str) { - tagged_ptr_.SetDefault(str); -} - -inline void ArenaStringPtr::InitAllocated(std::string* str, Arena* arena) { - if (arena != nullptr) { - tagged_ptr_.SetMutableArena(str); - arena->Own(str); - } else { - tagged_ptr_.SetAllocated(str); - } -} - -inline void ArenaStringPtr::Set(const char* s, Arena* arena) { - Set(ConstStringParam{s}, arena); -} - -inline void ArenaStringPtr::Set(const char* s, size_t n, Arena* arena) { - Set(ConstStringParam{s, n}, arena); -} - -inline void ArenaStringPtr::SetBytes(ConstStringParam value, Arena* arena) { - Set(value, arena); -} - -inline void ArenaStringPtr::SetBytes(std::string&& value, Arena* arena) { - Set(std::move(value), arena); -} - -inline void ArenaStringPtr::SetBytes(const char* s, Arena* arena) { - Set(s, arena); -} - -inline void ArenaStringPtr::SetBytes(const void* p, size_t n, Arena* arena) { - Set(ConstStringParam{static_cast(p), n}, arena); -} - -// Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs. -inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap( // - ArenaStringPtr* rhs, Arena* rhs_arena, // - ArenaStringPtr* lhs, Arena* lhs_arena) { - // Silence unused variable warnings in release buildls. - (void)rhs_arena; - (void)lhs_arena; - std::swap(lhs->tagged_ptr_, rhs->tagged_ptr_); -#ifdef PROTOBUF_FORCE_COPY_IN_SWAP - auto force_realloc = [](ArenaStringPtr* p, Arena* arena) { - if (p->IsDefault()) return; - std::string* old_value = p->tagged_ptr_.Get(); - std::string* new_value = - p->IsFixedSizeArena() - ? Arena::Create(arena, *old_value) - : Arena::Create(arena, std::move(*old_value)); - if (arena == nullptr) { - delete old_value; - p->tagged_ptr_.SetAllocated(new_value); - } else { - p->tagged_ptr_.SetMutableArena(new_value); - } - }; - // Because, at this point, tagged_ptr_ has been swapped, arena should also be - // swapped. - force_realloc(lhs, rhs_arena); - force_realloc(rhs, lhs_arena); -#endif // PROTOBUF_FORCE_COPY_IN_SWAP -} - -inline void ArenaStringPtr::ClearNonDefaultToEmpty() { - // Unconditionally mask away the tag. - tagged_ptr_.Get()->clear(); -} - -inline std::string* ArenaStringPtr::UnsafeMutablePointer() { - GOOGLE_DCHECK(tagged_ptr_.IsMutable()); - GOOGLE_DCHECK(tagged_ptr_.Get() != nullptr); - return tagged_ptr_.Get(); -} - - -} // namespace internal -} // namespace protobuf -} // namespace google - -#include - -#endif // GOOGLE_PROTOBUF_ARENASTRING_H__ diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arenaz_sampler.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arenaz_sampler.h deleted file mode 100644 index b04b0cc678..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/arenaz_sampler.h +++ /dev/null @@ -1,207 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_SRC_GOOGLE_PROTOBUF_ARENAZ_SAMPLER_H__ -#define GOOGLE_PROTOBUF_SRC_GOOGLE_PROTOBUF_ARENAZ_SAMPLER_H__ - -#include -#include -#include - - -// Must be included last. -#include - -namespace google { -namespace protobuf { -namespace internal { - -#if defined(PROTOBUF_ARENAZ_SAMPLE) -struct ThreadSafeArenaStats; -void RecordResetSlow(ThreadSafeArenaStats* info); -void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t requested, - size_t allocated, size_t wasted); -// Stores information about a sampled thread safe arena. All mutations to this -// *must* be made through `Record*` functions below. All reads from this *must* -// only occur in the callback to `ThreadSafeArenazSampler::Iterate`. -struct ThreadSafeArenaStats - : public absl::profiling_internal::Sample { - // Constructs the object but does not fill in any fields. - ThreadSafeArenaStats(); - ~ThreadSafeArenaStats(); - - // Puts the object into a clean state, fills in the logically `const` members, - // blocking for any readers that are currently sampling the object. - void PrepareForSampling() ABSL_EXCLUSIVE_LOCKS_REQUIRED(init_mu); - - // These fields are mutated by the various Record* APIs and need to be - // thread-safe. - std::atomic num_allocations; - std::atomic num_resets; - std::atomic bytes_requested; - std::atomic bytes_allocated; - std::atomic bytes_wasted; - // Records the largest size an arena ever had. Maintained across resets. - std::atomic max_bytes_allocated; - // Bit i when set to 1 indicates that a thread with tid % 63 = i accessed the - // underlying arena. The field is maintained across resets. - std::atomic thread_ids; - - // All of the fields below are set by `PrepareForSampling`, they must not - // be mutated in `Record*` functions. They are logically `const` in that - // sense. These are guarded by init_mu, but that is not externalized to - // clients, who can only read them during - // `ThreadSafeArenazSampler::Iterate` which will hold the lock. - static constexpr int kMaxStackDepth = 64; - int32_t depth; - void* stack[kMaxStackDepth]; - static void RecordAllocateStats(ThreadSafeArenaStats* info, size_t requested, - size_t allocated, size_t wasted) { - if (PROTOBUF_PREDICT_TRUE(info == nullptr)) return; - RecordAllocateSlow(info, requested, allocated, wasted); - } -}; - -ThreadSafeArenaStats* SampleSlow(int64_t* next_sample); -void UnsampleSlow(ThreadSafeArenaStats* info); - -class ThreadSafeArenaStatsHandle { - public: - explicit ThreadSafeArenaStatsHandle() = default; - explicit ThreadSafeArenaStatsHandle(ThreadSafeArenaStats* info) - : info_(info) {} - - ~ThreadSafeArenaStatsHandle() { - if (PROTOBUF_PREDICT_TRUE(info_ == nullptr)) return; - UnsampleSlow(info_); - } - - ThreadSafeArenaStatsHandle(ThreadSafeArenaStatsHandle&& other) noexcept - : info_(absl::exchange(other.info_, nullptr)) {} - - ThreadSafeArenaStatsHandle& operator=( - ThreadSafeArenaStatsHandle&& other) noexcept { - if (PROTOBUF_PREDICT_FALSE(info_ != nullptr)) { - UnsampleSlow(info_); - } - info_ = absl::exchange(other.info_, nullptr); - return *this; - } - - void RecordReset() { - if (PROTOBUF_PREDICT_TRUE(info_ == nullptr)) return; - RecordResetSlow(info_); - } - - ThreadSafeArenaStats* MutableStats() { return info_; } - - friend void swap(ThreadSafeArenaStatsHandle& lhs, - ThreadSafeArenaStatsHandle& rhs) { - std::swap(lhs.info_, rhs.info_); - } - - friend class ThreadSafeArenaStatsHandlePeer; - - private: - ThreadSafeArenaStats* info_ = nullptr; -}; - -using ThreadSafeArenazSampler = - ::absl::profiling_internal::SampleRecorder; - -extern PROTOBUF_THREAD_LOCAL int64_t global_next_sample; - -// Returns an RAII sampling handle that manages registration and unregistation -// with the global sampler. -inline ThreadSafeArenaStatsHandle Sample() { - if (PROTOBUF_PREDICT_TRUE(--global_next_sample > 0)) { - return ThreadSafeArenaStatsHandle(nullptr); - } - return ThreadSafeArenaStatsHandle(SampleSlow(&global_next_sample)); -} - -#else -struct ThreadSafeArenaStats { - static void RecordAllocateStats(ThreadSafeArenaStats*, size_t /*requested*/, - size_t /*allocated*/, size_t /*wasted*/) {} -}; - -ThreadSafeArenaStats* SampleSlow(int64_t* next_sample); -void UnsampleSlow(ThreadSafeArenaStats* info); - -class ThreadSafeArenaStatsHandle { - public: - explicit ThreadSafeArenaStatsHandle() = default; - explicit ThreadSafeArenaStatsHandle(ThreadSafeArenaStats*) {} - - void RecordReset() {} - - ThreadSafeArenaStats* MutableStats() { return nullptr; } - - friend void swap(ThreadSafeArenaStatsHandle&, ThreadSafeArenaStatsHandle&) {} - - private: - friend class ThreadSafeArenaStatsHandlePeer; -}; - -class ThreadSafeArenazSampler { - public: - void Unregister(ThreadSafeArenaStats*) {} - void SetMaxSamples(int32_t) {} -}; - -// Returns an RAII sampling handle that manages registration and unregistation -// with the global sampler. -inline ThreadSafeArenaStatsHandle Sample() { - return ThreadSafeArenaStatsHandle(nullptr); -} -#endif // defined(PROTOBUF_ARENAZ_SAMPLE) - -// Returns a global Sampler. -ThreadSafeArenazSampler& GlobalThreadSafeArenazSampler(); - -// Enables or disables sampling for thread safe arenas. -void SetThreadSafeArenazEnabled(bool enabled); - -// Sets the rate at which thread safe arena will be sampled. -void SetThreadSafeArenazSampleParameter(int32_t rate); - -// Sets a soft max for the number of samples that will be kept. -void SetThreadSafeArenazMaxSamples(int32_t max); - -// Sets the current value for when arenas should be next sampled. -void SetThreadSafeArenazGlobalNextSample(int64_t next_sample); - -} // namespace internal -} // namespace protobuf -} // namespace google - -#include -#endif // GOOGLE_PROTOBUF_SRC_PROTOBUF_ARENAZ_SAMPLER_H__ diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/compiler/importer.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/compiler/importer.h deleted file mode 100644 index 2fb88b923e..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/compiler/importer.h +++ /dev/null @@ -1,338 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file is the public interface to the .proto file parser. - -#ifndef GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ -#define GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ - -#include -#include -#include -#include - -#include -#include -#include - -// Must be included last. -#include - -namespace google { -namespace protobuf { - -namespace io { -class ZeroCopyInputStream; -} - -namespace compiler { - -// Defined in this file. -class Importer; -class MultiFileErrorCollector; -class SourceTree; -class DiskSourceTree; - -// TODO(kenton): Move all SourceTree stuff to a separate file? - -// An implementation of DescriptorDatabase which loads files from a SourceTree -// and parses them. -// -// Note: This class is not thread-safe since it maintains a table of source -// code locations for error reporting. However, when a DescriptorPool wraps -// a DescriptorDatabase, it uses mutex locking to make sure only one method -// of the database is called at a time, even if the DescriptorPool is used -// from multiple threads. Therefore, there is only a problem if you create -// multiple DescriptorPools wrapping the same SourceTreeDescriptorDatabase -// and use them from multiple threads. -// -// Note: This class does not implement FindFileContainingSymbol() or -// FindFileContainingExtension(); these will always return false. -class PROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabase { - public: - SourceTreeDescriptorDatabase(SourceTree* source_tree); - - // If non-NULL, fallback_database will be checked if a file doesn't exist in - // the specified source_tree. - SourceTreeDescriptorDatabase(SourceTree* source_tree, - DescriptorDatabase* fallback_database); - ~SourceTreeDescriptorDatabase() override; - - // Instructs the SourceTreeDescriptorDatabase to report any parse errors - // to the given MultiFileErrorCollector. This should be called before - // parsing. error_collector must remain valid until either this method - // is called again or the SourceTreeDescriptorDatabase is destroyed. - void RecordErrorsTo(MultiFileErrorCollector* error_collector) { - error_collector_ = error_collector; - } - - // Gets a DescriptorPool::ErrorCollector which records errors to the - // MultiFileErrorCollector specified with RecordErrorsTo(). This collector - // has the ability to determine exact line and column numbers of errors - // from the information given to it by the DescriptorPool. - DescriptorPool::ErrorCollector* GetValidationErrorCollector() { - using_validation_error_collector_ = true; - return &validation_error_collector_; - } - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const std::string& filename, - FileDescriptorProto* output) override; - bool FindFileContainingSymbol(const std::string& symbol_name, - FileDescriptorProto* output) override; - bool FindFileContainingExtension(const std::string& containing_type, - int field_number, - FileDescriptorProto* output) override; - - private: - class SingleFileErrorCollector; - - SourceTree* source_tree_; - DescriptorDatabase* fallback_database_; - MultiFileErrorCollector* error_collector_; - - class PROTOBUF_EXPORT ValidationErrorCollector - : public DescriptorPool::ErrorCollector { - public: - ValidationErrorCollector(SourceTreeDescriptorDatabase* owner); - ~ValidationErrorCollector() override; - - // implements ErrorCollector --------------------------------------- - void AddError(const std::string& filename, const std::string& element_name, - const Message* descriptor, ErrorLocation location, - const std::string& message) override; - - void AddWarning(const std::string& filename, - const std::string& element_name, const Message* descriptor, - ErrorLocation location, - const std::string& message) override; - - private: - SourceTreeDescriptorDatabase* owner_; - }; - friend class ValidationErrorCollector; - - bool using_validation_error_collector_; - SourceLocationTable source_locations_; - ValidationErrorCollector validation_error_collector_; -}; - -// Simple interface for parsing .proto files. This wraps the process -// of opening the file, parsing it with a Parser, recursively parsing all its -// imports, and then cross-linking the results to produce a FileDescriptor. -// -// This is really just a thin wrapper around SourceTreeDescriptorDatabase. -// You may find that SourceTreeDescriptorDatabase is more flexible. -// -// TODO(kenton): I feel like this class is not well-named. -class PROTOBUF_EXPORT Importer { - public: - Importer(SourceTree* source_tree, MultiFileErrorCollector* error_collector); - ~Importer(); - - // Import the given file and build a FileDescriptor representing it. If - // the file is already in the DescriptorPool, the existing FileDescriptor - // will be returned. The FileDescriptor is property of the DescriptorPool, - // and will remain valid until it is destroyed. If any errors occur, they - // will be reported using the error collector and Import() will return NULL. - // - // A particular Importer object will only report errors for a particular - // file once. All future attempts to import the same file will return NULL - // without reporting any errors. The idea is that you might want to import - // a lot of files without seeing the same errors over and over again. If - // you want to see errors for the same files repeatedly, you can use a - // separate Importer object to import each one (but use the same - // DescriptorPool so that they can be cross-linked). - const FileDescriptor* Import(const std::string& filename); - - // The DescriptorPool in which all imported FileDescriptors and their - // contents are stored. - inline const DescriptorPool* pool() const { return &pool_; } - - void AddUnusedImportTrackFile(const std::string& file_name, - bool is_error = false); - void ClearUnusedImportTrackFiles(); - - - private: - SourceTreeDescriptorDatabase database_; - DescriptorPool pool_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); -}; - -// If the importer encounters problems while trying to import the proto files, -// it reports them to a MultiFileErrorCollector. -class PROTOBUF_EXPORT MultiFileErrorCollector { - public: - inline MultiFileErrorCollector() {} - virtual ~MultiFileErrorCollector(); - - // Line and column numbers are zero-based. A line number of -1 indicates - // an error with the entire file (e.g. "not found"). - virtual void AddError(const std::string& filename, int line, int column, - const std::string& message) = 0; - - virtual void AddWarning(const std::string& /* filename */, int /* line */, - int /* column */, const std::string& /* message */) {} - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector); -}; - -// Abstract interface which represents a directory tree containing proto files. -// Used by the default implementation of Importer to resolve import statements -// Most users will probably want to use the DiskSourceTree implementation, -// below. -class PROTOBUF_EXPORT SourceTree { - public: - inline SourceTree() {} - virtual ~SourceTree(); - - // Open the given file and return a stream that reads it, or NULL if not - // found. The caller takes ownership of the returned object. The filename - // must be a path relative to the root of the source tree and must not - // contain "." or ".." components. - virtual io::ZeroCopyInputStream* Open(const std::string& filename) = 0; - - // If Open() returns NULL, calling this method immediately will return an - // description of the error. - // Subclasses should implement this method and return a meaningful value for - // better error reporting. - // TODO(xiaofeng): change this to a pure virtual function. - virtual std::string GetLastErrorMessage(); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); -}; - -// An implementation of SourceTree which loads files from locations on disk. -// Multiple mappings can be set up to map locations in the DiskSourceTree to -// locations in the physical filesystem. -class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { - public: - DiskSourceTree(); - ~DiskSourceTree() override; - - // Map a path on disk to a location in the SourceTree. The path may be - // either a file or a directory. If it is a directory, the entire tree - // under it will be mapped to the given virtual location. To map a directory - // to the root of the source tree, pass an empty string for virtual_path. - // - // If multiple mapped paths apply when opening a file, they will be searched - // in order. For example, if you do: - // MapPath("bar", "foo/bar"); - // MapPath("", "baz"); - // and then you do: - // Open("bar/qux"); - // the DiskSourceTree will first try to open foo/bar/qux, then baz/bar/qux, - // returning the first one that opens successfully. - // - // disk_path may be an absolute path or relative to the current directory, - // just like a path you'd pass to open(). - void MapPath(const std::string& virtual_path, const std::string& disk_path); - - // Return type for DiskFileToVirtualFile(). - enum DiskFileToVirtualFileResult { - SUCCESS, - SHADOWED, - CANNOT_OPEN, - NO_MAPPING - }; - - // Given a path to a file on disk, find a virtual path mapping to that - // file. The first mapping created with MapPath() whose disk_path contains - // the filename is used. However, that virtual path may not actually be - // usable to open the given file. Possible return values are: - // * SUCCESS: The mapping was found. *virtual_file is filled in so that - // calling Open(*virtual_file) will open the file named by disk_file. - // * SHADOWED: A mapping was found, but using Open() to open this virtual - // path will end up returning some different file. This is because some - // other mapping with a higher precedence also matches this virtual path - // and maps it to a different file that exists on disk. *virtual_file - // is filled in as it would be in the SUCCESS case. *shadowing_disk_file - // is filled in with the disk path of the file which would be opened if - // you were to call Open(*virtual_file). - // * CANNOT_OPEN: The mapping was found and was not shadowed, but the - // file specified cannot be opened. When this value is returned, - // errno will indicate the reason the file cannot be opened. *virtual_file - // will be set to the virtual path as in the SUCCESS case, even though - // it is not useful. - // * NO_MAPPING: Indicates that no mapping was found which contains this - // file. - DiskFileToVirtualFileResult DiskFileToVirtualFile( - const std::string& disk_file, std::string* virtual_file, - std::string* shadowing_disk_file); - - // Given a virtual path, find the path to the file on disk. - // Return true and update disk_file with the on-disk path if the file exists. - // Return false and leave disk_file untouched if the file doesn't exist. - bool VirtualFileToDiskFile(const std::string& virtual_file, - std::string* disk_file); - - // implements SourceTree ------------------------------------------- - io::ZeroCopyInputStream* Open(const std::string& filename) override; - - std::string GetLastErrorMessage() override; - - private: - struct Mapping { - std::string virtual_path; - std::string disk_path; - - inline Mapping(const std::string& virtual_path_param, - const std::string& disk_path_param) - : virtual_path(virtual_path_param), disk_path(disk_path_param) {} - }; - std::vector mappings_; - std::string last_error_message_; - - // Like Open(), but returns the on-disk path in disk_file if disk_file is - // non-NULL and the file could be successfully opened. - io::ZeroCopyInputStream* OpenVirtualFile(const std::string& virtual_file, - std::string* disk_file); - - // Like Open() but given the actual on-disk path. - io::ZeroCopyInputStream* OpenDiskFile(const std::string& filename); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); -}; - -} // namespace compiler -} // namespace protobuf -} // namespace google - -#include - -#endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/compiler/parser.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/compiler/parser.h deleted file mode 100644 index d4eb76302c..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/compiler/parser.h +++ /dev/null @@ -1,602 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Implements parsing of .proto files to FileDescriptorProtos. - -#ifndef GOOGLE_PROTOBUF_COMPILER_PARSER_H__ -#define GOOGLE_PROTOBUF_COMPILER_PARSER_H__ - -#include -#include -#include -#include - -#include -#include -#include -#include - -// Must be included last. -#include - -namespace google { -namespace protobuf { - -class Message; - -namespace compiler { - -// Defined in this file. -class Parser; -class SourceLocationTable; - -// Implements parsing of protocol definitions (such as .proto files). -// -// Note that most users will be more interested in the Importer class. -// Parser is a lower-level class which simply converts a single .proto file -// to a FileDescriptorProto. It does not resolve import directives or perform -// many other kinds of validation needed to construct a complete -// FileDescriptor. -class PROTOBUF_EXPORT Parser { - public: - Parser(); - ~Parser(); - - // Parse the entire input and construct a FileDescriptorProto representing - // it. Returns true if no errors occurred, false otherwise. - bool Parse(io::Tokenizer* input, FileDescriptorProto* file); - - // Optional features: - - // DEPRECATED: New code should use the SourceCodeInfo embedded in the - // FileDescriptorProto. - // - // Requests that locations of certain definitions be recorded to the given - // SourceLocationTable while parsing. This can be used to look up exact line - // and column numbers for errors reported by DescriptorPool during validation. - // Set to NULL (the default) to discard source location information. - void RecordSourceLocationsTo(SourceLocationTable* location_table) { - source_location_table_ = location_table; - } - - // Requests that errors be recorded to the given ErrorCollector while - // parsing. Set to NULL (the default) to discard error messages. - void RecordErrorsTo(io::ErrorCollector* error_collector) { - error_collector_ = error_collector; - } - - // Returns the identifier used in the "syntax = " declaration, if one was - // seen during the last call to Parse(), or the empty string otherwise. - const std::string& GetSyntaxIdentifier() { return syntax_identifier_; } - - // If set true, input files will be required to begin with a syntax - // identifier. Otherwise, files may omit this. If a syntax identifier - // is provided, it must be 'syntax = "proto2";' and must appear at the - // top of this file regardless of whether or not it was required. - void SetRequireSyntaxIdentifier(bool value) { - require_syntax_identifier_ = value; - } - - // Call SetStopAfterSyntaxIdentifier(true) to tell the parser to stop - // parsing as soon as it has seen the syntax identifier, or lack thereof. - // This is useful for quickly identifying the syntax of the file without - // parsing the whole thing. If this is enabled, no error will be recorded - // if the syntax identifier is something other than "proto2" (since - // presumably the caller intends to deal with that), but other kinds of - // errors (e.g. parse errors) will still be reported. When this is enabled, - // you may pass a NULL FileDescriptorProto to Parse(). - void SetStopAfterSyntaxIdentifier(bool value) { - stop_after_syntax_identifier_ = value; - } - - private: - class LocationRecorder; - struct MapField; - - // ================================================================= - // Error recovery helpers - - // Consume the rest of the current statement. This consumes tokens - // until it sees one of: - // ';' Consumes the token and returns. - // '{' Consumes the brace then calls SkipRestOfBlock(). - // '}' Returns without consuming. - // EOF Returns (can't consume). - // The Parser often calls SkipStatement() after encountering a syntax - // error. This allows it to go on parsing the following lines, allowing - // it to report more than just one error in the file. - void SkipStatement(); - - // Consume the rest of the current block, including nested blocks, - // ending after the closing '}' is encountered and consumed, or at EOF. - void SkipRestOfBlock(); - - // ----------------------------------------------------------------- - // Single-token consuming helpers - // - // These make parsing code more readable. - - // True if the current token is TYPE_END. - inline bool AtEnd(); - - // True if the next token matches the given text. - inline bool LookingAt(const char* text); - // True if the next token is of the given type. - inline bool LookingAtType(io::Tokenizer::TokenType token_type); - - // If the next token exactly matches the text given, consume it and return - // true. Otherwise, return false without logging an error. - bool TryConsume(const char* text); - - // These attempt to read some kind of token from the input. If successful, - // they return true. Otherwise they return false and add the given error - // to the error list. - - // Consume a token with the exact text given. - bool Consume(const char* text, const char* error); - // Same as above, but automatically generates the error "Expected \"text\".", - // where "text" is the expected token text. - bool Consume(const char* text); - // Consume a token of type IDENTIFIER and store its text in "output". - bool ConsumeIdentifier(std::string* output, const char* error); - // Consume an integer and store its value in "output". - bool ConsumeInteger(int* output, const char* error); - // Consume a signed integer and store its value in "output". - bool ConsumeSignedInteger(int* output, const char* error); - // Consume a 64-bit integer and store its value in "output". If the value - // is greater than max_value, an error will be reported. - bool ConsumeInteger64(uint64_t max_value, uint64_t* output, - const char* error); - // Consume a number and store its value in "output". This will accept - // tokens of either INTEGER or FLOAT type. - bool ConsumeNumber(double* output, const char* error); - // Consume a string literal and store its (unescaped) value in "output". - bool ConsumeString(std::string* output, const char* error); - - // Consume a token representing the end of the statement. Comments between - // this token and the next will be harvested for documentation. The given - // LocationRecorder should refer to the declaration that was just parsed; - // it will be populated with these comments. - // - // TODO(kenton): The LocationRecorder is const because historically locations - // have been passed around by const reference, for no particularly good - // reason. We should probably go through and change them all to mutable - // pointer to make this more intuitive. - bool TryConsumeEndOfDeclaration(const char* text, - const LocationRecorder* location); - bool TryConsumeEndOfDeclarationFinishScope(const char* text, - const LocationRecorder* location); - - bool ConsumeEndOfDeclaration(const char* text, - const LocationRecorder* location); - - // ----------------------------------------------------------------- - // Error logging helpers - - // Invokes error_collector_->AddError(), if error_collector_ is not NULL. - void AddError(int line, int column, const std::string& error); - - // Invokes error_collector_->AddError() with the line and column number - // of the current token. - void AddError(const std::string& error); - - // Invokes error_collector_->AddWarning() with the line and column number - // of the current token. - void AddWarning(const std::string& warning); - - // Records a location in the SourceCodeInfo.location table (see - // descriptor.proto). We use RAII to ensure that the start and end locations - // are recorded -- the constructor records the start location and the - // destructor records the end location. Since the parser is - // recursive-descent, this works out beautifully. - class PROTOBUF_EXPORT LocationRecorder { - public: - // Construct the file's "root" location. - LocationRecorder(Parser* parser); - - // Construct a location that represents a declaration nested within the - // given parent. E.g. a field's location is nested within the location - // for a message type. The parent's path will be copied, so you should - // call AddPath() only to add the path components leading from the parent - // to the child (as opposed to leading from the root to the child). - LocationRecorder(const LocationRecorder& parent); - - // Convenience constructors that call AddPath() one or two times. - LocationRecorder(const LocationRecorder& parent, int path1); - LocationRecorder(const LocationRecorder& parent, int path1, int path2); - - // Creates a recorder that generates locations into given source code info. - LocationRecorder(const LocationRecorder& parent, int path1, - SourceCodeInfo* source_code_info); - - ~LocationRecorder(); - - // Add a path component. See SourceCodeInfo.Location.path in - // descriptor.proto. - void AddPath(int path_component); - - // By default the location is considered to start at the current token at - // the time the LocationRecorder is created. StartAt() sets the start - // location to the given token instead. - void StartAt(const io::Tokenizer::Token& token); - - // Start at the same location as some other LocationRecorder. - void StartAt(const LocationRecorder& other); - - // By default the location is considered to end at the previous token at - // the time the LocationRecorder is destroyed. EndAt() sets the end - // location to the given token instead. - void EndAt(const io::Tokenizer::Token& token); - - // Records the start point of this location to the SourceLocationTable that - // was passed to RecordSourceLocationsTo(), if any. SourceLocationTable - // is an older way of keeping track of source locations which is still - // used in some places. - void RecordLegacyLocation( - const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location); - void RecordLegacyImportLocation(const Message* descriptor, - const std::string& name); - - // Returns the number of path components in the recorder's current location. - int CurrentPathSize() const; - - // Attaches leading and trailing comments to the location. The two strings - // will be swapped into place, so after this is called *leading and - // *trailing will be empty. - // - // TODO(kenton): See comment on TryConsumeEndOfDeclaration(), above, for - // why this is const. - void AttachComments(std::string* leading, std::string* trailing, - std::vector* detached_comments) const; - - private: - Parser* parser_; - SourceCodeInfo* source_code_info_; - SourceCodeInfo::Location* location_; - - void Init(const LocationRecorder& parent, SourceCodeInfo* source_code_info); - }; - - // ================================================================= - // Parsers for various language constructs - - // Parses the "syntax = \"proto2\";" line at the top of the file. Returns - // false if it failed to parse or if the syntax identifier was not - // recognized. - bool ParseSyntaxIdentifier(const LocationRecorder& parent); - - // These methods parse various individual bits of code. They return - // false if they completely fail to parse the construct. In this case, - // it is probably necessary to skip the rest of the statement to recover. - // However, if these methods return true, it does NOT mean that there - // were no errors; only that there were no *syntax* errors. For instance, - // if a service method is defined using proper syntax but uses a primitive - // type as its input or output, ParseMethodField() still returns true - // and only reports the error by calling AddError(). In practice, this - // makes logic much simpler for the caller. - - // Parse a top-level message, enum, service, etc. - bool ParseTopLevelStatement(FileDescriptorProto* file, - const LocationRecorder& root_location); - - // Parse various language high-level language construrcts. - bool ParseMessageDefinition(DescriptorProto* message, - const LocationRecorder& message_location, - const FileDescriptorProto* containing_file); - bool ParseEnumDefinition(EnumDescriptorProto* enum_type, - const LocationRecorder& enum_location, - const FileDescriptorProto* containing_file); - bool ParseServiceDefinition(ServiceDescriptorProto* service, - const LocationRecorder& service_location, - const FileDescriptorProto* containing_file); - bool ParsePackage(FileDescriptorProto* file, - const LocationRecorder& root_location, - const FileDescriptorProto* containing_file); - bool ParseImport(RepeatedPtrField* dependency, - RepeatedField* public_dependency, - RepeatedField* weak_dependency, - const LocationRecorder& root_location, - const FileDescriptorProto* containing_file); - - // These methods parse the contents of a message, enum, or service type and - // add them to the given object. They consume the entire block including - // the beginning and ending brace. - bool ParseMessageBlock(DescriptorProto* message, - const LocationRecorder& message_location, - const FileDescriptorProto* containing_file); - bool ParseEnumBlock(EnumDescriptorProto* enum_type, - const LocationRecorder& enum_location, - const FileDescriptorProto* containing_file); - bool ParseServiceBlock(ServiceDescriptorProto* service, - const LocationRecorder& service_location, - const FileDescriptorProto* containing_file); - - // Parse one statement within a message, enum, or service block, including - // final semicolon. - bool ParseMessageStatement(DescriptorProto* message, - const LocationRecorder& message_location, - const FileDescriptorProto* containing_file); - bool ParseEnumStatement(EnumDescriptorProto* message, - const LocationRecorder& enum_location, - const FileDescriptorProto* containing_file); - bool ParseServiceStatement(ServiceDescriptorProto* message, - const LocationRecorder& service_location, - const FileDescriptorProto* containing_file); - - // Parse a field of a message. If the field is a group, its type will be - // added to "messages". - // - // parent_location and location_field_number_for_nested_type are needed when - // parsing groups -- we need to generate a nested message type within the - // parent and record its location accordingly. Since the parent could be - // either a FileDescriptorProto or a DescriptorProto, we must pass in the - // correct field number to use. - bool ParseMessageField(FieldDescriptorProto* field, - RepeatedPtrField* messages, - const LocationRecorder& parent_location, - int location_field_number_for_nested_type, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - // Like ParseMessageField() but expects the label has already been filled in - // by the caller. - bool ParseMessageFieldNoLabel(FieldDescriptorProto* field, - RepeatedPtrField* messages, - const LocationRecorder& parent_location, - int location_field_number_for_nested_type, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - bool ParseMapType(MapField* map_field, FieldDescriptorProto* field, - LocationRecorder& type_name_location); - - // Parse an "extensions" declaration. - bool ParseExtensions(DescriptorProto* message, - const LocationRecorder& extensions_location, - const FileDescriptorProto* containing_file); - - // Parse a "reserved" declaration. - bool ParseReserved(DescriptorProto* message, - const LocationRecorder& message_location); - bool ParseReservedNames(DescriptorProto* message, - const LocationRecorder& parent_location); - bool ParseReservedNumbers(DescriptorProto* message, - const LocationRecorder& parent_location); - bool ParseReserved(EnumDescriptorProto* message, - const LocationRecorder& message_location); - bool ParseReservedNames(EnumDescriptorProto* message, - const LocationRecorder& parent_location); - bool ParseReservedNumbers(EnumDescriptorProto* message, - const LocationRecorder& parent_location); - - // Parse an "extend" declaration. (See also comments for - // ParseMessageField().) - bool ParseExtend(RepeatedPtrField* extensions, - RepeatedPtrField* messages, - const LocationRecorder& parent_location, - int location_field_number_for_nested_type, - const LocationRecorder& extend_location, - const FileDescriptorProto* containing_file); - - // Parse a "oneof" declaration. The caller is responsible for setting - // oneof_decl->label() since it will have had to parse the label before it - // knew it was parsing a oneof. - bool ParseOneof(OneofDescriptorProto* oneof_decl, - DescriptorProto* containing_type, int oneof_index, - const LocationRecorder& oneof_location, - const LocationRecorder& containing_type_location, - const FileDescriptorProto* containing_file); - - // Parse a single enum value within an enum block. - bool ParseEnumConstant(EnumValueDescriptorProto* enum_value, - const LocationRecorder& enum_value_location, - const FileDescriptorProto* containing_file); - - // Parse enum constant options, i.e. the list in square brackets at the end - // of the enum constant value definition. - bool ParseEnumConstantOptions(EnumValueDescriptorProto* value, - const LocationRecorder& enum_value_location, - const FileDescriptorProto* containing_file); - - // Parse a single method within a service definition. - bool ParseServiceMethod(MethodDescriptorProto* method, - const LocationRecorder& method_location, - const FileDescriptorProto* containing_file); - - // Parse options of a single method or stream. - bool ParseMethodOptions(const LocationRecorder& parent_location, - const FileDescriptorProto* containing_file, - const int optionsFieldNumber, - Message* mutable_options); - - // Parse "required", "optional", or "repeated" and fill in "label" - // with the value. Returns true if such a label is consumed. - bool ParseLabel(FieldDescriptorProto::Label* label, - const LocationRecorder& field_location); - - // Parse a type name and fill in "type" (if it is a primitive) or - // "type_name" (if it is not) with the type parsed. - bool ParseType(FieldDescriptorProto::Type* type, std::string* type_name); - // Parse a user-defined type and fill in "type_name" with the name. - // If a primitive type is named, it is treated as an error. - bool ParseUserDefinedType(std::string* type_name); - - // Parses field options, i.e. the stuff in square brackets at the end - // of a field definition. Also parses default value. - bool ParseFieldOptions(FieldDescriptorProto* field, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - // Parse the "default" option. This needs special handling because its - // type is the field's type. - bool ParseDefaultAssignment(FieldDescriptorProto* field, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - bool ParseJsonName(FieldDescriptorProto* field, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - enum OptionStyle { - OPTION_ASSIGNMENT, // just "name = value" - OPTION_STATEMENT // "option name = value;" - }; - - // Parse a single option name/value pair, e.g. "ctype = CORD". The name - // identifies a field of the given Message, and the value of that field - // is set to the parsed value. - bool ParseOption(Message* options, const LocationRecorder& options_location, - const FileDescriptorProto* containing_file, - OptionStyle style); - - // Parses a single part of a multipart option name. A multipart name consists - // of names separated by dots. Each name is either an identifier or a series - // of identifiers separated by dots and enclosed in parentheses. E.g., - // "foo.(bar.baz).moo". - bool ParseOptionNamePart(UninterpretedOption* uninterpreted_option, - const LocationRecorder& part_location, - const FileDescriptorProto* containing_file); - - // Parses a string surrounded by balanced braces. Strips off the outer - // braces and stores the enclosed string in *value. - // E.g., - // { foo } *value gets 'foo' - // { foo { bar: box } } *value gets 'foo { bar: box }' - // {} *value gets '' - // - // REQUIRES: LookingAt("{") - // When finished successfully, we are looking at the first token past - // the ending brace. - bool ParseUninterpretedBlock(std::string* value); - - struct MapField { - // Whether the field is a map field. - bool is_map_field; - // The types of the key and value if they are primitive types. - FieldDescriptorProto::Type key_type; - FieldDescriptorProto::Type value_type; - // Or the type names string if the types are customized types. - std::string key_type_name; - std::string value_type_name; - - MapField() : is_map_field(false) {} - }; - // Desugar the map syntax to generate a nested map entry message. - void GenerateMapEntry(const MapField& map_field, FieldDescriptorProto* field, - RepeatedPtrField* messages); - - // Whether fields without label default to optional fields. - bool DefaultToOptionalFields() const { - return syntax_identifier_ == "proto3"; - } - - bool ValidateEnum(const EnumDescriptorProto* proto); - - // ================================================================= - - io::Tokenizer* input_; - io::ErrorCollector* error_collector_; - SourceCodeInfo* source_code_info_; - SourceLocationTable* source_location_table_; // legacy - bool had_errors_; - bool require_syntax_identifier_; - bool stop_after_syntax_identifier_; - std::string syntax_identifier_; - - // Leading doc comments for the next declaration. These are not complete - // yet; use ConsumeEndOfDeclaration() to get the complete comments. - std::string upcoming_doc_comments_; - - // Detached comments are not connected to any syntax entities. Elements in - // this vector are paragraphs of comments separated by empty lines. The - // detached comments will be put into the leading_detached_comments field for - // the next element (See SourceCodeInfo.Location in descriptor.proto), when - // ConsumeEndOfDeclaration() is called. - std::vector upcoming_detached_comments_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Parser); -}; - -// A table mapping (descriptor, ErrorLocation) pairs -- as reported by -// DescriptorPool when validating descriptors -- to line and column numbers -// within the original source code. -// -// This is semi-obsolete: FileDescriptorProto.source_code_info now contains -// far more complete information about source locations. However, as of this -// writing you still need to use SourceLocationTable when integrating with -// DescriptorPool. -class PROTOBUF_EXPORT SourceLocationTable { - public: - SourceLocationTable(); - ~SourceLocationTable(); - - // Finds the precise location of the given error and fills in *line and - // *column with the line and column numbers. If not found, sets *line to - // -1 and *column to 0 (since line = -1 is used to mean "error has no exact - // location" in the ErrorCollector interface). Returns true if found, false - // otherwise. - bool Find(const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location, int* line, - int* column) const; - bool FindImport(const Message* descriptor, const std::string& name, int* line, - int* column) const; - - // Adds a location to the table. - void Add(const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location, int line, - int column); - void AddImport(const Message* descriptor, const std::string& name, int line, - int column); - - // Clears the contents of the table. - void Clear(); - - private: - typedef std::map< - std::pair, - std::pair > - LocationMap; - LocationMap location_map_; - std::map, std::pair > - import_location_map_; -}; - -} // namespace compiler -} // namespace protobuf -} // namespace google - -#include - -#endif // GOOGLE_PROTOBUF_COMPILER_PARSER_H__ diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/descriptor.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/descriptor.h deleted file mode 100644 index 1cb2421b53..0000000000 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/descriptor.h +++ /dev/null @@ -1,2448 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains classes which describe a type of protocol message. -// You can use a message's descriptor to learn at runtime what fields -// it contains and what the types of those fields are. The Message -// interface also allows you to dynamically access and modify individual -// fields by passing the FieldDescriptor of the field you are interested -// in. -// -// Most users will not care about descriptors, because they will write -// code specific to certain protocol types and will simply use the classes -// generated by the protocol compiler directly. Advanced users who want -// to operate on arbitrary types (not known at compile time) may want to -// read descriptors in order to learn about the contents of a message. -// A very small number of users will want to construct their own -// Descriptors, either because they are implementing Message manually or -// because they are writing something like the protocol compiler. -// -// For an example of how you might use descriptors, see the code example -// at the top of message.h. - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_H__ -#define GOOGLE_PROTOBUF_DESCRIPTOR_H__ - - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -// Must be included last. -#include - -// TYPE_BOOL is defined in the MacOS's ConditionalMacros.h. -#ifdef TYPE_BOOL -#undef TYPE_BOOL -#endif // TYPE_BOOL - -#ifdef SWIG -#define PROTOBUF_EXPORT -#endif - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#endif - -namespace google { -namespace protobuf { - -// Defined in this file. -class Descriptor; -class FieldDescriptor; -class OneofDescriptor; -class EnumDescriptor; -class EnumValueDescriptor; -class ServiceDescriptor; -class MethodDescriptor; -class FileDescriptor; -class DescriptorDatabase; -class DescriptorPool; - -// Defined in descriptor.proto -class DescriptorProto; -class DescriptorProto_ExtensionRange; -class FieldDescriptorProto; -class OneofDescriptorProto; -class EnumDescriptorProto; -class EnumValueDescriptorProto; -class ServiceDescriptorProto; -class MethodDescriptorProto; -class FileDescriptorProto; -class MessageOptions; -class FieldOptions; -class OneofOptions; -class EnumOptions; -class EnumValueOptions; -class ExtensionRangeOptions; -class ServiceOptions; -class MethodOptions; -class FileOptions; -class UninterpretedOption; -class SourceCodeInfo; - -// Defined in message.h -class Message; -class Reflection; - -// Defined in descriptor.cc -class DescriptorBuilder; -class FileDescriptorTables; -class Symbol; - -// Defined in unknown_field_set.h. -class UnknownField; - -// Defined in command_line_interface.cc -namespace compiler { -class CommandLineInterface; -namespace cpp { -// Defined in helpers.h -class Formatter; -} // namespace cpp -} // namespace compiler - -namespace descriptor_unittest { -class DescriptorTest; -} // namespace descriptor_unittest - -// Defined in printer.h -namespace io { -class Printer; -} // namespace io - -// NB, all indices are zero-based. -struct SourceLocation { - int start_line; - int end_line; - int start_column; - int end_column; - - // Doc comments found at the source location. - // See the comments in SourceCodeInfo.Location (descriptor.proto) for details. - std::string leading_comments; - std::string trailing_comments; - std::vector leading_detached_comments; -}; - -// Options when generating machine-parsable output from a descriptor with -// DebugString(). -struct DebugStringOptions { - // include original user comments as recorded in SourceLocation entries. N.B. - // that this must be |false| by default: several other pieces of code (for - // example, the C++ code generation for fields in the proto compiler) rely on - // DebugString() output being unobstructed by user comments. - bool include_comments; - // If true, elide the braced body in the debug string. - bool elide_group_body; - bool elide_oneof_body; - - DebugStringOptions() - : include_comments(false), - elide_group_body(false), - elide_oneof_body(false) { - } -}; - -// A class to handle the simplest cases of a lazily linked descriptor -// for a message type that isn't built at the time of cross linking, -// which is needed when a pool has lazily_build_dependencies_ set. -// Must be instantiated as mutable in a descriptor. -namespace internal { - -// The classes in this file represent a significant memory footprint for the -// library. We make sure we are not accidentally making them larger by -// hardcoding the struct size for a specific platform. Use as: -// -// PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(type, expected_size_in_x84-64); -// - -#if !defined(PROTOBUF_INTERNAL_CHECK_CLASS_SIZE) -#define PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(t, expected) -#endif - -class FlatAllocator; - -class PROTOBUF_EXPORT LazyDescriptor { - public: - // Init function to be called at init time of a descriptor containing - // a LazyDescriptor. - void Init() { - descriptor_ = nullptr; - once_ = nullptr; - } - - // Sets the value of the descriptor if it is known during the descriptor - // building process. Not thread safe, should only be called during the - // descriptor build process. Should not be called after SetLazy has been - // called. - void Set(const Descriptor* descriptor); - - // Sets the information needed to lazily cross link the descriptor at a later - // time, SetLazy is not thread safe, should be called only once at descriptor - // build time if the symbol wasn't found and building of the file containing - // that type is delayed because lazily_build_dependencies_ is set on the pool. - // Should not be called after Set() has been called. - void SetLazy(StringPiece name, const FileDescriptor* file); - - // Returns the current value of the descriptor, thread-safe. If SetLazy(...) - // has been called, will do a one-time cross link of the type specified, - // building the descriptor file that contains the type if necessary. - inline const Descriptor* Get(const ServiceDescriptor* service) { - Once(service); - return descriptor_; - } - - private: - void Once(const ServiceDescriptor* service); - - const Descriptor* descriptor_; - // The once_ flag is followed by a NUL terminated string for the type name. - internal::once_flag* once_; -}; - -class PROTOBUF_EXPORT SymbolBase { - private: - friend class google::protobuf::Symbol; - uint8_t symbol_type_; -}; - -// Some types have more than one SymbolBase because they have multiple -// identities in the table. We can't have duplicate direct bases, so we use this -// intermediate base to do so. -// See BuildEnumValue for details. -template -class PROTOBUF_EXPORT SymbolBaseN : public SymbolBase {}; - -} // namespace internal - -// Describes a type of protocol message, or a particular group within a -// message. To obtain the Descriptor for a given message object, call -// Message::GetDescriptor(). Generated message classes also have a -// static method called descriptor() which returns the type's descriptor. -// Use DescriptorPool to construct your own descriptors. -class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { - public: - typedef DescriptorProto Proto; - - // The name of the message type, not including its scope. - const std::string& name() const; - - // The fully-qualified name of the message type, scope delimited by - // periods. For example, message type "Foo" which is declared in package - // "bar" has full name "bar.Foo". If a type "Baz" is nested within - // Foo, Baz's full_name is "bar.Foo.Baz". To get only the part that - // comes after the last '.', use name(). - const std::string& full_name() const; - - // Index of this descriptor within the file or containing type's message - // type array. - int index() const; - - // The .proto file in which this message type was defined. Never nullptr. - const FileDescriptor* file() const; - - // If this Descriptor describes a nested type, this returns the type - // in which it is nested. Otherwise, returns nullptr. - const Descriptor* containing_type() const; - - // Get options for this message type. These are specified in the .proto file - // by placing lines like "option foo = 1234;" in the message definition. - // Allowed options are defined by MessageOptions in descriptor.proto, and any - // available extensions of that message. - const MessageOptions& options() const; - - // Write the contents of this Descriptor into the given DescriptorProto. - // The target DescriptorProto must be clear before calling this; if it - // isn't, the result may be garbage. - void CopyTo(DescriptorProto* proto) const; - - // Write the contents of this descriptor in a human-readable form. Output - // will be suitable for re-parsing. - std::string DebugString() const; - - // Similar to DebugString(), but additionally takes options (e.g., - // include original user comments in output). - std::string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Returns true if this is a placeholder for an unknown type. This will - // only be the case if this descriptor comes from a DescriptorPool - // with AllowUnknownDependencies() set. - bool is_placeholder() const; - - enum WellKnownType { - WELLKNOWNTYPE_UNSPECIFIED, // Not a well-known type. - - // Wrapper types. - WELLKNOWNTYPE_DOUBLEVALUE, // google.protobuf.DoubleValue - WELLKNOWNTYPE_FLOATVALUE, // google.protobuf.FloatValue - WELLKNOWNTYPE_INT64VALUE, // google.protobuf.Int64Value - WELLKNOWNTYPE_UINT64VALUE, // google.protobuf.UInt64Value - WELLKNOWNTYPE_INT32VALUE, // google.protobuf.Int32Value - WELLKNOWNTYPE_UINT32VALUE, // google.protobuf.UInt32Value - WELLKNOWNTYPE_STRINGVALUE, // google.protobuf.StringValue - WELLKNOWNTYPE_BYTESVALUE, // google.protobuf.BytesValue - WELLKNOWNTYPE_BOOLVALUE, // google.protobuf.BoolValue - - // Other well known types. - WELLKNOWNTYPE_ANY, // google.protobuf.Any - WELLKNOWNTYPE_FIELDMASK, // google.protobuf.FieldMask - WELLKNOWNTYPE_DURATION, // google.protobuf.Duration - WELLKNOWNTYPE_TIMESTAMP, // google.protobuf.Timestamp - WELLKNOWNTYPE_VALUE, // google.protobuf.Value - WELLKNOWNTYPE_LISTVALUE, // google.protobuf.ListValue - WELLKNOWNTYPE_STRUCT, // google.protobuf.Struct - - // New well-known types may be added in the future. - // Please make sure any switch() statements have a 'default' case. - __WELLKNOWNTYPE__DO_NOT_USE__ADD_DEFAULT_INSTEAD__, - }; - - WellKnownType well_known_type() const; - - // Field stuff ----------------------------------------------------- - - // The number of fields in this message type. - int field_count() const; - // Gets a field by index, where 0 <= index < field_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* field(int index) const; - - // Looks up a field by declared tag number. Returns nullptr if no such field - // exists. - const FieldDescriptor* FindFieldByNumber(int number) const; - // Looks up a field by name. Returns nullptr if no such field exists. - const FieldDescriptor* FindFieldByName(ConstStringParam name) const; - - // Looks up a field by lowercased name (as returned by lowercase_name()). - // This lookup may be ambiguous if multiple field names differ only by case, - // in which case the field returned is chosen arbitrarily from the matches. - const FieldDescriptor* FindFieldByLowercaseName( - ConstStringParam lowercase_name) const; - - // Looks up a field by camel-case name (as returned by camelcase_name()). - // This lookup may be ambiguous if multiple field names differ in a way that - // leads them to have identical camel-case names, in which case the field - // returned is chosen arbitrarily from the matches. - const FieldDescriptor* FindFieldByCamelcaseName( - ConstStringParam camelcase_name) const; - - // The number of oneofs in this message type. - int oneof_decl_count() const; - // The number of oneofs in this message type, excluding synthetic oneofs. - // Real oneofs always come first, so iterating up to real_oneof_decl_cout() - // will yield all real oneofs. - int real_oneof_decl_count() const; - // Get a oneof by index, where 0 <= index < oneof_decl_count(). - // These are returned in the order they were defined in the .proto file. - const OneofDescriptor* oneof_decl(int index) const; - - // Looks up a oneof by name. Returns nullptr if no such oneof exists. - const OneofDescriptor* FindOneofByName(ConstStringParam name) const; - - // Nested type stuff ----------------------------------------------- - - // The number of nested types in this message type. - int nested_type_count() const; - // Gets a nested type by index, where 0 <= index < nested_type_count(). - // These are returned in the order they were defined in the .proto file. - const Descriptor* nested_type(int index) const; - - // Looks up a nested type by name. Returns nullptr if no such nested type - // exists. - const Descriptor* FindNestedTypeByName(ConstStringParam name) const; - - // Enum stuff ------------------------------------------------------ - - // The number of enum types in this message type. - int enum_type_count() const; - // Gets an enum type by index, where 0 <= index < enum_type_count(). - // These are returned in the order they were defined in the .proto file. - const EnumDescriptor* enum_type(int index) const; - - // Looks up an enum type by name. Returns nullptr if no such enum type - // exists. - const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const; - - // Looks up an enum value by name, among all enum types in this message. - // Returns nullptr if no such value exists. - const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const; - - // Extensions ------------------------------------------------------ - - // A range of field numbers which are designated for third-party - // extensions. - struct ExtensionRange { - typedef DescriptorProto_ExtensionRange Proto; - - typedef ExtensionRangeOptions OptionsType; - - // See Descriptor::CopyTo(). - void CopyTo(DescriptorProto_ExtensionRange* proto) const; - - int start; // inclusive - int end; // exclusive - - const ExtensionRangeOptions* options_; - }; - - // The number of extension ranges in this message type. - int extension_range_count() const; - // Gets an extension range by index, where 0 <= index < - // extension_range_count(). These are returned in the order they were defined - // in the .proto file. - const ExtensionRange* extension_range(int index) const; - - // Returns true if the number is in one of the extension ranges. - bool IsExtensionNumber(int number) const; - - // Returns nullptr if no extension range contains the given number. - const ExtensionRange* FindExtensionRangeContainingNumber(int number) const; - - // The number of extensions defined nested within this message type's scope. - // See doc: - // https://developers.google.com/protocol-buffers/docs/proto#nested-extensions - // - // Note that the extensions may be extending *other* messages. - // - // For example: - // message M1 { - // extensions 1 to max; - // } - // - // message M2 { - // extend M1 { - // optional int32 foo = 1; - // } - // } - // - // In this case, - // DescriptorPool::generated_pool() - // ->FindMessageTypeByName("M2") - // ->extension(0) - // will return "foo", even though "foo" is an extension of M1. - // To find all known extensions of a given message, instead use - // DescriptorPool::FindAllExtensions. - int extension_count() const; - // Get an extension by index, where 0 <= index < extension_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* extension(int index) const; - - // Looks up a named extension (which extends some *other* message type) - // defined within this message type's scope. - const FieldDescriptor* FindExtensionByName(ConstStringParam name) const; - - // Similar to FindFieldByLowercaseName(), but finds extensions defined within - // this message type's scope. - const FieldDescriptor* FindExtensionByLowercaseName( - ConstStringParam name) const; - - // Similar to FindFieldByCamelcaseName(), but finds extensions defined within - // this message type's scope. - const FieldDescriptor* FindExtensionByCamelcaseName( - ConstStringParam name) const; - - // Reserved fields ------------------------------------------------- - - // A range of reserved field numbers. - struct ReservedRange { - int start; // inclusive - int end; // exclusive - }; - - // The number of reserved ranges in this message type. - int reserved_range_count() const; - // Gets an reserved range by index, where 0 <= index < - // reserved_range_count(). These are returned in the order they were defined - // in the .proto file. - const ReservedRange* reserved_range(int index) const; - - // Returns true if the number is in one of the reserved ranges. - bool IsReservedNumber(int number) const; - - // Returns nullptr if no reserved range contains the given number. - const ReservedRange* FindReservedRangeContainingNumber(int number) const; - - // The number of reserved field names in this message type. - int reserved_name_count() const; - - // Gets a reserved name by index, where 0 <= index < reserved_name_count(). - const std::string& reserved_name(int index) const; - - // Returns true if the field name is reserved. - bool IsReservedName(ConstStringParam name) const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this message declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - // Maps -------------------------------------------------------------- - - // Returns the FieldDescriptor for the "key" field. If this isn't a map entry - // field, returns nullptr. - const FieldDescriptor* map_key() const; - - // Returns the FieldDescriptor for the "value" field. If this isn't a map - // entry field, returns nullptr. - const FieldDescriptor* map_value() const; - - private: - friend class Symbol; - typedef MessageOptions OptionsType; - - // Allows tests to test CopyTo(proto, true). - friend class descriptor_unittest::DescriptorTest; - - // Allows access to GetLocationPath for annotations. - friend class io::Printer; - friend class compiler::cpp::Formatter; - - // Fill the json_name field of FieldDescriptorProto. - void CopyJsonNameTo(DescriptorProto* proto) const; - - // Internal version of DebugString; controls the level of indenting for - // correct depth. Takes |options| to control debug-string options, and - // |include_opening_clause| to indicate whether the "message ... " part of the - // clause has already been generated (this varies depending on context). - void DebugString(int depth, std::string* contents, - const DebugStringOptions& options, - bool include_opening_clause) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - // True if this is a placeholder for an unknown type. - bool is_placeholder_ : 1; - // True if this is a placeholder and the type name wasn't fully-qualified. - bool is_unqualified_placeholder_ : 1; - // Well known type. Stored like this to conserve space. - uint8_t well_known_type_ : 5; - - // This points to the last field _number_ that is part of the sequence - // starting at 1, where - // `desc->field(i)->number() == i + 1` - // A value of `0` means no field matches. That is, there are no fields or the - // first field is not field `1`. - // Uses 16-bit to avoid extra padding. Unlikely to have more than 2^16 - // sequentially numbered fields in a message. - uint16_t sequential_field_limit_; - - int field_count_; - - // all_names_ = [name, full_name] - const std::string* all_names_; - const FileDescriptor* file_; - const Descriptor* containing_type_; - const MessageOptions* options_; - - // These arrays are separated from their sizes to minimize padding on 64-bit. - FieldDescriptor* fields_; - OneofDescriptor* oneof_decls_; - Descriptor* nested_types_; - EnumDescriptor* enum_types_; - ExtensionRange* extension_ranges_; - FieldDescriptor* extensions_; - ReservedRange* reserved_ranges_; - const std::string** reserved_names_; - - int oneof_decl_count_; - int real_oneof_decl_count_; - int nested_type_count_; - int enum_type_count_; - int extension_range_count_; - int extension_count_; - int reserved_range_count_; - int reserved_name_count_; - - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in descriptor.cc - // and update them to initialize the field. - - // Must be constructed using DescriptorPool. - Descriptor() {} - friend class DescriptorBuilder; - friend class DescriptorPool; - friend class EnumDescriptor; - friend class FieldDescriptor; - friend class FileDescriptorTables; - friend class OneofDescriptor; - friend class MethodDescriptor; - friend class FileDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor); -}; - -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(Descriptor, 136); - -// Describes a single field of a message. To get the descriptor for a given -// field, first get the Descriptor for the message in which it is defined, -// then call Descriptor::FindFieldByName(). To get a FieldDescriptor for -// an extension, do one of the following: -// - Get the Descriptor or FileDescriptor for its containing scope, then -// call Descriptor::FindExtensionByName() or -// FileDescriptor::FindExtensionByName(). -// - Given a DescriptorPool, call DescriptorPool::FindExtensionByNumber() or -// DescriptorPool::FindExtensionByPrintableName(). -// Use DescriptorPool to construct your own descriptors. -class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { - public: - typedef FieldDescriptorProto Proto; - - // Identifies a field type. 0 is reserved for errors. The order is weird - // for historical reasons. Types 12 and up are new in proto2. - enum Type { - TYPE_DOUBLE = 1, // double, exactly eight bytes on the wire. - TYPE_FLOAT = 2, // float, exactly four bytes on the wire. - TYPE_INT64 = 3, // int64, varint on the wire. Negative numbers - // take 10 bytes. Use TYPE_SINT64 if negative - // values are likely. - TYPE_UINT64 = 4, // uint64, varint on the wire. - TYPE_INT32 = 5, // int32, varint on the wire. Negative numbers - // take 10 bytes. Use TYPE_SINT32 if negative - // values are likely. - TYPE_FIXED64 = 6, // uint64, exactly eight bytes on the wire. - TYPE_FIXED32 = 7, // uint32, exactly four bytes on the wire. - TYPE_BOOL = 8, // bool, varint on the wire. - TYPE_STRING = 9, // UTF-8 text. - TYPE_GROUP = 10, // Tag-delimited message. Deprecated. - TYPE_MESSAGE = 11, // Length-delimited message. - - TYPE_BYTES = 12, // Arbitrary byte array. - TYPE_UINT32 = 13, // uint32, varint on the wire - TYPE_ENUM = 14, // Enum, varint on the wire - TYPE_SFIXED32 = 15, // int32, exactly four bytes on the wire - TYPE_SFIXED64 = 16, // int64, exactly eight bytes on the wire - TYPE_SINT32 = 17, // int32, ZigZag-encoded varint on the wire - TYPE_SINT64 = 18, // int64, ZigZag-encoded varint on the wire - - MAX_TYPE = 18, // Constant useful for defining lookup tables - // indexed by Type. - }; - - // Specifies the C++ data type used to represent the field. There is a - // fixed mapping from Type to CppType where each Type maps to exactly one - // CppType. 0 is reserved for errors. - enum CppType { - CPPTYPE_INT32 = 1, // TYPE_INT32, TYPE_SINT32, TYPE_SFIXED32 - CPPTYPE_INT64 = 2, // TYPE_INT64, TYPE_SINT64, TYPE_SFIXED64 - CPPTYPE_UINT32 = 3, // TYPE_UINT32, TYPE_FIXED32 - CPPTYPE_UINT64 = 4, // TYPE_UINT64, TYPE_FIXED64 - CPPTYPE_DOUBLE = 5, // TYPE_DOUBLE - CPPTYPE_FLOAT = 6, // TYPE_FLOAT - CPPTYPE_BOOL = 7, // TYPE_BOOL - CPPTYPE_ENUM = 8, // TYPE_ENUM - CPPTYPE_STRING = 9, // TYPE_STRING, TYPE_BYTES - CPPTYPE_MESSAGE = 10, // TYPE_MESSAGE, TYPE_GROUP - - MAX_CPPTYPE = 10, // Constant useful for defining lookup tables - // indexed by CppType. - }; - - // Identifies whether the field is optional, required, or repeated. 0 is - // reserved for errors. - enum Label { - LABEL_OPTIONAL = 1, // optional - LABEL_REQUIRED = 2, // required - LABEL_REPEATED = 3, // repeated - - MAX_LABEL = 3, // Constant useful for defining lookup tables - // indexed by Label. - }; - - // Valid field numbers are positive integers up to kMaxNumber. - static const int kMaxNumber = (1 << 29) - 1; - - // First field number reserved for the protocol buffer library implementation. - // Users may not declare fields that use reserved numbers. - static const int kFirstReservedNumber = 19000; - // Last field number reserved for the protocol buffer library implementation. - // Users may not declare fields that use reserved numbers. - static const int kLastReservedNumber = 19999; - - const std::string& name() const; // Name of this field within the message. - const std::string& full_name() const; // Fully-qualified name of the field. - const std::string& json_name() const; // JSON name of this field. - const FileDescriptor* file() const; // File in which this field was defined. - bool is_extension() const; // Is this an extension field? - int number() const; // Declared tag number. - - // Same as name() except converted to lower-case. This (and especially the - // FindFieldByLowercaseName() method) can be useful when parsing formats - // which prefer to use lowercase naming style. (Although, technically - // field names should be lowercased anyway according to the protobuf style - // guide, so this only makes a difference when dealing with old .proto files - // which do not follow the guide.) - const std::string& lowercase_name() const; - - // Same as name() except converted to camel-case. In this conversion, any - // time an underscore appears in the name, it is removed and the next - // letter is capitalized. Furthermore, the first letter of the name is - // lower-cased. Examples: - // FooBar -> fooBar - // foo_bar -> fooBar - // fooBar -> fooBar - // This (and especially the FindFieldByCamelcaseName() method) can be useful - // when parsing formats which prefer to use camel-case naming style. - const std::string& camelcase_name() const; - - Type type() const; // Declared type of this field. - const char* type_name() const; // Name of the declared type. - CppType cpp_type() const; // C++ type of this field. - const char* cpp_type_name() const; // Name of the C++ type. - Label label() const; // optional/required/repeated - - bool is_required() const; // shorthand for label() == LABEL_REQUIRED - bool is_optional() const; // shorthand for label() == LABEL_OPTIONAL - bool is_repeated() const; // shorthand for label() == LABEL_REPEATED - bool is_packable() const; // shorthand for is_repeated() && - // IsTypePackable(type()) - bool is_packed() const; // shorthand for is_packable() && - // options().packed() - bool is_map() const; // shorthand for type() == TYPE_MESSAGE && - // message_type()->options().map_entry() - - // Returns true if this field was syntactically written with "optional" in the - // .proto file. Excludes singular proto3 fields that do not have a label. - bool has_optional_keyword() const; - - // Returns true if this field tracks presence, ie. does the field - // distinguish between "unset" and "present with default value." - // This includes required, optional, and oneof fields. It excludes maps, - // repeated fields, and singular proto3 fields without "optional". - // - // For fields where has_presence() == true, the return value of - // Reflection::HasField() is semantically meaningful. - bool has_presence() const; - - // Index of this field within the message's field array, or the file or - // extension scope's extensions array. - int index() const; - - // Does this field have an explicitly-declared default value? - bool has_default_value() const; - - // Whether the user has specified the json_name field option in the .proto - // file. - bool has_json_name() const; - - // Get the field default value if cpp_type() == CPPTYPE_INT32. If no - // explicit default was defined, the default is 0. - int32_t default_value_int32_t() const; - int32_t default_value_int32() const { return default_value_int32_t(); } - // Get the field default value if cpp_type() == CPPTYPE_INT64. If no - // explicit default was defined, the default is 0. - int64_t default_value_int64_t() const; - int64_t default_value_int64() const { return default_value_int64_t(); } - // Get the field default value if cpp_type() == CPPTYPE_UINT32. If no - // explicit default was defined, the default is 0. - uint32_t default_value_uint32_t() const; - uint32_t default_value_uint32() const { return default_value_uint32_t(); } - // Get the field default value if cpp_type() == CPPTYPE_UINT64. If no - // explicit default was defined, the default is 0. - uint64_t default_value_uint64_t() const; - uint64_t default_value_uint64() const { return default_value_uint64_t(); } - // Get the field default value if cpp_type() == CPPTYPE_FLOAT. If no - // explicit default was defined, the default is 0.0. - float default_value_float() const; - // Get the field default value if cpp_type() == CPPTYPE_DOUBLE. If no - // explicit default was defined, the default is 0.0. - double default_value_double() const; - // Get the field default value if cpp_type() == CPPTYPE_BOOL. If no - // explicit default was defined, the default is false. - bool default_value_bool() const; - // Get the field default value if cpp_type() == CPPTYPE_ENUM. If no - // explicit default was defined, the default is the first value defined - // in the enum type (all enum types are required to have at least one value). - // This never returns nullptr. - const EnumValueDescriptor* default_value_enum() const; - // Get the field default value if cpp_type() == CPPTYPE_STRING. If no - // explicit default was defined, the default is the empty string. - const std::string& default_value_string() const; - - // The Descriptor for the message of which this is a field. For extensions, - // this is the extended type. Never nullptr. - const Descriptor* containing_type() const; - - // If the field is a member of a oneof, this is the one, otherwise this is - // nullptr. - const OneofDescriptor* containing_oneof() const; - - // If the field is a member of a non-synthetic oneof, returns the descriptor - // for the oneof, otherwise returns nullptr. - const OneofDescriptor* real_containing_oneof() const; - - // If the field is a member of a oneof, returns the index in that oneof. - int index_in_oneof() const; - - // An extension may be declared within the scope of another message. If this - // field is an extension (is_extension() is true), then extension_scope() - // returns that message, or nullptr if the extension was declared at global - // scope. If this is not an extension, extension_scope() is undefined (may - // assert-fail). - const Descriptor* extension_scope() const; - - // If type is TYPE_MESSAGE or TYPE_GROUP, returns a descriptor for the - // message or the group type. Otherwise, returns null. - const Descriptor* message_type() const; - // If type is TYPE_ENUM, returns a descriptor for the enum. Otherwise, - // returns null. - const EnumDescriptor* enum_type() const; - - // Get the FieldOptions for this field. This includes things listed in - // square brackets after the field definition. E.g., the field: - // optional string text = 1 [ctype=CORD]; - // has the "ctype" option set. Allowed options are defined by FieldOptions in - // descriptor.proto, and any available extensions of that message. - const FieldOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(FieldDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - std::string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - std::string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Helper method to get the CppType for a particular Type. - static CppType TypeToCppType(Type type); - - // Helper method to get the name of a Type. - static const char* TypeName(Type type); - - // Helper method to get the name of a CppType. - static const char* CppTypeName(CppType cpp_type); - - // Return true iff [packed = true] is valid for fields of this type. - static inline bool IsTypePackable(Type field_type); - - // Returns full_name() except if the field is a MessageSet extension, - // in which case it returns the full_name() of the containing message type - // for backwards compatibility with proto1. - // - // A MessageSet extension is defined as an optional message extension - // whose containing type has the message_set_wire_format option set. - // This should be true of extensions of google.protobuf.bridge.MessageSet; - // by convention, such extensions are named "message_set_extension". - // - // The opposite operation (looking up an extension's FieldDescriptor given - // its printable name) can be accomplished with - // message->file()->pool()->FindExtensionByPrintableName(message, name) - // where the extension extends "message". - const std::string& PrintableNameForExtension() const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this field declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - friend class Symbol; - typedef FieldOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class io::Printer; - friend class compiler::cpp::Formatter; - friend class Reflection; - - // Fill the json_name field of FieldDescriptorProto. - void CopyJsonNameTo(FieldDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - void DebugString(int depth, std::string* contents, - const DebugStringOptions& options) const; - - // formats the default value appropriately and returns it as a string. - // Must have a default value to call this. If quote_string_type is true, then - // types of CPPTYPE_STRING will be surrounded by quotes and CEscaped. - std::string DefaultValueAsString(bool quote_string_type) const; - - // Helper function that returns the field type name for DebugString. - std::string FieldTypeNameDebugString() const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - // Returns true if this is a map message type. - bool is_map_message_type() const; - - bool has_default_value_ : 1; - bool proto3_optional_ : 1; - // Whether the user has specified the json_name field option in the .proto - // file. - bool has_json_name_ : 1; - bool is_extension_ : 1; - bool is_oneof_ : 1; - - // Actually a `Label` but stored as uint8_t to save space. - uint8_t label_ : 2; - - // Actually a `Type`, but stored as uint8_t to save space. - mutable uint8_t type_; - - // Logically: - // all_names_ = [name, full_name, lower, camel, json] - // However: - // duplicates will be omitted, so lower/camel/json might be in the same - // position. - // We store the true offset for each name here, and the bit width must be - // large enough to account for the worst case where all names are present. - uint8_t lowercase_name_index_ : 2; - uint8_t camelcase_name_index_ : 2; - uint8_t json_name_index_ : 3; - // Sadly, `number_` located here to reduce padding. Unrelated to all_names_ - // and its indices above. - int number_; - const std::string* all_names_; - const FileDescriptor* file_; - - // The once_flag is followed by a NUL terminated string for the type name and - // enum default value (or empty string if no default enum). - internal::once_flag* type_once_; - static void TypeOnceInit(const FieldDescriptor* to_init); - void InternalTypeOnceInit() const; - const Descriptor* containing_type_; - union { - const OneofDescriptor* containing_oneof; - const Descriptor* extension_scope; - } scope_; - union { - mutable const Descriptor* message_type; - mutable const EnumDescriptor* enum_type; - } type_descriptor_; - const FieldOptions* options_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - union { - int32_t default_value_int32_t_; - int64_t default_value_int64_t_; - uint32_t default_value_uint32_t_; - uint64_t default_value_uint64_t_; - float default_value_float_; - double default_value_double_; - bool default_value_bool_; - - mutable const EnumValueDescriptor* default_value_enum_; - const std::string* default_value_string_; - mutable std::atomic default_generated_instance_; - }; - - static const CppType *GetTypeToCppTypeMap(); - - static const char* const *GetTypeToName(); - - static const char* const *GetCppTypeToName(); - - static const char* const *GetLabelToName(); - - // Must be constructed using DescriptorPool. - FieldDescriptor() {} - friend class DescriptorBuilder; - friend class FileDescriptor; - friend class Descriptor; - friend class OneofDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor); -}; - -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FieldDescriptor, 72); - -// Describes a oneof defined in a message type. -class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase { - public: - typedef OneofDescriptorProto Proto; - - const std::string& name() const; // Name of this oneof. - const std::string& full_name() const; // Fully-qualified name of the oneof. - - // Index of this oneof within the message's oneof array. - int index() const; - - // Returns whether this oneof was inserted by the compiler to wrap a proto3 - // optional field. If this returns true, code generators should *not* emit it. - bool is_synthetic() const; - - // The .proto file in which this oneof was defined. Never nullptr. - const FileDescriptor* file() const; - // The Descriptor for the message containing this oneof. - const Descriptor* containing_type() const; - - // The number of (non-extension) fields which are members of this oneof. - int field_count() const; - // Get a member of this oneof, in the order in which they were declared in the - // .proto file. Does not include extensions. - const FieldDescriptor* field(int index) const; - - const OneofOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(OneofDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - std::string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - std::string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this oneof declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - friend class Symbol; - typedef OneofOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class io::Printer; - friend class compiler::cpp::Formatter; - - // See Descriptor::DebugString(). - void DebugString(int depth, std::string* contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - int field_count_; - - // all_names_ = [name, full_name] - const std::string* all_names_; - const Descriptor* containing_type_; - const OneofOptions* options_; - const FieldDescriptor* fields_; - - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() - // in descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - OneofDescriptor() {} - friend class DescriptorBuilder; - friend class Descriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofDescriptor); -}; - -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(OneofDescriptor, 40); - -// Describes an enum type defined in a .proto file. To get the EnumDescriptor -// for a generated enum type, call TypeName_descriptor(). Use DescriptorPool -// to construct your own descriptors. -class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase { - public: - typedef EnumDescriptorProto Proto; - - // The name of this enum type in the containing scope. - const std::string& name() const; - - // The fully-qualified name of the enum type, scope delimited by periods. - const std::string& full_name() const; - - // Index of this enum within the file or containing message's enum array. - int index() const; - - // The .proto file in which this enum type was defined. Never nullptr. - const FileDescriptor* file() const; - - // The number of values for this EnumDescriptor. Guaranteed to be greater - // than zero. - int value_count() const; - // Gets a value by index, where 0 <= index < value_count(). - // These are returned in the order they were defined in the .proto file. - const EnumValueDescriptor* value(int index) const; - - // Looks up a value by name. Returns nullptr if no such value exists. - const EnumValueDescriptor* FindValueByName(ConstStringParam name) const; - // Looks up a value by number. Returns nullptr if no such value exists. If - // multiple values have this number, the first one defined is returned. - const EnumValueDescriptor* FindValueByNumber(int number) const; - - // If this enum type is nested in a message type, this is that message type. - // Otherwise, nullptr. - const Descriptor* containing_type() const; - - // Get options for this enum type. These are specified in the .proto file by - // placing lines like "option foo = 1234;" in the enum definition. Allowed - // options are defined by EnumOptions in descriptor.proto, and any available - // extensions of that message. - const EnumOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(EnumDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - std::string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - std::string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Returns true if this is a placeholder for an unknown enum. This will - // only be the case if this descriptor comes from a DescriptorPool - // with AllowUnknownDependencies() set. - bool is_placeholder() const; - - // Reserved fields ------------------------------------------------- - - // A range of reserved field numbers. - struct ReservedRange { - int start; // inclusive - int end; // inclusive - }; - - // The number of reserved ranges in this message type. - int reserved_range_count() const; - // Gets an reserved range by index, where 0 <= index < - // reserved_range_count(). These are returned in the order they were defined - // in the .proto file. - const EnumDescriptor::ReservedRange* reserved_range(int index) const; - - // Returns true if the number is in one of the reserved ranges. - bool IsReservedNumber(int number) const; - - // Returns nullptr if no reserved range contains the given number. - const EnumDescriptor::ReservedRange* FindReservedRangeContainingNumber( - int number) const; - - // The number of reserved field names in this message type. - int reserved_name_count() const; - - // Gets a reserved name by index, where 0 <= index < reserved_name_count(). - const std::string& reserved_name(int index) const; - - // Returns true if the field name is reserved. - bool IsReservedName(ConstStringParam name) const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this enum declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - friend class Symbol; - typedef EnumOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class io::Printer; - friend class compiler::cpp::Formatter; - - // Allow access to FindValueByNumberCreatingIfUnknown. - friend class descriptor_unittest::DescriptorTest; - - // Looks up a value by number. If the value does not exist, dynamically - // creates a new EnumValueDescriptor for that value, assuming that it was - // unknown. If a new descriptor is created, this is done in a thread-safe way, - // and future calls will return the same value descriptor pointer. - // - // This is private but is used by Reflection (which is friended below) to - // return a valid EnumValueDescriptor from GetEnum() when this feature is - // enabled. - const EnumValueDescriptor* FindValueByNumberCreatingIfUnknown( - int number) const; - - // See Descriptor::DebugString(). - void DebugString(int depth, std::string* contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - // True if this is a placeholder for an unknown type. - bool is_placeholder_ : 1; - // True if this is a placeholder and the type name wasn't fully-qualified. - bool is_unqualified_placeholder_ : 1; - - // This points to the last value _index_ that is part of the sequence starting - // with the first label, where - // `enum->value(i)->number() == enum->value(0)->number() + i` - // We measure relative to the first label to adapt to enum labels starting at - // 0 or 1. - // Uses 16-bit to avoid extra padding. Unlikely to have more than 2^15 - // sequentially numbered labels in an enum. - int16_t sequential_value_limit_; - - int value_count_; - - // all_names_ = [name, full_name] - const std::string* all_names_; - const FileDescriptor* file_; - const Descriptor* containing_type_; - const EnumOptions* options_; - EnumValueDescriptor* values_; - - int reserved_range_count_; - int reserved_name_count_; - EnumDescriptor::ReservedRange* reserved_ranges_; - const std::string** reserved_names_; - - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - EnumDescriptor() {} - friend class DescriptorBuilder; - friend class Descriptor; - friend class FieldDescriptor; - friend class FileDescriptorTables; - friend class EnumValueDescriptor; - friend class FileDescriptor; - friend class DescriptorPool; - friend class Reflection; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor); -}; - -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(EnumDescriptor, 72); - -// Describes an individual enum constant of a particular type. To get the -// EnumValueDescriptor for a given enum value, first get the EnumDescriptor -// for its type, then use EnumDescriptor::FindValueByName() or -// EnumDescriptor::FindValueByNumber(). Use DescriptorPool to construct -// your own descriptors. -class PROTOBUF_EXPORT EnumValueDescriptor : private internal::SymbolBaseN<0>, - private internal::SymbolBaseN<1> { - public: - typedef EnumValueDescriptorProto Proto; - - const std::string& name() const; // Name of this enum constant. - int index() const; // Index within the enums's Descriptor. - int number() const; // Numeric value of this enum constant. - - // The full_name of an enum value is a sibling symbol of the enum type. - // e.g. the full name of FieldDescriptorProto::TYPE_INT32 is actually - // "google.protobuf.FieldDescriptorProto.TYPE_INT32", NOT - // "google.protobuf.FieldDescriptorProto.Type.TYPE_INT32". This is to conform - // with C++ scoping rules for enums. - const std::string& full_name() const; - - // The .proto file in which this value was defined. Never nullptr. - const FileDescriptor* file() const; - // The type of this value. Never nullptr. - const EnumDescriptor* type() const; - - // Get options for this enum value. These are specified in the .proto file by - // adding text like "[foo = 1234]" after an enum value definition. Allowed - // options are defined by EnumValueOptions in descriptor.proto, and any - // available extensions of that message. - const EnumValueOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(EnumValueDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - std::string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - std::string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this enum value declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - friend class Symbol; - typedef EnumValueOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class io::Printer; - friend class compiler::cpp::Formatter; - - // See Descriptor::DebugString(). - void DebugString(int depth, std::string* contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - int number_; - // all_names_ = [name, full_name] - const std::string* all_names_; - const EnumDescriptor* type_; - const EnumValueOptions* options_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() - // in descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - EnumValueDescriptor() {} - friend class DescriptorBuilder; - friend class EnumDescriptor; - friend class DescriptorPool; - friend class FileDescriptorTables; - friend class Reflection; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor); -}; - -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(EnumValueDescriptor, 32); - -// Describes an RPC service. Use DescriptorPool to construct your own -// descriptors. -class PROTOBUF_EXPORT ServiceDescriptor : private internal::SymbolBase { - public: - typedef ServiceDescriptorProto Proto; - - // The name of the service, not including its containing scope. - const std::string& name() const; - // The fully-qualified name of the service, scope delimited by periods. - const std::string& full_name() const; - // Index of this service within the file's services array. - int index() const; - - // The .proto file in which this service was defined. Never nullptr. - const FileDescriptor* file() const; - - // Get options for this service type. These are specified in the .proto file - // by placing lines like "option foo = 1234;" in the service definition. - // Allowed options are defined by ServiceOptions in descriptor.proto, and any - // available extensions of that message. - const ServiceOptions& options() const; - - // The number of methods this service defines. - int method_count() const; - // Gets a MethodDescriptor by index, where 0 <= index < method_count(). - // These are returned in the order they were defined in the .proto file. - const MethodDescriptor* method(int index) const; - - // Look up a MethodDescriptor by name. - const MethodDescriptor* FindMethodByName(ConstStringParam name) const; - - // See Descriptor::CopyTo(). - void CopyTo(ServiceDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - std::string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - std::string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this service declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - friend class Symbol; - typedef ServiceOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class io::Printer; - friend class compiler::cpp::Formatter; - - // See Descriptor::DebugString(). - void DebugString(std::string* contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - // all_names_ = [name, full_name] - const std::string* all_names_; - const FileDescriptor* file_; - const ServiceOptions* options_; - MethodDescriptor* methods_; - int method_count_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - ServiceDescriptor() {} - friend class DescriptorBuilder; - friend class FileDescriptor; - friend class MethodDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor); -}; - -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(ServiceDescriptor, 48); - -// Describes an individual service method. To obtain a MethodDescriptor given -// a service, first get its ServiceDescriptor, then call -// ServiceDescriptor::FindMethodByName(). Use DescriptorPool to construct your -// own descriptors. -class PROTOBUF_EXPORT MethodDescriptor : private internal::SymbolBase { - public: - typedef MethodDescriptorProto Proto; - - // Name of this method, not including containing scope. - const std::string& name() const; - // The fully-qualified name of the method, scope delimited by periods. - const std::string& full_name() const; - // Index within the service's Descriptor. - int index() const; - - // The .proto file in which this method was defined. Never nullptr. - const FileDescriptor* file() const; - // Gets the service to which this method belongs. Never nullptr. - const ServiceDescriptor* service() const; - - // Gets the type of protocol message which this method accepts as input. - const Descriptor* input_type() const; - // Gets the type of protocol message which this message produces as output. - const Descriptor* output_type() const; - - // Gets whether the client streams multiple requests. - bool client_streaming() const; - // Gets whether the server streams multiple responses. - bool server_streaming() const; - - // Get options for this method. These are specified in the .proto file by - // placing lines like "option foo = 1234;" in curly-braces after a method - // declaration. Allowed options are defined by MethodOptions in - // descriptor.proto, and any available extensions of that message. - const MethodOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(MethodDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - std::string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - std::string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this method declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - friend class Symbol; - typedef MethodOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class io::Printer; - friend class compiler::cpp::Formatter; - - // See Descriptor::DebugString(). - void DebugString(int depth, std::string* contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - bool client_streaming_; - bool server_streaming_; - // all_names_ = [name, full_name] - const std::string* all_names_; - const ServiceDescriptor* service_; - mutable internal::LazyDescriptor input_type_; - mutable internal::LazyDescriptor output_type_; - const MethodOptions* options_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - MethodDescriptor() {} - friend class DescriptorBuilder; - friend class ServiceDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MethodDescriptor); -}; - -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(MethodDescriptor, 64); - -// Describes a whole .proto file. To get the FileDescriptor for a compiled-in -// file, get the descriptor for something defined in that file and call -// descriptor->file(). Use DescriptorPool to construct your own descriptors. -class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase { - public: - typedef FileDescriptorProto Proto; - - // The filename, relative to the source tree. - // e.g. "foo/bar/baz.proto" - const std::string& name() const; - - // The package, e.g. "google.protobuf.compiler". - const std::string& package() const; - - // The DescriptorPool in which this FileDescriptor and all its contents were - // allocated. Never nullptr. - const DescriptorPool* pool() const; - - // The number of files imported by this one. - int dependency_count() const; - // Gets an imported file by index, where 0 <= index < dependency_count(). - // These are returned in the order they were defined in the .proto file. - const FileDescriptor* dependency(int index) const; - - // The number of files public imported by this one. - // The public dependency list is a subset of the dependency list. - int public_dependency_count() const; - // Gets a public imported file by index, where 0 <= index < - // public_dependency_count(). - // These are returned in the order they were defined in the .proto file. - const FileDescriptor* public_dependency(int index) const; - - // The number of files that are imported for weak fields. - // The weak dependency list is a subset of the dependency list. - int weak_dependency_count() const; - // Gets a weak imported file by index, where 0 <= index < - // weak_dependency_count(). - // These are returned in the order they were defined in the .proto file. - const FileDescriptor* weak_dependency(int index) const; - - // Number of top-level message types defined in this file. (This does not - // include nested types.) - int message_type_count() const; - // Gets a top-level message type, where 0 <= index < message_type_count(). - // These are returned in the order they were defined in the .proto file. - const Descriptor* message_type(int index) const; - - // Number of top-level enum types defined in this file. (This does not - // include nested types.) - int enum_type_count() const; - // Gets a top-level enum type, where 0 <= index < enum_type_count(). - // These are returned in the order they were defined in the .proto file. - const EnumDescriptor* enum_type(int index) const; - - // Number of services defined in this file. - int service_count() const; - // Gets a service, where 0 <= index < service_count(). - // These are returned in the order they were defined in the .proto file. - const ServiceDescriptor* service(int index) const; - - // Number of extensions defined at file scope. (This does not include - // extensions nested within message types.) - int extension_count() const; - // Gets an extension's descriptor, where 0 <= index < extension_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* extension(int index) const; - - // Get options for this file. These are specified in the .proto file by - // placing lines like "option foo = 1234;" at the top level, outside of any - // other definitions. Allowed options are defined by FileOptions in - // descriptor.proto, and any available extensions of that message. - const FileOptions& options() const; - - // Syntax of this file. - enum Syntax { - SYNTAX_UNKNOWN = 0, - SYNTAX_PROTO2 = 2, - SYNTAX_PROTO3 = 3, - }; - Syntax syntax() const; - static const char* SyntaxName(Syntax syntax); - - // Find a top-level message type by name (not full_name). Returns nullptr if - // not found. - const Descriptor* FindMessageTypeByName(ConstStringParam name) const; - // Find a top-level enum type by name. Returns nullptr if not found. - const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const; - // Find an enum value defined in any top-level enum by name. Returns nullptr - // if not found. - const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const; - // Find a service definition by name. Returns nullptr if not found. - const ServiceDescriptor* FindServiceByName(ConstStringParam name) const; - // Find a top-level extension definition by name. Returns nullptr if not - // found. - const FieldDescriptor* FindExtensionByName(ConstStringParam name) const; - // Similar to FindExtensionByName(), but searches by lowercased-name. See - // Descriptor::FindFieldByLowercaseName(). - const FieldDescriptor* FindExtensionByLowercaseName( - ConstStringParam name) const; - // Similar to FindExtensionByName(), but searches by camelcased-name. See - // Descriptor::FindFieldByCamelcaseName(). - const FieldDescriptor* FindExtensionByCamelcaseName( - ConstStringParam name) const; - - // See Descriptor::CopyTo(). - // Notes: - // - This method does NOT copy source code information since it is relatively - // large and rarely needed. See CopySourceCodeInfoTo() below. - void CopyTo(FileDescriptorProto* proto) const; - // Write the source code information of this FileDescriptor into the given - // FileDescriptorProto. See CopyTo() above. - void CopySourceCodeInfoTo(FileDescriptorProto* proto) const; - // Fill the json_name field of FieldDescriptorProto for all fields. Can only - // be called after CopyTo(). - void CopyJsonNameTo(FileDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - std::string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - std::string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Returns true if this is a placeholder for an unknown file. This will - // only be the case if this descriptor comes from a DescriptorPool - // with AllowUnknownDependencies() set. - bool is_placeholder() const; - - // Updates |*out_location| to the source location of the complete extent of - // this file declaration (namely, the empty path). - bool GetSourceLocation(SourceLocation* out_location) const; - - // Updates |*out_location| to the source location of the complete - // extent of the declaration or declaration-part denoted by |path|. - // Returns false and leaves |*out_location| unchanged iff location - // information was not available. (See SourceCodeInfo for - // description of path encoding.) - bool GetSourceLocation(const std::vector& path, - SourceLocation* out_location) const; - - private: - friend class Symbol; - typedef FileOptions OptionsType; - - bool is_placeholder_; - // Indicates the FileDescriptor is completed building. Used to verify - // that type accessor functions that can possibly build a dependent file - // aren't called during the process of building the file. - bool finished_building_; - // Actually a `Syntax` but stored as uint8_t to save space. - uint8_t syntax_; - // This one is here to fill the padding. - int extension_count_; - - const std::string* name_; - const std::string* package_; - const DescriptorPool* pool_; - - // dependencies_once_ contain a once_flag followed by N NUL terminated - // strings. Dependencies that do not need to be loaded will be empty. ie just - // {'\0'} - internal::once_flag* dependencies_once_; - static void DependenciesOnceInit(const FileDescriptor* to_init); - void InternalDependenciesOnceInit() const; - - // These are arranged to minimize padding on 64-bit. - int dependency_count_; - int public_dependency_count_; - int weak_dependency_count_; - int message_type_count_; - int enum_type_count_; - int service_count_; - - mutable const FileDescriptor** dependencies_; - int* public_dependencies_; - int* weak_dependencies_; - Descriptor* message_types_; - EnumDescriptor* enum_types_; - ServiceDescriptor* services_; - FieldDescriptor* extensions_; - const FileOptions* options_; - - const FileDescriptorTables* tables_; - const SourceCodeInfo* source_code_info_; - - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - FileDescriptor() {} - friend class DescriptorBuilder; - friend class DescriptorPool; - friend class Descriptor; - friend class FieldDescriptor; - friend class internal::LazyDescriptor; - friend class OneofDescriptor; - friend class EnumDescriptor; - friend class EnumValueDescriptor; - friend class MethodDescriptor; - friend class ServiceDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor); -}; - -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FileDescriptor, 144); - -// =================================================================== - -// Used to construct descriptors. -// -// Normally you won't want to build your own descriptors. Message classes -// constructed by the protocol compiler will provide them for you. However, -// if you are implementing Message on your own, or if you are writing a -// program which can operate on totally arbitrary types and needs to load -// them from some sort of database, you might need to. -// -// Since Descriptors are composed of a whole lot of cross-linked bits of -// data that would be a pain to put together manually, the -// DescriptorPool class is provided to make the process easier. It can -// take a FileDescriptorProto (defined in descriptor.proto), validate it, -// and convert it to a set of nicely cross-linked Descriptors. -// -// DescriptorPool also helps with memory management. Descriptors are -// composed of many objects containing static data and pointers to each -// other. In all likelihood, when it comes time to delete this data, -// you'll want to delete it all at once. In fact, it is not uncommon to -// have a whole pool of descriptors all cross-linked with each other which -// you wish to delete all at once. This class represents such a pool, and -// handles the memory management for you. -// -// You can also search for descriptors within a DescriptorPool by name, and -// extensions by number. -class PROTOBUF_EXPORT DescriptorPool { - public: - // Create a normal, empty DescriptorPool. - DescriptorPool(); - - // Constructs a DescriptorPool that, when it can't find something among the - // descriptors already in the pool, looks for it in the given - // DescriptorDatabase. - // Notes: - // - If a DescriptorPool is constructed this way, its BuildFile*() methods - // must not be called (they will assert-fail). The only way to populate - // the pool with descriptors is to call the Find*By*() methods. - // - The Find*By*() methods may block the calling thread if the - // DescriptorDatabase blocks. This in turn means that parsing messages - // may block if they need to look up extensions. - // - The Find*By*() methods will use mutexes for thread-safety, thus making - // them slower even when they don't have to fall back to the database. - // In fact, even the Find*By*() methods of descriptor objects owned by - // this pool will be slower, since they will have to obtain locks too. - // - An ErrorCollector may optionally be given to collect validation errors - // in files loaded from the database. If not given, errors will be printed - // to GOOGLE_LOG(ERROR). Remember that files are built on-demand, so this - // ErrorCollector may be called from any thread that calls one of the - // Find*By*() methods. - // - The DescriptorDatabase must not be mutated during the lifetime of - // the DescriptorPool. Even if the client takes care to avoid data races, - // changes to the content of the DescriptorDatabase may not be reflected - // in subsequent lookups in the DescriptorPool. - class ErrorCollector; - explicit DescriptorPool(DescriptorDatabase* fallback_database, - ErrorCollector* error_collector = nullptr); - - ~DescriptorPool(); - - // Get a pointer to the generated pool. Generated protocol message classes - // which are compiled into the binary will allocate their descriptors in - // this pool. Do not add your own descriptors to this pool. - static const DescriptorPool* generated_pool(); - - - // Find a FileDescriptor in the pool by file name. Returns nullptr if not - // found. - const FileDescriptor* FindFileByName(ConstStringParam name) const; - - // Find the FileDescriptor in the pool which defines the given symbol. - // If any of the Find*ByName() methods below would succeed, then this is - // equivalent to calling that method and calling the result's file() method. - // Otherwise this returns nullptr. - const FileDescriptor* FindFileContainingSymbol( - ConstStringParam symbol_name) const; - - // Looking up descriptors ------------------------------------------ - // These find descriptors by fully-qualified name. These will find both - // top-level descriptors and nested descriptors. They return nullptr if not - // found. - - const Descriptor* FindMessageTypeByName(ConstStringParam name) const; - const FieldDescriptor* FindFieldByName(ConstStringParam name) const; - const FieldDescriptor* FindExtensionByName(ConstStringParam name) const; - const OneofDescriptor* FindOneofByName(ConstStringParam name) const; - const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const; - const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const; - const ServiceDescriptor* FindServiceByName(ConstStringParam name) const; - const MethodDescriptor* FindMethodByName(ConstStringParam name) const; - - // Finds an extension of the given type by number. The extendee must be - // a member of this DescriptorPool or one of its underlays. - const FieldDescriptor* FindExtensionByNumber(const Descriptor* extendee, - int number) const; - - // Finds an extension of the given type by its printable name. - // See comments above PrintableNameForExtension() for the definition of - // "printable name". The extendee must be a member of this DescriptorPool - // or one of its underlays. Returns nullptr if there is no known message - // extension with the given printable name. - const FieldDescriptor* FindExtensionByPrintableName( - const Descriptor* extendee, ConstStringParam printable_name) const; - - // Finds extensions of extendee. The extensions will be appended to - // out in an undefined order. Only extensions defined directly in - // this DescriptorPool or one of its underlays are guaranteed to be - // found: extensions defined in the fallback database might not be found - // depending on the database implementation. - void FindAllExtensions(const Descriptor* extendee, - std::vector* out) const; - - // Building descriptors -------------------------------------------- - - // When converting a FileDescriptorProto to a FileDescriptor, various - // errors might be detected in the input. The caller may handle these - // programmatically by implementing an ErrorCollector. - class PROTOBUF_EXPORT ErrorCollector { - public: - inline ErrorCollector() {} - virtual ~ErrorCollector(); - - // These constants specify what exact part of the construct is broken. - // This is useful e.g. for mapping the error back to an exact location - // in a .proto file. - enum ErrorLocation { - NAME, // the symbol name, or the package name for files - NUMBER, // field or extension range number - TYPE, // field type - EXTENDEE, // field extendee - DEFAULT_VALUE, // field default value - INPUT_TYPE, // method input type - OUTPUT_TYPE, // method output type - OPTION_NAME, // name in assignment - OPTION_VALUE, // value in option assignment - IMPORT, // import error - OTHER // some other problem - }; - - // Reports an error in the FileDescriptorProto. Use this function if the - // problem occurred should interrupt building the FileDescriptorProto. - virtual void AddError( - const std::string& filename, // File name in which the error occurred. - const std::string& element_name, // Full name of the erroneous element. - const Message* descriptor, // Descriptor of the erroneous element. - ErrorLocation location, // One of the location constants, above. - const std::string& message // Human-readable error message. - ) = 0; - - // Reports a warning in the FileDescriptorProto. Use this function if the - // problem occurred should NOT interrupt building the FileDescriptorProto. - virtual void AddWarning( - const std::string& /*filename*/, // File name in which the error - // occurred. - const std::string& /*element_name*/, // Full name of the erroneous - // element. - const Message* /*descriptor*/, // Descriptor of the erroneous element. - ErrorLocation /*location*/, // One of the location constants, above. - const std::string& /*message*/ // Human-readable error message. - ) {} - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); - }; - - // Convert the FileDescriptorProto to real descriptors and place them in - // this DescriptorPool. All dependencies of the file must already be in - // the pool. Returns the resulting FileDescriptor, or nullptr if there were - // problems with the input (e.g. the message was invalid, or dependencies - // were missing). Details about the errors are written to GOOGLE_LOG(ERROR). - const FileDescriptor* BuildFile(const FileDescriptorProto& proto); - - // Same as BuildFile() except errors are sent to the given ErrorCollector. - const FileDescriptor* BuildFileCollectingErrors( - const FileDescriptorProto& proto, ErrorCollector* error_collector); - - // By default, it is an error if a FileDescriptorProto contains references - // to types or other files that are not found in the DescriptorPool (or its - // backing DescriptorDatabase, if any). If you call - // AllowUnknownDependencies(), however, then unknown types and files - // will be replaced by placeholder descriptors (which can be identified by - // the is_placeholder() method). This can allow you to - // perform some useful operations with a .proto file even if you do not - // have access to other .proto files on which it depends. However, some - // heuristics must be used to fill in the gaps in information, and these - // can lead to descriptors which are inaccurate. For example, the - // DescriptorPool may be forced to guess whether an unknown type is a message - // or an enum, as well as what package it resides in. Furthermore, - // placeholder types will not be discoverable via FindMessageTypeByName() - // and similar methods, which could confuse some descriptor-based algorithms. - // Generally, the results of this option should be handled with extreme care. - void AllowUnknownDependencies() { allow_unknown_ = true; } - - // By default, weak imports are allowed to be missing, in which case we will - // use a placeholder for the dependency and convert the field to be an Empty - // message field. If you call EnforceWeakDependencies(true), however, the - // DescriptorPool will report a import not found error. - void EnforceWeakDependencies(bool enforce) { enforce_weak_ = enforce; } - - // Internal stuff -------------------------------------------------- - // These methods MUST NOT be called from outside the proto2 library. - // These methods may contain hidden pitfalls and may be removed in a - // future library version. - - // Create a DescriptorPool which is overlaid on top of some other pool. - // If you search for a descriptor in the overlay and it is not found, the - // underlay will be searched as a backup. If the underlay has its own - // underlay, that will be searched next, and so on. This also means that - // files built in the overlay will be cross-linked with the underlay's - // descriptors if necessary. The underlay remains property of the caller; - // it must remain valid for the lifetime of the newly-constructed pool. - // - // Example: Say you want to parse a .proto file at runtime in order to use - // its type with a DynamicMessage. Say this .proto file has dependencies, - // but you know that all the dependencies will be things that are already - // compiled into the binary. For ease of use, you'd like to load the types - // right out of generated_pool() rather than have to parse redundant copies - // of all these .protos and runtime. But, you don't want to add the parsed - // types directly into generated_pool(): this is not allowed, and would be - // bad design anyway. So, instead, you could use generated_pool() as an - // underlay for a new DescriptorPool in which you add only the new file. - // - // WARNING: Use of underlays can lead to many subtle gotchas. Instead, - // try to formulate what you want to do in terms of DescriptorDatabases. - explicit DescriptorPool(const DescriptorPool* underlay); - - // Called by generated classes at init time to add their descriptors to - // generated_pool. Do NOT call this in your own code! filename must be a - // permanent string (e.g. a string literal). - static void InternalAddGeneratedFile(const void* encoded_file_descriptor, - int size); - - // Disallow [enforce_utf8 = false] in .proto files. - void DisallowEnforceUtf8() { disallow_enforce_utf8_ = true; } - - - // For internal use only: Gets a non-const pointer to the generated pool. - // This is called at static-initialization time only, so thread-safety is - // not a concern. If both an underlay and a fallback database are present, - // the underlay takes precedence. - static DescriptorPool* internal_generated_pool(); - - // For internal use only: Gets a non-const pointer to the generated - // descriptor database. - // Only used for testing. - static DescriptorDatabase* internal_generated_database(); - - // For internal use only: Changes the behavior of BuildFile() such that it - // allows the file to make reference to message types declared in other files - // which it did not officially declare as dependencies. - void InternalDontEnforceDependencies(); - - // For internal use only: Enables lazy building of dependencies of a file. - // Delay the building of dependencies of a file descriptor until absolutely - // necessary, like when message_type() is called on a field that is defined - // in that dependency's file. This will cause functional issues if a proto - // or one of its dependencies has errors. Should only be enabled for the - // generated_pool_ (because no descriptor build errors are guaranteed by - // the compilation generation process), testing, or if a lack of descriptor - // build errors can be guaranteed for a pool. - void InternalSetLazilyBuildDependencies() { - lazily_build_dependencies_ = true; - // This needs to be set when lazily building dependencies, as it breaks - // dependency checking. - InternalDontEnforceDependencies(); - } - - // For internal use only. - void internal_set_underlay(const DescriptorPool* underlay) { - underlay_ = underlay; - } - - // For internal (unit test) use only: Returns true if a FileDescriptor has - // been constructed for the given file, false otherwise. Useful for testing - // lazy descriptor initialization behavior. - bool InternalIsFileLoaded(ConstStringParam filename) const; - - // Add a file to unused_import_track_files_. DescriptorBuilder will log - // warnings or errors for those files if there is any unused import. - void AddUnusedImportTrackFile(ConstStringParam file_name, - bool is_error = false); - void ClearUnusedImportTrackFiles(); - - private: - friend class Descriptor; - friend class internal::LazyDescriptor; - friend class FieldDescriptor; - friend class EnumDescriptor; - friend class ServiceDescriptor; - friend class MethodDescriptor; - friend class FileDescriptor; - friend class DescriptorBuilder; - friend class FileDescriptorTables; - - // Return true if the given name is a sub-symbol of any non-package - // descriptor that already exists in the descriptor pool. (The full - // definition of such types is already known.) - bool IsSubSymbolOfBuiltType(StringPiece name) const; - - // Tries to find something in the fallback database and link in the - // corresponding proto file. Returns true if successful, in which case - // the caller should search for the thing again. These are declared - // const because they are called by (semantically) const methods. - bool TryFindFileInFallbackDatabase(StringPiece name) const; - bool TryFindSymbolInFallbackDatabase(StringPiece name) const; - bool TryFindExtensionInFallbackDatabase(const Descriptor* containing_type, - int field_number) const; - - // This internal find extension method only check with its table and underlay - // descriptor_pool's table. It does not check with fallback DB and no - // additional proto file will be build in this method. - const FieldDescriptor* InternalFindExtensionByNumberNoLock( - const Descriptor* extendee, int number) const; - - // Like BuildFile() but called internally when the file has been loaded from - // fallback_database_. Declared const because it is called by (semantically) - // const methods. - const FileDescriptor* BuildFileFromDatabase( - const FileDescriptorProto& proto) const; - - // Helper for when lazily_build_dependencies_ is set, can look up a symbol - // after the file's descriptor is built, and can build the file where that - // symbol is defined if necessary. Will create a placeholder if the type - // doesn't exist in the fallback database, or the file doesn't build - // successfully. - Symbol CrossLinkOnDemandHelper(StringPiece name, - bool expecting_enum) const; - - // Create a placeholder FileDescriptor of the specified name - FileDescriptor* NewPlaceholderFile(StringPiece name) const; - FileDescriptor* NewPlaceholderFileWithMutexHeld( - StringPiece name, internal::FlatAllocator& alloc) const; - - enum PlaceholderType { - PLACEHOLDER_MESSAGE, - PLACEHOLDER_ENUM, - PLACEHOLDER_EXTENDABLE_MESSAGE - }; - // Create a placeholder Descriptor of the specified name - Symbol NewPlaceholder(StringPiece name, - PlaceholderType placeholder_type) const; - Symbol NewPlaceholderWithMutexHeld(StringPiece name, - PlaceholderType placeholder_type) const; - - // If fallback_database_ is nullptr, this is nullptr. Otherwise, this is a - // mutex which must be locked while accessing tables_. - internal::WrappedMutex* mutex_; - - // See constructor. - DescriptorDatabase* fallback_database_; - ErrorCollector* default_error_collector_; - const DescriptorPool* underlay_; - - // This class contains a lot of hash maps with complicated types that - // we'd like to keep out of the header. - class Tables; - std::unique_ptr tables_; - - bool enforce_dependencies_; - bool lazily_build_dependencies_; - bool allow_unknown_; - bool enforce_weak_; - bool disallow_enforce_utf8_; - - // Set of files to track for unused imports. The bool value when true means - // unused imports are treated as errors (and as warnings when false). - std::map unused_import_track_files_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool); -}; - - -// inline methods ==================================================== - -// These macros makes this repetitive code more readable. -#define PROTOBUF_DEFINE_ACCESSOR(CLASS, FIELD, TYPE) \ - inline TYPE CLASS::FIELD() const { return FIELD##_; } - -// Strings fields are stored as pointers but returned as const references. -#define PROTOBUF_DEFINE_STRING_ACCESSOR(CLASS, FIELD) \ - inline const std::string& CLASS::FIELD() const { return *FIELD##_; } - -// Name and full name are stored in a single array to save space. -#define PROTOBUF_DEFINE_NAME_ACCESSOR(CLASS) \ - inline const std::string& CLASS::name() const { return all_names_[0]; } \ - inline const std::string& CLASS::full_name() const { return all_names_[1]; } - -// Arrays take an index parameter, obviously. -#define PROTOBUF_DEFINE_ARRAY_ACCESSOR(CLASS, FIELD, TYPE) \ - inline TYPE CLASS::FIELD(int index) const { return FIELD##s_ + index; } - -#define PROTOBUF_DEFINE_OPTIONS_ACCESSOR(CLASS, TYPE) \ - inline const TYPE& CLASS::options() const { return *options_; } - -PROTOBUF_DEFINE_NAME_ACCESSOR(Descriptor) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, containing_type, const Descriptor*) - -PROTOBUF_DEFINE_ACCESSOR(Descriptor, field_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, oneof_decl_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, real_oneof_decl_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, nested_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, enum_type_count, int) - -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, field, const FieldDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, oneof_decl, const OneofDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, nested_type, const Descriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, enum_type, const EnumDescriptor*) - -PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_range_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension_range, - const Descriptor::ExtensionRange*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension, const FieldDescriptor*) - -PROTOBUF_DEFINE_ACCESSOR(Descriptor, reserved_range_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, reserved_range, - const Descriptor::ReservedRange*) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, reserved_name_count, int) - -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(Descriptor, MessageOptions) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, is_placeholder, bool) - -PROTOBUF_DEFINE_NAME_ACCESSOR(FieldDescriptor) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, number, int) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, is_extension, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_json_name, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32_t, int32_t) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int64_t, int64_t) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint32_t, uint32_t) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64_t, uint64_t) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float, float) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool, bool) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string) - -PROTOBUF_DEFINE_NAME_ACCESSOR(OneofDescriptor) -PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, containing_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, field_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(OneofDescriptor, field, const FieldDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(OneofDescriptor, OneofOptions) - -PROTOBUF_DEFINE_NAME_ACCESSOR(EnumDescriptor) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, containing_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, value_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, value, - const EnumValueDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumDescriptor, EnumOptions) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, is_placeholder, bool) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, reserved_range_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, reserved_range, - const EnumDescriptor::ReservedRange*) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, reserved_name_count, int) - -PROTOBUF_DEFINE_NAME_ACCESSOR(EnumValueDescriptor) -PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, number, int) -PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, type, const EnumDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumValueDescriptor, EnumValueOptions) - -PROTOBUF_DEFINE_NAME_ACCESSOR(ServiceDescriptor) -PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, method_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(ServiceDescriptor, method, - const MethodDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(ServiceDescriptor, ServiceOptions) - -PROTOBUF_DEFINE_NAME_ACCESSOR(MethodDescriptor) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, service, const ServiceDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(MethodDescriptor, MethodOptions) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, client_streaming, bool) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, server_streaming, bool) - -PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, package) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, pool, const DescriptorPool*) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, dependency_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, public_dependency_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, weak_dependency_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, message_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, enum_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, service_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, extension_count, int) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FileDescriptor, FileOptions) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, is_placeholder, bool) - -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, message_type, const Descriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, enum_type, const EnumDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, service, - const ServiceDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, extension, - const FieldDescriptor*) - -#undef PROTOBUF_DEFINE_ACCESSOR -#undef PROTOBUF_DEFINE_STRING_ACCESSOR -#undef PROTOBUF_DEFINE_ARRAY_ACCESSOR - -// A few accessors differ from the macros... - -inline Descriptor::WellKnownType Descriptor::well_known_type() const { - return static_cast(well_known_type_); -} - -inline bool Descriptor::IsExtensionNumber(int number) const { - return FindExtensionRangeContainingNumber(number) != nullptr; -} - -inline bool Descriptor::IsReservedNumber(int number) const { - return FindReservedRangeContainingNumber(number) != nullptr; -} - -inline bool Descriptor::IsReservedName(ConstStringParam name) const { - for (int i = 0; i < reserved_name_count(); i++) { - if (name == static_cast(reserved_name(i))) { - return true; - } - } - return false; -} - -// Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because reserved_names_ is actually -// an array of pointers rather than the usual array of objects. -inline const std::string& Descriptor::reserved_name(int index) const { - return *reserved_names_[index]; -} - -inline bool EnumDescriptor::IsReservedNumber(int number) const { - return FindReservedRangeContainingNumber(number) != nullptr; -} - -inline bool EnumDescriptor::IsReservedName(ConstStringParam name) const { - for (int i = 0; i < reserved_name_count(); i++) { - if (name == static_cast(reserved_name(i))) { - return true; - } - } - return false; -} - -// Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because reserved_names_ is actually -// an array of pointers rather than the usual array of objects. -inline const std::string& EnumDescriptor::reserved_name(int index) const { - return *reserved_names_[index]; -} - -inline const std::string& FieldDescriptor::lowercase_name() const { - return all_names_[lowercase_name_index_]; -} - -inline const std::string& FieldDescriptor::camelcase_name() const { - return all_names_[camelcase_name_index_]; -} - -inline const std::string& FieldDescriptor::json_name() const { - return all_names_[json_name_index_]; -} - -inline const OneofDescriptor* FieldDescriptor::containing_oneof() const { - return is_oneof_ ? scope_.containing_oneof : nullptr; -} - -inline int FieldDescriptor::index_in_oneof() const { - GOOGLE_DCHECK(is_oneof_); - return static_cast(this - scope_.containing_oneof->field(0)); -} - -inline const Descriptor* FieldDescriptor::extension_scope() const { - GOOGLE_CHECK(is_extension_); - return scope_.extension_scope; -} - -inline FieldDescriptor::Label FieldDescriptor::label() const { - return static_cast