PostGIS  2.1.10dev-r@@SVN_REVISION@@
static uint8_t* double_to_wkb_buf ( const double  d,
uint8_t *  buf,
uint8_t  variant 
)
static

Definition at line 227 of file lwout_wkb.c.

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

Referenced by ptarray_to_wkb_buf().

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

Here is the call graph for this function:

Here is the caller graph for this function: