json: new relaxed decode object function
With new funtion it is allowed to successfully parse json values even if doceder for given key is not found. Signed-off-by: Jacek Kalwas <jacek.kalwas@intel.com> Change-Id: I036f263e9050bd2b96aaa3ff61a9542c98365892 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4340 Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
de016f2756
commit
90472b8663
@ -144,6 +144,8 @@ struct spdk_json_object_decoder {
|
|||||||
|
|
||||||
int spdk_json_decode_object(const struct spdk_json_val *values,
|
int spdk_json_decode_object(const struct spdk_json_val *values,
|
||||||
const struct spdk_json_object_decoder *decoders, size_t num_decoders, void *out);
|
const struct spdk_json_object_decoder *decoders, size_t num_decoders, void *out);
|
||||||
|
int spdk_json_decode_object_relaxed(const struct spdk_json_val *values,
|
||||||
|
const struct spdk_json_object_decoder *decoders, size_t num_decoders, void *out);
|
||||||
int spdk_json_decode_array(const struct spdk_json_val *values, spdk_json_decode_fn decode_func,
|
int spdk_json_decode_array(const struct spdk_json_val *values, spdk_json_decode_fn decode_func,
|
||||||
void *out, size_t max_size, size_t *out_size, size_t stride);
|
void *out, size_t max_size, size_t *out_size, size_t stride);
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
|||||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||||
|
|
||||||
SO_VER := 2
|
SO_VER := 2
|
||||||
SO_MINOR := 0
|
SO_MINOR := 1
|
||||||
|
|
||||||
C_SRCS = json_parse.c json_util.c json_write.c
|
C_SRCS = json_parse.c json_util.c json_write.c
|
||||||
LIBNAME = json
|
LIBNAME = json
|
||||||
|
@ -298,9 +298,9 @@ spdk_json_number_to_uint64(const struct spdk_json_val *val, uint64_t *num)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
spdk_json_decode_object(const struct spdk_json_val *values,
|
_json_decode_object(const struct spdk_json_val *values,
|
||||||
const struct spdk_json_object_decoder *decoders, size_t num_decoders, void *out)
|
const struct spdk_json_object_decoder *decoders, size_t num_decoders, void *out, bool relaxed)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
bool invalid = false;
|
bool invalid = false;
|
||||||
@ -344,7 +344,7 @@ spdk_json_decode_object(const struct spdk_json_val *values,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!relaxed && !found) {
|
||||||
invalid = true;
|
invalid = true;
|
||||||
SPDK_JSON_DEBUG("Decoder not found for key '%.*s'\n", name->len, (char *)name->start);
|
SPDK_JSON_DEBUG("Decoder not found for key '%.*s'\n", name->len, (char *)name->start);
|
||||||
}
|
}
|
||||||
@ -364,6 +364,20 @@ spdk_json_decode_object(const struct spdk_json_val *values,
|
|||||||
return invalid ? -1 : 0;
|
return invalid ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
spdk_json_decode_object(const struct spdk_json_val *values,
|
||||||
|
const struct spdk_json_object_decoder *decoders, size_t num_decoders, void *out)
|
||||||
|
{
|
||||||
|
return _json_decode_object(values, decoders, num_decoders, out, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
spdk_json_decode_object_relaxed(const struct spdk_json_val *values,
|
||||||
|
const struct spdk_json_object_decoder *decoders, size_t num_decoders, void *out)
|
||||||
|
{
|
||||||
|
return _json_decode_object(values, decoders, num_decoders, out, true);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
spdk_json_decode_array(const struct spdk_json_val *values, spdk_json_decode_fn decode_func,
|
spdk_json_decode_array(const struct spdk_json_val *values, spdk_json_decode_fn decode_func,
|
||||||
void *out, size_t max_size, size_t *out_size, size_t stride)
|
void *out, size_t max_size, size_t *out_size, size_t stride)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
# public functions
|
# public functions
|
||||||
spdk_json_parse;
|
spdk_json_parse;
|
||||||
spdk_json_decode_object;
|
spdk_json_decode_object;
|
||||||
|
spdk_json_decode_object_relaxed;
|
||||||
spdk_json_decode_array;
|
spdk_json_decode_array;
|
||||||
spdk_json_decode_bool;
|
spdk_json_decode_bool;
|
||||||
spdk_json_decode_uint16;
|
spdk_json_decode_uint16;
|
||||||
|
Loading…
Reference in New Issue
Block a user