title: Is there a better way to do object serialization for this class?
body: <p>I am reading  other's code  and there is a serialization  version of this class:</p>
  <pre><code>struct ObjectInfo
  {
      int32_t m_typeId;
      string m_objectName;
      vector&lt;int32_t&gt; m_haveKeysId; 
      map&lt;int32_t,double&gt; m_objectFeatures;
      
      ObjectInfo():m_typeId(-1),m_objectName(&quot;&quot;)
      {
          m_objectFeatures.clear();
          m_haveKeysId.clear();
      }
  }
  </code></pre>
  <p>The binary version of it is  the following:</p>
  <pre><code>struct ObjectInfo_B
  {
      int32_t m_typeId;
      int32_t m_objectNamePos;
      
      int32_t m_startIndex;
      int32_t m_endIndex;
  
      int32_t m_haveKeysIdStartIndex;
      int32_t m_haveKeysIdEndIndex;
      
      ObjectInfo_B()
      {
          m_typeId = -1;
          m_objectNamePos = 0;
          m_startIndex = -1;
          m_endIndex = -1;
          m_haveKeysIdStartIndex = -1;
          m_haveKeysIdEndIndex = -1;
      }
  </code></pre>
  <p>Then there is a vector of  ObjectInfo:</p>
  <pre><code>vector&lt;ObjectInfo&gt; *objectsVec;
  ObjectInfo_B *bObjects;
  </code></pre>
  <p>...</p>
  <p>Now the code to convert is like below:</p>
  <pre><code>startIndex = 0;
  int32_t curBufferSize = 0;
  for(size_t i = 0;i&lt;objectsVec-&gt;size();i++)
  {
      bObjects[i].m_typeId = (*objectsVec)[i].m_typeId;
      bObjects[i].m_objectNamePos = curBufferSize;
      
      strcpy(m_objectNameBuffer+curBufferSize,(*objectsVec)[i].m_objectName.c_str());
      curBufferSize += (*objectsVec)[i].m_objectName.size() + 1;
      
      bObjects[i].m_startIndex = startIndex;
      bObjects[i].m_endIndex = startIndex + (*objectsVec)[i].m_objectFeatures.size();
      startIndex = bObjects[i].m_endIndex;
  
      bObjects[i].m_haveKeysIdStartIndex = haveKeyStartIndex;
      bObjects[i].m_haveKeysIdEndIndex = haveKeyStartIndex +(*objectsVec)[i].m_haveKeysId.size();
  
  ...
  
  fwrite((char*)bObjects,sizeof(ObjectInfo_B),wcount,output);
  </code></pre>
  <p>This seems to be very complicated, and I am not farmilaria with serialization. Is there an easier way to do it in C++? A quick search indicates that this below can do similar things, but can it do the conversion for the above code in a much simpler way?</p>
  <pre><code>https://www.boost.org/doc/libs/1_37_0/libs/serialization/doc/index.html
  </code></pre>