The following works for me. It may not be the best code in the world but it&#39;s simple, lightweight, and works. It&#39;s what others suggested I think as well.<br><br>// A class you can serialize/deserialize:<br>class Version<br>
{<br>public:<br>    Version();<br>    char v;<br>    unsigned long Number;<br><br>    friend std::ostream&amp; operator&lt;&lt;( std::ostream&amp; stream, const Version&amp; v);<br>    friend std::istream&amp; operator&gt;&gt;( std::istream&amp; stream, Version&amp; v);<br>
};<br><br>// write to the stream<br>std::ostream&amp; operator&lt;&lt;( std::ostream&amp; stream, const Version&amp; ver )<br>{<br>   stream &lt;&lt; ver.v &lt;&lt; ver.Number;<br>   return stream;<br>}<br><br>// read from the stream<br>
std::istream&amp; operator&gt;&gt;( std::istream&amp; stream, Version&amp; ver )<br>{<br>   stream &gt;&gt; ver.v &gt;&gt; ver.Number;<br>   if ( ver.v != &#39;v&#39; )<br>      throw new std::exception;<br>   return stream;<br>
}<br><br><br>To deserialize a received packet:<br><br>void deserialize( ENetPacket* packet )<br>{<br>   // copy packet data to a stream<br>   std::stringstream stream;<br>   stream.write( (char*)packet-&gt;data, packet-&gt;dataLength );<br>
<br>   switch ( *packet-&gt;data )<br>   {<br>      case &#39;v&#39;:<br>         {<br>          Version v;<br>         stream &gt;&gt; v;<br>         }<br>         break;<br>      default:<br>         throw new std::runtime_error( &quot;unknown packet data received from peer&quot; );<br>
         break;<br>   }<br>}<br><br><br><br><br><div class="gmail_quote">On Sun, Jan 17, 2010 at 4:31 PM, Eugene Marcotte <span dir="ltr">&lt;<a href="mailto:eugene@emarcotte.com">eugene@emarcotte.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Sun, Jan 17, 2010 at 02:54:10PM -0500, Alex Milstead wrote:<br>
&gt; In that case, is there a solid way to extract that identifier? Or will<br>
&gt; I need to do some I&#39;m aware of sprintf calls, is it common practice to<br>
&gt; simply &quot;sprintf&quot; the first integer of the received binary data into a<br>
&gt; buffer and (effectively) switch-case on that buffer, then memcpy the<br>
&gt; remaining data that follows? Or is there a better way of doing this?<br>
<br>
</div>What I do in my project is send google protocal buffer messages back and<br>
forth. To figure out which is which, each time I send I wrap them in<br>
another message that has two fields, a name and a blob where I serialize<br>
whatever the real message is.<br>
<br>
Using the built-in reflection of protocol buffers I can figure out what to<br>
call each message, and using some templates and maps I am able to make use<br>
of the protocol buffers builders on the receive side to build messages up<br>
as objects. From there its just a matter of dispatching to various event<br>
handlers.<br>
<br>
It took a bit of work to get functional, but now that it works it&#39;s pretty<br>
nice to just say send(whateverObject) and hook up some event handler for<br>
that type on the other end.<br>
<br>
It does feel rather heavy compared to what other people are suggesting<br>
about enums and structs too :)<br>
<font color="#888888"><br>
Eugene<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Cause united breaks guitars<br><a href="http://www.youtube.com/watch?v=5YGc4zOqozo">http://www.youtube.com/watch?v=5YGc4zOqozo</a><br><br>