71{
75 FuncCallContext *funcctx;
78 TupleDesc tupdesc;
79 HeapTuple tuple;
80 MemoryContext oldcontext, newcontext;
82 char address[256];
83 char *ptr;
84 int i;
85 char *values[2];
86
87 if (SRF_IS_FIRSTCALL())
88 {
89 funcctx = SRF_FIRSTCALL_INIT();
90 newcontext = funcctx->multi_call_memory_ctx;
91
92 oldcontext = MemoryContextSwitchTo(newcontext);
93
94 pglwgeom = PG_GETARG_GSERIALIZED_P_COPY(0);
96
97
101
103 {
104
105
106
111 }
112
113 funcctx->user_fctx = state;
114
115
116
117
118
119 get_call_result_type(fcinfo, 0, &tupdesc);
120 BlessTupleDesc(tupdesc);
121
122
123
124
125
126 funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);;
127
128 MemoryContextSwitchTo(oldcontext);
129 }
130
131
132 funcctx = SRF_PERCALL_SETUP();
133 newcontext = funcctx->multi_call_memory_ctx;
134
135
136 state = funcctx->user_fctx;
137
138
139 if ( ! state->
root ) SRF_RETURN_DONE(funcctx);
140
143 {
144 values[0] = "{}";
146 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
147 result = HeapTupleGetDatum(tuple);
148
150 SRF_RETURN_NEXT(funcctx,
result);
151 }
152
153 while (1)
154 {
157
159 {
162 {
163
164 ptr=address;
165 *ptr++='{';
167 {
168 if ( i ) ptr += sprintf(ptr, ",");
169 ptr += sprintf(ptr,
"%d", state->
stack[i]->
idx+1);
170 }
171 *ptr++='}';
172 *ptr='\0';
173
174 break;
175 }
176
177
178
179
180
181
182
184 elog(ERROR, "Unable to dump overly nested collection.");
185
186 oldcontext = MemoryContextSwitchTo(newcontext);
187
192
193 MemoryContextSwitchTo(oldcontext);
194
195 continue;
196 }
197
198 if ( !
POP(state) ) SRF_RETURN_DONE(funcctx);
200 }
201
203
204 values[0] = address;
206 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
207 result = TupleGetDatum(funcctx->slot, tuple);
209 SRF_RETURN_NEXT(funcctx,
result);
210}
char result[OUT_DOUBLE_BUFFER_SIZE]
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
char * lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant)
void * lwalloc(size_t size)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM contains sub-geometries or not This basically just checks that the struct ...
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
GEOMDUMPNODE * stack[MAXDEPTH]