-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket.hpp
executable file
·60 lines (46 loc) · 1.24 KB
/
packet.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef PACKET_HPP
#define PACKET_HPP
#include <string>
#include <deque>
#include "protocol.hpp"
// Encapsulates serialized raw data that can be passed
// over a network.
class Packet
{
public:
explicit Packet();
explicit Packet(int type);
Packet(char *dataWithHeader, int sizeWithHeader);
~Packet();
void putChar(char value);
void putShort(short value);
void putInt(int value);
void putFloat(float value);
void putString(const std::string &value);
char getChar();
short getShort();
int getInt();
float getFloat();
std::string getString();
const char *getData();
int getSize() const;
Packet *clone();
private:
// Pass by value? I think not, sir!
Packet(const Packet &rhs);
void init();
void expand(int numBytes);
// This should in fact be unsigned, unless someone knows of a more
// clever bit-shifting trick...
unsigned char *data;
int pos;
int size;
int alloc;
};
typedef std::deque<Packet *> MessageQueue;
void logTrafficIncoming(Packet *packet);
void logTrafficOutgoing(Packet *packet);
void logTrafficClear();
void logTrafficSave(std::string filename);
void logTrafficStats(int &bytesSent, int &bytesRecv, int &packSent, int &packRecv);
#endif //PACKET_HPP