refactor Frame::Content to use Message::Property
This commit is contained in:
parent
bdd9bae8ea
commit
840efb037d
|
|
@ -250,15 +250,15 @@ void Exchange::publish(const QByteArray &message, const QString &routingKey,
|
||||||
|
|
||||||
Frame::Content content(Frame::fcBasic);
|
Frame::Content content(Frame::fcBasic);
|
||||||
content.setChannel(d->channelNumber);
|
content.setChannel(d->channelNumber);
|
||||||
content.setProperty(Frame::Content::cpContentType, mimeType);
|
content.setProperty(Message::ContentType, mimeType);
|
||||||
content.setProperty(Frame::Content::cpContentEncoding, "utf-8");
|
content.setProperty(Message::ContentEncoding, "utf-8");
|
||||||
content.setProperty(Frame::Content::cpHeaders, headers);
|
content.setProperty(Message::Headers, headers);
|
||||||
content.setProperty(Frame::Content::cpMessageId, "0");
|
content.setProperty(Message::MessageId, "0");
|
||||||
|
|
||||||
Message::PropertyHash::ConstIterator it;
|
Message::PropertyHash::ConstIterator it;
|
||||||
Message::PropertyHash::ConstIterator itEnd = properties.constEnd();
|
Message::PropertyHash::ConstIterator itEnd = properties.constEnd();
|
||||||
for (it = properties.constBegin(); it != itEnd; ++it)
|
for (it = properties.constBegin(); it != itEnd; ++it)
|
||||||
content.setProperty(static_cast<Frame::Content::Property>(it.key()), it.value());
|
content.setProperty(it.key(), it.value());
|
||||||
content.setBodySize(message.size());
|
content.setBodySize(message.size());
|
||||||
d->sendFrame(content);
|
d->sendFrame(content);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -300,47 +300,47 @@ qint32 Content::size() const
|
||||||
prop_ |= p;
|
prop_ |= p;
|
||||||
out << prop_;
|
out << prop_;
|
||||||
|
|
||||||
if (prop_ & cpContentType)
|
if (prop_ & Message::ContentType)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpContentType]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::ContentType]);
|
||||||
|
|
||||||
if (prop_ & cpContentEncoding)
|
if (prop_ & Message::ContentEncoding)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpContentEncoding]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::ContentEncoding]);
|
||||||
|
|
||||||
if (prop_ & cpHeaders)
|
if (prop_ & Message::Headers)
|
||||||
writeAmqpField(out, MetaType::Hash, properties_[cpHeaders]);
|
writeAmqpField(out, MetaType::Hash, properties_[Message::Headers]);
|
||||||
|
|
||||||
if (prop_ & cpDeliveryMode)
|
if (prop_ & Message::DeliveryMode)
|
||||||
writeAmqpField(out, MetaType::ShortShortUint, properties_[cpDeliveryMode]);
|
writeAmqpField(out, MetaType::ShortShortUint, properties_[Message::DeliveryMode]);
|
||||||
|
|
||||||
if (prop_ & cpPriority)
|
if (prop_ & Message::Priority)
|
||||||
writeAmqpField(out, MetaType::ShortShortUint, properties_[cpPriority]);
|
writeAmqpField(out, MetaType::ShortShortUint, properties_[Message::Priority]);
|
||||||
|
|
||||||
if (prop_ & cpCorrelationId)
|
if (prop_ & Message::CorrelationId)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpCorrelationId]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::CorrelationId]);
|
||||||
|
|
||||||
if (prop_ & cpReplyTo)
|
if (prop_ & Message::ReplyTo)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpReplyTo]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::ReplyTo]);
|
||||||
|
|
||||||
if (prop_ & cpExpiration)
|
if (prop_ & Message::Expiration)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpExpiration]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::Expiration]);
|
||||||
|
|
||||||
if (prop_ & cpMessageId)
|
if (prop_ & Message::MessageId)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpMessageId]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::MessageId]);
|
||||||
|
|
||||||
if (prop_ & cpTimestamp)
|
if (prop_ & Message::Timestamp)
|
||||||
writeAmqpField(out, MetaType::Timestamp, properties_[cpTimestamp]);
|
writeAmqpField(out, MetaType::Timestamp, properties_[Message::Timestamp]);
|
||||||
|
|
||||||
if (prop_ & cpType)
|
if (prop_ & Message::Type)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpType]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::Type]);
|
||||||
|
|
||||||
if (prop_ & cpUserId)
|
if (prop_ & Message::UserId)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpUserId]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::UserId]);
|
||||||
|
|
||||||
if (prop_ & cpAppId)
|
if (prop_ & Message::AppId)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpAppId]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::AppId]);
|
||||||
|
|
||||||
if (prop_ & cpClusterID)
|
if (prop_ & Message::ClusterID)
|
||||||
writeAmqpField(out, MetaType::ShortString, properties_[cpClusterID]);
|
writeAmqpField(out, MetaType::ShortString, properties_[Message::ClusterID]);
|
||||||
|
|
||||||
return buffer_.size();
|
return buffer_.size();
|
||||||
}
|
}
|
||||||
|
|
@ -355,12 +355,12 @@ void Content::setBodySize(qlonglong size)
|
||||||
bodySize_ = size;
|
bodySize_ = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Content::setProperty(Property prop, const QVariant &value)
|
void Content::setProperty(Message::Property prop, const QVariant &value)
|
||||||
{
|
{
|
||||||
properties_[prop] = value;
|
properties_[prop] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Content::property(Property prop) const
|
QVariant Content::property(Message::Property prop) const
|
||||||
{
|
{
|
||||||
return properties_.value(prop);
|
return properties_.value(prop);
|
||||||
}
|
}
|
||||||
|
|
@ -377,47 +377,47 @@ void Content::readPayload(QDataStream &in)
|
||||||
in >> bodySize_;
|
in >> bodySize_;
|
||||||
qint16 flags_ = 0;
|
qint16 flags_ = 0;
|
||||||
in >> flags_;
|
in >> flags_;
|
||||||
if (flags_ & cpContentType)
|
if (flags_ & Message::ContentType)
|
||||||
properties_[cpContentType] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::ContentType] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpContentEncoding)
|
if (flags_ & Message::ContentEncoding)
|
||||||
properties_[cpContentEncoding] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::ContentEncoding] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpHeaders)
|
if (flags_ & Message::Headers)
|
||||||
properties_[cpHeaders] = readAmqpField(in, MetaType::Hash);
|
properties_[Message::Headers] = readAmqpField(in, MetaType::Hash);
|
||||||
|
|
||||||
if (flags_ & cpDeliveryMode)
|
if (flags_ & Message::DeliveryMode)
|
||||||
properties_[cpDeliveryMode] = readAmqpField(in, MetaType::ShortShortUint);
|
properties_[Message::DeliveryMode] = readAmqpField(in, MetaType::ShortShortUint);
|
||||||
|
|
||||||
if (flags_ & cpPriority)
|
if (flags_ & Message::Priority)
|
||||||
properties_[cpPriority] = readAmqpField(in, MetaType::ShortShortUint);
|
properties_[Message::Priority] = readAmqpField(in, MetaType::ShortShortUint);
|
||||||
|
|
||||||
if (flags_ & cpCorrelationId)
|
if (flags_ & Message::CorrelationId)
|
||||||
properties_[cpCorrelationId] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::CorrelationId] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpReplyTo)
|
if (flags_ & Message::ReplyTo)
|
||||||
properties_[cpReplyTo] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::ReplyTo] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpExpiration)
|
if (flags_ & Message::Expiration)
|
||||||
properties_[cpExpiration] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::Expiration] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpMessageId)
|
if (flags_ & Message::MessageId)
|
||||||
properties_[cpMessageId] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::MessageId] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpTimestamp)
|
if (flags_ & Message::Timestamp)
|
||||||
properties_[cpTimestamp] = readAmqpField(in, MetaType::Timestamp);
|
properties_[Message::Timestamp] = readAmqpField(in, MetaType::Timestamp);
|
||||||
|
|
||||||
if (flags_ & cpType)
|
if (flags_ & Message::Type)
|
||||||
properties_[cpType] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::Type] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpUserId)
|
if (flags_ & Message::UserId)
|
||||||
properties_[cpUserId] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::UserId] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpAppId)
|
if (flags_ & Message::AppId)
|
||||||
properties_[cpAppId] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::AppId] = readAmqpField(in, MetaType::ShortString);
|
||||||
|
|
||||||
if (flags_ & cpClusterID)
|
if (flags_ & Message::ClusterID)
|
||||||
properties_[cpClusterID] = readAmqpField(in, MetaType::ShortString);
|
properties_[Message::ClusterID] = readAmqpField(in, MetaType::ShortString);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "amqp_global.h"
|
#include "amqp_global.h"
|
||||||
|
#include "amqp_message.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Library namespace
|
* Library namespace
|
||||||
|
|
@ -219,22 +220,22 @@ namespace Frame
|
||||||
* short short long long short remainder...
|
* short short long long short remainder...
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* | Property | Description |
|
* | Property | Description |
|
||||||
* | ------------------ | -------------------------------------- |
|
* | ---------------- | -------------------------------------- |
|
||||||
* | cpContentType | MIME content type |
|
* | ContentType | MIME content type |
|
||||||
* | cpContentEncoding | MIME content encoding |
|
* | ContentEncoding | MIME content encoding |
|
||||||
* | cpHeaders | message header field table |
|
* | Headers | message header field table |
|
||||||
* | cpDeliveryMode | nonpersistent (1) or persistent (2) |
|
* | DeliveryMode | nonpersistent (1) or persistent (2) |
|
||||||
* | cpPriority | message priority, 0 to 9 |
|
* | Priority | message priority, 0 to 9 |
|
||||||
* | cpCorrelationId | application correlation identifier |
|
* | CorrelationId | application correlation identifier |
|
||||||
* | cpReplyTo | address to reply to |
|
* | ReplyTo | address to reply to |
|
||||||
* | cpExpiration | message expiration specification |
|
* | Expiration | message expiration specification |
|
||||||
* | cpMessageId | application message identifier |
|
* | MessageId | application message identifier |
|
||||||
* | cpTimestamp | message timestamp |
|
* | Timestamp | message timestamp |
|
||||||
* | cpType | message type name |
|
* | Type | message type name |
|
||||||
* | cpUserId | creating user id |
|
* | UserId | creating user id |
|
||||||
* | cpAppId | creating application id |
|
* | AppId | creating application id |
|
||||||
* | cpClusterID | cluster ID |
|
* | ClusterID | cluster ID |
|
||||||
*
|
*
|
||||||
* Default property:
|
* Default property:
|
||||||
* @sa setProperty
|
* @sa setProperty
|
||||||
|
|
@ -243,28 +244,6 @@ namespace Frame
|
||||||
class QAMQP_EXPORT Content : public Base
|
class QAMQP_EXPORT Content : public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*
|
|
||||||
* Default content frame property
|
|
||||||
*/
|
|
||||||
enum Property
|
|
||||||
{
|
|
||||||
cpContentType = AMQP_BASIC_CONTENT_TYPE_FLAG,
|
|
||||||
cpContentEncoding = AMQP_BASIC_CONTENT_ENCODING_FLAG,
|
|
||||||
cpHeaders = AMQP_BASIC_HEADERS_FLAG,
|
|
||||||
cpDeliveryMode = AMQP_BASIC_DELIVERY_MODE_FLAG,
|
|
||||||
cpPriority = AMQP_BASIC_PRIORITY_FLAG,
|
|
||||||
cpCorrelationId = AMQP_BASIC_CORRELATION_ID_FLAG,
|
|
||||||
cpReplyTo = AMQP_BASIC_REPLY_TO_FLAG,
|
|
||||||
cpExpiration = AMQP_BASIC_EXPIRATION_FLAG,
|
|
||||||
cpMessageId = AMQP_BASIC_MESSAGE_ID_FLAG,
|
|
||||||
cpTimestamp = AMQP_BASIC_TIMESTAMP_FLAG,
|
|
||||||
cpType = AMQP_BASIC_TYPE_FLAG,
|
|
||||||
cpUserId = AMQP_BASIC_USER_ID_FLAG,
|
|
||||||
cpAppId = AMQP_BASIC_APP_ID_FLAG,
|
|
||||||
cpClusterID = AMQP_BASIC_CLUSTER_ID_FLAG
|
|
||||||
};
|
|
||||||
Q_DECLARE_FLAGS(Properties, Property)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Content class constructor.
|
* Content class constructor.
|
||||||
* @detailed Construct frame content header class for sending.
|
* @detailed Construct frame content header class for sending.
|
||||||
|
|
@ -296,13 +275,13 @@ namespace Frame
|
||||||
* @param prop Any default content header property
|
* @param prop Any default content header property
|
||||||
* @param value Associated data
|
* @param value Associated data
|
||||||
*/
|
*/
|
||||||
void setProperty(Property prop, const QVariant &value);
|
void setProperty(Message::Property prop, const QVariant &value);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return associated with property value
|
* Return associated with property value
|
||||||
* @param prop Any default content header property
|
* @param prop Any default content header property
|
||||||
*/
|
*/
|
||||||
QVariant property(Property prop) const;
|
QVariant property(Message::Property prop) const;
|
||||||
|
|
||||||
qlonglong bodySize() const;
|
qlonglong bodySize() const;
|
||||||
void setBodySize(qlonglong size);
|
void setBodySize(qlonglong size);
|
||||||
|
|
@ -313,7 +292,7 @@ namespace Frame
|
||||||
short methodClass_;
|
short methodClass_;
|
||||||
qint16 id_;
|
qint16 id_;
|
||||||
mutable QByteArray buffer_;
|
mutable QByteArray buffer_;
|
||||||
QHash<int, QVariant> properties_;
|
Message::PropertyHash properties_;
|
||||||
qlonglong bodySize_;
|
qlonglong bodySize_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -88,10 +88,10 @@ void QueuePrivate::_q_content(const Frame::Content &frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentMessage.d->leftSize = frame.bodySize();
|
currentMessage.d->leftSize = frame.bodySize();
|
||||||
QHash<int, QVariant>::ConstIterator it;
|
Message::PropertyHash::ConstIterator it;
|
||||||
QHash<int, QVariant>::ConstIterator itEnd = frame.properties_.constEnd();
|
Message::PropertyHash::ConstIterator itEnd = frame.properties_.constEnd();
|
||||||
for (it = frame.properties_.constBegin(); it != itEnd; ++it) {
|
for (it = frame.properties_.constBegin(); it != itEnd; ++it) {
|
||||||
Message::Property property = static_cast<Message::Property>(it.key());
|
Message::Property property = (it.key());
|
||||||
if (property == Message::Headers)
|
if (property == Message::Headers)
|
||||||
currentMessage.d->headers = (it.value()).toHash();
|
currentMessage.d->headers = (it.value()).toHash();
|
||||||
currentMessage.d->properties[property] = it.value();
|
currentMessage.d->properties[property] = it.value();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue