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(
"function returning record called in context "
179 "that cannot accept type record")));
181 data = PG_GETARG_BYTEA_PP(1);
183 ctx = palloc0(
sizeof(*
ctx));
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;
194 funcctx->user_fctx =
ctx;
196 if (
ctx->ctx->size == 0) {
197 POSTGIS_DEBUG(2,
"no data");
198 MemoryContextSwitchTo(oldcontext);
199 SRF_RETURN_DONE(funcctx);
203 flatgeobuf_decode_header(
ctx->ctx);
205 POSTGIS_DEBUGF(2,
"header decoded now at offset %ld",
ctx->ctx->offset);
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);
214 MemoryContextSwitchTo(oldcontext);
217 funcctx = SRF_PERCALL_SETUP();
218 ctx = funcctx->user_fctx;
222 POSTGIS_DEBUG(2,
"Calling SRF_RETURN_NEXT");
223 SRF_RETURN_NEXT(funcctx,
ctx->result);
225 POSTGIS_DEBUG(2,
"Calling SRF_RETURN_DONE");
226 SRF_RETURN_DONE(funcctx);
void flatgeobuf_check_magicbytes(struct flatgeobuf_decode_ctx *ctx)
void flatgeobuf_decode_row(struct flatgeobuf_decode_ctx *ctx)