PostGIS  2.2.7dev-r@@SVN_REVISION@@
static void header_from_twkb_state ( twkb_parse_state s)
static

Definition at line 476 of file lwin_twkb.c.

References byte_from_twkb_state(), twkb_parse_state::factor, twkb_parse_state::factor_m, twkb_parse_state::factor_z, twkb_parse_state::has_bbox, twkb_parse_state::has_idlist, twkb_parse_state::has_m, twkb_parse_state::has_size, twkb_parse_state::has_z, twkb_parse_state::is_empty, LWDEBUG, twkb_parse_state::lwtype, lwtype_from_twkb_type(), twkb_parse_state::ndims, precision, twkb_parse_state::size, twkb_parse_state_uvarint(), and unzigzag8().

Referenced by lwgeom_from_twkb_state().

477 {
478  LWDEBUG(2,"Entering magicbyte_from_twkb_state");
479 
480  uint8_t extended_dims;
481 
482  /* Read the first two bytes */
483  uint8_t type_precision = byte_from_twkb_state(s);
484  uint8_t metadata = byte_from_twkb_state(s);
485 
486  /* Strip type and precision out of first byte */
487  uint8_t type = type_precision & 0x0F;
488  int8_t precision = unzigzag8((type_precision & 0xF0) >> 4);
489 
490  /* Convert TWKB type to internal type */
491  s->lwtype = lwtype_from_twkb_type(type);
492 
493  /* Convert the precision into factor */
494  s->factor = pow(10, (double)precision);
495 
496  /* Strip metadata flags out of second byte */
497  s->has_bbox = metadata & 0x01;
498  s->has_size = (metadata & 0x02) >> 1;
499  s->has_idlist = (metadata & 0x04) >> 2;
500  extended_dims = (metadata & 0x08) >> 3;
501  s->is_empty = (metadata & 0x10) >> 4;
502 
503  /* Flag for higher dims means read a third byte */
504  if ( extended_dims )
505  {
506  int8_t precision_z, precision_m;
507 
508  extended_dims = byte_from_twkb_state(s);
509 
510  /* Strip Z/M presence and precision from ext byte */
511  s->has_z = (extended_dims & 0x01);
512  s->has_m = (extended_dims & 0x02) >> 1;
513  precision_z = (extended_dims & 0x1C) >> 2;
514  precision_m = (extended_dims & 0xE0) >> 5;
515 
516  /* Convert the precision into factor */
517  s->factor_z = pow(10, (double)precision_z);
518  s->factor_m = pow(10, (double)precision_m);
519  }
520  else
521  {
522  s->has_z = 0;
523  s->has_m = 0;
524  s->factor_z = 0;
525  s->factor_m = 0;
526  }
527 
528  /* Read the size, if there is one */
529  if ( s->has_size )
530  {
532  }
533 
534  /* Calculate the number of dimensions */
535  s->ndims = 2 + s->has_z + s->has_m;
536 
537  return;
538 }
uint8_t has_z
Definition: lwin_twkb.c:35
uint8_t is_empty
Definition: lwin_twkb.c:37
double factor_z
Definition: lwin_twkb.c:41
uint64_t size
Definition: lwin_twkb.c:44
uint8_t has_m
Definition: lwin_twkb.c:36
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
uint8_t has_idlist
Definition: lwin_twkb.c:34
static uint32_t lwtype_from_twkb_type(uint8_t twkb_type)
Definition: lwin_twkb.c:116
uint8_t has_bbox
Definition: lwin_twkb.c:32
static uint8_t byte_from_twkb_state(twkb_parse_state *s)
Byte Read a byte and advance the parse state forward.
Definition: lwin_twkb.c:146
uint32_t lwtype
Definition: lwin_twkb.c:30
uint8_t precision
Definition: cu_in_twkb.c:25
double factor_m
Definition: lwin_twkb.c:42
static uint64_t twkb_parse_state_uvarint(twkb_parse_state *s)
Definition: lwin_twkb.c:87
uint8_t has_size
Definition: lwin_twkb.c:33
int8_t unzigzag8(uint8_t val)
Definition: varint.c:195

Here is the call graph for this function:

Here is the caller graph for this function: