PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ double_to_wkb_buf()

static uint8_t* double_to_wkb_buf ( const double  d,
uint8_t *  buf,
uint8_t  variant 
)
static

Definition at line 243 of file lwout_wkb.c.

References hexchr, lwerror(), WKB_DOUBLE_SIZE, WKB_HEX, and wkb_swap_bytes().

Referenced by empty_to_wkb_buf(), and ptarray_to_wkb_buf().

244 {
245  char *dptr = (char*)(&d);
246  int i = 0;
247 
248  if ( sizeof(double) != WKB_DOUBLE_SIZE )
249  {
250  lwerror("Machine double size is not %d bytes!", WKB_DOUBLE_SIZE);
251  }
252 
253  if ( variant & WKB_HEX )
254  {
255  int swap = wkb_swap_bytes(variant);
256  /* Machine/request arch mismatch, so flip byte order */
257  for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
258  {
259  int j = (swap ? WKB_DOUBLE_SIZE - 1 - i : i);
260  uint8_t b = dptr[j];
261  /* Top four bits to 0-F */
262  buf[2*i] = hexchr[b >> 4];
263  /* Bottom four bits to 0-F */
264  buf[2*i+1] = hexchr[b & 0x0F];
265  }
266  return buf + (2 * WKB_DOUBLE_SIZE);
267  }
268  else
269  {
270  /* Machine/request arch mismatch, so flip byte order */
271  if ( wkb_swap_bytes(variant) )
272  {
273  for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
274  {
275  buf[i] = dptr[WKB_DOUBLE_SIZE - 1 - i];
276  }
277  }
278  /* If machine arch and requested arch match, don't flip byte order */
279  else
280  {
281  memcpy(buf, dptr, WKB_DOUBLE_SIZE);
282  }
283  return buf + WKB_DOUBLE_SIZE;
284  }
285 }
uint8_t variant
Definition: cu_in_twkb.c:26
static char * hexchr
Definition: lwout_wkb.c:37
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
static int wkb_swap_bytes(uint8_t variant)
Definition: lwout_wkb.c:182
#define WKB_HEX
Definition: liblwgeom.h:2051
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: