pw-cli: add support for creating Struct in pod

Support creating Struct as well. When an object property is marked as
Struct, use [] to start the struct and copy each item with its type into
the struct:

pw-cli s 0 Route '{ info = [ "foo": 0.1  "bar": null [ 0.1 10 "hat" ]] }'
This commit is contained in:
Wim Taymans 2021-04-30 17:18:56 +02:00
parent ca72738fee
commit 7145b2becf

View file

@ -1563,10 +1563,15 @@ static int json_to_pod(struct spa_pod_builder *b, uint32_t id,
spa_pod_builder_pop(b, &f[0]);
}
else if (spa_json_is_array(value, len) && info != NULL) {
spa_pod_builder_push_array(b, &f[0]);
if (info->parent == SPA_TYPE_Struct) {
spa_pod_builder_push_struct(b, &f[0]);
} else {
spa_pod_builder_push_array(b, &f[0]);
info = info->values;
}
spa_json_enter(iter, &it[0]);
while ((l = spa_json_next(&it[0], &v)) > 0)
if ((res = json_to_pod(b, id, info->values, &it[0], v, l)) < 0)
if ((res = json_to_pod(b, id, info, &it[0], v, l)) < 0)
return res;
spa_pod_builder_pop(b, &f[0]);
}
@ -1586,6 +1591,12 @@ static int json_to_pod(struct spa_pod_builder *b, uint32_t id,
case SPA_TYPE_Long:
spa_pod_builder_long(b, val);
break;
case SPA_TYPE_Struct:
if (spa_json_is_int(value, len))
spa_pod_builder_int(b, val);
else
spa_pod_builder_float(b, val);
break;
case SPA_TYPE_Float:
spa_pod_builder_float(b, val);
break;
@ -1614,6 +1625,7 @@ static int json_to_pod(struct spa_pod_builder *b, uint32_t id,
return -EINVAL;
spa_pod_builder_id(b, ti->type);
break;
case SPA_TYPE_Struct:
case SPA_TYPE_String:
spa_pod_builder_string(b, val);
break;