// 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. #include "google/protobuf/descriptor.h" #include #include #include #include #include #include #include #include #include #include #include #include "google/protobuf/stubs/common.h" #include "absl/base/call_once.h" #include "absl/base/casts.h" #include "absl/base/dynamic_annotations.h" #include "absl/container/btree_map.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/functional/function_ref.h" #include "absl/hash/hash.h" #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/status/statusor.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "absl/strings/substitute.h" #include "absl/synchronization/mutex.h" #include "absl/types/optional.h" #include "google/protobuf/any.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor_database.h" #include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/descriptor_visitor.h" #include "google/protobuf/dynamic_message.h" #ifdef PROTOBUF_FUTURE_EDITIONS #include "google/protobuf/cpp_features.pb.h" #include "google/protobuf/feature_resolver.h" #endif // PROTOBUF_FUTURE_EDITIONS #include "google/protobuf/generated_message_util.h" #include "google/protobuf/io/strtod.h" #include "google/protobuf/io/tokenizer.h" #include "google/protobuf/port.h" #include "google/protobuf/repeated_ptr_field.h" #include "google/protobuf/text_format.h" #include "google/protobuf/unknown_field_set.h" // Must be included last. #include "google/protobuf/port_def.inc" namespace google { namespace protobuf { namespace { using ::google::protobuf::internal::DownCast; const int kPackageLimit = 100; std::string ToCamelCase(const std::string& input, bool lower_first) { bool capitalize_next = !lower_first; std::string result; result.reserve(input.size()); for (char character : input) { if (character == '_') { capitalize_next = true; } else if (capitalize_next) { result.push_back(absl::ascii_toupper(character)); capitalize_next = false; } else { result.push_back(character); } } // Lower-case the first letter. if (lower_first && !result.empty()) { result[0] = absl::ascii_tolower(result[0]); } return result; } std::string ToJsonName(const std::string& input) { bool capitalize_next = false; std::string result; result.reserve(input.size()); for (char character : input) { if (character == '_') { capitalize_next = true; } else if (capitalize_next) { result.push_back(absl::ascii_toupper(character)); capitalize_next = false; } else { result.push_back(character); } } return result; } template bool IsLegacyJsonFieldConflictEnabled(const OptionsT& options) { #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif return options.deprecated_legacy_json_field_conflicts(); #ifdef __GNUC__ #pragma GCC diagnostic pop #endif } // Backport of fold expressions for the comma operator to C++11. // Usage: Fold({expr...}); // Guaranteed to evaluate left-to-right struct ExpressionEater { template ExpressionEater(T&&) {} // NOLINT }; void Fold(std::initializer_list) {} template constexpr size_t RoundUpTo(size_t n) { static_assert((R & (R - 1)) == 0, "Must be power of two"); return (n + (R - 1)) & ~(R - 1); } constexpr size_t Max(size_t a, size_t b) { return a > b ? a : b; } template constexpr size_t Max(T a, Ts... b) { return Max(a, Max(b...)); } template constexpr size_t EffectiveAlignof() { // `char` is special in that it gets aligned to 8. It is where we drop the // trivial structs. return std::is_same::value ? 8 : alignof(T); } template using AppendIfAlign = typename std::conditional() == align, void (*)(T..., U), void (*)(T...)>::type; // Metafunction to sort types in descending order of alignment. // Useful for the flat allocator to ensure proper alignment of all elements // without having to add padding. // Instead of implementing a proper sort metafunction we just do a // filter+merge, which is much simpler to write as a metafunction. // We have a fixed set of alignments we can filter on. // For simplicity we use a function pointer as a type list. template struct TypeListSortImpl; template struct TypeListSortImpl { using type = void (*)(T16..., T8..., T4..., T2..., T1...); }; template struct TypeListSortImpl { using type = typename TypeListSortImpl< void (*)(Rest...), AppendIfAlign<16, First, T16...>, AppendIfAlign<8, First, T8...>, AppendIfAlign<4, First, T4...>, AppendIfAlign<2, First, T2...>, AppendIfAlign<1, First, T1...>>::type; }; template using SortByAlignment = typename TypeListSortImpl::type; template