void lcbvrow_free(lcbvrow_PARSER *ctx) { jsonsl_jpr_match_state_cleanup(ctx->jsn); jsonsl_destroy(ctx->jsn); jsonsl_destroy(ctx->jsn_rdetails); jsonsl_jpr_destroy(ctx->jpr); lcb_string_release(&ctx->current_buf); lcb_string_release(&ctx->meta_buf); lcb_string_release(&ctx->last_hk); free(ctx); }
bool Parser::parseFile(const string &filename) { FILE *f = fopen(filename.c_str(), "rt"); if (!f) return false; jsonsl_t jsn = jsonsl_new(0x1000); jsonsl_enable_all_callbacks(jsn); jsn->action_callback = jsonslAction; jsn->error_callback = jsonslError; Parser parser; jsn->data = &parser; const size_t bufferSize = 4096; char buffer[bufferSize]; for (;;) { size_t n = fread(buffer,1,bufferSize,f); jsonsl_feed(jsn, buffer, n); if (n<bufferSize) break; } jsonsl_destroy(jsn); fclose(f); return true; }
bson_t * sepia_read_json(struct sepia_request * request, int * error) { jsonsl_t parser = jsonsl_new(MAX_NESTING_LEVEL); jsonsl_enable_all_callbacks(parser); parser->action_callback = on_stack_change; parser->error_callback = on_error; char * buffer = GC_MALLOC(BUFFER_SIZE); struct bson_state state; state.cur_entry = -1; state.error = JSONSL_ERROR_SUCCESS; state.entry[0].bson = NULL; state.text = buffer; parser->data = &state; int read; do { read = sepia_read_data(request, buffer, BUFFER_SIZE); jsonsl_feed(parser, buffer, read); } while (read > 0); if (error != NULL) { * error = state.error; } jsonsl_destroy(parser); return (state.cur_entry == -1 && state.error == JSONSL_ERROR_SUCCESS) ? state.entry[0].bson : NULL; }
void lcbex_vrow_free(lcbex_vrow_ctx_t *ctx) { jsonsl_jpr_match_state_cleanup(ctx->jsn); jsonsl_destroy(ctx->jsn); jsonsl_jpr_destroy(ctx->jpr); buffer_reset(&ctx->current_buf, 1); buffer_reset(&ctx->meta_buf, 1); buffer_reset(&ctx->last_hk, 1); free(ctx); }
bool Parser::parseString(const char *json) { jsonsl_t jsn = jsonsl_new(0x1000); jsonsl_enable_all_callbacks(jsn); jsn->action_callback = jsonslAction; jsn->error_callback = jsonslError; Parser parser; jsn->data = &parser; jsonsl_feed(jsn, json, strlen(json)); jsonsl_destroy(jsn); return true; }