PostGIS  2.3.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 259 of file bytebuffer.c.

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

260 {
261  LWDEBUGF(2,"Entered bytebuffer_append_double with value %lf swap = %d", val, swap);
262 
263  LWDEBUGF(4,"buf_start = %p and write_cursor=%p", buf->buf_start,buf->writecursor);
264  char *dptr = (char*)(&val);
265  int i = 0;
266 
267  if ( sizeof(double) != WKB_DOUBLE_SIZE )
268  {
269  lwerror("Machine double size is not %d bytes!", WKB_DOUBLE_SIZE);
270  }
271 
273 
274  /* Machine/request arch mismatch, so flip byte order */
275  if ( swap )
276  {
277  LWDEBUG(4,"Ok, let's do the swapping thing");
278  for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
279  {
280  *(buf->writecursor) = dptr[WKB_DOUBLE_SIZE - 1 - i];
281  buf->writecursor += 1;
282  }
283  }
284  /* If machine arch and requested arch match, don't flip byte order */
285  else
286  {
287  LWDEBUG(4,"Ok, let's do the memcopying thing");
288  memcpy(buf->writecursor, dptr, WKB_DOUBLE_SIZE);
290  }
291 
292  LWDEBUG(4,"Return from bytebuffer_append_double");
293  return;
294 
295 }
uint8_t * writecursor
Definition: bytebuffer.h:41
#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:40
#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:119
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: