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.
|For Gerrit Dashboard: QTBUG-44418|
|107985,33||QDataStream: handle incomplete reads from QIODevice||dev||qt/qtbase||Status: MERGED||+2||0|
|114792,26||QIODevice: handle incomplete reads||dev||qt/qtbase||Status: MERGED||+2||0|