PostGIS  2.5.0dev-r@@SVN_REVISION@@
static uint32_t* parse_jsonb ( mvt_agg_context ctx,
Jsonb *  jb,
uint32_t tags 
)
static

Definition at line 492 of file mvt.c.

References add_key(), add_value_as_string(), mvt_agg_context::c, get_key_index(), mvt_agg_context::keys_hash_i, MVT_PARSE_INT_VALUE, MVT_PARSE_VALUE, r, UINT32_MAX, and genraster::value.

Referenced by parse_values().

494 {
495  JsonbIterator *it;
496  JsonbValue v;
497  bool skipNested = false;
498  JsonbIteratorToken r;
499  uint32_t k;
500 
501  if (!JB_ROOT_IS_OBJECT(jb))
502  return tags;
503 
504  it = JsonbIteratorInit(&jb->root);
505 
506  while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE) {
507  skipNested = true;
508 
509  if (r == WJB_KEY && v.type != jbvNull) {
510  char *key;
511  key = palloc(v.val.string.len + 1 * sizeof(char));
512  memcpy(key, v.val.string.val, v.val.string.len);
513  key[v.val.string.len] = '\0';
514 
515  k = get_key_index(ctx, key);
516  if (k == UINT32_MAX) {
517  uint32_t newSize = ctx->keys_hash_i + 1;
518  tags = repalloc(tags, newSize * 2 * sizeof(*tags));
519  k = add_key(ctx, key);
520  }
521 
522  r = JsonbIteratorNext(&it, &v, skipNested);
523 
524  if (v.type == jbvString) {
525  char *value;
526  value = palloc(v.val.string.len + 1 * sizeof(char));
527  memcpy(value, v.val.string.val, v.val.string.len);
528  value[v.val.string.len] = '\0';
529  add_value_as_string(ctx, value, tags, k);
530  ctx->c++;
531  } else if (v.type == jbvBool) {
532  MVT_PARSE_VALUE(v.val.boolean, mvt_kv_bool_value,
533  bool_values_hash, bool_value, sizeof(protobuf_c_boolean));
534  ctx->c++;
535  } else if (v.type == jbvNumeric) {
536  char *str;
537  str = DatumGetCString(DirectFunctionCall1(numeric_out,
538  PointerGetDatum(v.val.numeric)));
539  double d = strtod(str, NULL);
540  long l = strtol(str, NULL, 10);
541  if ((long) d != l) {
542  MVT_PARSE_VALUE(d, mvt_kv_double_value, double_values_hash,
543  double_value, sizeof(double));
544  } else {
546  }
547  ctx->c++;
548  }
549  }
550  }
551 
552  return tags;
553 }
uint32_t c
Definition: mvt.h:68
char * r
Definition: cu_in_wkt.c:24
static void add_value_as_string(mvt_agg_context *ctx, char *value, uint32_t *tags, uint32_t k)
Definition: mvt.c:457
static uint32_t get_key_index(mvt_agg_context *ctx, char *name)
Definition: mvt.c:283
static uint32_t add_key(mvt_agg_context *ctx, char *name)
Definition: mvt.c:293
unsigned int uint32_t
Definition: uthash.h:78
uint32_t keys_hash_i
Definition: mvt.h:67
#define UINT32_MAX
Definition: lwin_wkt_lex.c:128
#define MVT_PARSE_VALUE(value, kvtype, hash, valuefield, size)
Definition: mvt.c:412
#define MVT_PARSE_INT_VALUE(value)
Definition: mvt.c:430

Here is the call graph for this function:

Here is the caller graph for this function: