PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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
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("first argument of function must be composite type")));
179
180 data = PG_GETARG_BYTEA_PP(1);
181
182 ctx = palloc0(sizeof(*ctx));
183 ctx->tupdesc = tupdesc;
184 ctx->ctx = palloc0(sizeof(flatgeobuf_ctx));
185 ctx->ctx->size = VARSIZE_ANY_EXHDR(data);
186 POSTGIS_DEBUGF(3, "VARSIZE_ANY_EXHDR %lld", ctx->ctx->size);
187 ctx->ctx->buf = palloc(ctx->ctx->size);
188 memcpy(ctx->ctx->buf, VARDATA_ANY(data), ctx->ctx->size);
189 ctx->ctx->offset = 0;
190 ctx->done = false;
191 ctx->fid = 0;
192
193 funcctx->user_fctx = ctx;
194
195 if (ctx->ctx->size == 0) {
196 POSTGIS_DEBUG(2, "no data");
197 MemoryContextSwitchTo(oldcontext);
198 SRF_RETURN_DONE(funcctx);
199 }
200
202 flatgeobuf_decode_header(ctx->ctx);
203
204 POSTGIS_DEBUGF(2, "header decoded now at offset %lld", ctx->ctx->offset);
205
206 if (ctx->ctx->size == ctx->ctx->offset) {
207 POSTGIS_DEBUGF(2, "no feature data offset %lld", ctx->ctx->offset);
208 MemoryContextSwitchTo(oldcontext);
209 SRF_RETURN_DONE(funcctx);
210 }
211
212 // TODO: get table and verify structure against header
213 MemoryContextSwitchTo(oldcontext);
214 }
215
216 funcctx = SRF_PERCALL_SETUP();
217 ctx = funcctx->user_fctx;
218
219 if (!ctx->done) {
221 POSTGIS_DEBUG(2, "Calling SRF_RETURN_NEXT");
222 SRF_RETURN_NEXT(funcctx, ctx->result);
223 } else {
224 POSTGIS_DEBUG(2, "Calling SRF_RETURN_DONE");
225 SRF_RETURN_DONE(funcctx);
226 }
227}
void flatgeobuf_check_magicbytes(struct flatgeobuf_decode_ctx *ctx)
Definition flatgeobuf.c:268
void flatgeobuf_decode_row(struct flatgeobuf_decode_ctx *ctx)
Definition flatgeobuf.c:464
flatgeobuf_ctx * ctx
Definition flatgeobuf.h:62

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

Here is the call graph for this function: