PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ header_from_twkb_state()

static void header_from_twkb_state ( twkb_parse_state s)
static

Definition at line 490 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(), ovdump::type, and unzigzag8().

Referenced by lwgeom_from_twkb_state().

491 {
492  LWDEBUG(2,"Entering magicbyte_from_twkb_state");
493 
494  uint8_t extended_dims;
495 
496  /* Read the first two bytes */
497  uint8_t type_precision = byte_from_twkb_state(s);
498  uint8_t metadata = byte_from_twkb_state(s);
499 
500  /* Strip type and precision out of first byte */
501  uint8_t type = type_precision & 0x0F;
502  int8_t precision = unzigzag8((type_precision & 0xF0) >> 4);
503 
504  /* Convert TWKB type to internal type */
505  s->lwtype = lwtype_from_twkb_type(type);
506 
507  /* Convert the precision into factor */
508  s->factor = pow(10, (double)precision);
509 
510  /* Strip metadata flags out of second byte */
511  s->has_bbox = metadata & 0x01;
512  s->has_size = (metadata & 0x02) >> 1;
513  s->has_idlist = (metadata & 0x04) >> 2;
514  extended_dims = (metadata & 0x08) >> 3;
515  s->is_empty = (metadata & 0x10) >> 4;
516 
517  /* Flag for higher dims means read a third byte */
518  if ( extended_dims )
519  {
520  int8_t precision_z, precision_m;
521 
522  extended_dims = byte_from_twkb_state(s);
523 
524  /* Strip Z/M presence and precision from ext byte */
525  s->has_z = (extended_dims & 0x01);
526  s->has_m = (extended_dims & 0x02) >> 1;
527  precision_z = (extended_dims & 0x1C) >> 2;
528  precision_m = (extended_dims & 0xE0) >> 5;
529 
530  /* Convert the precision into factor */
531  s->factor_z = pow(10, (double)precision_z);
532  s->factor_m = pow(10, (double)precision_m);
533  }
534  else
535  {
536  s->has_z = 0;
537  s->has_m = 0;
538  s->factor_z = 0;
539  s->factor_m = 0;
540  }
541 
542  /* Read the size, if there is one */
543  if ( s->has_size )
544  {
546  }
547 
548  /* Calculate the number of dimensions */
549  s->ndims = 2 + s->has_z + s->has_m;
550 
551  return;
552 }
uint8_t has_z
Definition: lwin_twkb.c:49
uint8_t is_empty
Definition: lwin_twkb.c:51
double factor_z
Definition: lwin_twkb.c:55
uint64_t size
Definition: lwin_twkb.c:58
uint8_t has_m
Definition: lwin_twkb.c:50
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
uint8_t has_idlist
Definition: lwin_twkb.c:48
static uint32_t lwtype_from_twkb_type(uint8_t twkb_type)
Definition: lwin_twkb.c:130
uint8_t has_bbox
Definition: lwin_twkb.c:46
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:160
uint32_t lwtype
Definition: lwin_twkb.c:44
uint8_t precision
Definition: cu_in_twkb.c:25
double factor_m
Definition: lwin_twkb.c:56
static uint64_t twkb_parse_state_uvarint(twkb_parse_state *s)
Definition: lwin_twkb.c:101
type
Definition: ovdump.py:41
unsigned char uint8_t
Definition: uthash.h:79
uint8_t has_size
Definition: lwin_twkb.c:47
int8_t unzigzag8(uint8_t val)
Definition: varint.c:203
Here is the call graph for this function:
Here is the caller graph for this function: