PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ encode_properties()

static void encode_properties ( flatgeobuf_agg_ctx ctx)
static

Definition at line 152 of file flatgeobuf.c.

153 {
154  uint16_t ci = 0;
155  size_t offset = 0;
156  Datum datum;
157  bool isnull;
158  Oid typoid;
159  uint32_t len;
160  uint32_t i;
161 
162  uint8_t byte_value;
163  int16_t short_value;
164  int32_t int_value;
165  int64_t long_value;
166  float float_value;
167  double double_value;
168  char *string_value;
169 
170  //Jsonb *jb;
171 
172  for (i = 0; i < (uint32_t) ctx->tupdesc->natts; i++) {
173  if (ctx->geom_index == i)
174  continue;
175  datum = GetAttributeByNum(ctx->row, i + 1, &isnull);
176  if (isnull)
177  continue;
178  ensure_properties_size(ctx, offset + sizeof(ci));
179  memcpy(ctx->ctx->properties + offset, &ci, sizeof(ci));
180  offset += sizeof(ci);
181  typoid = getBaseType(TupleDescAttr(ctx->tupdesc, i)->atttypid);
182  switch (typoid) {
183  case BOOLOID:
184  byte_value = DatumGetBool(datum) ? 1 : 0;
185  ensure_properties_size(ctx, offset + sizeof(byte_value));
186  memcpy(ctx->ctx->properties + offset, &byte_value, sizeof(byte_value));
187  offset += sizeof(byte_value);
188  break;
189  case INT2OID:
190  short_value = DatumGetInt16(datum);
191  ensure_properties_size(ctx, offset + sizeof(short_value));
192  memcpy(ctx->ctx->properties + offset, &short_value, sizeof(short_value));
193  offset += sizeof(short_value);
194  break;
195  case INT4OID:
196  int_value = DatumGetInt32(datum);
197  ensure_properties_size(ctx, offset + sizeof(int_value));
198  memcpy(ctx->ctx->properties + offset, &int_value, sizeof(int_value));
199  offset += sizeof(int_value);
200  break;
201  case INT8OID:
202  long_value = DatumGetInt64(datum);
203  ensure_properties_size(ctx, offset + sizeof(long_value));
204  memcpy(ctx->ctx->properties + offset, &long_value, sizeof(long_value));
205  offset += sizeof(long_value);
206  break;
207  case FLOAT4OID:
208  float_value = DatumGetFloat4(datum);
209  ensure_properties_size(ctx, offset + sizeof(float_value));
210  memcpy(ctx->ctx->properties + offset, &float_value, sizeof(float_value));
211  offset += sizeof(float_value);
212  break;
213  case FLOAT8OID:
214  double_value = DatumGetFloat8(datum);
215  ensure_properties_size(ctx, offset + sizeof(double_value));
216  memcpy(ctx->ctx->properties + offset, &double_value, sizeof(double_value));
217  offset += sizeof(double_value);
218  break;
219  case TEXTOID:
220  string_value = text_to_cstring(DatumGetTextP(datum));
221  len = strlen(string_value);
222  ensure_properties_size(ctx, offset + sizeof(len));
223  memcpy(ctx->ctx->properties + offset, &len, sizeof(len));
224  offset += sizeof(len);
225  ensure_properties_size(ctx, offset + len);
226  memcpy(ctx->ctx->properties + offset, string_value, len);
227  offset += len;
228  break;
229  case TIMESTAMPTZOID: {
230  struct pg_tm tm;
231  fsec_t fsec;
232  int tz;
233  const char *tzn = NULL;
234  TimestampTz timestamp;
235  timestamp = DatumGetTimestampTz(datum);
236  timestamp2tm(timestamp, &tz, &tm, &fsec, &tzn, NULL);
237  string_value = palloc(MAXDATELEN + 1);
238  EncodeDateTime(&tm, fsec, true, tz, tzn, USE_ISO_DATES, string_value);
239  len = strlen(string_value);
240  ensure_properties_size(ctx, offset + sizeof(len));
241  memcpy(ctx->ctx->properties + offset, &len, sizeof(len));
242  offset += sizeof(len);
243  ensure_properties_size(ctx, offset + len);
244  memcpy(ctx->ctx->properties + offset, string_value, len);
245  offset += len;
246  break;
247  }
248  // TODO: handle date/time types
249  // case JSONBOID:
250  // jb = DatumGetJsonbP(datum);
251  // string_value = JsonbToCString(NULL, &jb->root, VARSIZE(jb));
252  // len = strlen(string_value);
253  // memcpy(data + offset, &len, sizeof(len));
254  // offset += sizeof(len);
255  // memcpy(data + offset, string_value, len);
256  // offset += len;
257  // break;
258  }
259  ci++;
260  }
261 
262  if (offset > 0) {
263  POSTGIS_DEBUGF(3, "offset %ld", offset);
264  ctx->ctx->properties_len = offset;
265  }
266 }
static void ensure_properties_size(struct flatgeobuf_agg_ctx *ctx, size_t size)
Definition: flatgeobuf.c:122
HeapTupleHeader row
Definition: flatgeobuf.h:52
flatgeobuf_ctx * ctx
Definition: flatgeobuf.h:48
uint32_t geom_index
Definition: flatgeobuf.h:50
TupleDesc tupdesc
Definition: flatgeobuf.h:51

References flatgeobuf_agg_ctx::ctx, ensure_properties_size(), flatgeobuf_agg_ctx::geom_index, flatgeobuf_agg_ctx::row, and flatgeobuf_agg_ctx::tupdesc.

Referenced by flatgeobuf_agg_transfn().

Here is the call graph for this function:
Here is the caller graph for this function: