PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ bytebuffer_append_int()

void bytebuffer_append_int ( bytebuffer_t buf,
const int  val,
int  swap 
)

Definition at line 262 of file bytebuffer.c.

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

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