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

Definition at line 72 of file lwin_wkb.c.

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

Referenced by lwgeom_from_hexwkb(), and LWGEOM_in().

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

Here is the call graph for this function:

Here is the caller graph for this function: