DataStreamOperatorWrapper Class Reference

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.
 

Detailed Description

Wraps around QDataStream stream operators to provide cleaner reading interface.

Definition at line 36 of file datastreamoperatorwrapper.h.

Member Function Documentation

QDataStream * DataStreamOperatorWrapper::dataStream ( )

Gets underlying QDataStream.

Definition at line 51 of file datastreamoperatorwrapper.cpp.

const QDataStream * DataStreamOperatorWrapper::dataStream ( ) const

Gets underlying QDataStream.

Definition at line 56 of file datastreamoperatorwrapper.cpp.

bool DataStreamOperatorWrapper::hasRemaining ( ) const
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.

Parameters
lengthAmount of bytes to read.
Returns
QByteArray of read bytes.

Definition at line 116 of file datastreamoperatorwrapper.cpp.

QByteArray DataStreamOperatorWrapper::readRawAll ( )

Reads all remaining raw bytes.

This calls QIODevice::readAll() directly.

Returns
QByteArray of read bytes.

Definition at line 121 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.

Parameters
lengthMax length. Negative values effectively disable length checks.

Definition at line 131 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.

Parameters
stopByteWhen method encounters this byte, then the read will stop and the currently read data is returned.
Returns
All read data plus the stopByte (if encountered).

Definition at line 126 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 148 of file datastreamoperatorwrapper.cpp.

int DataStreamOperatorWrapper::skipRawData ( int  len)

Reads and discards specified amount of data.

Calls QIODevice::skipRawData() directly.

Returns
Number of bytes actually skipped or -1 on error.

Definition at line 153 of file datastreamoperatorwrapper.cpp.


The documentation for this class was generated from the following files: