PostGIS  2.5.0dev-r@@SVN_REVISION@@
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 333 of file lwin_wkb.c.

References double_from_wkb_state(), wkb_parse_state::has_m, wkb_parse_state::has_z, integer_from_wkb_state(), LWDEBUGF, lwerror(), wkb_parse_state::pos, ptarray_construct(), ptarray_construct_copy_data(), POINTARRAY::serialized_pointlist, wkb_parse_state::swap_bytes, 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().

334 {
335  POINTARRAY *pa = NULL;
336  size_t pa_size;
337  uint32_t ndims = 2;
338  uint32_t npoints = 0;
339  static uint32_t maxpoints = UINT_MAX / WKB_DOUBLE_SIZE / 4;
340 
341  /* Calculate the size of this point array. */
342  npoints = integer_from_wkb_state(s);
343  if (npoints > maxpoints)
344  {
345  lwerror("Pointarray length (%d) is too large");
346  return NULL;
347  }
348 
349  LWDEBUGF(4,"Pointarray has %d points", npoints);
350 
351  if( s->has_z ) ndims++;
352  if( s->has_m ) ndims++;
353  pa_size = npoints * ndims * WKB_DOUBLE_SIZE;
354 
355  /* Empty! */
356  if( npoints == 0 )
357  return ptarray_construct(s->has_z, s->has_m, npoints);
358 
359  /* Does the data we want to read exist? */
360  wkb_parse_state_check(s, pa_size);
361 
362  /* If we're in a native endianness, we can just copy the data directly! */
363  if( ! s->swap_bytes )
364  {
365  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
366  s->pos += pa_size;
367  }
368  /* Otherwise we have to read each double, separately. */
369  else
370  {
371  uint32_t i = 0;
372  double *dlist;
373  pa = ptarray_construct(s->has_z, s->has_m, npoints);
374  dlist = (double*)(pa->serialized_pointlist);
375  for( i = 0; i < npoints * ndims; i++ )
376  {
377  dlist[i] = double_from_wkb_state(s);
378  }
379  }
380 
381  return pa;
382 }
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:62
uint8_t * serialized_pointlist
Definition: liblwgeom.h:365
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:271
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
unsigned int uint32_t
Definition: uthash.h:78
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:307
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:126
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
unsigned char uint8_t
Definition: uthash.h:79
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:301
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
const uint8_t * pos
Definition: lwin_wkb.c:47

Here is the call graph for this function:

Here is the caller graph for this function: