PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ decode_properties()

static void decode_properties ( struct flatgeobuf_decode_ctx ctx,
Datum *  values,
bool *  isnull 
)
static

Definition at line 280 of file flatgeobuf.c.

281 {
282  uint16_t i, ci;
283  flatgeobuf_column *column;
284  uint8_t type;
285  uint32_t offset = 0;
286  uint8_t *data = ctx->ctx->properties;
287  uint32_t size = ctx->ctx->properties_len;
288 
289  POSTGIS_DEBUGF(3, "flatgeobuf: decode_properties from byte array with length %d at offset %d", size, offset);
290 
291  // TODO: init isnull
292 
293  if (size > 0 && size < (sizeof(uint16_t) + sizeof(uint8_t)))
294  elog(ERROR, "flatgeobuf: decode_properties: Unexpected properties data size %d", size);
295  while (offset + 1 < size) {
296  if (offset + sizeof(uint16_t) > size)
297  elog(ERROR, "flatgeobuf: decode_properties: Unexpected offset %d", offset);
298  memcpy(&i, data + offset, sizeof(uint16_t));
299  ci = i + 2;
300  offset += sizeof(uint16_t);
301  if (i >= ctx->ctx->columns_size)
302  elog(ERROR, "flatgeobuf: decode_properties: Column index %hu out of range", i);
303  column = ctx->ctx->columns[i];
304  type = column->type;
305  isnull[ci] = false;
306  switch (type) {
307  case flatgeobuf_column_type_bool: {
308  uint8_t value;
309  if (offset + sizeof(uint8_t) > size)
310  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for bool value");
311  memcpy(&value, data + offset, sizeof(uint8_t));
312  values[ci] = BoolGetDatum(value);
313  offset += sizeof(uint8_t);
314  break;
315  }
316  case flatgeobuf_column_type_byte: {
317  int8_t value;
318  if (offset + sizeof(int8_t) > size)
319  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for byte value");
320  memcpy(&value, data + offset, sizeof(int8_t));
321  values[ci] = Int8GetDatum(value);
322  offset += sizeof(int8_t);
323  break;
324  }
325  case flatgeobuf_column_type_ubyte: {
326  uint8_t value;
327  if (offset + sizeof(uint8_t) > size)
328  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for ubyte value");
329  memcpy(&value, data + offset, sizeof(uint8_t));
330  values[ci] = UInt8GetDatum(value);
331  offset += sizeof(uint8_t);
332  break;
333  }
334  case flatgeobuf_column_type_short: {
335  int16_t value;
336  if (offset + sizeof(int16_t) > size)
337  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for short value");
338  memcpy(&value, data + offset, sizeof(int16_t));
339  values[ci] = Int16GetDatum(value);
340  offset += sizeof(int16_t);
341  break;
342  }
343  case flatgeobuf_column_type_ushort: {
344  uint16_t value;
345  if (offset + sizeof(uint16_t) > size)
346  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for ushort value");
347  memcpy(&value, data + offset, sizeof(uint16_t));
348  values[ci] = UInt16GetDatum(value);
349  offset += sizeof(uint16_t);
350  break;
351  }
352  case flatgeobuf_column_type_int: {
353  int32_t value;
354  if (offset + sizeof(int32_t) > size)
355  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for int value");
356  memcpy(&value, data + offset, sizeof(int32_t));
357  values[ci] = Int32GetDatum(value);
358  offset += sizeof(int32_t);
359  break;
360  }
361  case flatgeobuf_column_type_uint: {
362  uint32_t value;
363  if (offset + sizeof(uint32_t) > size)
364  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for uint value");
365  memcpy(&value, data + offset, sizeof(uint32_t));
366  values[ci] = UInt32GetDatum(value);
367  offset += sizeof(uint32_t);
368  break;
369  }
370  case flatgeobuf_column_type_long: {
371  int64_t value;
372  if (offset + sizeof(int64_t) > size)
373  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for long value");
374  memcpy(&value, data + offset, sizeof(int64_t));
375  values[ci] = Int64GetDatum(value);
376  offset += sizeof(int64_t);
377  break;
378  }
379  case flatgeobuf_column_type_ulong: {
380  uint64_t value;
381  if (offset + sizeof(uint64_t) > size)
382  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for ulong value");
383  memcpy(&value, data + offset, sizeof(uint64_t));
384  values[ci] = UInt64GetDatum(value);
385  offset += sizeof(uint64_t);
386  break;
387  }
388  case flatgeobuf_column_type_float: {
389  float value;
390  if (offset + sizeof(float) > size)
391  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for float value");
392  memcpy(&value, data + offset, sizeof(float));
393  values[ci] = Float4GetDatum(value);
394  offset += sizeof(float);
395  break;
396  }
397  case flatgeobuf_column_type_double: {
398  double value;
399  if (offset + sizeof(double) > size)
400  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for double value");
401  memcpy(&value, data + offset, sizeof(double));
402  values[ci] = Float8GetDatum(value);
403  offset += sizeof(double);
404  break;
405  }
406  case flatgeobuf_column_type_string: {
407  uint32_t len;
408  if (offset + sizeof(len) > size)
409  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for string value");
410  memcpy(&len, data + offset, sizeof(uint32_t));
411  offset += sizeof(len);
412  values[ci] = PointerGetDatum(cstring_to_text_with_len((const char *) data + offset, len));
413  offset += len;
414  break;
415  }
416  case flatgeobuf_column_type_datetime: {
417  uint32_t len;
418  char *buf;
419  char workbuf[MAXDATELEN + MAXDATEFIELDS];
420  char *field[MAXDATEFIELDS];
421  int ftype[MAXDATEFIELDS];
422  int dtype;
423  int nf;
424  struct pg_tm tt, *tm = &tt;
425  fsec_t fsec;
426  int tzp;
427  TimestampTz dttz;
428 #if POSTGIS_PGSQL_VERSION >= 160
429  DateTimeErrorExtra extra;
430 #endif
431  if (offset + sizeof(len) > size)
432  elog(ERROR, "flatgeobuf: decode_properties: Invalid size for string value");
433  memcpy(&len, data + offset, sizeof(uint32_t));
434  offset += sizeof(len);
435  buf = palloc0(len + 1);
436  memcpy(buf, (const char *) data + offset, len);
437  ParseDateTime((const char *) buf, workbuf, sizeof(workbuf), field, ftype, MAXDATEFIELDS, &nf);
438 
439 #if POSTGIS_PGSQL_VERSION >= 160
440  DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp, &extra);
441 #else
442  DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp);
443 #endif
444  tm2timestamp(tm, fsec, &tzp, &dttz);
445  values[ci] = TimestampTzGetDatum(dttz);
446  offset += len;
447  break;
448  }
449  // TODO: find out how to handle string to jsonb Datum
450  // case FlatGeobuf_ColumnType_Json:
451  // if (offset + sizeof(len) > size)
452  // elog(ERROR, "flatgeobuf: decode_properties: Invalid size for json value");
453  // len = *((uint32_t *)(data + offset));
454  // offset += sizeof(len);
455  // values[ci] = jsonb_from_cstring((const char *) data + offset, len);
456  // offset += len;
457  // break;
458  default:
459  elog(ERROR, "flatgeobuf: decode_properties: Unknown type %d", type);
460  }
461  }
462 
463 }
int value
Definition: genraster.py:62
type
Definition: ovdump.py:42
data
Definition: ovdump.py:104
flatgeobuf_ctx * ctx
Definition: flatgeobuf.h:62

References flatgeobuf_decode_ctx::ctx, ovdump::data, ovdump::type, and genraster::value.

Referenced by flatgeobuf_decode_row().

Here is the caller graph for this function: