Decode a hex string written by markerHexEncode.
| 563 | |
| 564 | /// Decode a hex string written by markerHexEncode. |
| 565 | static String markerHexDecode(const String & s) |
| 566 | { |
| 567 | if (s.size() % 2 != 0) |
| 568 | throw Exception(ErrorCodes::CANNOT_PARSE_TEXT, "markerHexDecode: odd-length input '{}'", s); |
| 569 | auto nibble = [&](const char c) -> uint8_t |
| 570 | { |
| 571 | if (c >= '0' && c <= '9') |
| 572 | return static_cast<uint8_t>(c - '0'); |
| 573 | if (c >= 'A' && c <= 'F') |
| 574 | return static_cast<uint8_t>(c - 'A' + 10); |
| 575 | if (c >= 'a' && c <= 'f') |
| 576 | return static_cast<uint8_t>(c - 'a' + 10); |
| 577 | throw Exception(ErrorCodes::CANNOT_PARSE_TEXT, "markerHexDecode: invalid hex character '{}' in '{}'", c, s); |
| 578 | }; |
| 579 | String result; |
| 580 | result.reserve(s.size() / 2); |
| 581 | for (size_t i = 0; i < s.size(); i += 2) |
| 582 | result += static_cast<char>((nibble(s[i]) << 4) | nibble(s[i + 1])); |
| 583 | return result; |
| 584 | } |
| 585 | |
| 586 | /// Returns false when server is not available. |
| 587 | bool Client::buzzHouse() |