DataStreamPeer: Optimize message serialization format
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 28 Jan 2014 23:08:34 +0000 (00:08 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 15 Feb 2014 21:01:01 +0000 (22:01 +0100)
commit89aa3d278f7b5fac996f0b9480737e5932d54c41
treea96473fe713ce67581c1d433ac632d62a08bf87c
parent9cefd598107fcb5dfe6cd100524ab016eae0dca0
DataStreamPeer: Optimize message serialization format

The legacy protocol serializes all messages as QVariant-in-a-QByteArray.
Except with compression, then it is QVariant-in-a-compressed-
QByteArray-in-a-QByteArray. While the actual messages either
comes as a QVariantList or a QVariantMap which is encapsulated
in above QVariant-in-a-mess.

In other words, this seems a bit excessive and causes unneeded overhead.

So for the DataStreamPeer, we're simplifying this. As all post-handshake messages
are structured as a QVariantList, we're now making this the on-wire format
as well. Since we need to know the message size for deserialization, we
first send the total message size as a quint32, followed by the number of items
as a quint32, followed by the QVariants. [1]

Since handshake messages are QVariantMaps, and we want to avoid over-nesting things,
we now send those as such a QVariantList as well, where the items are key-value
pairs - the key as UTF-8 string (as a QByteArray), and the value as a QVariant.

[1] This happens to be the same format as a QByteArray containing a QVariantList,
    so the code for that gets rather simple.
src/common/protocols/datastream/datastreampeer.cpp
src/common/protocols/datastream/datastreampeer.h