|
@@ -21,27 +21,50 @@ namespace QDNS
|
21
|
21
|
}
|
22
|
22
|
|
23
|
23
|
QDnsHeader QDnsHeader::parse(const QByteArray& data)
|
|
24
|
+ {
|
|
25
|
+ QDataStream dataStream(data);
|
|
26
|
+ return QDnsHeader::parse(dataStream);
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ QDnsHeader QDnsHeader::parse(QDataStream& dataStream)
|
24
|
30
|
{
|
25
|
31
|
QDnsHeader header;
|
26
|
32
|
|
27
|
|
- if (data.size() < 12)
|
|
33
|
+ if (dataStream.device()->bytesAvailable() < 12)
|
28
|
34
|
{
|
29
|
35
|
header.m_isValid = false;
|
30
|
36
|
}
|
31
|
37
|
else
|
32
|
38
|
{
|
33
|
|
- QDataStream ds(data);
|
34
|
|
- ds >> header.m_id;
|
35
|
|
- ds >> header.m_flags;
|
36
|
|
- ds >> header.m_questionCount;
|
37
|
|
- ds >> header.m_answerCount;
|
38
|
|
- ds >> header.m_authorityCount;
|
39
|
|
- ds >> header.m_additionalCount;
|
|
39
|
+ dataStream >> header.m_id;
|
|
40
|
+ dataStream >> header.m_flags;
|
|
41
|
+ dataStream >> header.m_questionCount;
|
|
42
|
+ dataStream >> header.m_answerCount;
|
|
43
|
+ dataStream >> header.m_authorityCount;
|
|
44
|
+ dataStream >> header.m_additionalCount;
|
40
|
45
|
}
|
41
|
46
|
|
42
|
47
|
return header;
|
43
|
48
|
}
|
44
|
49
|
|
|
50
|
+ QByteArray QDnsHeader::serialize() const
|
|
51
|
+ {
|
|
52
|
+ QByteArray byteArray;
|
|
53
|
+ QDataStream dataStream(&byteArray, QIODevice::WriteOnly);
|
|
54
|
+ serialize(dataStream);
|
|
55
|
+ return byteArray;
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ void QDnsHeader::serialize(QDataStream& dataStream) const
|
|
59
|
+ {
|
|
60
|
+ dataStream << m_id;
|
|
61
|
+ dataStream << m_flags;
|
|
62
|
+ dataStream << m_questionCount;
|
|
63
|
+ dataStream << m_answerCount;
|
|
64
|
+ dataStream << m_authorityCount;
|
|
65
|
+ dataStream << m_additionalCount;
|
|
66
|
+ }
|
|
67
|
+
|
45
|
68
|
bool QDnsHeader::isValid() const
|
46
|
69
|
{
|
47
|
70
|
return m_isValid;
|
|
@@ -230,21 +253,4 @@ namespace QDNS
|
230
|
253
|
m_additionalCount = additionalCount;
|
231
|
254
|
}
|
232
|
255
|
|
233
|
|
- QByteArray QDnsHeader::serialize() const
|
234
|
|
- {
|
235
|
|
- if (isValid())
|
236
|
|
- {
|
237
|
|
- QByteArray data;
|
238
|
|
- QDataStream ds(&data, QIODevice::WriteOnly);
|
239
|
|
- ds << m_id;
|
240
|
|
- ds << m_flags;
|
241
|
|
- ds << m_questionCount;
|
242
|
|
- ds << m_answerCount;
|
243
|
|
- ds << m_authorityCount;
|
244
|
|
- ds << m_additionalCount;
|
245
|
|
- return data;
|
246
|
|
- }
|
247
|
|
- return QByteArray();
|
248
|
|
- }
|
249
|
|
-
|
250
|
256
|
}
|