+template <class VariantSelectorMappingIntegerType>
+typename lst::variant_type<VariantSelectorMappingIntegerType>::choices create_typed_variant_choices(
+ const lttng_ust_ctl_field *current,
+ const lttng_ust_ctl_field *end,
+ const session_attributes& session_attributes,
+ const lttng_ust_ctl_field **next_ust_ctl_field,
+ lookup_field_fn lookup_field,
+ lst::field_location::root lookup_root,
+ lst::field_location::elements& current_field_location_elements,
+ unsigned int choice_count,
+ const lst::field& selector_field,
+ lsu::ctl_field_quirks quirks)
+{
+ typename lst::variant_type<VariantSelectorMappingIntegerType>::choices choices;
+ const auto& typed_enumeration = static_cast<
+ const lst::typed_enumeration_type<VariantSelectorMappingIntegerType>&>(
+ selector_field.get_type());
+
+ for (unsigned int i = 0; i < choice_count; i++) {
+ create_field_from_ust_ctl_fields(
+ current, end, session_attributes, next_ust_ctl_field,
+ [&choices, typed_enumeration, &selector_field, quirks](
+ lst::field::uptr field) {
+ /*
+ * Find the enumeration mapping that matches the
+ * field's name.
+ */
+ const auto mapping_it = std::find_if(
+ typed_enumeration.mappings_->begin(),
+ typed_enumeration.mappings_->end(),
+ [&field, quirks](const typename std::remove_reference<
+ decltype(typed_enumeration)>::type::
+ mapping& mapping) {
+ if (static_cast<bool>(quirks & lsu::ctl_field_quirks::UNDERSCORE_PREFIXED_VARIANT_TAG_MAPPINGS)) {
+ /*
+ * Check if they match with
+ * a prepended underscore
+ * and, if not, perform the
+ * regular check.
+ */
+ if ((std::string("_") + field->name) == mapping.name) {
+ return true;
+ }
+ }
+
+ return mapping.name == field->name;
+ });
+
+ if (mapping_it == typed_enumeration.mappings_->end()) {
+ LTTNG_THROW_PROTOCOL_ERROR(fmt::format(
+ "Invalid variant choice: `{}` does not match any mapping in `{}` enumeration",
+ field->name, selector_field.name));
+ }
+
+ choices.emplace_back(*mapping_it, field->move_type());
+ },
+ lookup_field, lookup_root, current_field_location_elements, quirks);
+
+ current = *next_ust_ctl_field;
+ }
+
+ return choices;
+}
+