9#include "../microfmt.hpp"
10#include <boost/asio/ip/address.hpp>
11#include <boost/asio/ip/basic_endpoint.hpp>
19 const auto bytes = address.to_bytes();
24 const auto bytes = address.to_bytes();
27 RELOCO_BEGIN_UNSAFE_BUFFER_USAGE;
28 for (std::size_t index = 0; index < 8; ++index) {
29 words[index] =
static_cast<uint16_t
>((
static_cast<uint16_t
>(
bytes[index * 2]) << 8) |
bytes[index * 2 + 1]);
32 std::size_t best_start = 8;
33 std::size_t best_length = 0;
34 for (std::size_t index = 0; index < 8;) {
35 if (words[index] != 0) {
39 const std::size_t start = index;
40 while (index < 8 && words[index] == 0) {
43 const std::size_t length = index - start;
44 if (length >= 2 && length > best_length) {
50 for (std::size_t index = 0; index < 8;) {
51 if (index == best_start) {
56 if (index != 0 && index != best_start + best_length) {
59 detail::format_unsigned<detail::radix::hex>(out, words[index],
false, 0);
62 RELOCO_END_UNSAFE_BUFFER_USAGE;
64 if (address.scope_id() != 0) {
66 detail::format_unsigned<detail::radix::decimal>(out, address.scope_id(),
false, 0);
72template <>
struct formatter<boost::asio::ip::address_v4> {
75 void format(
const boost::asio::ip::address_v4 &address,
const sink &out)
const noexcept {
80template <>
struct formatter<boost::asio::ip::address_v6> {
83 void format(
const boost::asio::ip::address_v6 &address,
const sink &out)
const noexcept {
88template <>
struct formatter<boost::asio::ip::address> {
91 void format(
const boost::asio::ip::address &address,
const sink &out)
const noexcept {
92 if (address.is_v4()) {
100template <
typename InternetProtocol>
struct formatter<boost::asio::ip::basic_endpoint<InternetProtocol>> {
103 void format(
const boost::asio::ip::basic_endpoint<InternetProtocol> &endpoint,
const sink &out)
const noexcept {
104 const auto address = endpoint.address();
105 if (address.is_v6()) {
113 detail::format_unsigned<detail::radix::decimal>(out, endpoint.port(),
false, 0);
Definition microfmt.hpp:881
void format_boost_address_v6(const boost::asio::ip::address_v6 &address, const sink &out) noexcept
Definition boost_net.hpp:23
void format_boost_address_v4(const boost::asio::ip::address_v4 &address, const sink &out) noexcept
Definition boost_net.hpp:18
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
RELOCO_CONSTEXPR20 void format_to(const sink &out, microfmt::string_view fmt, const Args &...args) noexcept
Definition microfmt.hpp:1766
constexpr bytes_view bytes(uint64_t count) noexcept
Definition format_helpers.hpp:82