mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
spa: add spa_json_begin_array/object and relaxed versions
Add spa_json_begin_array/object to replace spa_json_init+spa_json_begin_array/object This function is better because it does not waste a useless spa_json structure as an iterator. The relaxed versions also error out when the container is mismatched because parsing a mismatched container is not going to give any results anyway.
This commit is contained in:
parent
feccb882b6
commit
cd81b5f39a
51 changed files with 401 additions and 452 deletions
|
|
@ -283,20 +283,19 @@ static int do_help(struct adp *adp, const char *args, FILE *out)
|
|||
|
||||
static int do_discover(struct adp *adp, const char *args, FILE *out)
|
||||
{
|
||||
struct spa_json it[2];
|
||||
struct spa_json it[1];
|
||||
char key[128];
|
||||
uint64_t entity_id = 0ULL;
|
||||
|
||||
spa_json_init(&it[0], args, strlen(args));
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_object(&it[0], args, strlen(args)) <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[0], key, sizeof(key)) > 0) {
|
||||
int len;
|
||||
const char *value;
|
||||
uint64_t id_val;
|
||||
|
||||
if ((len = spa_json_next(&it[1], &value)) <= 0)
|
||||
if ((len = spa_json_next(&it[0], &value)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_json_is_null(value, len))
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ static int load_state(struct maap *maap)
|
|||
{
|
||||
const char *str;
|
||||
char key[512];
|
||||
struct spa_json it[3];
|
||||
struct spa_json it[2];
|
||||
bool have_offset = false;
|
||||
int count = 0, offset = 0;
|
||||
|
||||
|
|
@ -263,18 +263,17 @@ static int load_state(struct maap *maap)
|
|||
if ((str = pw_properties_get(maap->props, "maap.addresses")) == NULL)
|
||||
return 0;
|
||||
|
||||
spa_json_init(&it[0], str, strlen(str));
|
||||
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
|
||||
if (spa_json_begin_array(&it[0], str, strlen(str)) <= 0)
|
||||
return 0;
|
||||
|
||||
if (spa_json_enter_object(&it[1], &it[2]) <= 0)
|
||||
if (spa_json_enter_object(&it[0], &it[1]) <= 0)
|
||||
return 0;
|
||||
|
||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
||||
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
|
||||
const char *val;
|
||||
int len;
|
||||
|
||||
if ((len = spa_json_next(&it[2], &val)) <= 0)
|
||||
if ((len = spa_json_next(&it[1], &val)) <= 0)
|
||||
break;
|
||||
|
||||
if (spa_streq(key, "start")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue