26std::string
ipv6(
const std::array<uint16_t, 8>& address)
noexcept {
27 size_t compress_length = 0;
31 if (compress_length <= 1) {
34 compress = compress_length = 8;
37 std::string output(4 * 8 + 7 + 2,
'\0');
38 size_t piece_index = 0;
39 char* point = output.data();
40 char* point_end = output.data() + output.size();
43 if (piece_index == compress) {
47 if (piece_index == 0) {
50 piece_index += compress_length;
51 if (piece_index == 8) {
55 point = std::to_chars(point, point_end, address[piece_index], 16).ptr;
57 if (piece_index == 8) {
63 output.resize(point - output.data());
67std::string
ipv4(
const uint64_t address)
noexcept {
68 std::string output(15,
'\0');
69 char* point = output.data();
70 char* point_end = output.data() + output.size();
71 point = std::to_chars(point, point_end, uint8_t(address >> 24)).ptr;
72 for (
int i = 2; i >= 0; i--) {
74 point = std::to_chars(point, point_end, uint8_t(address >> (i * 8))).ptr;
76 output.resize(point - output.data());