diff --git a/src/util/output.hpp b/src/util/output.hpp index 60b32b2..4906d87 100644 --- a/src/util/output.hpp +++ b/src/util/output.hpp @@ -143,6 +143,30 @@ std::ostream & operator<<(std::ostream & os, const print_hex & s) { return os; } +struct print_hex_string { + + const char * data; + size_t size; + + explicit print_hex_string(const char * data, size_t size) : data(data), size(size) { } + +}; + +inline std::ostream & operator<<(std::ostream & os, const print_hex_string & s) { + + std::ios_base::fmtflags old = os.flags(); + char oldfill = os.fill('0'); + + os << std::hex; + for(size_t i = 0; i < s.size; i++) { + os << std::setw(2) << int(boost::uint8_t(s.data[i])); + } + + os.fill(oldfill); + os.setf(old, std::ios_base::basefield); + return os; +} + } // namespace detail template @@ -150,6 +174,14 @@ detail::print_hex print_hex(T value) { return detail::print_hex(value); } +inline detail::print_hex_string print_hex(const char * data, size_t size) { + return detail::print_hex_string(data, size); +} + +inline detail::print_hex_string print_hex(const std::string & data) { + return print_hex(data.c_str(), data.size()); +} + const char * const byte_size_units[] = { "B", "KiB",