Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 83 lines (63 sloc) 2.227 kb
d26c5519 »
2012-04-10 Initial commit
1 #include "messages-serializers.h"
2
b0a4bda7 »
2012-04-10 Make serializers return QByteArray*
3 void setupHeader(Message *msg, QDataStream &stream)
d26c5519 »
2012-04-10 Initial commit
4 {
d39afcbe »
2012-04-10 Implement serializers
5 // version: 1
f4b1ae1c »
2012-04-17 Use static_cast instead of C-type casts
6 stream << static_cast<quint8>(1);
d39afcbe »
2012-04-10 Implement serializers
7 // other header infortmation
f4b1ae1c »
2012-04-17 Use static_cast instead of C-type casts
8 stream << static_cast<quint32>(msg->num) << static_cast<quint16>(msg->port)
9 << static_cast<quint8>(msg->type);
d26c5519 »
2012-04-10 Initial commit
10 }
11
b0a4bda7 »
2012-04-10 Make serializers return QByteArray*
12 QByteArray *serializeMessageMove(MessageMove *msg)
d26c5519 »
2012-04-10 Initial commit
13 {
d39afcbe »
2012-04-10 Implement serializers
14 QByteArray *arr = new QByteArray();
15 QDataStream stream(arr, QIODevice::WriteOnly);
16
17 setupHeader(msg, stream);
f4b1ae1c »
2012-04-17 Use static_cast instead of C-type casts
18 stream << static_cast<quint32>(msg->coordX) << static_cast<quint32>(msg->coordY);
d39afcbe »
2012-04-10 Implement serializers
19
20 return arr;
d26c5519 »
2012-04-10 Initial commit
21 }
22
b0a4bda7 »
2012-04-10 Make serializers return QByteArray*
23 QByteArray *serializeMessageTurn(MessageTurn *msg)
d26c5519 »
2012-04-10 Initial commit
24 {
d39afcbe »
2012-04-10 Implement serializers
25 QByteArray *arr = new QByteArray();
26 QDataStream stream(arr, QIODevice::WriteOnly);
27
28 setupHeader(msg, stream);
f4b1ae1c »
2012-04-17 Use static_cast instead of C-type casts
29 stream << static_cast<quint32>(msg->degrees * 3600);
d39afcbe »
2012-04-10 Implement serializers
30
31 return arr;
d26c5519 »
2012-04-10 Initial commit
32 }
33
b0a4bda7 »
2012-04-10 Make serializers return QByteArray*
34 QByteArray *serializeMessageChangeSize(MessageChangeSize *msg)
d26c5519 »
2012-04-10 Initial commit
35 {
d39afcbe »
2012-04-10 Implement serializers
36 QByteArray *arr = new QByteArray();
37 QDataStream stream(arr, QIODevice::WriteOnly);
38
39 setupHeader(msg, stream);
f4b1ae1c »
2012-04-17 Use static_cast instead of C-type casts
40 stream << static_cast<quint32>(msg->diameter);
d39afcbe »
2012-04-10 Implement serializers
41
42 return arr;
d26c5519 »
2012-04-10 Initial commit
43 }
44
b0a4bda7 »
2012-04-10 Make serializers return QByteArray*
45 QByteArray *serializeMessageChangeColor(MessageChangeColor *msg)
46 {
d39afcbe »
2012-04-10 Implement serializers
47 QByteArray *arr = new QByteArray();
48 QDataStream stream(arr, QIODevice::WriteOnly);
49
50 setupHeader(msg, stream);
f4b1ae1c »
2012-04-17 Use static_cast instead of C-type casts
51 stream << static_cast<quint8>(msg->red) << static_cast<quint8>(msg->green)
52 << static_cast<quint8>(msg->blue);
d39afcbe »
2012-04-10 Implement serializers
53
54 return arr;
b0a4bda7 »
2012-04-10 Make serializers return QByteArray*
55 }
56
57 QByteArray *serializeMessageWhoIsThere(MessageWhoIsThere *msg)
58 {
d39afcbe »
2012-04-10 Implement serializers
59 QByteArray *arr = new QByteArray();
60 QDataStream stream(arr, QIODevice::WriteOnly);
61
62 setupHeader(msg, stream);
f4b1ae1c »
2012-04-17 Use static_cast instead of C-type casts
63 stream << static_cast<quint32>(msg->coordX) << static_cast<quint32>(msg->coordY)
64 << static_cast<quint32>(msg->radius);
d39afcbe »
2012-04-10 Implement serializers
65
66 return arr;
b0a4bda7 »
2012-04-10 Make serializers return QByteArray*
67 }
68
69 QByteArray *serializeMessageParameterReport(MessageParameterReport *msg)
d26c5519 »
2012-04-10 Initial commit
70 {
d39afcbe »
2012-04-10 Implement serializers
71 QByteArray *arr = new QByteArray();
72 QDataStream stream(arr, QIODevice::WriteOnly);
73
74 setupHeader(msg, stream);
f4b1ae1c »
2012-04-17 Use static_cast instead of C-type casts
75 stream << static_cast<quint8>(msg->id) << static_cast<quint32>(msg->integral)
76 << static_cast<quint32>(msg->real);
d39afcbe »
2012-04-10 Implement serializers
77
78 return arr;
d26c5519 »
2012-04-10 Initial commit
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.