jsontree: add int pointer types

This commit is contained in:
Jeff Kent 2015-12-28 09:45:29 -06:00
parent bcc7d0a1eb
commit a65d566dee
3 changed files with 37 additions and 0 deletions

View file

@ -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,

View file

@ -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);

View file

@ -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)}