PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ parse_jsonb()

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

Definition at line 550 of file mvt.c.

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

Referenced by parse_values().

552 {
553  JsonbIterator *it;
554  JsonbValue v;
555  bool skipNested = false;
556  JsonbIteratorToken r;
557  uint32_t k;
558 
559  if (!JB_ROOT_IS_OBJECT(jb))
560  return tags;
561 
562  it = JsonbIteratorInit(&jb->root);
563 
564  while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
565  {
566  skipNested = true;
567 
568  if (r == WJB_KEY && v.type != jbvNull)
569  {
570 
571  k = get_key_index_with_size(ctx, v.val.string.val, v.val.string.len);
572  if (k == UINT32_MAX)
573  {
574  char *key;
575  uint32_t newSize = ctx->keys_hash_i + 1;
576 
577  key = palloc(v.val.string.len + 1);
578  memcpy(key, v.val.string.val, v.val.string.len);
579  key[v.val.string.len] = '\0';
580 
581  tags = repalloc(tags, newSize * 2 * sizeof(*tags));
582  k = add_key(ctx, key);
583  }
584 
585  r = JsonbIteratorNext(&it, &v, skipNested);
586 
587  if (v.type == jbvString)
588  {
589  char *value;
590  value = palloc(v.val.string.len + 1);
591  memcpy(value, v.val.string.val, v.val.string.len);
592  value[v.val.string.len] = '\0';
593  add_value_as_string(ctx, value, tags, k);
594  ctx->row_columns++;
595  }
596  else if (v.type == jbvBool)
597  {
598  MVT_PARSE_VALUE(v.val.boolean, mvt_kv_bool_value,
599  bool_values_hash, bool_value, sizeof(protobuf_c_boolean));
600  ctx->row_columns++;
601  }
602  else if (v.type == jbvNumeric)
603  {
604  char *str;
605  double d;
606  long l;
607  str = DatumGetCString(DirectFunctionCall1(numeric_out,
608  PointerGetDatum(v.val.numeric)));
609  d = strtod(str, NULL);
610  l = strtol(str, NULL, 10);
611  if ((long) d != l)
612  {
613  MVT_PARSE_VALUE(d, mvt_kv_double_value, double_values_hash,
614  double_value, sizeof(double));
615  }
616  else
617  {
619  }
620  ctx->row_columns++;
621  }
622  }
623  }
624 
625  return tags;
626 }
uint32_t row_columns
Definition: mvt.h:78
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:530
static uint32_t add_key(mvt_agg_context *ctx, char *name)
Definition: mvt.c:307
unsigned int uint32_t
Definition: uthash.h:78
uint32_t keys_hash_i
Definition: mvt.h:77
#define UINT32_MAX
Definition: lwin_wkt_lex.c:343
#define MVT_PARSE_VALUE(value, kvtype, hash, valuefield, size)
Definition: mvt.c:458
static uint32_t get_key_index_with_size(mvt_agg_context *ctx, const char *name, size_t size)
Definition: mvt.c:298
#define MVT_PARSE_INT_VALUE(value)
Definition: mvt.c:479
int value
Definition: genraster.py:61
Here is the call graph for this function:
Here is the caller graph for this function: