PostGIS  2.1.10dev-r@@SVN_REVISION@@
uint8_t* bytes_from_hexbytes ( const char *  hexbuf,
size_t  hexsize 
)

Definition at line 69 of file lwin_wkb.c.

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

Referenced by lwgeom_from_hexwkb(), and LWGEOM_in().

70 {
71  uint8_t *buf = NULL;
72  register uint8_t h1, h2;
73  int i;
74 
75  if( hexsize % 2 )
76  lwerror("Invalid hex string, length (%d) has to be a multiple of two!", hexsize);
77 
78  buf = lwalloc(hexsize/2);
79 
80  if( ! buf )
81  lwerror("Unable to allocate memory buffer.");
82 
83  for( i = 0; i < hexsize/2; i++ )
84  {
85  h1 = hex2char[(int)hexbuf[2*i]];
86  h2 = hex2char[(int)hexbuf[2*i+1]];
87  if( h1 > 15 )
88  lwerror("Invalid hex character (%c) encountered", hexbuf[2*i]);
89  if( h2 > 15 )
90  lwerror("Invalid hex character (%c) encountered", hexbuf[2*i+1]);
91  /* First character is high bits, second is low bits */
92  buf[i] = ((h1 & 0x0F) << 4) | (h2 & 0x0F);
93  }
94  return buf;
95 }
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
static uint8_t hex2char[256]
Definition: lwin_wkb.c:43
void * lwalloc(size_t size)
Definition: lwutil.c:175

Here is the call graph for this function:

Here is the caller graph for this function: