+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)
+{
+ 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](
+ 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](const typename std::remove_reference<
+ decltype(typed_enumeration)>::type::
+ mapping& mapping) {
+ 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);
+
+ current = *next_ust_ctl_field;
+ }
+
+ return choices;
+}
+