I've also found the Boost class for serialization, but what most
serialization classes have in common is that they seem aimed at file
access, which means they may be somewhat less economical for
networking. The most appropriate solution will have to be custom-built.
The way I'm currently solving this is by using 16 arrays of 16
different data types (or 32 of 8, or 64 of 4, etc depending on the
project), which can be used by all messages. A message is built up of
one byte for message ID (so I know how to deal with it) and then an
arbitrary list of parameters each prepended with a byte identifying
the type (0-15) and array index (0-15) of the data chunk to come. This
way I can use one method to compose and one to decompose the
parameters regardless of the message type, and deal with the message
data by accessing the required array values, which may be different
per function.
Messages that have missing params (e.g. because the connecting party
uses an earlier version of the interface) have these parameters still
set to initial values if they aren't received, so they can be handled
accordingly. The only drawback may be that there is a slight
performance penalty in having to clear the arrays before receiving the
message.
-MR
Quoting Thorbjørn Lindeijer <[email protected]>:
On Sun, Jan 17, 2010 at 23:22, M. Rijks <[email protected]> wrote:
Note to self: don't ask questions that can be researched. Turns out that
structs cannot be iterated over, let alone determining the type of a field
at such an index. Will take a little more effort to serialize structs, but I
still think it's the preferred method.
Since it is indeed a little more work, there have also been solutions
developed for this already. Personally I think this library looks nice
for the purpose:
http://tpl.sourceforge.net/ (tpl)
But there are also:
http://www.enlightenment.org/p.php?p=about/efl/eet&l=en (Eet)
http://s11n.net/c11n/ (libc11n)
However I prefer doing it manually since, as somebody said before,
that makes it easier to remain backwards compatible and allows you to
vary the contents of a message more easily.
Regards,
Bjørn
_______________________________________________
ENet-discuss mailing list
[email protected]
http://lists.cubik.org/mailman/listinfo/enet-discuss
_______________________________________________
ENet-discuss mailing list
[email protected]
http://lists.cubik.org/mailman/listinfo/enet-discuss