PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ bytes_from_hexbytes()

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

Definition at line 86 of file lwin_wkb.c.

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

Referenced by lwgeom_from_hexwkb(), and LWGEOM_in().

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