+ int ret;
+ int64_t choice_index;
+ struct bt_ctf_field *container;
+ struct bt_field_type_common_variant *var_ft = (void *) ft;
+ struct bt_ctf_field_type *ret_ft = NULL;
+
+ BT_ASSERT_PRE_NON_NULL(ft, "Field type");
+ BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft, BT_FIELD_TYPE_ID_VARIANT,
+ "Field type");
+ BT_ASSERT_PRE_NON_NULL(tag_field, "Tag field");
+ BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(
+ (struct bt_field_common *) tag_field,
+ BT_CTF_FIELD_TYPE_ID_ENUM, "Tag field");
+ BT_ASSERT_PRE_FIELD_COMMON_IS_SET((struct bt_field_common *) tag_field,
+ "Tag field");
+
+ container = bt_ctf_field_enumeration_borrow_container(tag_field);
+ BT_ASSERT(container);
+
+ if (var_ft->tag_ft->container_ft->is_signed) {
+ int64_t val;
+
+ ret = bt_ctf_field_integer_signed_get_value(container,
+ &val);
+ BT_ASSERT(ret == 0);
+ choice_index = bt_field_type_common_variant_find_choice_index(
+ (void *) ft, (uint64_t) val, true);
+ } else {
+ uint64_t val;
+
+ ret = bt_ctf_field_integer_unsigned_get_value(container,
+ &val);
+ BT_ASSERT(ret == 0);
+ choice_index = bt_field_type_common_variant_find_choice_index(
+ (void *) ft, val, false);
+ }
+
+ if (choice_index < 0) {
+ BT_LIB_LOGW("Cannot find variant field type's field: "
+ "%![var-ft-]+wF, %![tag-field-]+wf", ft, tag_field);
+ goto end;
+ }
+
+ ret = bt_ctf_field_type_variant_get_field_by_index(ft, NULL,
+ &ret_ft, choice_index);
+ BT_ASSERT(ret == 0);
+
+end:
+ return ret_ft;