File indexing completed on 2026-07-13 08:23:31
0001 #ifndef GOOGLE_PROTOBUF_INTERNAL_FEATURE_HELPER_H__
0002 #define GOOGLE_PROTOBUF_INTERNAL_FEATURE_HELPER_H__
0003
0004 #include <cstdint>
0005
0006 #include "absl/strings/string_view.h"
0007 #include "google/protobuf/descriptor.h"
0008 #include "google/protobuf/descriptor.pb.h"
0009 #include "google/protobuf/extension_set.h"
0010
0011
0012 #include "google/protobuf/port_def.inc"
0013
0014 namespace google {
0015 namespace protobuf {
0016 namespace internal {
0017 class InternalFeatureHelperTest;
0018
0019
0020
0021
0022 class PROTOBUF_EXPORT InternalFeatureHelper {
0023 public:
0024 template <typename DescriptorT>
0025 static const FeatureSet& GetFeatures(const DescriptorT& desc) {
0026 return desc.features();
0027 }
0028
0029 private:
0030 friend class ::google::protobuf::compiler::CodeGenerator;
0031 friend class ::google::protobuf::compiler::CommandLineInterface;
0032 friend class ::google::protobuf::internal::InternalFeatureHelperTest;
0033
0034 static const DescriptorPool& GetDescriptorPool(const FileDescriptor& file) {
0035 return *file.pool();
0036 }
0037
0038 template <typename DescriptorT>
0039 static const DescriptorPool& GetDescriptorPool(const DescriptorT& desc) {
0040 return GetDescriptorPool(*desc.file());
0041 }
0042
0043
0044
0045
0046
0047
0048 template <typename DescriptorT, typename TypeTraitsT, uint8_t field_type,
0049 bool is_packed>
0050 static typename TypeTraitsT::ConstType GetUnresolvedFeatures(
0051 const DescriptorT& descriptor,
0052 const google::protobuf::internal::ExtensionIdentifier<
0053 FeatureSet, TypeTraitsT, field_type, is_packed>& extension) {
0054 return descriptor.proto_features_->GetExtension(extension);
0055 }
0056
0057
0058
0059
0060 static Edition GetEdition(const FileDescriptor& desc) {
0061 return desc.edition();
0062 }
0063
0064 template <typename DescriptorT>
0065 static Edition GetEdition(const DescriptorT& desc) {
0066 return GetEdition(*desc.file());
0067 }
0068
0069
0070
0071 static FeatureSet ParseAndGetEditionResolvedFeatureSet(absl::string_view data,
0072 Edition edition);
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 template <typename DescriptorT, typename ExtType, uint8_t field_type,
0083 bool is_packed>
0084 static auto GetResolvedFeatureExtension(
0085 const DescriptorT& descriptor,
0086 const google::protobuf::internal::ExtensionIdentifier<
0087 FeatureSet, MessageTypeTraits<ExtType>, field_type, is_packed>&
0088 extension) {
0089 auto lang_features = GetFeatures(descriptor).GetExtension(extension);
0090 if (GetDescriptorPool(descriptor).ResolvesFeaturesFor(extension)) {
0091 return lang_features;
0092 }
0093
0094 auto lang_features_ret =
0095 ParseAndGetEditionResolvedFeatureSet(
0096 ::pb::internal::GetFeatureSetDefaultsData<ExtType>(),
0097 GetEdition(descriptor))
0098 .GetExtension(extension);
0099 lang_features_ret.MergeFrom(lang_features);
0100 return lang_features_ret;
0101 }
0102 };
0103 }
0104 }
0105 }
0106
0107 #include "google/protobuf/port_undef.inc"
0108
0109 #endif