b3c0aa04d2b94047f7537432998117d80b78bcec
[quassel.git] / src / common / serializers / serializers.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include <QDataStream>
24 #include <QHostAddress>
25 #include <QTime>
26 #include <QVariantList>
27 #include <QtEndian>
28
29 #include "bufferinfo.h"
30 #include "identity.h"
31 #include "message.h"
32 #include "network.h"
33 #include "peer.h"
34
35 namespace Serializers {
36     namespace Types {
37         enum class VariantType : quint32 {
38             Void = 0,
39             Bool = 1,
40             Int = 2,
41             UInt = 3,
42
43             QChar = 7,
44             QVariantMap = 8,
45             QVariantList = 9,
46             QString = 10,
47             QStringList = 11,
48             QByteArray = 12,
49
50             QDate = 14,
51             QTime = 15,
52             QDateTime = 16,
53
54             Long = 129,
55             Short = 130,
56             Char = 131,
57             ULong = 132,
58             UShort = 133,
59             UChar = 134,
60
61             QVariant = 138,
62
63             UserType = 127
64         };
65
66         enum class QuasselType {
67             Invalid,
68             BufferId,
69             BufferInfo,
70             Identity,
71             IdentityId,
72             Message,
73             MsgId,
74             NetworkId,
75             NetworkInfo,
76             Network_Server,
77             PeerPtr
78         };
79
80         VariantType variantType(QuasselType type);
81         QString toName(QuasselType type);
82         Types::QuasselType fromName(::QByteArray &name);
83     }
84
85     bool deserialize(QDataStream &stream, const Quassel::Features &features, QVariant &data);
86     bool deserialize(QDataStream &stream, const Quassel::Features &features, QVariantList &list);
87     bool deserialize(QDataStream &stream, const Quassel::Features &features, QVariantMap &data);
88     bool deserialize(QDataStream &stream, const Quassel::Features &features, QVariant &data, Types::VariantType type);
89     bool deserialize(QDataStream &stream, const Quassel::Features &features, QVariant &data, Types::QuasselType type);
90     bool deserialize(QDataStream &stream, const Quassel::Features &features, bool &data);
91     bool deserialize(QDataStream &stream, const Quassel::Features &features, int8_t &data);
92     bool deserialize(QDataStream &stream, const Quassel::Features &features, uint8_t &data);
93     bool deserialize(QDataStream &stream, const Quassel::Features &features, int16_t &data);
94     bool deserialize(QDataStream &stream, const Quassel::Features &features, uint16_t &data);
95     bool deserialize(QDataStream &stream, const Quassel::Features &features, int32_t &data);
96     bool deserialize(QDataStream &stream, const Quassel::Features &features, uint32_t &data);
97     bool deserialize(QDataStream &stream, const Quassel::Features &features, qlonglong &data);
98     bool deserialize(QDataStream &stream, const Quassel::Features &features, qulonglong &data);
99     bool deserialize(QDataStream &stream, const Quassel::Features &features, Types::VariantType &data);
100     bool deserialize(QDataStream &stream, const Quassel::Features &features, QChar &data);
101     bool deserialize(QDataStream &stream, const Quassel::Features &features, QString &data);
102     bool deserialize(QDataStream &stream, const Quassel::Features &features, QTime &data);
103     bool deserialize(QDataStream &stream, const Quassel::Features &features, QDate &data);
104     bool deserialize(QDataStream &stream, const Quassel::Features &features, QDateTime &data);
105     bool deserialize(QDataStream &stream, const Quassel::Features &features, QByteArray &data);
106     bool deserialize(QDataStream &stream, const Quassel::Features &features, QStringList &data);
107     bool deserialize(QDataStream &stream, const Quassel::Features &features, Message &data);
108     bool deserialize(QDataStream &stream, const Quassel::Features &features, BufferInfo &data);
109     bool deserialize(QDataStream &stream, const Quassel::Features &features, BufferId &data);
110     bool deserialize(QDataStream &stream, const Quassel::Features &features, IdentityId &data);
111     bool deserialize(QDataStream &stream, const Quassel::Features &features, NetworkId &data);
112     bool deserialize(QDataStream &stream, const Quassel::Features &features, MsgId &data);
113     bool deserialize(QDataStream &stream, const Quassel::Features &features, PeerPtr &data);
114     bool deserialize(QDataStream &stream, const Quassel::Features &features, NetworkInfo &data);
115     bool deserialize(QDataStream &stream, const Quassel::Features &features, Identity &data);
116     bool deserialize(QDataStream &stream, const Quassel::Features &features, Network::Server &data);
117 };