00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef PACKET_HH_
00018 # define PACKET_HH_
00019
00020 # include <sstream>
00021
00028 struct Packet
00029 {
00031 unsigned token;
00035 int client_id;
00037 unsigned data_size;
00038
00039 Packet(int token = 0, int client_id = -1);
00040 friend std::ostream& operator<< (std::ostream& os, const Packet& pkt);
00041 };
00042
00043
00044 inline Packet::Packet(int token, int client_id)
00045 : token(token), client_id(client_id)
00046 {
00047 data_size = sizeof(*this);
00048 }
00049
00050 inline std::ostream& operator<< (std::ostream& os, const Packet& pkt)
00051 {
00052 os << "*** Packet dump ***" << std::endl;
00053 os << " - token : " << pkt.token << std::endl;
00054 os << " - player_id : " << pkt.client_id << std::endl;
00055 os << " - data_size : " << pkt.data_size << std::endl;
00056 return os;
00057 }
00058
00061
00066 void stringToPacket(int* dst, const std::string& src, unsigned max_size);
00067
00069 std::string packetToString(const int* src);
00070
00072
00073 #endif