From a65d566dee9b4a82dff0969d9e6e7cd91e11183d Mon Sep 17 00:00:00 2001 From: Jeff Kent Date: Mon, 28 Dec 2015 09:45:29 -0600 Subject: [PATCH] jsontree: add int pointer types --- apps/json/json.h | 8 ++++++++ apps/json/jsontree.c | 24 ++++++++++++++++++++++++ apps/json/jsontree.h | 5 +++++ 3 files changed, 37 insertions(+) diff --git a/apps/json/json.h b/apps/json/json.h index d91cf93ef..51ef652f8 100644 --- a/apps/json/json.h +++ b/apps/json/json.h @@ -57,6 +57,14 @@ #define JSON_TYPE_CALLBACK 'C' +/* integer pointer types */ +#define JSON_TYPE_S8PTR 'b' +#define JSON_TYPE_U8PTR 'B' +#define JSON_TYPE_S16PTR 'w' +#define JSON_TYPE_U16PTR 'W' +#define JSON_TYPE_S32PTR 'd' +#define JSON_TYPE_U32PTR 'D' + enum { JSON_ERROR_OK, JSON_ERROR_SYNTAX, diff --git a/apps/json/jsontree.c b/apps/json/jsontree.c index 4ffe68161..13d7d8604 100644 --- a/apps/json/jsontree.c +++ b/apps/json/jsontree.c @@ -234,6 +234,30 @@ jsontree_print_next(struct jsontree_context *js_ctx) } /* Default operation: back up one level! */ break; + case JSON_TYPE_S8PTR: + jsontree_write_int(js_ctx, *((int8_t *)((struct jsontree_ptr *)v)->value)); + /* Default operation: back up one level! */ + break; + case JSON_TYPE_U8PTR: + jsontree_write_uint(js_ctx, *((uint8_t *)((struct jsontree_ptr *)v)->value)); + /* Default operation: back up one level! */ + break; + case JSON_TYPE_S16PTR: + jsontree_write_int(js_ctx, *((int16_t *)((struct jsontree_ptr *)v)->value)); + /* Default operation: back up one level! */ + break; + case JSON_TYPE_U16PTR: + jsontree_write_uint(js_ctx, *((uint16_t *)((struct jsontree_ptr *)v)->value)); + /* Default operation: back up one level! */ + break; + case JSON_TYPE_S32PTR: + jsontree_write_int(js_ctx, *((int32_t *)((struct jsontree_ptr *)v)->value)); + /* Default operation: back up one level! */ + break; + case JSON_TYPE_U32PTR: + jsontree_write_uint(js_ctx, *((uint32_t *)((struct jsontree_ptr *)v)->value)); + /* Default operation: back up one level! */ + break; } default: PRINTF("\nError: Illegal json type:'%c'\n", v->type); diff --git a/apps/json/jsontree.h b/apps/json/jsontree.h index 3434565a2..a6c349d80 100644 --- a/apps/json/jsontree.h +++ b/apps/json/jsontree.h @@ -109,6 +109,11 @@ struct jsontree_array { struct jsontree_value **values; }; +struct jsontree_ptr { + uint8_t type; + const void *value; +}; + #define JSONTREE_STRING(text) {JSON_TYPE_STRING, (text)} #define JSONTREE_PAIR(name, value) {(name), (struct jsontree_value *)(value)} #define JSONTREE_CALLBACK(output, set) {JSON_TYPE_CALLBACK, (output), (set)}