PostGIS  2.1.10dev-r@@SVN_REVISION@@
static uint8_t* integer_to_wkb_buf ( const int  ival,
uint8_t *  buf,
uint8_t  variant 
)
static

Definition at line 180 of file lwout_wkb.c.

References hexchr, LWDEBUGF, lwerror(), WKB_HEX, WKB_INT_SIZE, and wkb_swap_bytes().

Referenced by empty_to_wkb_buf(), lwcollection_to_wkb_buf(), lwline_to_wkb_buf(), lwpoint_to_wkb_buf(), lwpoly_to_wkb_buf(), lwtriangle_to_wkb_buf(), and ptarray_to_wkb_buf().

181 {
182  char *iptr = (char*)(&ival);
183  int i = 0;
184 
185  if ( sizeof(int) != WKB_INT_SIZE )
186  {
187  lwerror("Machine int size is not %d bytes!", WKB_INT_SIZE);
188  }
189  LWDEBUGF(4, "Writing value '%u'", ival);
190  if ( variant & WKB_HEX )
191  {
192  int swap = wkb_swap_bytes(variant);
193  /* Machine/request arch mismatch, so flip byte order */
194  for ( i = 0; i < WKB_INT_SIZE; i++ )
195  {
196  int j = (swap ? WKB_INT_SIZE - 1 - i : i);
197  uint8_t b = iptr[j];
198  /* Top four bits to 0-F */
199  buf[2*i] = hexchr[b >> 4];
200  /* Bottom four bits to 0-F */
201  buf[2*i+1] = hexchr[b & 0x0F];
202  }
203  return buf + (2 * WKB_INT_SIZE);
204  }
205  else
206  {
207  /* Machine/request arch mismatch, so flip byte order */
208  if ( wkb_swap_bytes(variant) )
209  {
210  for ( i = 0; i < WKB_INT_SIZE; i++ )
211  {
212  buf[i] = iptr[WKB_INT_SIZE - 1 - i];
213  }
214  }
215  /* If machine arch and requested arch match, don't flip byte order */
216  else
217  {
218  memcpy(buf, iptr, WKB_INT_SIZE);
219  }
220  return buf + WKB_INT_SIZE;
221  }
222 }
#define WKB_INT_SIZE
static char * hexchr
Definition: lwout_wkb.c:21
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
static int wkb_swap_bytes(uint8_t variant)
Definition: lwout_wkb.c:166
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
#define WKB_HEX
Definition: liblwgeom.h:1772

Here is the call graph for this function:

Here is the caller graph for this function: