]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/include/beast/websocket/detail/debug.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / websocket / detail / debug.hpp
1 //
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7
8 #ifndef BEAST_WEBSOCKET_DETAIL_DEBUG_HPP
9 #define BEAST_WEBSOCKET_DETAIL_DEBUG_HPP
10
11 #include <boost/asio/buffer.hpp>
12 #include <iomanip>
13 #include <sstream>
14 #include <string>
15
16 namespace beast {
17 namespace websocket {
18 namespace detail {
19
20 template<class = void>
21 std::string
22 to_hex(boost::asio::const_buffer b)
23 {
24 using namespace boost::asio;
25 std::stringstream ss;
26 auto p = buffer_cast<std::uint8_t const*>(b);
27 auto n = buffer_size(b);
28 while(n--)
29 {
30 ss <<
31 std::setfill('0') <<
32 std::setw(2) <<
33 std::hex << int(*p++) << " ";
34 }
35 return ss.str();
36 }
37
38 template<class Buffers>
39 std::string
40 to_hex(Buffers const& bs)
41 {
42 std::string s;
43 for(auto const& b : bs)
44 s.append(to_hex(boost::asio::const_buffer(b)));
45 return s;
46 }
47
48 template<class Buffers>
49 std::string
50 buffers_to_string(Buffers const& bs)
51 {
52 using namespace boost::asio;
53 std::string s;
54 s.reserve(buffer_size(bs));
55 for(auto const& b : bs)
56 s.append(buffer_cast<char const*>(b),
57 buffer_size(b));
58 return s;
59 }
60
61 template<class = void>
62 std::string
63 format(std::string s)
64 {
65 auto const w = 84;
66 for(int n = w*(s.size()/w); n>0; n-=w)
67 s.insert(n, 1, '\n');
68 return s;
69 }
70
71 } // detail
72 } // websocket
73 } // beast
74
75 #endif