PostGIS  2.4.9dev-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 311 of file bytebuffer.c.

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

312 {
313  LWDEBUGF(2,"Entered bytebuffer_append_double with value %lf swap = %d", val, swap);
314 
315  LWDEBUGF(4,"buf_start = %p and write_cursor=%p", buf->buf_start,buf->writecursor);
316  char *dptr = (char*)(&val);
317  int i = 0;
318 
319  if ( sizeof(double) != WKB_DOUBLE_SIZE )
320  {
321  lwerror("Machine double size is not %d bytes!", WKB_DOUBLE_SIZE);
322  }
323 
325 
326  /* Machine/request arch mismatch, so flip byte order */
327  if ( swap )
328  {
329  LWDEBUG(4,"Ok, let's do the swapping thing");
330  for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
331  {
332  *(buf->writecursor) = dptr[WKB_DOUBLE_SIZE - 1 - i];
333  buf->writecursor += 1;
334  }
335  }
336  /* If machine arch and requested arch match, don't flip byte order */
337  else
338  {
339  LWDEBUG(4,"Ok, let's do the memcopying thing");
340  memcpy(buf->writecursor, dptr, WKB_DOUBLE_SIZE);
342  }
343 
344  LWDEBUG(4,"Return from bytebuffer_append_double");
345  return;
346 
347 }
uint8_t * writecursor
Definition: bytebuffer.h:42
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
uint8_t * buf_start
Definition: bytebuffer.h:41
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
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:140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function: