Working with QDataStream and QTcpSocket
The missing piece of the SDK is MesssageUtils
. It deserves a dedicated section because it covers two major topics: serialization and QDataStream
transactions.
We will start with the serialization. We already know that Message
stores only an opaque QByteArray
data member. As a consequence, the desired data has to be serialized as QByteArray
before being passed to Message
.
If we take the example of a JobRequest
object, it is not directly sent. We first put it in a generic Message
object with the appropriate Message
type. The following diagram summarizes the sequence of actions to be done:

The JobRequest
object is first serialized to a QByteArray
class. It is then passed to a Message
instance, which is in turn serialized to a final QByteArray
. The deserialization process is the exact opposite of this sequence (from right to left).
Serializing data brings a lot of questions. How can we do it in a generic fashion? How do we handle the possible endianness of...