PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_raster_from_hexwkb()

rt_raster rt_raster_from_hexwkb ( const char *  hexwkb,
uint32_t  hexwkbsize 
)

Construct an rt_raster from a text HEXWKB representation.

Parameters
hexwkb: an hex-encoded stream
hexwkbsize: size (in bytes) of the hexwkb stream
Returns
an rt_raster or NULL on error (out of memory or malformed WKB).

Definition at line 406 of file rt_wkb.c.

406  {
407  rt_raster ret = NULL;
408  uint8_t* wkb = NULL;
409  uint32_t wkbsize = 0;
410  uint32_t i = 0;
411 
412  assert(NULL != hexwkb);
413 
414  RASTER_DEBUGF(3, "input wkb: %s", hexwkb);
415  RASTER_DEBUGF(3, "input wkbsize: %d", hexwkbsize);
416 
417  if (hexwkbsize % 2) {
418  rterror("rt_raster_from_hexwkb: Raster HEXWKB input must have an even number of characters");
419  return NULL;
420  }
421  wkbsize = hexwkbsize / 2;
422 
423  wkb = rtalloc(wkbsize);
424  if (!wkb) {
425  rterror("rt_raster_from_hexwkb: Out of memory allocating memory for decoding HEXWKB");
426  return NULL;
427  }
428 
429  /* parse full hex */
430  for (i = 0; i < wkbsize; ++i) {
431  wkb[i] = parse_hex((char*) & (hexwkb[i * 2]));
432  }
433 
434  ret = rt_raster_from_wkb(wkb, wkbsize);
435  rtdealloc(wkb); /* as long as rt_raster_from_wkb copies memory */
436 
437  return ret;
438 }
uint8_t parse_hex(char *str)
Convert a single hex digit into the corresponding char.
Definition: lwgeom_api.c:547
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
void rtdealloc(void *mem)
Definition: rt_context.c:186
rt_raster rt_raster_from_wkb(const uint8_t *wkb, uint32_t wkbsize)
Construct an rt_raster from a binary WKB representation.
Definition: rt_wkb.c:276
unsigned int uint32_t
Definition: uthash.h:78
unsigned char uint8_t
Definition: uthash.h:79

References parse_hex(), RASTER_DEBUGF, rt_raster_from_wkb(), rtalloc(), rtdealloc(), and rterror().

Referenced by RASTER_fromHexWKB(), RASTER_in(), and test_raster_wkb().

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