-
Notifications
You must be signed in to change notification settings - Fork 0
/
packetacknick.cpp
45 lines (39 loc) · 920 Bytes
/
packetacknick.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
#include "packetacknick.h"
PacketAckNick::PacketAckNick(const QString& nick)
:nick_(nick),
ack_(false)
{
}
bool PacketAckNick::acked()
{
return ack_;
}
const char * PacketAckNick::getPayload()
{
return payload_;
}
int PacketAckNick::payloadSize()
{
QString ack = ack_ ? "true" :"false";
return nick_.size() + ack.size()+1;
}
void PacketAckNick::setPayload(char* payload)
{
const char *cursor = payload;
QString nick = cursor;
cursor+=nick.size()+1;
QString ack = cursor;
nick_ = nick;
ack_ = ack == "true"? true : false;
}
QDataStream& operator>>(QDataStream& stream, PacketAckNick& pack)
{
pack.setHeader(stream);
stream>>pack.nick_;
QString ack;
stream>>ack;
pack.ack_ = ack == "true"? true : false;
if (!pack.checkHeader())
qDebug()<<"Bad header checksum for packet Ack Nick: "<< pack.header_.head_checksum;
return stream;
}