| 25 | namespace cel::extensions { |
| 26 | |
| 27 | absl::Status RegisterProtobufEnum( |
| 28 | TypeRegistry& registry, const google::protobuf::EnumDescriptor* enum_descriptor) { |
| 29 | if (registry.resolveable_enums().contains(enum_descriptor->full_name())) { |
| 30 | return absl::AlreadyExistsError( |
| 31 | absl::StrCat(enum_descriptor->full_name(), " already registered.")); |
| 32 | } |
| 33 | |
| 34 | // TODO(uncreated-issue/42): the registry enum implementation runs linear lookups for |
| 35 | // constants since this isn't expected to happen at runtime. Consider updating |
| 36 | // if / when strong enum typing is implemented. |
| 37 | std::vector<TypeRegistry::Enumerator> enumerators; |
| 38 | enumerators.reserve(enum_descriptor->value_count()); |
| 39 | for (int i = 0; i < enum_descriptor->value_count(); i++) { |
| 40 | enumerators.push_back({std::string(enum_descriptor->value(i)->name()), |
| 41 | enum_descriptor->value(i)->number()}); |
| 42 | } |
| 43 | registry.RegisterEnum(enum_descriptor->full_name(), std::move(enumerators)); |
| 44 | |
| 45 | return absl::OkStatus(); |
| 46 | } |
| 47 | |
| 48 | } // namespace cel::extensions |
no test coverage detected