PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ bytebuffer_append_double()

void bytebuffer_append_double ( bytebuffer_t buf,
const double  val,
int  swap 
)

Writes a float64 to the buffer.

Definition at line 271 of file bytebuffer.c.

References bytebuffer_t::buf_start, bytebuffer_makeroom(), LWDEBUG, LWDEBUGF, lwerror(), WKB_DOUBLE_SIZE, and bytebuffer_t::writecursor.

272 {
273  LWDEBUGF(2,"Entered bytebuffer_append_double with value %lf swap = %d", val, swap);
274 
275  LWDEBUGF(4,"buf_start = %p and write_cursor=%p", buf->buf_start,buf->writecursor);
276  char *dptr = (char*)(&val);
277  int i = 0;
278 
279  if ( sizeof(double) != WKB_DOUBLE_SIZE )
280  {
281  lwerror("Machine double size is not %d bytes!", WKB_DOUBLE_SIZE);
282  }
283 
285 
286  /* Machine/request arch mismatch, so flip byte order */
287  if ( swap )
288  {
289  LWDEBUG(4,"Ok, let's do the swapping thing");
290  for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
291  {
292  *(buf->writecursor) = dptr[WKB_DOUBLE_SIZE - 1 - i];
293  buf->writecursor += 1;
294  }
295  }
296  /* If machine arch and requested arch match, don't flip byte order */
297  else
298  {
299  LWDEBUG(4,"Ok, let's do the memcopying thing");
300  memcpy(buf->writecursor, dptr, WKB_DOUBLE_SIZE);
302  }
303 
304  LWDEBUG(4,"Return from bytebuffer_append_double");
305  return;
306 
307 }
uint8_t * writecursor
Definition: bytebuffer.h:53
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
uint8_t * buf_start
Definition: bytebuffer.h:52
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
static void bytebuffer_makeroom(bytebuffer_t *s, size_t size_to_add)
If necessary, expand the bytebuffer_t internal buffer to accomodate the specified additional size...
Definition: bytebuffer.c:131
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: