static void feed_data(lcbex_vrow_ctx_t *ctx, const char *data, size_t ndata) { size_t old_len = ctx->current_buf.len; buffer_append(&ctx->current_buf, data, ndata); jsonsl_feed(ctx->jsn, ctx->current_buf.s + old_len, ndata); /** * Do we need to cut off some bytes? */ if (ctx->keep_pos > ctx->min_pos) { size_t lentmp, diff = ctx->keep_pos - ctx->min_pos; const char *buf = get_buffer_region(ctx, ctx->keep_pos, -1, &lentmp); memmove(ctx->current_buf.s, buf, ctx->current_buf.len - diff); ctx->current_buf.len -= diff; } ctx->min_pos = ctx->keep_pos; }
static void row_pop_callback(jsonsl_t jsn, jsonsl_action_t action, struct jsonsl_state_st *state, const jsonsl_char_t *at) { lcbex_vrow_ctx_t *ctx = (lcbex_vrow_ctx_t*)jsn->data; const char *rowbuf; size_t szdummy; if (ctx->have_error) { return; } ctx->keep_pos = state->pos_cur; ctx->last_row_endpos = state->pos_cur; ctx->rowcount++; if (state->data == JOBJ_ROWSET) { /* don't care anymore.. */ jsn->action_callback_POP = trailer_pop_callback; jsn->action_callback_PUSH = NULL; return; } /* must be a JSON object! */ if (!ctx->callback) { return; } rowbuf = get_buffer_region(ctx, state->pos_begin, -1, &szdummy); { /** * Create our context.. */ lcbex_vrow_datum_t dt = { 0 }; dt.type = LCBEX_VROW_ROW; dt.data = rowbuf; dt.ndata = state->pos_cur - state->pos_begin + 1; ctx->callback(ctx, ctx->user_cookie, &dt); } (void)action; (void)at; }
static void row_pop_callback(jsonsl_t jsn, jsonsl_action_t action, struct jsonsl_state_st *state, const jsonsl_char_t *at) { lcbvrow_ROW dt = { 0 }; lcbvrow_PARSER *ctx = jsn->data; const char *rowbuf; size_t szdummy; if (ctx->have_error) { return; } ctx->keep_pos = jsn->pos; ctx->last_row_endpos = jsn->pos; if (state->data == JOBJ_ROWSET) { /** The closing ] of "rows" : [ ... ] */ jsn->action_callback_POP = trailer_pop_callback; jsn->action_callback_PUSH = NULL; if (ctx->rowcount == 0) { /* Emulate what meta_header_complete callback does. */ /* While the entire meta is available to us, the _closing_ part * of the meta is handled in a different callback. */ buffer_append(&ctx->meta_buf, jsn->base, jsn->pos); ctx->header_len = jsn->pos; } return; } ctx->rowcount++; if (!ctx->callback) { return; } rowbuf = get_buffer_region(ctx, state->pos_begin, -1, &szdummy); dt.type = LCB_VRESP_ROW; dt.row.iov_base = (void *)rowbuf; dt.row.iov_len = jsn->pos - state->pos_begin + 1; ctx->callback(ctx, &dt); (void)action; (void)at; }
static void feed_data(lcbjsp_PARSER *ctx, const char *data, size_t ndata) { size_t old_len = ctx->current_buf.nused; buffer_append(&ctx->current_buf, data, ndata); jsonsl_feed(ctx->jsn, ctx->current_buf.base + old_len, ndata); /* Do we need to cut off some bytes? */ if (ctx->keep_pos > ctx->min_pos) { size_t lentmp, diff = ctx->keep_pos - ctx->min_pos; const char *buf = get_buffer_region(ctx, ctx->keep_pos, -1, &lentmp); memmove(ctx->current_buf.base, buf, ctx->current_buf.nused - diff); ctx->current_buf.nused -= diff; } ctx->min_pos = ctx->keep_pos; }
/** * Consolidate the meta data into a single parsable string.. */ static void combine_meta(lcbvrow_PARSER *ctx) { const char *meta_trailer; size_t ntrailer; if (ctx->meta_complete) { return; } assert(ctx->header_len <= ctx->meta_buf.nused); /* Adjust the length for the first portion */ ctx->meta_buf.nused = ctx->header_len; /* Append any trailing data */ meta_trailer = get_buffer_region(ctx, ctx->last_row_endpos, -1, &ntrailer); buffer_append(&ctx->meta_buf, meta_trailer, ntrailer); ctx->meta_complete = 1; }