+ case lttng_ust_string_encoding_UTF8:
+ *ue = ustctl_encode_UTF8;
+ break;
+ case lttng_ust_string_encoding_ASCII:
+ *ue = ustctl_encode_ASCII;
+ break;
+ default:
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static
+int serialize_integer_type(struct ustctl_integer_type *uit,
+ const struct lttng_ust_type_integer *lit,
+ enum lttng_ust_string_encoding lencoding)
+{
+ int32_t encoding;
+
+ uit->size = lit->size;
+ uit->signedness = lit->signedness;
+ uit->reverse_byte_order = lit->reverse_byte_order;
+ uit->base = lit->base;
+ if (serialize_string_encoding(&encoding, lencoding))
+ return -EINVAL;
+ uit->encoding = encoding;
+ uit->alignment = lit->alignment;
+ return 0;
+}
+
+static
+int serialize_dynamic_type(struct lttng_ust_session *session,
+ struct ustctl_field *fields, size_t *iter_output,
+ const char *field_name)
+{
+ struct lttng_ust_event_field **choices;
+ char tag_field_name[LTTNG_UST_ABI_SYM_NAME_LEN];
+ struct lttng_ust_type_common *tag_type;
+ struct lttng_ust_event_field *tag_field_generic;
+ struct lttng_ust_event_field tag_field = {
+ .name = tag_field_name,
+ .nowrite = 0,
+ };
+ struct ustctl_field *uf;
+ size_t nr_choices, i;
+ int ret;
+
+ tag_field_generic = lttng_ust_dynamic_type_tag_field();
+ tag_type = tag_field_generic->type;
+
+ /* Serialize enum field. */
+ strncpy(tag_field_name, field_name, LTTNG_UST_ABI_SYM_NAME_LEN);
+ tag_field_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0';
+ strncat(tag_field_name,
+ "_tag",
+ LTTNG_UST_ABI_SYM_NAME_LEN - strlen(tag_field_name) - 1);
+ tag_field.type = tag_type;
+ ret = serialize_one_field(session, fields, iter_output,
+ &tag_field);
+ if (ret)
+ return ret;
+
+ /* Serialize variant field. */
+ uf = &fields[*iter_output];
+ ret = lttng_ust_dynamic_type_choices(&nr_choices, &choices);
+ if (ret)
+ return ret;
+
+ strncpy(uf->name, field_name, LTTNG_UST_ABI_SYM_NAME_LEN);
+ uf->name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0';
+ uf->type.atype = ustctl_atype_variant;
+ uf->type.u.variant_nestable.nr_choices = nr_choices;
+ strncpy(uf->type.u.variant_nestable.tag_name,
+ tag_field_name,
+ LTTNG_UST_ABI_SYM_NAME_LEN);
+ uf->type.u.variant_nestable.tag_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0';
+ uf->type.u.variant_nestable.alignment = 0;
+ (*iter_output)++;
+
+ /* Serialize choice fields after variant. */
+ for (i = 0; i < nr_choices; i++) {
+ ret = serialize_one_field(session, fields,
+ iter_output, choices[i]);
+ if (ret)
+ return ret;