PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ encode_properties()

static void encode_properties ( flatgeobuf_agg_ctx ctx)
static

Definition at line 153 of file flatgeobuf.c.

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