PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ bytes_from_hexbytes()

uint8_t* bytes_from_hexbytes ( const char *  hexbuf,
size_t  hexsize 
)

Definition at line 87 of file lwin_wkb.c.

References hex2char, lwalloc(), and lwerror().

Referenced by lwgeom_from_hexwkb(), and LWGEOM_in().

88 {
89  uint8_t *buf = NULL;
90  register uint8_t h1, h2;
91  uint32_t i;
92 
93  if( hexsize % 2 )
94  lwerror("Invalid hex string, length (%d) has to be a multiple of two!", hexsize);
95 
96  buf = lwalloc(hexsize/2);
97 
98  if( ! buf )
99  lwerror("Unable to allocate memory buffer.");
100 
101  for( i = 0; i < hexsize/2; i++ )
102  {
103  h1 = hex2char[(int)hexbuf[2*i]];
104  h2 = hex2char[(int)hexbuf[2*i+1]];
105  if( h1 > 15 )
106  lwerror("Invalid hex character (%c) encountered", hexbuf[2*i]);
107  if( h2 > 15 )
108  lwerror("Invalid hex character (%c) encountered", hexbuf[2*i+1]);
109  /* First character is high bits, second is low bits */
110  buf[i] = ((h1 & 0x0F) << 4) | (h2 & 0x0F);
111  }
112  return buf;
113 }
unsigned int uint32_t
Definition: uthash.h:78
static uint8_t hex2char[256]
Definition: lwin_wkb.c:61
void * lwalloc(size_t size)
Definition: lwutil.c:229
unsigned char uint8_t
Definition: uthash.h:79
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: