title: boost::asio read n bytes from socket to streambuf
body: <p>I have a serialized structure, which is being sent via socket. I need to read it in chunks, since one of its fields contains the size of the data remaining: I need to read first few bytes, find out the length and read the rest. This is what I have got:</p>
  
  <pre><code>    boost::asio::streambuf buffer;
      boost::system::error_code err_code;
      // here I need to read only first 16 bytes
      boost::asio::read(socket, buffer, err_code);
      std::istream is(&amp;buffer);
      boost::archive::binary_iarchive ia(is);
      ia &gt;&gt; my_struct;
  </code></pre>
  
  <p>I have taken a look at</p>
  
  <pre><code>    boost::asio::async_read(s, boost::asio::buffer(data, size), handler);
  </code></pre>
  
  <p>but it can only read data to boost::asio::buffer. I am wondering if I could do the same with boost::asio::streambuf? Thank you in advance.</p>