Boost C++ Libraries: Ticket #3233: serialization problem: enum : __int64 https://svn.boost.org/trac10/ticket/3233 <p> I have a enum and structure: </p> <div class="wiki-code"><div class="code"><pre><span class="k">typedef</span> <span class="k">enum</span> <span class="o">:</span> <span class="kt">unsigned</span> <span class="kr">__int64</span> <span class="p">{</span> <span class="n">epUnknown</span> <span class="o">=</span> <span class="mh">0x0</span><span class="p">,</span> <span class="n">epCpuSystem</span> <span class="o">=</span> <span class="mh">0x0001LL</span><span class="p">,</span> <span class="p">....</span> <span class="n">epAvgCpu</span><span class="o">=</span> <span class="mh">0x100000000LL</span> <span class="p">}</span> <span class="n">CGenericParamParam</span><span class="p">;</span> <span class="k">struct</span> <span class="n">fee</span> <span class="p">{</span> <span class="p">....</span> <span class="n">CGenericParamParam</span> <span class="n">param</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> Then i try to serialize this structure into boost::archive::binary_oarchive via boost::serialization: </p> <div class="wiki-code"><div class="code"><pre><span class="n">template</span><span class="o">&lt;</span><span class="n">class</span> <span class="n">Archive</span><span class="p">,</span> <span class="n">class</span> <span class="n">T</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">save_enum_type</span> <span class="p">{</span> <span class="k">static</span> <span class="kt">void</span> <span class="n">invoke</span><span class="p">(</span><span class="n">Archive</span> <span class="o">&amp;</span><span class="n">ar</span><span class="p">,</span> <span class="k">const</span> <span class="n">T</span> <span class="o">&amp;</span><span class="n">t</span><span class="p">){</span> <span class="c1">// convert enum to integers on save</span> <span class="k">const</span> <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">static_cast</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="p">(</span><span class="n">t</span><span class="p">);</span> <span class="n">ar</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">serialization</span><span class="o">::</span><span class="n">make_nvp</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span> <span class="p">}</span> <span class="p">};</span> </pre></div></div><p> Casting <span class="underline">0x100000000LL </span></p> <blockquote> <p> into int gives 0. </p> </blockquote> <p> Any ideas? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3233 Trac 1.4.3 Robert Ramey Thu, 09 Jul 2009 15:08:21 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3233#comment:1 https://svn.boost.org/trac10/ticket/3233#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> this would make binary archives larger for every user of the library. And also require code to recognise old archives. All in all just not worth it. Try something like </p> <p> enum { </p> <blockquote> <p> epAvgCpu </p> </blockquote> <p> ... } const int_64 lookup_table[] = { 0x10000000l ... </p> <p> and use </p> <p> lookup_table[epAvgCpu instead of epAvgCpu. </p> Ticket Dmitry <ban_dos@…> Wed, 29 Jul 2009 11:18:30 GMT <link>https://svn.boost.org/trac10/ticket/3233#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3233#comment:2</guid> <description> <div class="wiki-code"><div class="code"><pre><span class="n">namespace</span> <span class="n">boost</span> <span class="p">{</span> <span class="n">namespace</span> <span class="n">archive</span> <span class="p">{</span> <span class="n">namespace</span> <span class="n">detail</span> <span class="p">{</span> <span class="n">template</span><span class="o">&lt;</span><span class="n">class</span> <span class="n">Archive</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">save_enum_type</span><span class="o">&lt;</span><span class="n">Archive</span><span class="p">,</span> <span class="n">CGenericParamParam</span><span class="o">&gt;</span> <span class="p">{</span> <span class="k">static</span> <span class="kt">void</span> <span class="n">invoke</span><span class="p">(</span><span class="n">Archive</span> <span class="o">&amp;</span><span class="n">ar</span><span class="p">,</span> <span class="k">const</span> <span class="n">CGenericParamParam</span> <span class="o">&amp;</span> <span class="n">param</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// convert enum to integers on save</span> <span class="k">const</span> <span class="kr">__int64</span> <span class="n">i</span> <span class="o">=</span> <span class="n">static_cast</span><span class="o">&lt;</span><span class="kr">__int64</span><span class="o">&gt;</span><span class="p">(</span> <span class="n">param</span> <span class="p">);</span> <span class="n">ar</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">serialization</span><span class="o">::</span><span class="n">make_nvp</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span> <span class="p">}</span> <span class="p">};</span> <span class="n">template</span><span class="o">&lt;</span><span class="n">class</span> <span class="n">Archive</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="n">load_enum_type</span><span class="o">&lt;</span><span class="n">Archive</span><span class="p">,</span> <span class="n">CGenericParamParam</span><span class="o">&gt;</span> <span class="p">{</span> <span class="k">static</span> <span class="kt">void</span> <span class="n">invoke</span><span class="p">(</span><span class="n">Archive</span> <span class="o">&amp;</span><span class="n">ar</span><span class="p">,</span> <span class="n">CGenericParamParam</span> <span class="o">&amp;</span> <span class="n">param</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// convert integers to correct enum to load</span> <span class="kr">__int64</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">ar</span> <span class="o">&gt;&gt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">serialization</span><span class="o">::</span><span class="n">make_nvp</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span> <span class="n">param</span> <span class="o">=</span> <span class="n">static_cast</span><span class="o">&lt;</span><span class="n">CGenericParamParam</span><span class="o">&gt;</span><span class="p">(</span><span class="n">i</span><span class="p">);</span> <span class="p">}</span> <span class="p">};</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> </pre></div></div> </description> <category>Ticket</category> </item> </channel> </rss>