PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ bytes_from_hexbytes()

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

Definition at line 92 of file lwin_wkb.c.

93 {
94  uint8_t *buf = NULL;
95  register uint8_t h1, h2;
96  uint32_t i;
97 
98  if( hexsize % 2 )
99  lwerror("Invalid hex string, length (%d) has to be a multiple of two!", hexsize);
100 
101  buf = lwalloc(hexsize/2);
102 
103  if( ! buf )
104  lwerror("Unable to allocate memory buffer.");
105 
106  for( i = 0; i < hexsize/2; i++ )
107  {
108  h1 = hex2char[(int)hexbuf[2*i]];
109  h2 = hex2char[(int)hexbuf[2*i+1]];
110  if( h1 > 15 )
111  lwerror("Invalid hex character (%c) encountered", hexbuf[2*i]);
112  if( h2 > 15 )
113  lwerror("Invalid hex character (%c) encountered", hexbuf[2*i+1]);
114  /* First character is high bits, second is low bits */
115  buf[i] = ((h1 & 0x0F) << 4) | (h2 & 0x0F);
116  }
117  return buf;
118 }
void * lwalloc(size_t size)
Definition: lwutil.c:227
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static uint8_t hex2char[256]
Definition: lwin_wkb.c:66

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

Referenced by lwgeom_from_hexwkb(), and LWGEOM_in().

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