283 flatgeobuf_column *column;
286 uint8_t *
data = ctx->
ctx->properties;
287 uint32_t size = ctx->
ctx->properties_len;
289 POSTGIS_DEBUGF(3,
"flatgeobuf: decode_properties from byte array with length %d at offset %d", size, offset);
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));
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];
307 case flatgeobuf_column_type_bool: {
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);
316 case flatgeobuf_column_type_byte: {
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);
325 case flatgeobuf_column_type_ubyte: {
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);
334 case flatgeobuf_column_type_short: {
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);
343 case flatgeobuf_column_type_ushort: {
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);
352 case flatgeobuf_column_type_int: {
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);
361 case flatgeobuf_column_type_uint: {
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);
370 case flatgeobuf_column_type_long: {
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);
379 case flatgeobuf_column_type_ulong: {
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);
388 case flatgeobuf_column_type_float: {
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);
397 case flatgeobuf_column_type_double: {
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);
406 case flatgeobuf_column_type_string: {
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));
416 case flatgeobuf_column_type_datetime: {
419 char workbuf[MAXDATELEN + MAXDATEFIELDS];
420 char *field[MAXDATEFIELDS];
421 int ftype[MAXDATEFIELDS];
424 struct pg_tm tt, *tm = &tt;
428 #if POSTGIS_PGSQL_VERSION >= 160
429 DateTimeErrorExtra extra;
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);
439 #if POSTGIS_PGSQL_VERSION >= 160
440 DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp, &extra);
442 DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp);
444 tm2timestamp(tm, fsec, &tzp, &dttz);
445 values[ci] = TimestampTzGetDatum(dttz);
459 elog(ERROR,
"flatgeobuf: decode_properties: Unknown type %d",
type);