Wraps around QDataStream stream operators to provide cleaner reading interface. More...
#include <datastreamoperatorwrapper.h>
Public Member Functions | |
DataStreamOperatorWrapper (QDataStream *stream) | |
QDataStream * | dataStream () |
Gets underlying QDataStream. | |
const QDataStream * | dataStream () const |
Gets underlying QDataStream. | |
bool | hasRemaining () const |
Returns true if there is any data remaining in the stream. | |
bool | readBool () |
double | readDouble () |
float | readFloat () |
qint16 | readQInt16 () |
qint32 | readQInt32 () |
qint64 | readQInt64 () |
qint8 | readQInt8 () |
quint16 | readQUInt16 () |
quint32 | readQUInt32 () |
quint64 | readQUInt64 () |
quint8 | readQUInt8 () |
QByteArray | readRaw (qint64 length) |
Reads specified amount of raw bytes. | |
QByteArray | readRawAll () |
Reads all remaining raw bytes. | |
QByteArray | readRawMaxUntilByte (char stopByte, qint64 length) |
Reads up to 'length' bytes; can stop early on stopByte. | |
QByteArray | readRawUntilByte (char stopByte) |
Reads raw data from the current position of passed QDataStream until a specified byte is encountered. | |
qint64 | remaining () const |
Returns a remaining amount of bytes from the underlying QIODevice. | |
int | skipRawData (int len) |
Reads and discards specified amount of data. | |
Wraps around QDataStream stream operators to provide cleaner reading interface.
Definition at line 36 of file datastreamoperatorwrapper.h.
QDataStream * DataStreamOperatorWrapper::dataStream | ( | ) |
Gets underlying QDataStream.
Definition at line 52 of file datastreamoperatorwrapper.cpp.
const QDataStream * DataStreamOperatorWrapper::dataStream | ( | ) | const |
Gets underlying QDataStream.
Definition at line 57 of file datastreamoperatorwrapper.cpp.
|
inline |
Returns true if there is any data remaining in the stream.
The check is performed through 'remaining() > 0' instruction.
Definition at line 57 of file datastreamoperatorwrapper.h.
QByteArray DataStreamOperatorWrapper::readRaw | ( | qint64 | length | ) |
Reads specified amount of raw bytes.
length | Amount of bytes to read. |
Definition at line 117 of file datastreamoperatorwrapper.cpp.
QByteArray DataStreamOperatorWrapper::readRawAll | ( | ) |
Reads all remaining raw bytes.
This calls QIODevice::readAll() directly.
Definition at line 122 of file datastreamoperatorwrapper.cpp.
QByteArray DataStreamOperatorWrapper::readRawMaxUntilByte | ( | char | stopByte, |
qint64 | length | ||
) |
Reads up to 'length' bytes; can stop early on stopByte.
An expansion of readRawUntilByte(). Usage principle is the same.
length | Max length. Negative values effectively disable length checks. |
Definition at line 132 of file datastreamoperatorwrapper.cpp.
QByteArray DataStreamOperatorWrapper::readRawUntilByte | ( | char | stopByte | ) |
Reads raw data from the current position of passed QDataStream until a specified byte is encountered.
The primary use for this method is to read '\0' terminated strings.
The operator>>(char*&) in QDataStream expects the size of the string to be written first in a quint32 variable. Because this data is not always available, a custom method must be used. This is this method.
The read will occur from current position until the stopByte byte is encountered. Read may also stop when an end of stream is encountered in which case the data read up to this point will be returned.
stopByte | When method encounters this byte, then the read will stop and the currently read data is returned. |
Definition at line 127 of file datastreamoperatorwrapper.cpp.
qint64 DataStreamOperatorWrapper::remaining | ( | ) | const |
Returns a remaining amount of bytes from the underlying QIODevice.
This is done by performing QIODevice::size() - QIODevice::pos()
. It is assumed that the QIODevice can return both values, ie. is not sequential.
Definition at line 149 of file datastreamoperatorwrapper.cpp.
int DataStreamOperatorWrapper::skipRawData | ( | int | len | ) |
Reads and discards specified amount of data.
Calls QIODevice::skipRawData() directly.
Definition at line 154 of file datastreamoperatorwrapper.cpp.