File indexing completed on 2025-01-31 10:12:20
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__
0009 #define GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__
0010
0011 #include <cstddef>
0012 #include <cstdint>
0013 #include <string>
0014 #include <type_traits>
0015 #include <vector>
0016
0017 #include "absl/strings/string_view.h"
0018 #include "absl/types/span.h"
0019 #include "google/protobuf/explicitly_constructed.h"
0020 #include "google/protobuf/message_lite.h"
0021
0022
0023 #include "google/protobuf/port_def.inc"
0024
0025 #ifdef SWIG
0026 #error "You cannot SWIG proto headers"
0027 #endif
0028
0029 namespace google {
0030 namespace protobuf {
0031
0032
0033
0034 template <typename T>
0035 struct is_proto_enum : ::std::false_type {};
0036
0037 namespace internal {
0038
0039
0040
0041
0042 struct EnumEntry {
0043 absl::string_view name;
0044 int value;
0045 };
0046
0047
0048 PROTOBUF_EXPORT bool LookUpEnumValue(const EnumEntry* enums, size_t size,
0049 absl::string_view name, int* value);
0050
0051
0052 PROTOBUF_EXPORT int LookUpEnumName(const EnumEntry* enums,
0053 const int* sorted_indices, size_t size,
0054 int value);
0055
0056
0057 PROTOBUF_EXPORT bool InitializeEnumStrings(
0058 const EnumEntry* enums, const int* sorted_indices, size_t size,
0059 internal::ExplicitlyConstructed<std::string>* enum_strings);
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 PROTOBUF_EXPORT bool ValidateEnum(int value, const uint32_t* data);
0075 PROTOBUF_EXPORT std::vector<uint32_t> GenerateEnumData(
0076 absl::Span<const int32_t> values);
0077
0078 inline PROTOBUF_ALWAYS_INLINE bool ValidateEnumInlined(int value,
0079 const uint32_t* data) {
0080 const int16_t min_seq = static_cast<int16_t>(data[0] & 0xFFFF);
0081 const uint16_t length_seq = static_cast<uint16_t>(data[0] >> 16);
0082 uint64_t adjusted =
0083 static_cast<uint64_t>(static_cast<int64_t>(value)) - min_seq;
0084
0085 if (PROTOBUF_PREDICT_TRUE(adjusted < length_seq)) {
0086 return true;
0087 }
0088
0089 const uint16_t length_bitmap = static_cast<uint16_t>(data[1] & 0xFFFF);
0090 adjusted -= length_seq;
0091
0092 if (PROTOBUF_PREDICT_TRUE(adjusted < length_bitmap)) {
0093 return ((data[2 + (adjusted / 32)] >> (adjusted % 32)) & 1) == 1;
0094 }
0095
0096
0097 const uint16_t num_ordered = static_cast<uint16_t>(data[1] >> 16);
0098 data += 2 + length_bitmap / 32;
0099 size_t pos = 0;
0100 while (pos < num_ordered) {
0101 const int32_t sample = static_cast<int32_t>(data[pos]);
0102 if (sample == value) return true;
0103 pos = 2 * pos + (sample > value ? 1 : 2);
0104 }
0105 return false;
0106 }
0107
0108 }
0109 }
0110 }
0111
0112 #include "google/protobuf/port_undef.inc"
0113
0114 #endif