PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ptarray_from_wkb_state()

static POINTARRAY* ptarray_from_wkb_state ( wkb_parse_state s)
static

POINTARRAY Read a dynamically sized point array and advance the parse state forward.

First read the number of points, then read the points.

Definition at line 347 of file lwin_wkb.c.

348 {
349  POINTARRAY *pa = NULL;
350  size_t pa_size;
351  uint32_t ndims = 2;
352  uint32_t npoints = 0;
353  static uint32_t maxpoints = UINT_MAX / WKB_DOUBLE_SIZE / 4;
354 
355  /* Calculate the size of this point array. */
356  npoints = integer_from_wkb_state(s);
357  if (s->error)
358  return NULL;
359 
360  if (npoints > maxpoints)
361  {
362  s->error = LW_TRUE;
363  lwerror("Pointarray length (%d) is too large", npoints);
364  return NULL;
365  }
366 
367  LWDEBUGF(4,"Pointarray has %d points", npoints);
368 
369  if( s->has_z ) ndims++;
370  if( s->has_m ) ndims++;
371  pa_size = npoints * ndims * WKB_DOUBLE_SIZE;
372 
373  /* Empty! */
374  if( npoints == 0 )
375  return ptarray_construct(s->has_z, s->has_m, npoints);
376 
377  /* Does the data we want to read exist? */
378  wkb_parse_state_check(s, pa_size);
379  if (s->error)
380  return NULL;
381 
382  /* If we're in a native endianness, we can just copy the data directly! */
383  if( ! s->swap_bytes )
384  {
385  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
386  s->pos += pa_size;
387  }
388  /* Otherwise we have to read each double, separately. */
389  else
390  {
391  uint32_t i = 0;
392  double *dlist;
393  pa = ptarray_construct(s->has_z, s->has_m, npoints);
394  dlist = (double*)(pa->serialized_pointlist);
395  for( i = 0; i < npoints * ndims; i++ )
396  {
397  dlist[i] = double_from_wkb_state(s);
398  }
399  }
400 
401  return pa;
402 }
char * s
Definition: cu_in_wkt.c:23
POINTARRAY * ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist)
Construct a new POINTARRAY, copying in the data from ptlist.
Definition: ptarray.c:297
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:51
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static uint32_t integer_from_wkb_state(wkb_parse_state *s)
Int32 Read 4-byte integer and advance the parse state forward.
Definition: lwin_wkb.c:285
static void wkb_parse_state_check(wkb_parse_state *s, size_t next)
Check that we are not about to read off the end of the WKB array.
Definition: lwin_wkb.c:131
static double double_from_wkb_state(wkb_parse_state *s)
Double Read an 8-byte double and advance the parse state forward.
Definition: lwin_wkb.c:317
uint8_t * serialized_pointlist
Definition: liblwgeom.h:434

References double_from_wkb_state(), integer_from_wkb_state(), LW_TRUE, LWDEBUGF, lwerror(), ptarray_construct(), ptarray_construct_copy_data(), s, POINTARRAY::serialized_pointlist, WKB_DOUBLE_SIZE, and wkb_parse_state_check().

Referenced by lwcircstring_from_wkb_state(), lwline_from_wkb_state(), lwpoly_from_wkb_state(), and lwtriangle_from_wkb_state().

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