2014-08-27 03:05:39 +08:00
|
|
|
#ifndef QAMQPFRAME_P_H
|
|
|
|
|
#define QAMQPFRAME_P_H
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
#include <QDataStream>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
2014-08-27 03:05:39 +08:00
|
|
|
#include "qamqpglobal.h"
|
|
|
|
|
#include "qamqpmessage.h"
|
2014-05-29 03:33:15 +08:00
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
/**
|
|
|
|
|
* Library namespace
|
|
|
|
|
* @namespace QAMQP
|
|
|
|
|
*/
|
|
|
|
|
namespace QAMQP
|
|
|
|
|
{
|
|
|
|
|
|
2014-06-04 21:46:15 +08:00
|
|
|
class QueuePrivate;
|
2014-05-29 00:25:28 +08:00
|
|
|
namespace Frame
|
|
|
|
|
{
|
|
|
|
|
typedef quint16 channel_t;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Header size in bytes
|
|
|
|
|
*/
|
|
|
|
|
static const qint64 HEADER_SIZE = 7;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Frame end indicator size in bytes
|
|
|
|
|
*/
|
|
|
|
|
static const qint64 FRAME_END_SIZE = 1;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Frame end marker
|
|
|
|
|
*/
|
|
|
|
|
static const quint8 FRAME_END = 0xCE;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Frame type
|
|
|
|
|
*/
|
|
|
|
|
enum Type
|
|
|
|
|
{
|
|
|
|
|
ftMethod = 1, /*!< Used define method frame */
|
|
|
|
|
ftHeader = 2, /*!< Used define content header frame */
|
|
|
|
|
ftBody = 3, /*!< Used define content body frame */
|
|
|
|
|
ftHeartbeat = 8 /*!< Used define heartbeat frame */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Frame method class
|
|
|
|
|
* @enum MethodClass
|
|
|
|
|
*/
|
|
|
|
|
enum MethodClass
|
|
|
|
|
{
|
|
|
|
|
fcConnection = 10, // Define class of methods related to connection
|
|
|
|
|
fcChannel = 20, // Define class of methods related to channel
|
|
|
|
|
fcExchange = 40, // Define class of methods related to exchange
|
|
|
|
|
fcQueue = 50, // Define class of methods related to queue
|
|
|
|
|
fcBasic = 60, // Define class of methods related to basic command
|
|
|
|
|
fcTx = 90,
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-27 02:02:43 +08:00
|
|
|
QVariant readAmqpField(QDataStream &s, MetaType::ValueType type);
|
|
|
|
|
void writeAmqpField(QDataStream &s, MetaType::ValueType type, const QVariant &value);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Base class for any frames.
|
|
|
|
|
* @detailed Implement main methods for serialize and deserialize raw frame data.
|
|
|
|
|
* All frames start with a 7-octet header composed of a type field (octet), a channel field (short integer) and a
|
|
|
|
|
* size field (long integer):
|
|
|
|
|
* @code Frame struct
|
|
|
|
|
* 0 1 3 7 size+7 size+8
|
|
|
|
|
* +------+---------+---------+ +-------------+ +-----------+
|
|
|
|
|
* | type | channel | size | | payload | | frame-end |
|
|
|
|
|
* +------+---------+---------+ +-------------+ +-----------+
|
|
|
|
|
* @endcode
|
|
|
|
|
* octet short long 'size' octets octet
|
|
|
|
|
*/
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT Base
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/*
|
|
|
|
|
* Base class constructor.
|
|
|
|
|
* @detailed Construct frame class for sending.
|
|
|
|
|
* @param type Define type of constructed frame.
|
|
|
|
|
*/
|
|
|
|
|
Base(Type type);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Base class constructor.
|
|
|
|
|
* @detailed Construct frame class from received raw data.
|
|
|
|
|
* @param raw Data stream for reading source data.
|
|
|
|
|
*/
|
2014-05-30 23:12:09 +08:00
|
|
|
Base(QDataStream &raw);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Base class virtual destructor
|
|
|
|
|
*/
|
|
|
|
|
virtual ~Base();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Frame type
|
|
|
|
|
* @detailed Return type of current frame.
|
|
|
|
|
*/
|
|
|
|
|
Type type() const;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set number of associated channel.
|
|
|
|
|
* @param channel Number of channel.
|
|
|
|
|
* @sa channel()
|
|
|
|
|
*/
|
|
|
|
|
void setChannel(qint16 channel);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return number of associated channel.
|
|
|
|
|
* @sa setChannel()
|
|
|
|
|
*/
|
|
|
|
|
qint16 channel() const;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return size of frame.
|
|
|
|
|
*/
|
|
|
|
|
virtual qint32 size() const;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Output frame to stream.
|
|
|
|
|
* @param stream Stream for serilize frame.
|
|
|
|
|
*/
|
|
|
|
|
void toStream(QDataStream &stream) const;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void writeHeader(QDataStream &stream) const;
|
2014-07-30 01:35:01 +08:00
|
|
|
virtual void writePayload(QDataStream &stream) const = 0;
|
2014-05-29 00:25:28 +08:00
|
|
|
void writeEnd(QDataStream &stream) const;
|
|
|
|
|
|
|
|
|
|
void readHeader(QDataStream &stream);
|
2014-07-30 01:35:01 +08:00
|
|
|
virtual void readPayload(QDataStream &stream) = 0;
|
|
|
|
|
// void readEnd(QDataStream &stream);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
qint32 size_;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
qint8 type_;
|
|
|
|
|
qint16 channel_;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Class for working with method frames.
|
|
|
|
|
* @detailed Implement main methods for serialize and deserialize raw method frame data.
|
|
|
|
|
* Method frame bodies consist of an invariant list of data fields, called "arguments". All method bodies start
|
|
|
|
|
* with identifier numbers for the class and method:
|
|
|
|
|
* @code Frame struct
|
|
|
|
|
* 0 2 4
|
|
|
|
|
* +----------+-----------+-------------- - -
|
|
|
|
|
* | class-id | method-id | arguments...
|
|
|
|
|
* +----------+-----------+-------------- - -
|
|
|
|
|
* short short ...
|
|
|
|
|
* @endcode
|
|
|
|
|
*/
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT Method : public Base
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/*
|
|
|
|
|
* Method class constructor.
|
|
|
|
|
* @detailed Construct frame class for sending.
|
|
|
|
|
* @param methodClass Define method class id of constructed frame.
|
|
|
|
|
* @param id Define method id of constructed frame.
|
|
|
|
|
*/
|
2014-07-30 01:35:01 +08:00
|
|
|
explicit Method(MethodClass methodClass, qint16 id);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Method class constructor.
|
|
|
|
|
* @detailed Construct frame class from received raw data.
|
|
|
|
|
* @param raw Data stream for reading source data.
|
|
|
|
|
*/
|
2014-07-30 01:35:01 +08:00
|
|
|
explicit Method(QDataStream &raw);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Method class type.
|
|
|
|
|
*/
|
|
|
|
|
MethodClass methodClass() const;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Method id.
|
|
|
|
|
*/
|
|
|
|
|
qint16 id() const;
|
|
|
|
|
qint32 size() const;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set arguments for method.
|
|
|
|
|
* @param data Serialized method arguments.
|
|
|
|
|
* @sa arguments
|
|
|
|
|
*/
|
|
|
|
|
void setArguments(const QByteArray &data);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return arguments for method.
|
|
|
|
|
* @sa setArguments
|
|
|
|
|
*/
|
|
|
|
|
QByteArray arguments() const;
|
|
|
|
|
|
|
|
|
|
protected:
|
2014-05-30 23:12:09 +08:00
|
|
|
void writePayload(QDataStream &stream) const;
|
|
|
|
|
void readPayload(QDataStream &stream);
|
2014-05-29 00:25:28 +08:00
|
|
|
short methodClass_;
|
|
|
|
|
qint16 id_;
|
|
|
|
|
QByteArray arguments_;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Class for working with content frames.
|
|
|
|
|
* @detailed Implement main methods for serialize and deserialize raw content frame data.
|
|
|
|
|
* A content header payload has this format:
|
|
|
|
|
* @code Frame struct
|
|
|
|
|
* +----------+--------+-----------+----------------+------------- - -
|
|
|
|
|
* | class-id | weight | body size | property flags | property list...
|
|
|
|
|
* +----------+--------+-----------+----------------+------------- - -
|
|
|
|
|
* short short long long short remainder...
|
|
|
|
|
* @endcode
|
|
|
|
|
*
|
2014-08-27 02:45:50 +08:00
|
|
|
* | Property | Description |
|
|
|
|
|
* | ---------------- | -------------------------------------- |
|
|
|
|
|
* | ContentType | MIME content type |
|
|
|
|
|
* | ContentEncoding | MIME content encoding |
|
|
|
|
|
* | Headers | message header field table |
|
|
|
|
|
* | DeliveryMode | nonpersistent (1) or persistent (2) |
|
|
|
|
|
* | Priority | message priority, 0 to 9 |
|
|
|
|
|
* | CorrelationId | application correlation identifier |
|
|
|
|
|
* | ReplyTo | address to reply to |
|
|
|
|
|
* | Expiration | message expiration specification |
|
|
|
|
|
* | MessageId | application message identifier |
|
|
|
|
|
* | Timestamp | message timestamp |
|
|
|
|
|
* | Type | message type name |
|
|
|
|
|
* | UserId | creating user id |
|
|
|
|
|
* | AppId | creating application id |
|
|
|
|
|
* | ClusterID | cluster ID |
|
2014-05-29 00:25:28 +08:00
|
|
|
*
|
|
|
|
|
* Default property:
|
|
|
|
|
* @sa setProperty
|
|
|
|
|
* @sa property
|
|
|
|
|
*/
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT Content : public Base
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/*
|
|
|
|
|
* Content class constructor.
|
|
|
|
|
* @detailed Construct frame content header class for sending.
|
|
|
|
|
*/
|
|
|
|
|
Content();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Content class constructor.
|
|
|
|
|
* @detailed Construct frame content header class for sending.
|
|
|
|
|
* @param methodClass Define method class id of constructed frame.
|
|
|
|
|
*/
|
|
|
|
|
Content(MethodClass methodClass);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Content class constructor.
|
|
|
|
|
* @detailed Construct frame content header class for sending.
|
|
|
|
|
* @param raw Data stream for reading source data.
|
|
|
|
|
*/
|
|
|
|
|
Content(QDataStream &raw);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Method class type.
|
|
|
|
|
*/
|
|
|
|
|
MethodClass methodClass() const;
|
|
|
|
|
qint32 size() const;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set default content header property
|
|
|
|
|
* @param prop Any default content header property
|
|
|
|
|
* @param value Associated data
|
|
|
|
|
*/
|
2014-08-27 02:45:50 +08:00
|
|
|
void setProperty(Message::Property prop, const QVariant &value);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return associated with property value
|
|
|
|
|
* @param prop Any default content header property
|
|
|
|
|
*/
|
2014-08-27 02:45:50 +08:00
|
|
|
QVariant property(Message::Property prop) const;
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
qlonglong bodySize() const;
|
2014-08-04 02:11:21 +08:00
|
|
|
void setBodySize(qlonglong size);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void writePayload(QDataStream &stream) const;
|
|
|
|
|
void readPayload(QDataStream &stream);
|
|
|
|
|
short methodClass_;
|
|
|
|
|
qint16 id_;
|
|
|
|
|
mutable QByteArray buffer_;
|
2014-08-27 02:45:50 +08:00
|
|
|
Message::PropertyHash properties_;
|
2014-05-29 00:25:28 +08:00
|
|
|
qlonglong bodySize_;
|
2014-05-29 01:52:27 +08:00
|
|
|
|
|
|
|
|
private:
|
2014-06-04 21:46:15 +08:00
|
|
|
friend class QAMQP::QueuePrivate;
|
|
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
};
|
|
|
|
|
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT ContentBody : public Base
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ContentBody();
|
|
|
|
|
ContentBody(QDataStream &raw);
|
|
|
|
|
|
|
|
|
|
void setBody(const QByteArray &data);
|
|
|
|
|
QByteArray body() const;
|
|
|
|
|
|
|
|
|
|
qint32 size() const;
|
|
|
|
|
protected:
|
|
|
|
|
void writePayload(QDataStream &stream) const;
|
|
|
|
|
void readPayload(QDataStream &stream);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QByteArray body_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief Class for working with heartbeat frames.
|
|
|
|
|
* @detailed Implement frame for heartbeat send.
|
|
|
|
|
*/
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT Heartbeat : public Base
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/*
|
|
|
|
|
* Heartbeat class constructor.
|
|
|
|
|
* @detailed Construct frame class for sending.
|
|
|
|
|
*/
|
|
|
|
|
Heartbeat();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void writePayload(QDataStream &stream) const;
|
|
|
|
|
void readPayload(QDataStream &stream);
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT MethodHandler
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
public:
|
2014-06-04 21:46:15 +08:00
|
|
|
virtual bool _q_method(const Frame::Method &frame) = 0;
|
2014-05-29 00:25:28 +08:00
|
|
|
};
|
|
|
|
|
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT ContentHandler
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
public:
|
2014-05-30 23:12:09 +08:00
|
|
|
virtual void _q_content(const Frame::Content &frame) = 0;
|
2014-05-29 00:25:28 +08:00
|
|
|
};
|
|
|
|
|
|
2014-05-29 03:33:15 +08:00
|
|
|
class QAMQP_EXPORT ContentBodyHandler
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
public:
|
2014-05-30 23:12:09 +08:00
|
|
|
virtual void _q_body(const Frame::ContentBody &frame) = 0;
|
2014-05-29 00:25:28 +08:00
|
|
|
};
|
2014-05-29 01:52:27 +08:00
|
|
|
|
|
|
|
|
} // namespace Frame
|
|
|
|
|
|
|
|
|
|
} // namespace QAMQP
|
2014-05-29 00:25:28 +08:00
|
|
|
|
2014-08-27 03:05:39 +08:00
|
|
|
#endif // QAMQPFRAME_P_H
|