PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ parse_jsonb()

static uint32_t* parse_jsonb ( mvt_agg_context ctx,
Jsonb *  jb,
uint32_t tags 
)
static

Definition at line 499 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().

501 {
502  JsonbIterator *it;
503  JsonbValue v;
504  bool skipNested = false;
505  JsonbIteratorToken r;
506  uint32_t k;
507 
508  if (!JB_ROOT_IS_OBJECT(jb))
509  return tags;
510 
511  it = JsonbIteratorInit(&jb->root);
512 
513  while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE) {
514  skipNested = true;
515 
516  if (r == WJB_KEY && v.type != jbvNull) {
517  char *key;
518  key = palloc(v.val.string.len + 1 * sizeof(char));
519  memcpy(key, v.val.string.val, v.val.string.len);
520  key[v.val.string.len] = '\0';
521 
522  k = get_key_index(ctx, key);
523  if (k == UINT32_MAX) {
524  uint32_t newSize = ctx->keys_hash_i + 1;
525  tags = repalloc(tags, newSize * 2 * sizeof(*tags));
526  k = add_key(ctx, key);
527  }
528 
529  r = JsonbIteratorNext(&it, &v, skipNested);
530 
531  if (v.type == jbvString) {
532  char *value;
533  value = palloc(v.val.string.len + 1 * sizeof(char));
534  memcpy(value, v.val.string.val, v.val.string.len);
535  value[v.val.string.len] = '\0';
536  add_value_as_string(ctx, value, tags, k);
537  ctx->c++;
538  } else if (v.type == jbvBool) {
539  MVT_PARSE_VALUE(v.val.boolean, mvt_kv_bool_value,
540  bool_values_hash, bool_value, sizeof(protobuf_c_boolean));
541  ctx->c++;
542  } else if (v.type == jbvNumeric) {
543  char *str;
544  double d;
545  long l;
546  str = DatumGetCString(DirectFunctionCall1(numeric_out,
547  PointerGetDatum(v.val.numeric)));
548  d = strtod(str, NULL);
549  l = strtol(str, NULL, 10);
550  if ((long) d != l) {
551  MVT_PARSE_VALUE(d, mvt_kv_double_value, double_values_hash,
552  double_value, sizeof(double));
553  } else {
555  }
556  ctx->c++;
557  }
558  }
559  }
560 
561  return tags;
562 }
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:464
static uint32_t get_key_index(mvt_agg_context *ctx, char *name)
Definition: mvt.c:284
static uint32_t add_key(mvt_agg_context *ctx, char *name)
Definition: mvt.c:294
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:343
#define MVT_PARSE_VALUE(value, kvtype, hash, valuefield, size)
Definition: mvt.c:417
#define MVT_PARSE_INT_VALUE(value)
Definition: mvt.c:437
int value
Definition: genraster.py:61
Here is the call graph for this function:
Here is the caller graph for this function: