Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QPacket Class Reference

The QPacket class encapsulates an unfragmentable packet of data to be transmitted by QPacketProtocol. More...

#include <qpacket_p.h>

+ Inheritance diagram for QPacket:
+ Collaboration diagram for QPacket:

Public Member Functions

 QPacket (int version)
 Constructs an empty write-only packet.
 
 QPacket (int version, const QByteArray &ba)
 Constructs a read-only packet.
 
const QByteArraydata () const
 Returns a reference to the raw packet data.
 
QByteArray squeezedData () const
 Returns a copy of the raw packet data, with extra reserved space removed.
 
void clear ()
 Clears the packet, discarding any data.
 
- Public Member Functions inherited from QDataStream
enum Version QT7_ONLY (:quint8)
 
enum Status QT7_ONLY (:quint8)
 
enum FloatingPointPrecision QT7_ONLY (:quint8)
 
 QDataStream ()
 Constructs a data stream that has no I/O device.
 
 QDataStream (QIODevice *)
 Constructs a data stream that uses the I/O device d.
 
 QDataStream (QByteArray *, OpenMode flags)
 Constructs a data stream that operates on a byte array, a.
 
 QDataStream (const QByteArray &)
 Constructs a read-only data stream that operates on byte array a.
 
 ~QDataStream ()
 Destroys the data stream.
 
QIODevicedevice () const
 Returns the I/O device currently set, or \nullptr if no device is currently set.
 
void setDevice (QIODevice *)
 void QDataStream::setDevice(QIODevice *d)
 
bool atEnd () const
 Returns true if the I/O device has reached the end position (end of the stream or file) or if there is no I/O device set; otherwise returns false.
 
Status status () const
 Returns the status of the data stream.
 
void setStatus (Status status)
 Sets the status of the data stream to the status given.
 
void resetStatus ()
 Resets the status of the data stream.
 
FloatingPointPrecision floatingPointPrecision () const
 Returns the floating point precision of the data stream.
 
void setFloatingPointPrecision (FloatingPointPrecision precision)
 Sets the floating point precision of the data stream to precision.
 
ByteOrder byteOrder () const
 Returns the current byte order setting – either BigEndian or LittleEndian.
 
void setByteOrder (ByteOrder)
 Sets the serialization byte order to bo.
 
int version () const
 Returns the version number of the data serialization format.
 
void setVersion (int)
 Sets the version number of the data serialization format to v, a value of the \l Version enum.
 
QDataStreamoperator>> (char &i)
 
QDataStreamoperator>> (qint8 &i)
 Reads a signed byte from the stream into i, and returns a reference to the stream.
 
QDataStreamoperator>> (quint8 &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads an unsigned byte from the stream into i, and returns a reference to the stream.
 
QDataStreamoperator>> (qint16 &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a signed 16-bit integer from the stream into i, and returns a reference to the stream.
 
QDataStreamoperator>> (quint16 &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads an unsigned 16-bit integer from the stream into i, and returns a reference to the stream.
 
QDataStreamoperator>> (qint32 &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a signed 32-bit integer from the stream into i, and returns a reference to the stream.
 
QDataStreamoperator>> (quint32 &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads an unsigned 32-bit integer from the stream into i, and returns a reference to the stream.
 
QDataStreamoperator>> (qint64 &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a signed 64-bit integer from the stream into i, and returns a reference to the stream.
 
QDataStreamoperator>> (quint64 &i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads an unsigned 64-bit integer from the stream, into i, and returns a reference to the stream.
 
QDataStreamoperator>> (std::nullptr_t &ptr)
 
QDataStreamoperator>> (bool &i)
 Reads a boolean value from the stream into i.
 
QDataStreamoperator>> (float &f)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a floating point number from the stream into f, using the standard IEEE 754 format.
 
QDataStreamoperator>> (double &f)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a floating point number from the stream into f, using the standard IEEE 754 format.
 
QDataStreamoperator>> (char *&str)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads string s from the stream and returns a reference to the stream.
 
QDataStreamoperator>> (char16_t &c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QDataStreamoperator>> (char32_t &c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QDataStreamoperator<< (char i)
 
QDataStreamoperator<< (qint8 i)
 Writes a signed byte, i, to the stream and returns a reference to the stream.
 
QDataStreamoperator<< (quint8 i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes an unsigned byte, i, to the stream and returns a reference to the stream.
 
QDataStreamoperator<< (qint16 i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes a signed 16-bit integer, i, to the stream and returns a reference to the stream.
 
QDataStreamoperator<< (quint16 i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes an unsigned 16-bit integer, i, to the stream and returns a reference to the stream.
 
QDataStreamoperator<< (qint32 i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes a signed 32-bit integer, i, to the stream and returns a reference to the stream.
 
QDataStreamoperator<< (quint32 i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes an unsigned integer, i, to the stream as a 32-bit unsigned integer (quint32).
 
QDataStreamoperator<< (qint64 i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes a signed 64-bit integer, i, to the stream and returns a reference to the stream.
 
QDataStreamoperator<< (quint64 i)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes an unsigned 64-bit integer, i, to the stream and returns a reference to the stream.
 
QDataStreamoperator<< (std::nullptr_t)
 
template<typename T , std::enable_if_t< std::is_same_v< T, bool >, bool > = true>
QDataStreamoperator<< (T i)
 
QDataStreamoperator<< (float f)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes a floating point number, f, to the stream using the standard IEEE 754 format.
 
QDataStreamoperator<< (double f)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes a floating point number, f, to the stream using the standard IEEE 754 format.
 
QDataStreamoperator<< (const char *str)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes the '\0'-terminated string s to the stream and returns a reference to the stream.
 
QDataStreamoperator<< (char16_t c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QDataStreamoperator<< (char32_t c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QDataStreamreadBytes (char *&, qint64 &len)
 
qint64 readRawData (char *, qint64 len)
 Reads at most len bytes from the stream into s and returns the number of bytes read.
 
QDataStreamwriteBytes (const char *, qint64 len)
 Writes the length specifier len and the buffer s to the stream and returns a reference to the stream.
 
qint64 writeRawData (const char *, qint64 len)
 Writes len bytes from s to the stream.
 
qint64 skipRawData (qint64 len)
 
void startTransaction ()
 
bool commitTransaction ()
 
void rollbackTransaction ()
 
void abortTransaction ()
 
bool isDeviceTransactionStarted () const
 

Additional Inherited Members

- Public Types inherited from QDataStream
enum  ByteOrder { BigEndian = QSysInfo::BigEndian , LittleEndian = QSysInfo::LittleEndian }
 The byte order used for reading/writing the data. More...
 
- Public Types inherited from QIODeviceBase
enum  OpenModeFlag {
  NotOpen = 0x0000 , ReadOnly = 0x0001 , WriteOnly = 0x0002 , ReadWrite = ReadOnly | WriteOnly ,
  Append = 0x0004 , Truncate = 0x0008 , Text = 0x0010 , Unbuffered = 0x0020 ,
  NewOnly = 0x0040 , ExistingOnly = 0x0080
}
 This enum is used with QIODevice::open() to describe the mode in which a device is opened. More...
 
- Protected Member Functions inherited from QIODeviceBase
 ~QIODeviceBase ()=default
 

Detailed Description

The QPacket class encapsulates an unfragmentable packet of data to be transmitted by QPacketProtocol.

The QPacket class works together with QPacketProtocol to make it simple to send arbitrary sized data "packets" across fragmented transports such as TCP and UDP.

QPacket provides a QDataStream interface to an unfragmentable packet. Applications should construct a QPacket, propagate it with data and then transmit it over a QPacketProtocol instance. For example:

int version = QDataStream::Qt_DefaultCompiledVersion;
QPacketProtocol protocol(...);
QPacket myPacket(version);
myPacket << "Hello world!" << 123;
protocol.send(myPacket.data());
int version() const
Returns the version number of the data serialization format.
The QPacketProtocol class encapsulates communicating discrete packets across fragmented IO channels,...
The QPacket class encapsulates an unfragmentable packet of data to be transmitted by QPacketProtocol.
Definition qpacket_p.h:24

As long as both ends of the connection are using the QPacketProtocol class and the same data stream version, the data within this packet will be delivered unfragmented at the other end, ready for extraction.

QByteArray greeting;
int count;
QPacket myPacket(version, protocol.read());
myPacket >> greeting >> count;
\inmodule QtCore
Definition qbytearray.h:57
GLenum GLenum GLsizei count

Only packets constructed from raw byte arrays may be read from. Empty QPacket instances are for transmission only and are considered "write only". Attempting to read data from them will result in undefined behavior.

See also
QPacketProtocol

Definition at line 23 of file qpacket_p.h.

Constructor & Destructor Documentation

◆ QPacket() [1/2]

QPacket::QPacket ( int version)

Constructs an empty write-only packet.

Definition at line 56 of file qpacket.cpp.

References QDataStream::setDevice(), QDataStream::setVersion(), QDataStream::version(), and QIODeviceBase::WriteOnly.

+ Here is the call graph for this function:

◆ QPacket() [2/2]

QPacket::QPacket ( int version,
const QByteArray & ba )
explicit

Constructs a read-only packet.

Definition at line 66 of file qpacket.cpp.

References QIODeviceBase::ReadOnly, QDataStream::setDevice(), QDataStream::setVersion(), and QDataStream::version().

+ Here is the call graph for this function:

Member Function Documentation

◆ clear()

void QPacket::clear ( )

Clears the packet, discarding any data.

Definition at line 96 of file qpacket.cpp.

References QByteArray::reserve().

Referenced by QQmlEngineDebugClient::messageReceived(), qQmlProfilerDataToByteArrays(), QQuick3DProfilerDataToByteArrays(), and qQuickProfilerDataToByteArrays().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ data()

const QByteArray & QPacket::data ( ) const

Returns a reference to the raw packet data.

Definition at line 77 of file qpacket.cpp.

References QByteArray::data().

Referenced by QQmlEngineDebugClient::addWatch(), QQmlEngineDebugClient::addWatch(), QQmlEngineDebugClient::addWatch(), QQmlDebugConnectionPrivate::advertisePlugins(), QQmlInspectorClient::createObject(), QQmlInspectorClient::destroyObject(), encodeFrame(), QQmlPreviewServiceImpl::forwardError(), QQmlPreviewServiceImpl::forwardFps(), QQmlPreviewServiceImpl::forwardRequest(), QQmlInspectorClient::moveObject(), QQmlEngineDebugClient::queryAvailableEngines(), QQmlEngineDebugClient::queryExpressionResult(), QQmlEngineDebugClient::queryExpressionResultBC(), QQmlEngineDebugClient::queryObject(), QQmlEngineDebugClient::queryObjectRecursive(), QQmlEngineDebugClient::queryObjectsForLocation(), QQmlEngineDebugClient::queryObjectsForLocationRecursive(), QQmlEngineDebugClient::queryRootContexts(), QQmlEngineDebugClient::removeWatch(), QQmlEngineDebugClient::resetBindingForObject(), QQmlInspectorClient::select(), QQmlPreviewClient::sendDirectory(), QQmlPreviewClient::sendError(), QQmlPreviewClient::sendFile(), QQmlDebugConnection::sendMessage(), QQmlInspectorClient::setAnimationSpeed(), QQmlEngineDebugClient::setBindingForObject(), QQmlInspectorClient::setInspectToolEnabled(), QQmlEngineDebugClient::setMethodBody(), QQmlInspectorClient::setShowAppOnTop(), QQmlPreviewClient::triggerLoad(), QQmlPreviewClient::triggerRerun(), and QQmlPreviewClient::triggerZoom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ squeezedData()

QByteArray QPacket::squeezedData ( ) const

Returns a copy of the raw packet data, with extra reserved space removed.

Mind that this triggers a deep copy. Use it if you anticipate the data to be detached soon anyway.

Definition at line 86 of file qpacket.cpp.

References QByteArray::data(), and ret.

Referenced by qQmlProfilerDataToByteArrays(), QQuick3DProfilerDataToByteArrays(), and qQuickProfilerDataToByteArrays().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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