mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -05:00
properties: improve containter serialize
If we are not recursing, take the complete property value without attempting to parse it as json, only do this when recursing. If the property value looks like a container is is exactly of the right length, print is as a container, otherwise print is as string. This makes properties like "[192.0.0.1]:45000" be printed as a string instead of the array [192.0.0.1]. but still makes "[FL FR]" be an array. Fixes #3290
This commit is contained in:
parent
7c7e814b02
commit
81fd6d5275
1 changed files with 6 additions and 7 deletions
|
|
@ -706,8 +706,11 @@ static int dump(struct dump_config *c, int indent, struct spa_json *it, const ch
|
||||||
if (value == NULL || len == 0) {
|
if (value == NULL || len == 0) {
|
||||||
fprintf(file, "%snull%s", LITERAL(c), NORMAL(c));
|
fprintf(file, "%snull%s", LITERAL(c), NORMAL(c));
|
||||||
} else if (spa_json_is_container(value, len) && !c->recurse) {
|
} else if (spa_json_is_container(value, len) && !c->recurse) {
|
||||||
len = spa_json_container_len(it, value, len);
|
spa_json_enter_container(it, &sub, value[0]);
|
||||||
fprintf(file, "%s%.*s%s", CONTAINER(c), len, value, NORMAL(c));
|
if (spa_json_container_len(&sub, value, len) == len)
|
||||||
|
fprintf(file, "%s%.*s%s", CONTAINER(c), len, value, NORMAL(c));
|
||||||
|
else
|
||||||
|
encode_string(c, STRING(c), value, len, NORMAL(c));
|
||||||
} else if (spa_json_is_array(value, len)) {
|
} else if (spa_json_is_array(value, len)) {
|
||||||
fprintf(file, "[");
|
fprintf(file, "[");
|
||||||
spa_json_enter(it, &sub);
|
spa_json_enter(it, &sub);
|
||||||
|
|
@ -782,15 +785,11 @@ int pw_properties_serialize_dict(FILE *f, const struct spa_dict *dict, uint32_t
|
||||||
fprintf(f, "%s%s%s: ", KEY(c), key, NORMAL(c));
|
fprintf(f, "%s%s%s: ", KEY(c), key, NORMAL(c));
|
||||||
}
|
}
|
||||||
value = it->value;
|
value = it->value;
|
||||||
|
|
||||||
len = value ? strlen(value) : 0;
|
len = value ? strlen(value) : 0;
|
||||||
spa_json_init(&sub, value, len);
|
spa_json_init(&sub, value, len);
|
||||||
if ((len = spa_json_next(&sub, &value)) < 0)
|
if (c->recurse && spa_json_next(&sub, &value) < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!spa_json_is_container(value, len))
|
|
||||||
len = value ? strlen(value) : 0;
|
|
||||||
|
|
||||||
dump(c, c->indent, &sub, value, len);
|
dump(c, c->indent, &sub, value, len);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue