+static
+int bt_ctf_field_generic_reset(struct bt_ctf_field *field)
+{
+ int ret = 0;
+
+ if (!field) {
+ ret = -1;
+ goto end;
+ }
+
+ field->payload_set = 0;
+end:
+ return ret;
+}
+
+static
+int bt_ctf_field_enumeration_reset(struct bt_ctf_field *field)
+{
+ int ret = 0;
+ struct bt_ctf_field_enumeration *enumeration;
+
+ if (!field) {
+ ret = -1;
+ goto end;
+ }
+
+ enumeration = container_of(field, struct bt_ctf_field_enumeration,
+ parent);
+ if (!enumeration->payload) {
+ goto end;
+ }
+
+ ret = bt_ctf_field_reset(enumeration->payload);
+end:
+ return ret;
+}
+
+static
+int bt_ctf_field_structure_reset(struct bt_ctf_field *field)
+{
+ size_t i;
+ int ret = 0;
+ struct bt_ctf_field_structure *structure;
+
+ if (!field) {
+ ret = -1;
+ goto end;
+ }
+
+ structure = container_of(field, struct bt_ctf_field_structure, parent);
+ for (i = 0; i < structure->fields->len; i++) {
+ struct bt_ctf_field *member = structure->fields->pdata[i];
+
+ if (!member) {
+ /*
+ * Structure members are lazily initialized; skip if
+ * this member has not been allocated yet.
+ */
+ continue;
+ }
+
+ ret = bt_ctf_field_reset(member);
+ if (ret) {
+ goto end;
+ }
+ }
+end:
+ return ret;
+}
+
+static
+int bt_ctf_field_variant_reset(struct bt_ctf_field *field)
+{
+ int ret = 0;
+ struct bt_ctf_field_variant *variant;
+
+ if (!field) {
+ ret = -1;
+ goto end;
+ }
+
+ variant = container_of(field, struct bt_ctf_field_variant, parent);
+ if (variant->payload) {
+ ret = bt_ctf_field_reset(variant->payload);
+ }
+end:
+ return ret;
+}
+
+static
+int bt_ctf_field_array_reset(struct bt_ctf_field *field)
+{
+ size_t i;
+ int ret = 0;
+ struct bt_ctf_field_array *array;
+
+ if (!field) {
+ ret = -1;
+ goto end;
+ }
+
+ array = container_of(field, struct bt_ctf_field_array, parent);
+ for (i = 0; i < array->elements->len; i++) {
+ struct bt_ctf_field *member = array->elements->pdata[i];
+
+ if (!member) {
+ /*
+ * Array elements are lazily initialized; skip if
+ * this member has not been allocated yet.
+ */
+ continue;
+ }
+
+ ret = bt_ctf_field_reset(member);
+ if (ret) {
+ goto end;
+ }
+ }
+end:
+ return ret;
+}
+
+static
+int bt_ctf_field_sequence_reset(struct bt_ctf_field *field)
+{
+ size_t i;
+ int ret = 0;
+ struct bt_ctf_field_sequence *sequence;
+
+ if (!field) {
+ ret = -1;
+ goto end;
+ }
+
+ sequence = container_of(field, struct bt_ctf_field_sequence, parent);
+ for (i = 0; i < sequence->elements->len; i++) {
+ struct bt_ctf_field *member = sequence->elements->pdata[i];
+
+ if (!member) {
+ /*
+ * Sequence elements are lazily initialized; skip if
+ * this member has not been allocated yet.
+ */
+ continue;
+ }
+
+ ret = bt_ctf_field_reset(member);
+ if (ret) {
+ goto end;
+ }
+ }
+end:
+ return ret;
+}
+
+static
+int bt_ctf_field_string_reset(struct bt_ctf_field *field)
+{
+ int ret = 0;
+ struct bt_ctf_field_string *string;
+
+ if (!field) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = bt_ctf_field_generic_reset(field);
+ if (ret) {
+ goto end;
+ }
+
+ string = container_of(field, struct bt_ctf_field_string, parent);
+ if (string->payload) {
+ g_string_truncate(string->payload, 0);
+ }
+end:
+ return ret;
+}
+