PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ pgis_fromflatgeobuf()

Datum pgis_fromflatgeobuf ( PG_FUNCTION_ARGS  )

Definition at line 159 of file lwgeom_in_flatgeobuf.c.

160 {
161  FuncCallContext *funcctx;
162 
163  TupleDesc tupdesc;
164  bytea *data;
165  MemoryContext oldcontext;
166 
167  struct flatgeobuf_decode_ctx *ctx;
168 
169  if (SRF_IS_FIRSTCALL()) {
170  funcctx = SRF_FIRSTCALL_INIT();
171  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
172 
173  funcctx->max_calls = 0;
174 
175  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
176  ereport(ERROR,
177  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
178  errmsg("function returning record called in context "
179  "that cannot accept type record")));
180 
181  data = PG_GETARG_BYTEA_PP(1);
182 
183  ctx = palloc0(sizeof(*ctx));
184  ctx->tupdesc = tupdesc;
185  ctx->ctx = palloc0(sizeof(flatgeobuf_ctx));
186  ctx->ctx->size = VARSIZE_ANY_EXHDR(data);
187  POSTGIS_DEBUGF(3, "VARSIZE_ANY_EXHDR %ld", ctx->ctx->size);
188  ctx->ctx->buf = palloc(ctx->ctx->size);
189  memcpy(ctx->ctx->buf, VARDATA_ANY(data), ctx->ctx->size);
190  ctx->ctx->offset = 0;
191  ctx->done = false;
192  ctx->fid = 0;
193 
194  funcctx->user_fctx = ctx;
195 
196  if (ctx->ctx->size == 0) {
197  POSTGIS_DEBUG(2, "no data");
198  MemoryContextSwitchTo(oldcontext);
199  SRF_RETURN_DONE(funcctx);
200  }
201 
203  flatgeobuf_decode_header(ctx->ctx);
204 
205  POSTGIS_DEBUGF(2, "header decoded now at offset %ld", ctx->ctx->offset);
206 
207  if (ctx->ctx->size == ctx->ctx->offset) {
208  POSTGIS_DEBUGF(2, "no feature data offset %ld", ctx->ctx->offset);
209  MemoryContextSwitchTo(oldcontext);
210  SRF_RETURN_DONE(funcctx);
211  }
212 
213  // TODO: get table and verify structure against header
214  MemoryContextSwitchTo(oldcontext);
215  }
216 
217  funcctx = SRF_PERCALL_SETUP();
218  ctx = funcctx->user_fctx;
219 
220  if (!ctx->done) {
222  POSTGIS_DEBUG(2, "Calling SRF_RETURN_NEXT");
223  SRF_RETURN_NEXT(funcctx, ctx->result);
224  } else {
225  POSTGIS_DEBUG(2, "Calling SRF_RETURN_DONE");
226  SRF_RETURN_DONE(funcctx);
227  }
228 }
void flatgeobuf_check_magicbytes(struct flatgeobuf_decode_ctx *ctx)
Definition: flatgeobuf.c:269
void flatgeobuf_decode_row(struct flatgeobuf_decode_ctx *ctx)
Definition: flatgeobuf.c:465
data
Definition: ovdump.py:104
flatgeobuf_ctx * ctx
Definition: flatgeobuf.h:62

References flatgeobuf_decode_ctx::ctx, ovdump::data, flatgeobuf_check_magicbytes(), flatgeobuf_decode_row(), and flatgeobuf_decode_ctx::tupdesc.

Here is the call graph for this function: