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

◆ lwcollection_from_gserialized2_buffer()

static LWCOLLECTION * lwcollection_from_gserialized2_buffer ( uint8_t *  data_ptr,
lwflags_t  lwflags,
size_t *  size,
int32_t  srid 
)
static

Definition at line 1399 of file gserialized2.c.

1400{
1401 uint32_t type;
1402 uint8_t *start_ptr = data_ptr;
1403 LWCOLLECTION *collection;
1404 uint32_t ngeoms = 0;
1405 uint32_t i = 0;
1406
1407 assert(data_ptr);
1408
1409 type = gserialized2_get_uint32_t(data_ptr);
1410 data_ptr += 4; /* Skip past the type. */
1411
1412 collection = (LWCOLLECTION*)lwalloc(sizeof(LWCOLLECTION));
1413 collection->srid = srid;
1414 collection->bbox = NULL;
1415 collection->type = type;
1416 collection->flags = lwflags;
1417
1418 ngeoms = gserialized2_get_uint32_t(data_ptr);
1419 collection->ngeoms = ngeoms; /* Zero => empty geometry */
1420 data_ptr += 4; /* Skip past the ngeoms. */
1421
1422 if (ngeoms > 0)
1423 {
1424 collection->geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
1425 collection->maxgeoms = ngeoms;
1426 }
1427 else
1428 {
1429 collection->geoms = NULL;
1430 collection->maxgeoms = 0;
1431 }
1432
1433 /* Sub-geometries are never de-serialized with boxes (#1254) */
1435
1436 for (i = 0; i < ngeoms; i++)
1437 {
1438 uint32_t subtype = gserialized2_get_uint32_t(data_ptr);
1439 size_t subsize = 0;
1440
1441 if (!lwcollection_allows_subtype(type, subtype))
1442 {
1443 lwerror("Invalid subtype (%s) for collection type (%s)", lwtype_name(subtype), lwtype_name(type));
1444 lwfree(collection);
1445 return NULL;
1446 }
1447 collection->geoms[i] = lwgeom_from_gserialized2_buffer(data_ptr, lwflags, &subsize, srid);
1448 data_ptr += subsize;
1449 }
1450
1451 if (size)
1452 *size = data_ptr - start_ptr;
1453
1454 return collection;
1455}
static uint32_t gserialized2_get_uint32_t(const uint8_t *loc)
static LWGEOM * lwgeom_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
#define FLAGS_SET_BBOX(flags, value)
Definition liblwgeom.h:174
void * lwalloc(size_t size)
Definition lwutil.c:227
void lwfree(void *mem)
Definition lwutil.c:248
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition lwutil.c:477
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
lwflags_t flags
Definition liblwgeom.h:577
uint32_t ngeoms
Definition liblwgeom.h:580
uint32_t maxgeoms
Definition liblwgeom.h:581
uint8_t type
Definition liblwgeom.h:578
GBOX * bbox
Definition liblwgeom.h:574
LWGEOM ** geoms
Definition liblwgeom.h:575
int32_t srid
Definition liblwgeom.h:576

References LWCOLLECTION::bbox, LWCOLLECTION::flags, FLAGS_SET_BBOX, LWCOLLECTION::geoms, gserialized2_get_uint32_t(), lwalloc(), lwcollection_allows_subtype(), lwerror(), lwflags(), lwfree(), lwgeom_from_gserialized2_buffer(), lwtype_name(), LWCOLLECTION::maxgeoms, LWCOLLECTION::ngeoms, LWCOLLECTION::srid, and LWCOLLECTION::type.

Referenced by lwgeom_from_gserialized2_buffer().

Here is the call graph for this function:
Here is the caller graph for this function: