+14
−0
+1
−3
Loading
Sometimes, it might be useful to decode a JSON array, but store the
result in a single place. For instance, one might want to decode a set
of flags passed as an array of strings and store them in a single
uint64_t, e.g.:
static int
decode_flag(const struct spdk_json_val *val, void *out)
{
uint64_t *flags = out;
char *flag = NULL;
int rc = 0;
spdk_json_decode_string(val, &flag);
if (strcmp(flag, "foo") == 0) {
*flags |= FLAG_FOO;
} else if (strcmp(flag, "bar") == 0) {
*flags |= FLAG_BAR;
} else {
rc = -1;
}
free(flag);
return rc;
}
uint64_t flags = 0;
spdk_json_decode_array(j, decode_flag, &flags, UINT32_MAX, &count, 0);
With this patch, it's possible to do this by passing stride=0 to
spdk_json_decode_array().
Signed-off-by:
Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I27b30dec85d3ccef5df1a307798d79b074768a99
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22020
Tested-by:
SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by:
Jim Harris <jim.harris@samsung.com>
Reviewed-by:
Ben Walker <ben@nvidia.com>
Community-CI: Mellanox Build Bot