Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

yuriks

By: a guest on Dec 2nd, 2008  |  syntax: C++  |  size: 0.57 KB  |  views: 494  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Packet.cpp
  2.  
  3. Packet::Packet()
  4. {
  5. }
  6.  
  7. Packet::~Packet()
  8. {
  9. }
  10.  
  11. void Packet::serialize(Uint8 *data) const
  12. {
  13.         data[0] = getId();
  14.         SDLNet_Write16(packetId, data+1);
  15. }
  16.  
  17. Packet *Packet::createPacket(Uint8 *data)
  18. {
  19.         Packet *packet = globalPacketFactory.createFromId(PacketFactory::PacketIds(data[0]));
  20.         packet->packetId = SDLNet_Read16(data+1);
  21.  
  22.         packet->deserialize(data);
  23.  
  24.         return packet;
  25. }
  26.  
  27. void Packet::deserialize(Uint8 *data)
  28. {
  29. }
  30.  
  31. int Packet::getPacketSize() const
  32. {
  33.         return 3;
  34. }
  35.  
  36. /*
  37. Packet layout:
  38.  
  39. 0: Packet Type
  40. 1+2: Packet UID
  41.  
  42. Size: 3
  43. */