json: add printf-style spdk_json_write_string_fmt()
Change-Id: I9ea18072d4e54344f145a0b2d16aa6ab7f4d5e03 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
022b8a6df4
commit
1cb7e396a7
@ -200,6 +200,8 @@ 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_uint64(struct spdk_json_write_ctx *w, uint64_t val);
|
||||||
int spdk_json_write_string(struct spdk_json_write_ctx *w, const char *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_string_raw(struct spdk_json_write_ctx *w, const char *val, size_t len);
|
||||||
|
int spdk_json_write_string_fmt(struct spdk_json_write_ctx *w, const char *fmt,
|
||||||
|
...) __attribute__((__format__(__printf__, 2, 3)));
|
||||||
int spdk_json_write_array_begin(struct spdk_json_write_ctx *w);
|
int spdk_json_write_array_begin(struct spdk_json_write_ctx *w);
|
||||||
int spdk_json_write_array_end(struct spdk_json_write_ctx *w);
|
int spdk_json_write_array_end(struct spdk_json_write_ctx *w);
|
||||||
int spdk_json_write_object_begin(struct spdk_json_write_ctx *w);
|
int spdk_json_write_object_begin(struct spdk_json_write_ctx *w);
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include "spdk/json.h"
|
#include "spdk/json.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -46,6 +47,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "spdk/string.h"
|
||||||
|
|
||||||
#define SPDK_JSON_MAX_NESTING_DEPTH 64
|
#define SPDK_JSON_MAX_NESTING_DEPTH 64
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
|
@ -317,6 +317,26 @@ spdk_json_write_string(struct spdk_json_write_ctx *w, const char *val)
|
|||||||
return spdk_json_write_string_raw(w, val, strlen(val));
|
return spdk_json_write_string_raw(w, val, strlen(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
spdk_json_write_string_fmt(struct spdk_json_write_ctx *w, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
va_list args;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
s = spdk_vsprintf_alloc(fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (s == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = spdk_json_write_string(w, s);
|
||||||
|
free(s);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
spdk_json_write_array_begin(struct spdk_json_write_ctx *w)
|
spdk_json_write_array_begin(struct spdk_json_write_ctx *w)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
|
|||||||
JSON_DIR := $(SPDK_ROOT_DIR)/lib/json
|
JSON_DIR := $(SPDK_ROOT_DIR)/lib/json
|
||||||
JSONRPC_DIR := $(SPDK_ROOT_DIR)/lib/jsonrpc
|
JSONRPC_DIR := $(SPDK_ROOT_DIR)/lib/jsonrpc
|
||||||
|
|
||||||
SPDK_LIB_LIST = json log
|
SPDK_LIB_LIST = json util log
|
||||||
|
|
||||||
C_SRCS = $(TEST_FILE) $(OTHER_FILES)
|
C_SRCS = $(TEST_FILE) $(OTHER_FILES)
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ APP = jsoncat
|
|||||||
|
|
||||||
C_SRCS = jsoncat.c
|
C_SRCS = jsoncat.c
|
||||||
|
|
||||||
SPDK_LIB_LIST = json
|
SPDK_LIB_LIST = json util
|
||||||
|
|
||||||
LIBS += $(SPDK_LIB_LINKER_ARGS)
|
LIBS += $(SPDK_LIB_LINKER_ARGS)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user