PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ double_to_wkb_buf()

static uint8_t * double_to_wkb_buf ( const double  d,
uint8_t *  buf,
uint8_t  variant 
)
static

Definition at line 272 of file lwout_wkb.c.

273{
274 uint8_t *dptr = (uint8_t *)(&d);
275 int i = 0;
276
277 if ( sizeof(double) != WKB_DOUBLE_SIZE )
278 {
279 lwerror("Machine double size is not %d bytes!", WKB_DOUBLE_SIZE);
280 }
281
282 if ( variant & WKB_HEX )
283 {
284 int swap = wkb_swap_bytes(variant);
285 /* Machine/request arch mismatch, so flip byte order */
286 for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
287 {
288 int j = (swap ? WKB_DOUBLE_SIZE - 1 - i : i);
289 uint8_t b = dptr[j];
290 /* Top four bits to 0-F */
291 buf[2*i] = hexchr[b >> 4];
292 /* Bottom four bits to 0-F */
293 buf[2*i+1] = hexchr[b & 0x0F];
294 }
295 return buf + (2 * WKB_DOUBLE_SIZE);
296 }
297 else
298 {
299 /* Machine/request arch mismatch, so flip byte order */
300 if ( wkb_swap_bytes(variant) )
301 {
302 for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
303 {
304 buf[i] = dptr[WKB_DOUBLE_SIZE - 1 - i];
305 }
306 }
307 /* If machine arch and requested arch match, don't flip byte order */
308 else
309 {
310 memcpy(buf, dptr, WKB_DOUBLE_SIZE);
311 }
312 return buf + WKB_DOUBLE_SIZE;
313 }
314}
static uint8_t variant
Definition cu_in_twkb.c:26
#define WKB_HEX
Definition liblwgeom.h:2215
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static char * hexchr
Definition lwout_wkb.c:38
static int wkb_swap_bytes(uint8_t variant)
Definition lwout_wkb.c:182

References hexchr, lwerror(), variant, WKB_DOUBLE_SIZE, WKB_HEX, and wkb_swap_bytes().

Referenced by ptarray_to_wkb_buf().

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