json: Added support for 8 bit unsigned value converter in json
Signed-off-by: Jacek Kalwas <jacek.kalwas@intel.com> Change-Id: Id670be974f5d07f5292d338448cb0ada9510b105 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9787 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
bec627fcb0
commit
a827fd7eec
@ -153,6 +153,7 @@ int spdk_json_decode_array(const struct spdk_json_val *values, spdk_json_decode_
|
||||
void *out, size_t max_size, size_t *out_size, size_t stride);
|
||||
|
||||
int spdk_json_decode_bool(const struct spdk_json_val *val, void *out);
|
||||
int spdk_json_decode_uint8(const struct spdk_json_val *val, void *out);
|
||||
int spdk_json_decode_uint16(const struct spdk_json_val *val, void *out);
|
||||
int spdk_json_decode_int32(const struct spdk_json_val *val, void *out);
|
||||
int spdk_json_decode_uint32(const struct spdk_json_val *val, void *out);
|
||||
@ -191,6 +192,7 @@ bool spdk_json_strequal(const struct spdk_json_val *val, const char *str);
|
||||
*/
|
||||
char *spdk_json_strdup(const struct spdk_json_val *val);
|
||||
|
||||
int spdk_json_number_to_uint8(const struct spdk_json_val *val, uint8_t *num);
|
||||
int spdk_json_number_to_uint16(const struct spdk_json_val *val, uint16_t *num);
|
||||
int spdk_json_number_to_int32(const struct spdk_json_val *val, int32_t *num);
|
||||
int spdk_json_number_to_uint32(const struct spdk_json_val *val, uint32_t *num);
|
||||
|
@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
SO_VER := 3
|
||||
SO_MINOR := 1
|
||||
SO_MINOR := 2
|
||||
|
||||
C_SRCS = json_parse.c json_util.c json_write.c
|
||||
LIBNAME = json
|
||||
|
@ -204,6 +204,28 @@ json_number_split(const struct spdk_json_val *val, struct spdk_json_num *num)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_json_number_to_uint8(const struct spdk_json_val *val, uint8_t *num)
|
||||
{
|
||||
struct spdk_json_num split_num;
|
||||
int rc;
|
||||
|
||||
rc = json_number_split(val, &split_num);
|
||||
if (rc) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (split_num.exponent || split_num.negative) {
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
if (split_num.significand > UINT8_MAX) {
|
||||
return -ERANGE;
|
||||
}
|
||||
*num = (uint8_t)split_num.significand;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_json_number_to_uint16(const struct spdk_json_val *val, uint16_t *num)
|
||||
{
|
||||
@ -448,6 +470,14 @@ spdk_json_decode_bool(const struct spdk_json_val *val, void *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_json_decode_uint8(const struct spdk_json_val *val, void *out)
|
||||
{
|
||||
uint8_t *i = out;
|
||||
|
||||
return spdk_json_number_to_uint8(val, i);
|
||||
}
|
||||
|
||||
int
|
||||
spdk_json_decode_uint16(const struct spdk_json_val *val, void *out)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
spdk_json_decode_object_relaxed;
|
||||
spdk_json_decode_array;
|
||||
spdk_json_decode_bool;
|
||||
spdk_json_decode_uint8;
|
||||
spdk_json_decode_uint16;
|
||||
spdk_json_decode_int32;
|
||||
spdk_json_decode_uint32;
|
||||
@ -19,6 +20,7 @@
|
||||
spdk_json_strequal;
|
||||
spdk_json_strdup;
|
||||
|
||||
spdk_json_number_to_uint8;
|
||||
spdk_json_number_to_uint16;
|
||||
spdk_json_number_to_int32;
|
||||
spdk_json_number_to_uint32;
|
||||
|
Loading…
Reference in New Issue
Block a user