2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_BUFFERS_TO_STRING_HPP
11 #define BOOST_BEAST_BUFFERS_TO_STRING_HPP
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/detail/type_traits.hpp>
15 #include <boost/asio/buffer.hpp>
21 /** Return a string representing the contents of a buffer sequence.
23 This function returns a string representing an entire buffer
24 sequence. Nulls and unprintable characters in the buffer
25 sequence are inserted to the resulting string as-is. No
26 character conversions are performed.
28 @param buffers The buffer sequence to convert
32 This function writes a buffer sequence converted to a string
36 template<class ConstBufferSequence>
37 void print(ConstBufferSequence const& buffers)
39 std::cout << buffers_to_string(buffers) << std::endl;
43 template<class ConstBufferSequence>
45 buffers_to_string(ConstBufferSequence const& buffers)
48 result.reserve(boost::asio::buffer_size(buffers));
49 for(boost::asio::const_buffer buffer :
50 detail::buffers_range(buffers))
51 result.append(reinterpret_cast<
52 char const*>(buffer.data()), buffer.size());