PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ bytebuffer_append_int()

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

Definition at line 266 of file bytebuffer.c.

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

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