diff --git a/apps/json/json.h b/apps/json/json.h index a698464a5..d91cf93ef 100644 --- a/apps/json/json.h +++ b/apps/json/json.h @@ -45,6 +45,7 @@ #define JSON_TYPE_PAIR ':' #define JSON_TYPE_PAIR_NAME 'N' /* for N:V pairs */ #define JSON_TYPE_STRING '"' +#define JSON_TYPE_UINT 'U' #define JSON_TYPE_INT 'I' #define JSON_TYPE_NUMBER '0' #define JSON_TYPE_ERROR 0 diff --git a/apps/json/jsontree.c b/apps/json/jsontree.c index e397ae47b..4ffe68161 100644 --- a/apps/json/jsontree.c +++ b/apps/json/jsontree.c @@ -79,16 +79,11 @@ jsontree_write_string(const struct jsontree_context *js_ctx, const char *text) } /*---------------------------------------------------------------------------*/ void -jsontree_write_int(const struct jsontree_context *js_ctx, int value) +jsontree_write_uint(const struct jsontree_context *js_ctx, unsigned int value) { char buf[10]; int l; - if(value < 0) { - js_ctx->putchar('-'); - value = -value; - } - l = sizeof(buf) - 1; do { buf[l--] = '0' + (value % 10); @@ -101,6 +96,17 @@ jsontree_write_int(const struct jsontree_context *js_ctx, int value) } /*---------------------------------------------------------------------------*/ void +jsontree_write_int(const struct jsontree_context *js_ctx, int value) +{ + if(value < 0) { + js_ctx->putchar('-'); + value = -value; + } + + jsontree_write_uint(js_ctx, value); +} +/*---------------------------------------------------------------------------*/ +void jsontree_setup(struct jsontree_context *js_ctx, struct jsontree_value *root, int (* putchar)(int)) { @@ -203,6 +209,10 @@ jsontree_print_next(struct jsontree_context *js_ctx) jsontree_write_string(js_ctx, ((struct jsontree_string *)v)->value); /* Default operation: back up one level! */ break; + case JSON_TYPE_UINT: + jsontree_write_uint(js_ctx, ((struct jsontree_uint *)v)->value); + /* Default operation: back up one level! */ + break; case JSON_TYPE_INT: jsontree_write_int(js_ctx, ((struct jsontree_int *)v)->value); /* Default operation: back up one level! */ diff --git a/apps/json/jsontree.h b/apps/json/jsontree.h index b378d36b5..3434565a2 100644 --- a/apps/json/jsontree.h +++ b/apps/json/jsontree.h @@ -74,6 +74,11 @@ struct jsontree_string { const char *value; }; +struct jsontree_uint { + uint8_t type; + unsigned int value; +}; + struct jsontree_int { uint8_t type; int value; @@ -136,6 +141,8 @@ void jsontree_reset(struct jsontree_context *js_ctx); const char *jsontree_path_name(const struct jsontree_context *js_ctx, int depth); +void jsontree_write_uint(const struct jsontree_context *js_ctx, + unsigned int value); void jsontree_write_int(const struct jsontree_context *js_ctx, int value); void jsontree_write_atom(const struct jsontree_context *js_ctx, const char *text);