PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ lwcollection_from_gserialized_buffer()

static LWCOLLECTION* lwcollection_from_gserialized_buffer ( uint8_t *  data_ptr,
uint8_t  g_flags,
size_t *  g_size 
)
static

Definition at line 1185 of file g_serialized.c.

References LWCOLLECTION::bbox, LWCOLLECTION::flags, FLAGS_SET_BBOX, LWCOLLECTION::geoms, lw_get_uint32_t(), lwalloc(), lwcollection_allows_subtype(), lwerror(), lwfree(), lwgeom_from_gserialized_buffer(), lwtype_name(), LWCOLLECTION::ngeoms, LWCOLLECTION::srid, SRID_UNKNOWN, ovdump::type, and LWCOLLECTION::type.

Referenced by lwgeom_from_gserialized_buffer().

1186 {
1187  uint32_t type;
1188  uint8_t *start_ptr = data_ptr;
1189  LWCOLLECTION *collection;
1190  uint32_t ngeoms = 0;
1191  int i = 0;
1192 
1193  assert(data_ptr);
1194 
1195  type = lw_get_uint32_t(data_ptr);
1196  data_ptr += 4; /* Skip past the type. */
1197 
1198  collection = (LWCOLLECTION*)lwalloc(sizeof(LWCOLLECTION));
1199  collection->srid = SRID_UNKNOWN; /* Default */
1200  collection->bbox = NULL;
1201  collection->type = type;
1202  collection->flags = g_flags;
1203 
1204  ngeoms = lw_get_uint32_t(data_ptr);
1205  collection->ngeoms = ngeoms; /* Zero => empty geometry */
1206  data_ptr += 4; /* Skip past the ngeoms. */
1207 
1208  if ( ngeoms > 0 )
1209  collection->geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
1210  else
1211  collection->geoms = NULL;
1212 
1213  /* Sub-geometries are never de-serialized with boxes (#1254) */
1214  FLAGS_SET_BBOX(g_flags, 0);
1215 
1216  for ( i = 0; i < ngeoms; i++ )
1217  {
1218  uint32_t subtype = lw_get_uint32_t(data_ptr);
1219  size_t subsize = 0;
1220 
1221  if ( ! lwcollection_allows_subtype(type, subtype) )
1222  {
1223  lwerror("Invalid subtype (%s) for collection type (%s)", lwtype_name(subtype), lwtype_name(type));
1224  lwfree(collection);
1225  return NULL;
1226  }
1227  collection->geoms[i] = lwgeom_from_gserialized_buffer(data_ptr, g_flags, &subsize);
1228  data_ptr += subsize;
1229  }
1230 
1231  if ( g_size )
1232  *g_size = data_ptr - start_ptr;
1233 
1234  return collection;
1235 }
void lwfree(void *mem)
Definition: lwutil.c:242
uint8_t type
Definition: liblwgeom.h:502
GBOX * bbox
Definition: liblwgeom.h:504
uint8_t flags
Definition: liblwgeom.h:503
uint32_t lw_get_uint32_t(const uint8_t *loc)
Definition: lwgeom_api.c:582
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
LWGEOM ** geoms
Definition: liblwgeom.h:508
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
int32_t srid
Definition: liblwgeom.h:505
static LWGEOM * lwgeom_from_gserialized_buffer(uint8_t *data_ptr, uint8_t g_flags, size_t *g_size)
#define FLAGS_SET_BBOX(flags, value)
Definition: liblwgeom.h:147
type
Definition: ovdump.py:41
tuple g_size
Definition: genraster.py:41
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
Definition: lwcollection.c:536
void * lwalloc(size_t size)
Definition: lwutil.c:227
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: