You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/quic/log.cpp

46 lines
1.0 KiB
C++

#include "log.hpp"
namespace llarp::quic
{
std::ostream&
operator<<(std::ostream& o, const buffer_printer& bp)
{
auto& b = bp.buf;
auto oldfill = o.fill();
o.fill('0');
o << "Buffer[" << b.size() << "/0x" << std::hex << b.size() << " bytes]:";
for (size_t i = 0; i < b.size(); i += 32)
{
o << "\n" << std::setw(4) << i << " ";
size_t stop = std::min(b.size(), i + 32);
for (size_t j = 0; j < 32; j++)
{
auto k = i + j;
if (j % 4 == 0)
o << ' ';
if (k >= stop)
o << " ";
else
o << std::setw(2) << std::to_integer<uint_fast16_t>(b[k]);
}
o << u8"";
for (size_t j = i; j < stop; j++)
{
auto c = std::to_integer<char>(b[j]);
if (c == 0x00)
o << u8"";
else if (c < 0x20 || c > 0x7e)
o << u8"·";
else
o << c;
}
o << u8"";
}
o << std::dec;
o.fill(oldfill);
return o;
}
} // namespace llarp::quic