Commit 70f185ea authored by Thanos Makatos's avatar Thanos Makatos Committed by Tomasz Zawadzki
Browse files

json: add spdk_json_write_named_double

parent 4475295e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -60,6 +60,11 @@ It can now be found inside `examples/bdev/bdevperf`.
New API `spdk_fd_group_get_epoll_event` that returns the epoll(7) event that
caused a function callback in file descriptor group to execute.

### json

Added API `spdk_json_write_double` and `spdk_json_write_named_double` to allow
for writing and decoding of the the double data type.

## v22.09

### accel
+3 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ int spdk_json_write_uint32(struct spdk_json_write_ctx *w, uint32_t val);
int spdk_json_write_int64(struct spdk_json_write_ctx *w, int64_t val);
int spdk_json_write_uint64(struct spdk_json_write_ctx *w, uint64_t val);
int spdk_json_write_uint128(struct spdk_json_write_ctx *w, uint64_t low_val, uint64_t high_val);
int spdk_json_write_double(struct spdk_json_write_ctx *w, double val);
int spdk_json_write_string(struct spdk_json_write_ctx *w, const char *val);
int spdk_json_write_string_raw(struct spdk_json_write_ctx *w, const char *val, size_t len);
int spdk_json_write_bytearray(struct spdk_json_write_ctx *w, const void *val, size_t len);
@@ -243,6 +244,8 @@ int spdk_json_write_named_int64(struct spdk_json_write_ctx *w, const char *name,
int spdk_json_write_named_uint64(struct spdk_json_write_ctx *w, const char *name, uint64_t val);
int spdk_json_write_named_uint128(struct spdk_json_write_ctx *w, const char *name,
				  uint64_t low_val, uint64_t high_val);
int spdk_json_write_named_double(struct spdk_json_write_ctx *w, const char *name, double val);

int spdk_json_write_named_string(struct spdk_json_write_ctx *w, const char *name, const char *val);
int spdk_json_write_named_string_fmt(struct spdk_json_write_ctx *w, const char *name,
				     const char *fmt, ...) __attribute__((__format__(__printf__, 3, 4)));
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 4
SO_MINOR := 0
SO_MINOR := 1

C_SRCS = json_parse.c json_util.c json_write.c
LIBNAME = json
+20 −0
Original line number Diff line number Diff line
@@ -309,6 +309,18 @@ spdk_json_write_named_uint128(struct spdk_json_write_ctx *w, const char *name,
	return rc ? rc : spdk_json_write_uint128(w, low_val, high_val);
}

int
spdk_json_write_double(struct spdk_json_write_ctx *w, double val)
{
	char buf[32];
	int count;

	if (begin_value(w)) { return fail(w); }
	count = snprintf(buf, sizeof(buf), "%.20e", val);
	if (count <= 0 || (size_t)count >= sizeof(buf)) { return fail(w); }
	return emit(w, buf, count);
}

static void
write_hex_2(void *dest, uint8_t val)
{
@@ -724,6 +736,14 @@ spdk_json_write_named_uint64(struct spdk_json_write_ctx *w, const char *name, ui
	return rc ? rc : spdk_json_write_uint64(w, val);
}

int
spdk_json_write_named_double(struct spdk_json_write_ctx *w, const char *name, double val)
{
	int rc = spdk_json_write_name(w, name);

	return rc ? rc : spdk_json_write_double(w, val);
}

int
spdk_json_write_named_string(struct spdk_json_write_ctx *w, const char *name, const char *val)
{
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
	spdk_json_write_int64;
	spdk_json_write_uint64;
	spdk_json_write_uint128;
	spdk_json_write_double;
	spdk_json_write_string;
	spdk_json_write_string_raw;
	spdk_json_write_string_utf16le;
@@ -62,6 +63,7 @@
	spdk_json_write_named_int64;
	spdk_json_write_named_uint64;
	spdk_json_write_named_uint128;
	spdk_json_write_named_double;
	spdk_json_write_named_string;
	spdk_json_write_named_string_fmt;
	spdk_json_write_named_string_fmt_v;
Loading