PostGIS  2.4.9dev-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 196 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().

197 {
198  char *iptr = (char*)(&ival);
199  int i = 0;
200 
201  if ( sizeof(int) != WKB_INT_SIZE )
202  {
203  lwerror("Machine int size is not %d bytes!", WKB_INT_SIZE);
204  }
205  LWDEBUGF(4, "Writing value '%u'", ival);
206  if ( variant & WKB_HEX )
207  {
208  int swap = wkb_swap_bytes(variant);
209  /* Machine/request arch mismatch, so flip byte order */
210  for ( i = 0; i < WKB_INT_SIZE; i++ )
211  {
212  int j = (swap ? WKB_INT_SIZE - 1 - i : i);
213  uint8_t b = iptr[j];
214  /* Top four bits to 0-F */
215  buf[2*i] = hexchr[b >> 4];
216  /* Bottom four bits to 0-F */
217  buf[2*i+1] = hexchr[b & 0x0F];
218  }
219  return buf + (2 * WKB_INT_SIZE);
220  }
221  else
222  {
223  /* Machine/request arch mismatch, so flip byte order */
224  if ( wkb_swap_bytes(variant) )
225  {
226  for ( i = 0; i < WKB_INT_SIZE; i++ )
227  {
228  buf[i] = iptr[WKB_INT_SIZE - 1 - i];
229  }
230  }
231  /* If machine arch and requested arch match, don't flip byte order */
232  else
233  {
234  memcpy(buf, iptr, WKB_INT_SIZE);
235  }
236  return buf + WKB_INT_SIZE;
237  }
238 }
#define WKB_INT_SIZE
uint8_t variant
Definition: cu_in_twkb.c:26
static char * hexchr
Definition: lwout_wkb.c:37
static int wkb_swap_bytes(uint8_t variant)
Definition: lwout_wkb.c:182
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
unsigned char uint8_t
Definition: uthash.h:79
#define WKB_HEX
Definition: liblwgeom.h:2079
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:
Here is the caller graph for this function: