Reputation: 4376
I want to make a read-only buffer from raw data I have so that I can call boost::asio::buffer_copy
several times in a row without worrying about maintaining the right offset and length.
Is the streambuf the right solutions in this case? If it is, how can I create streambuf from const char* raw data without copying it?
Upvotes: 2
Views: 685
Reputation: 103751
Since you're using Boost, you can use Boost.Iostreams.
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/stream_buffer.hpp>
int main()
{
namespace bio = boost::iostreams;
const char source[] = "hello world";
bio::stream_buffer<bio::array_source> stream_buffer(source, sizeof(source));
}
Upvotes: 2