Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 84 lines (63 sloc) 2.227 kb
d26c551 @Minoru Initial commit
authored
1 #include "messages-serializers.h"
2
b0a4bda @Minoru Make serializers return QByteArray*
authored
3 void setupHeader(Message *msg, QDataStream &stream)
d26c551 @Minoru Initial commit
authored
4 {
d39afcb @Minoru Implement serializers
authored
5 // version: 1
f4b1ae1 @Minoru Use static_cast instead of C-type casts
authored
6 stream << static_cast<quint8>(1);
d39afcb @Minoru Implement serializers
authored
7 // other header infortmation
f4b1ae1 @Minoru Use static_cast instead of C-type casts
authored
8 stream << static_cast<quint32>(msg->num) << static_cast<quint16>(msg->port)
9 << static_cast<quint8>(msg->type);
d26c551 @Minoru Initial commit
authored
10 }
11
b0a4bda @Minoru Make serializers return QByteArray*
authored
12 QByteArray *serializeMessageMove(MessageMove *msg)
d26c551 @Minoru Initial commit
authored
13 {
d39afcb @Minoru Implement serializers
authored
14 QByteArray *arr = new QByteArray();
15 QDataStream stream(arr, QIODevice::WriteOnly);
16
17 setupHeader(msg, stream);
f4b1ae1 @Minoru Use static_cast instead of C-type casts
authored
18 stream << static_cast<quint32>(msg->coordX) << static_cast<quint32>(msg->coordY);
d39afcb @Minoru Implement serializers
authored
19
20 return arr;
d26c551 @Minoru Initial commit
authored
21 }
22
b0a4bda @Minoru Make serializers return QByteArray*
authored
23 QByteArray *serializeMessageTurn(MessageTurn *msg)
d26c551 @Minoru Initial commit
authored
24 {
d39afcb @Minoru Implement serializers
authored
25 QByteArray *arr = new QByteArray();
26 QDataStream stream(arr, QIODevice::WriteOnly);
27
28 setupHeader(msg, stream);
f4b1ae1 @Minoru Use static_cast instead of C-type casts
authored
29 stream << static_cast<quint32>(msg->degrees * 3600);
d39afcb @Minoru Implement serializers
authored
30
31 return arr;
d26c551 @Minoru Initial commit
authored
32 }
33
b0a4bda @Minoru Make serializers return QByteArray*
authored
34 QByteArray *serializeMessageChangeSize(MessageChangeSize *msg)
d26c551 @Minoru Initial commit
authored
35 {
d39afcb @Minoru Implement serializers
authored
36 QByteArray *arr = new QByteArray();
37 QDataStream stream(arr, QIODevice::WriteOnly);
38
39 setupHeader(msg, stream);
f4b1ae1 @Minoru Use static_cast instead of C-type casts
authored
40 stream << static_cast<quint32>(msg->diameter);
d39afcb @Minoru Implement serializers
authored
41
42 return arr;
d26c551 @Minoru Initial commit
authored
43 }
44
b0a4bda @Minoru Make serializers return QByteArray*
authored
45 QByteArray *serializeMessageChangeColor(MessageChangeColor *msg)
46 {
d39afcb @Minoru Implement serializers
authored
47 QByteArray *arr = new QByteArray();
48 QDataStream stream(arr, QIODevice::WriteOnly);
49
50 setupHeader(msg, stream);
f4b1ae1 @Minoru Use static_cast instead of C-type casts
authored
51 stream << static_cast<quint8>(msg->red) << static_cast<quint8>(msg->green)
52 << static_cast<quint8>(msg->blue);
d39afcb @Minoru Implement serializers
authored
53
54 return arr;
b0a4bda @Minoru Make serializers return QByteArray*
authored
55 }
56
57 QByteArray *serializeMessageWhoIsThere(MessageWhoIsThere *msg)
58 {
d39afcb @Minoru Implement serializers
authored
59 QByteArray *arr = new QByteArray();
60 QDataStream stream(arr, QIODevice::WriteOnly);
61
62 setupHeader(msg, stream);
f4b1ae1 @Minoru Use static_cast instead of C-type casts
authored
63 stream << static_cast<quint32>(msg->coordX) << static_cast<quint32>(msg->coordY)
64 << static_cast<quint32>(msg->radius);
d39afcb @Minoru Implement serializers
authored
65
66 return arr;
b0a4bda @Minoru Make serializers return QByteArray*
authored
67 }
68
69 QByteArray *serializeMessageParameterReport(MessageParameterReport *msg)
d26c551 @Minoru Initial commit
authored
70 {
d39afcb @Minoru Implement serializers
authored
71 QByteArray *arr = new QByteArray();
72 QDataStream stream(arr, QIODevice::WriteOnly);
73
74 setupHeader(msg, stream);
f4b1ae1 @Minoru Use static_cast instead of C-type casts
authored
75 stream << static_cast<quint8>(msg->id) << static_cast<quint32>(msg->integral)
76 << static_cast<quint32>(msg->real);
d39afcb @Minoru Implement serializers
authored
77
78 return arr;
d26c551 @Minoru Initial commit
authored
79 }
80
81 /* Limit line length to 100 characters; highlight 99th column
82 * vim: set textwidth=100 colorcolumn=-1:
83 */
Something went wrong with that request. Please try again.