| 327 | } |
| 328 | |
| 329 | bool Data::fromHex(std::string in, void *data) |
| 330 | { |
| 331 | if (in.empty() || !data || !String::validateHex(in)) |
| 332 | return false; |
| 333 | |
| 334 | size_t length = in.length(); |
| 335 | auto *byteData = reinterpret_cast<uint8_t *>(data); |
| 336 | |
| 337 | auto charToNibble = [](char c) -> uint8_t { |
| 338 | if (c >= '0' && c <= '9') |
| 339 | return c - '0'; |
| 340 | if (c >= 'a' && c <= 'f') |
| 341 | return c - 'a' + 10; |
| 342 | if (c >= 'A' && c <= 'F') |
| 343 | return c - 'A' + 10; |
| 344 | return 0; |
| 345 | }; |
| 346 | |
| 347 | for (size_t strIndex = 0, dataIndex = 0; strIndex < length; strIndex += 2, ++dataIndex) |
| 348 | { |
| 349 | byteData[dataIndex] = (charToNibble(in[strIndex]) << 4) | charToNibble(in[strIndex + 1]); |
| 350 | } |
| 351 | |
| 352 | return true; |
| 353 | } |
| 354 | |
| 355 | std::string Data::toHex(const void *data, const size_t dataLength) |
| 356 | { |
nothing calls this directly
no outgoing calls
no test coverage detected