PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ integer_to_wkb_buf()

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

Definition at line 197 of file lwout_wkb.c.

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

References hexchr, LWDEBUGF, lwerror(), variant, 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().

Here is the call graph for this function:
Here is the caller graph for this function: