PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ integer_to_wkb_buf()

static uint8_t* integer_to_wkb_buf ( const int  ival,
uint8_t *  buf,
uint8_t  variant 
)
static

Definition at line 182 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().

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