I am trying to use a std::istream as data source. I want to place custom binary data in the istream's stream buffer so it can later be retrieved from the istream.
I have read about boost::asio::streambuf and how it is used to do exactly what I want but using a socket as data source instead of an in-memory buffer, which is what I would like to use.
From what I understand from the documentation, the steps should be:
- Create a boost::asio::streambuf
- Create a std::istream passing the streambuf
- Invoke boost::asio::streambuf::prepare to get the list of buffers representing the output sequence.
- Somehow write in the output sequence.
- Invoke boost::asio::streambuf::commit to move what I wrote in the output sequence to the input sequence.
- Read from the std::istream from step 2 normally with std::stream::read.
I don't know how to address step 4, so I don't know even if I'm going in the right direction.
Are the depicted steps correct? If so, how to address step 4?