title: How to avoid "boost::archive::archive_exception" when deserializing multiple structs from a message queue?
body: <p>I´m reading a message queue, using <a href="http://www.boost.org/doc/libs/1_46_0/libs/serialization/doc/index.html" rel="nofollow">Boost.Serialization (v1.46)</a>. Everything works fine as long as the queue contains only one element. But when I read a queue which contains more than one element the, following exception is thrown:</p>
  
  <pre><code>terminate called after throwing an instance of 'boost::archive::archive_exception'
  what():  invalid signature
  </code></pre>
  
  <p>The <code>archive_exception.hpp</code> says <code>invalid signature</code> <code>// first line of archive does not contain expected string"</code></p>
  
  <p>The class I´m serializing and deserializing looks as followed:</p>
  
  <p></p>
  
  <pre><code>#define MAX_SIZE 1000
  
  class IpcMsg {
  
  public:
      IpcMsg(int logLevel = 0, std::string logMsg = "") :
              logLevel(logLevel), logMsg(logMsg) {
      }
      ;
  
      int logLevel;
      std::string logMsg;
  
  private:
      friend class boost::serialization::access;
  
      template&lt;class Archive&gt;
      void serialize(Archive &amp; ar, const unsigned int version) {
          ar &amp; logLevel;
          ar &amp; logMsg;
      }
  };
  </code></pre>
  
  <p></p>
  
  <p>serializing :</p>
  
  <p></p>
  
  <pre><code>try
      {
          message_queue mq
              (
               open_or_create,
               "mq",
               100,
               MAX_SIZE
              );
  
          IpcMsg logMsg(1, "Test");
  
          std::stringstream oss;
  
          boost::archive::text_oarchive oa(oss);
          oa &lt;&lt; logMsg;
  
          std::string serialized_string(oss.str());
          mq.send(serialized_string.data(), serialized_string.size(), 0);
      }
      catch(interprocess_exception &amp;ex)
      {
          std::cerr &lt;&lt; ex.what() &lt;&lt; std::endl;
      }
  </code></pre>
  
  <p></p>
  
  <p>deserializing:</p>
  
  <p></p>
  
  <pre><code>...
  IpcMsg logEntry;
  
  std::stringstream iss;
  std::string serialized_string;
  serialized_string.resize(MAX_SIZE);
  
  while(mq.try_receive(&amp;serialized_string[0], MAX_SIZE, recvd_size, priority)){
  
      iss &lt;&lt; serialized_string;
  
      boost::archive::text_iarchive ia(iss);
      ia &gt;&gt; logEntry;
  
       msgs.push_back(logEntry);
  
       std::cout &lt;&lt; logEntry.logLevel &lt;&lt; std::endl;
       std::cout &lt;&lt; logEntry.logMsg &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p></p>