spa: add spa_json_object_next

This gets the next key and value from an object. This function is better
because it will skip key/value pairs that don't fit in the array to hold
the key.

The previous code patter would stop parsing the object as soon as a key
larger than the available space was found.
This commit is contained in:
Wim Taymans 2024-09-13 16:26:36 +02:00
parent cd81b5f39a
commit ce390d5b22
24 changed files with 171 additions and 269 deletions

View file

@ -82,14 +82,12 @@ static int dump(FILE *file, int indent, struct spa_json *it, const char *value,
spa_json_enter(it, &sub);
else
sub = *it;
while (spa_json_get_string(&sub, key, sizeof(key)) > 0) {
while ((len = spa_json_object_next(&sub, key, sizeof(key), &value)) > 0) {
fprintf(file, "%s\n%*s",
count++ > 0 ? "," : "",
indent+2, "");
encode_string(file, key, strlen(key));
fprintf(file, ": ");
if ((len = spa_json_next(&sub, &value)) <= 0)
break;
res = dump(file, indent+2, &sub, value, len);
if (res < 0) {
if (toplevel)