title: Binary Serialization Using Boost and uint8_t
body: <p>When working with binary data I tend to use <code>uint8_t</code>. I guess that just seems like the type of a byte to me. However, I can't figure out how to get the binary serialization in boost to work with that type. Am I asking the impossible or just missing something simple?</p>
  
  <p>This example program doesn't compile on VS2013 with some complaint about not being about to convert the streams into <code>std::ostream</code> or <code>std::istream</code>.</p>
  
  <p>The program works fine with <code>char</code> instead of <code>uint8_t</code>, but that bugs me. :)</p>
  
  <pre><code>#include &lt;cstdlib&gt; // EXIT_SUCCESS
  #include &lt;vector&gt;
  
  #include "boost/archive/binary_iarchive.hpp"
  #include "boost/archive/binary_oarchive.hpp"
  #include "boost/iostreams/device/array.hpp"
  #include "boost/iostreams/device/back_inserter.hpp"
  #include "boost/iostreams/stream_buffer.hpp"
  
  int main(int argc, char** argv)
  {
     typedef std::vector&lt; uint8_t &gt; Buffer;
     Buffer buffer;
  
     // Serialization
     {
        int foo = 1;
  
        typedef boost::iostreams::back_insert_device&lt; Buffer &gt; Device;
        Device device(buffer);
  
        typedef boost::iostreams::stream_buffer&lt; Device &gt; Stream;
        Stream stream(device);
  
        {
           boost::archive::binary_oarchive archive(stream);
           archive &lt;&lt; foo;
        }
     }
  
     // Deserialization
     {
        int foo;
  
        typedef boost::iostreams::basic_array_source&lt; uint8_t &gt; Device;
        Device device(buffer.data(), buffer.size());
  
        typedef boost::iostreams::stream_buffer&lt; Device &gt; Stream;
        Stream stream(device);
  
        {
           boost::archive::binary_iarchive archive(stream);
           archive &gt;&gt; foo;
        }
     }
  
     return EXIT_SUCCESS;
  }
  </code></pre>