PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ bytes_from_hexbytes()

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

Definition at line 91 of file lwin_wkb.c.

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

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: