pw-dump: only output [] when something changed

This commit is contained in:
Wim Taymans 2021-01-14 20:17:22 +01:00
parent a97d4c44b4
commit 688b3c5ed4

View file

@ -1265,12 +1265,13 @@ static void dump_objects(struct data *d)
{ NULL, }, { NULL, },
}; };
d->state = STATE_FIRST; d->state = STATE_FIRST;
put_begin(d, NULL, "[", 0);
spa_list_for_each(o, &d->object_list, link) { spa_list_for_each(o, &d->object_list, link) {
if (d->id != SPA_ID_INVALID && d->id != o->id) if (d->id != SPA_ID_INVALID && d->id != o->id)
continue; continue;
if (o->changed == 0) if (o->changed == 0)
continue; continue;
if (d->state == STATE_FIRST)
put_begin(d, NULL, "[", 0);
put_begin(d, NULL, "{", 0); put_begin(d, NULL, "{", 0);
put_int(d, "id", o->id); put_int(d, "id", o->id);
put_value(d, "type", o->type); put_value(d, "type", o->type);
@ -1283,7 +1284,8 @@ static void dump_objects(struct data *d)
put_end(d, "}", 0); put_end(d, "}", 0);
o->changed = 0; o->changed = 0;
} }
put_end(d, "]\n", 0); if (d->state != STATE_FIRST)
put_end(d, "]\n", 0);
} }
static void on_core_error(void *data, uint32_t id, int seq, int res, const char *message) static void on_core_error(void *data, uint32_t id, int seq, int res, const char *message)