PostGIS  2.2.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 229 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().

230 {
231  char *dptr = (char*)(&d);
232  int i = 0;
233 
234  if ( sizeof(double) != WKB_DOUBLE_SIZE )
235  {
236  lwerror("Machine double size is not %d bytes!", WKB_DOUBLE_SIZE);
237  }
238 
239  if ( variant & WKB_HEX )
240  {
241  int swap = wkb_swap_bytes(variant);
242  /* Machine/request arch mismatch, so flip byte order */
243  for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
244  {
245  int j = (swap ? WKB_DOUBLE_SIZE - 1 - i : i);
246  uint8_t b = dptr[j];
247  /* Top four bits to 0-F */
248  buf[2*i] = hexchr[b >> 4];
249  /* Bottom four bits to 0-F */
250  buf[2*i+1] = hexchr[b & 0x0F];
251  }
252  return buf + (2 * WKB_DOUBLE_SIZE);
253  }
254  else
255  {
256  /* Machine/request arch mismatch, so flip byte order */
257  if ( wkb_swap_bytes(variant) )
258  {
259  for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
260  {
261  buf[i] = dptr[WKB_DOUBLE_SIZE - 1 - i];
262  }
263  }
264  /* If machine arch and requested arch match, don't flip byte order */
265  else
266  {
267  memcpy(buf, dptr, WKB_DOUBLE_SIZE);
268  }
269  return buf + WKB_DOUBLE_SIZE;
270  }
271 }
uint8_t variant
Definition: cu_in_twkb.c:26
static char * hexchr
Definition: lwout_wkb.c:23
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
static int wkb_swap_bytes(uint8_t variant)
Definition: lwout_wkb.c:168
#define WKB_HEX
Definition: liblwgeom.h:1935
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: