/*---------------------------------------------------------------------------*/ void jsontree_setup(struct jsontree_context *js_ctx, struct jsontree_value *root, int (* putchar)(int)) { js_ctx->values[0] = root; js_ctx->putchar = putchar; js_ctx->path = 0; jsontree_reset(js_ctx); }
int ICACHE_FLASH_ATTR pando_json_print(struct jsontree_value * json_value, char * dst, int len) { if( dst == NULL) { return -1; } json_buf = dst; json_buf_len = len; pos = 0; struct jsontree_context js_ctx; js_ctx.values[0] = json_value; jsontree_reset(&js_ctx); js_ctx.putchar = json_putchar; while (jsontree_print_next(&js_ctx)); json_buf[pos] = 0; return pos; }
/****************************************************************************** * FunctionName : json_ws_send * Description : set up the JSON format tree for string * Parameters : tree -- A pointer to the JSON format tree * path -- A pointer to the JSON format tree's path * pbuf -- A pointer for the data sent * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR json_ws_send(struct jsontree_value *tree, const char *path, char *pbuf) { struct jsontree_context json; /* maxsize = 128 bytes */ json_buf = (char *)os_malloc(jsonSize); /* reset state and set max-size */ /* NOTE: packet will be truncated at 512 bytes */ pos = 0; size = jsonSize; json.values[0] = (struct jsontree_value *)tree; // jsontree_reset(&json); find_json_path(&json, path); json.path = json.depth; json.putchar = json_putchar; while (jsontree_print_next(&json) && json.path <= json.depth); json_buf[pos] = 0; os_memcpy(pbuf, json_buf, pos); os_free(json_buf); }