Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualsamoth

Posted 11 February 2013 - 11:29 AM

If your event structure does not contain any pointers, and if your software does not need to be endian-portable (e.g. client runs on x86 and server runs on PPC), and if you use the same layout/padding options when compiling (and assuming trivial constructors/destructors, likely the case here) then you can usually just copy sizeof(event) bytes from an event's address to your packet.

In every other case, see the previous answer ("serialization"). Implementations that are well-tested and work for many people are msgpack and protocol buffers (with slightly different features and overhead).

Note: If you run your own serialization, be sure to also include at least a "protocol version" when your client connects, even if you'll never going to need it. In case you do need to change something later, you avoid one big nightmare.

#1samoth

Posted 11 February 2013 - 11:26 AM

If your event structure does not contain any pointers, and if your software does not need to be endian-portable (e.g. client runs on x86 and server runs on PPC), and if you use the same layout/padding options when compiling (and assuming trivial constructors/destructors, likely the case here) then you can usually just copy sizeof(event) bytes from an event's address to your packet.

In every other case, see the previous answer ("serialization"). Implementations that are well-tested and work for many people are msgpack and protocol buffers (with slightly different features and overhead).

PARTNERS