161 FuncCallContext *funcctx;
165 MemoryContext oldcontext;
169 if (SRF_IS_FIRSTCALL()) {
170 funcctx = SRF_FIRSTCALL_INIT();
171 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
173 funcctx->max_calls = 0;
175 if (get_call_result_type(fcinfo, NULL, &
tupdesc) != TYPEFUNC_COMPOSITE)
177 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
178 errmsg(
"first argument of function must be composite type")));
180 data = PG_GETARG_BYTEA_PP(1);
182 ctx = palloc0(
sizeof(*
ctx));
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;
193 funcctx->user_fctx =
ctx;
195 if (
ctx->ctx->size == 0) {
196 POSTGIS_DEBUG(2,
"no data");
197 MemoryContextSwitchTo(oldcontext);
198 SRF_RETURN_DONE(funcctx);
202 flatgeobuf_decode_header(
ctx->ctx);
204 POSTGIS_DEBUGF(2,
"header decoded now at offset %lld",
ctx->ctx->offset);
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);
213 MemoryContextSwitchTo(oldcontext);
216 funcctx = SRF_PERCALL_SETUP();
217 ctx = funcctx->user_fctx;
221 POSTGIS_DEBUG(2,
"Calling SRF_RETURN_NEXT");
222 SRF_RETURN_NEXT(funcctx,
ctx->result);
224 POSTGIS_DEBUG(2,
"Calling SRF_RETURN_DONE");
225 SRF_RETURN_DONE(funcctx);
void flatgeobuf_check_magicbytes(struct flatgeobuf_decode_ctx *ctx)
void flatgeobuf_decode_row(struct flatgeobuf_decode_ctx *ctx)