| | 143 | |
| | 144 | |
| | 145 | static inline uint8_t hextodec(uint8_t val) |
| | 146 | { |
| | 147 | if(val >= '0' && val<='9') |
| | 148 | return val-'0'; |
| | 149 | else if(val >= 'A' && val<='F') |
| | 150 | return 10+(val-'A'); |
| | 151 | else if(val >= 'a' && val<='f') |
| | 152 | return 10+(val-'a'); |
| | 153 | else |
| | 154 | throw RecordTextException("Unknown hexadecimal character '"+lexical_cast<string>(val)+"'"); |
| | 155 | } |
| | 156 | |
| | 157 | |
| | 158 | void HEXDecode(const char* begin, const char* end, string& val) |
| | 159 | { |
| | 160 | if((end - begin)%2) |
| | 161 | throw RecordTextException("Hexadecimal blob with odd number of characters"); |
| | 162 | |
| | 163 | int limit=(end-begin)/2; |
| | 164 | val.resize(limit); |
| | 165 | for(int n=0; n < limit; ++n) { |
| | 166 | val[n] = hextodec(begin[2*n])*16 + hextodec(begin[2*n+1]); |
| | 167 | } |
| | 168 | } |
| | 169 | |
| | 170 | void RecordTextReader::xfrHexBlob(string& val) |
| | 171 | { |
| | 172 | skipSpaces(); |
| | 173 | int pos=d_pos; |
| | 174 | while(d_pos < d_end && !dns_isspace(d_string[d_pos])) |
| | 175 | d_pos++; |
| | 176 | |
| | 177 | HEXDecode(d_string.c_str()+pos, d_string.c_str() + d_pos, val); |
| | 178 | } |
| | 179 | |