P3: Somewhat important
If QDataStream encounters a ReadPastEnd it should reset the device to the last known state, putting back any characters that have not successfully been parsed yet.
It should be straightforward to use a QDataStream e.g. for communication over a socket. However, all relevant network protocols are packet based, and it's not guaranteed that the chunks of data arriving with readyRead can be de-serialized completely.
If one tries to process an incomplete chunk QDataStream will flag this with ReadPastEnd. However, it won't put any characters back to the device, meaning that the user cannot reasonably recover, and wait for more data to arrive.
The fortuneclient example works around this by wrapping the streamed data again in a QByteArray, and prepending it with it's own size. However, this relies on the implementation detail that streaming a qint16 will write exactly 2 bytes on the device.
All QDataStream::operator<<() should use e.g. ungetChar to restore the QIODevice data into a consistent state. This way, the user can easily just 'bail out' in case of an uncomplete read, and wait for more data to arrive to continue reading.
- relates to
QTBUG-56032 [REG 5.6->5.7] Performance drop for QIODevice::peek