PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ bytebuffer_append_int()

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

Definition at line 214 of file bytebuffer.c.

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

215 {
216  LWDEBUGF(2,"Entered bytebuffer_append_int with value %d, swap = %d", val, swap);
217 
218  LWDEBUGF(4,"buf_start = %p and write_cursor=%p", buf->buf_start,buf->writecursor);
219  char *iptr = (char*)(&val);
220  int i = 0;
221 
222  if ( sizeof(int) != WKB_INT_SIZE )
223  {
224  lwerror("Machine int size is not %d bytes!", WKB_INT_SIZE);
225  }
226 
228  /* Machine/request arch mismatch, so flip byte order */
229  if ( swap)
230  {
231  LWDEBUG(4,"Ok, let's do the swaping thing");
232  for ( i = 0; i < WKB_INT_SIZE; i++ )
233  {
234  *(buf->writecursor) = iptr[WKB_INT_SIZE - 1 - i];
235  buf->writecursor += 1;
236  }
237  }
238  /* If machine arch and requested arch match, don't flip byte order */
239  else
240  {
241  LWDEBUG(4,"Ok, let's do the memcopying thing");
242  memcpy(buf->writecursor, iptr, WKB_INT_SIZE);
243  buf->writecursor += WKB_INT_SIZE;
244  }
245 
246  LWDEBUGF(4,"buf_start = %p and write_cursor=%p", buf->buf_start,buf->writecursor);
247  return;
248 
249 }
#define WKB_INT_SIZE
uint8_t * writecursor
Definition: bytebuffer.h:41
#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: