-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.cpp
61 lines (47 loc) · 1.33 KB
/
packet.cpp
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
61
#include "packet.h"
using namespace DG;
Packet::Packet(){
}
Packet::Packet(PacketType type, int state):_state(state), _type(type){
}
Packet::PacketType Packet::type() const{
return _type;
}
Packet::CommonHeader::CommonHeader(){
id = _id++;
time = QTime::currentTime();
size = 0;
}
Packet::CommonHeader::CommonHeader(quint32 sz, PacketType type){
id = _id++;
time = QTime::currentTime();
size = sz;
packetType = type;
}
QDataStream& DG::operator<<(QDataStream& stream, const Packet::CommonHeader& header){
stream << header.id;
stream << header.size;
stream << header.time;
stream << header.packetType;
return stream;
}
QDataStream& DG::operator>>(QDataStream& stream, Packet::CommonHeader& header){
int packetType;
stream >> header.id;
stream >> header.size;
stream >> header.time;
stream >> packetType;
header.packetType = (DG::Packet::PacketType)packetType;
return stream;
}
QDataStream& DG::operator<<(QDataStream& stream, const Packet& packet){
stream << packet._state << packet._type;
return packet.serialize(stream);
}
QDataStream& DG::operator>>(QDataStream& stream, Packet& packet){
int _type;
stream >> packet._state >> _type;
packet._type = (DG::Packet::PacketType)_type;
return packet.unserialize(stream);
}
quint64 Packet::CommonHeader::_id = 0;