[C++] Serializing packets

Thanks for the reply. I already have a packet handling system with a simple function pointer array (handlers[opcode](params)) so execute function might be inapplicable. I'm not sure which one is better though, having the factory inside the base class or basically having an external factory which would take required data and return a NetworkMessage which is basically an std::vector<unsigned char> . Second option would save me from writing all those derived classes(considering there're over a 100 packets it feels second option might have an advantage).
 
Obiective programming is about beauty, and extensibility. To add new packet all you do is create new implementation (yes there will be a LOT of derived classes but also the same ammount of them in any other way of handling it) and add it to factory. Tell me about your handlers[opcode](params). What if one packet sends a single int (lets say, quest ID accepted), and other packet sends a 3 ints (xyz update)? In C++ it impossible to create array of function pointers with different ammount/type of arguments, how do you solve the issue? If u cast, then its bad already. Take a look at java implementation of packet handling in Lineage2 server. It is decent: - Revision 6670: /trunk/L2J_Server/java/com/l2jserver/gameserver/network

Greetz
 
Parameters aren't packet specific. Packet data is dissolved within handlers. Handler prototypes are simply like: handler(iocp_sock, protocol, msg).
 
Back