refactor Frame::Content to use Message::Property

This commit is contained in:
Matt Broadstone 2014-08-26 14:45:50 -04:00
parent bdd9bae8ea
commit 840efb037d
4 changed files with 86 additions and 107 deletions

View File

@ -250,15 +250,15 @@ void Exchange::publish(const QByteArray &message, const QString &routingKey,
Frame::Content content(Frame::fcBasic);
content.setChannel(d->channelNumber);
content.setProperty(Frame::Content::cpContentType, mimeType);
content.setProperty(Frame::Content::cpContentEncoding, "utf-8");
content.setProperty(Frame::Content::cpHeaders, headers);
content.setProperty(Frame::Content::cpMessageId, "0");
content.setProperty(Message::ContentType, mimeType);
content.setProperty(Message::ContentEncoding, "utf-8");
content.setProperty(Message::Headers, headers);
content.setProperty(Message::MessageId, "0");
Message::PropertyHash::ConstIterator it;
Message::PropertyHash::ConstIterator itEnd = properties.constEnd();
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());
d->sendFrame(content);

View File

@ -300,47 +300,47 @@ qint32 Content::size() const
prop_ |= p;
out << prop_;
if (prop_ & cpContentType)
writeAmqpField(out, MetaType::ShortString, properties_[cpContentType]);
if (prop_ & Message::ContentType)
writeAmqpField(out, MetaType::ShortString, properties_[Message::ContentType]);
if (prop_ & cpContentEncoding)
writeAmqpField(out, MetaType::ShortString, properties_[cpContentEncoding]);
if (prop_ & Message::ContentEncoding)
writeAmqpField(out, MetaType::ShortString, properties_[Message::ContentEncoding]);
if (prop_ & cpHeaders)
writeAmqpField(out, MetaType::Hash, properties_[cpHeaders]);
if (prop_ & Message::Headers)
writeAmqpField(out, MetaType::Hash, properties_[Message::Headers]);
if (prop_ & cpDeliveryMode)
writeAmqpField(out, MetaType::ShortShortUint, properties_[cpDeliveryMode]);
if (prop_ & Message::DeliveryMode)
writeAmqpField(out, MetaType::ShortShortUint, properties_[Message::DeliveryMode]);
if (prop_ & cpPriority)
writeAmqpField(out, MetaType::ShortShortUint, properties_[cpPriority]);
if (prop_ & Message::Priority)
writeAmqpField(out, MetaType::ShortShortUint, properties_[Message::Priority]);
if (prop_ & cpCorrelationId)
writeAmqpField(out, MetaType::ShortString, properties_[cpCorrelationId]);
if (prop_ & Message::CorrelationId)
writeAmqpField(out, MetaType::ShortString, properties_[Message::CorrelationId]);
if (prop_ & cpReplyTo)
writeAmqpField(out, MetaType::ShortString, properties_[cpReplyTo]);
if (prop_ & Message::ReplyTo)
writeAmqpField(out, MetaType::ShortString, properties_[Message::ReplyTo]);
if (prop_ & cpExpiration)
writeAmqpField(out, MetaType::ShortString, properties_[cpExpiration]);
if (prop_ & Message::Expiration)
writeAmqpField(out, MetaType::ShortString, properties_[Message::Expiration]);
if (prop_ & cpMessageId)
writeAmqpField(out, MetaType::ShortString, properties_[cpMessageId]);
if (prop_ & Message::MessageId)
writeAmqpField(out, MetaType::ShortString, properties_[Message::MessageId]);
if (prop_ & cpTimestamp)
writeAmqpField(out, MetaType::Timestamp, properties_[cpTimestamp]);
if (prop_ & Message::Timestamp)
writeAmqpField(out, MetaType::Timestamp, properties_[Message::Timestamp]);
if (prop_ & cpType)
writeAmqpField(out, MetaType::ShortString, properties_[cpType]);
if (prop_ & Message::Type)
writeAmqpField(out, MetaType::ShortString, properties_[Message::Type]);
if (prop_ & cpUserId)
writeAmqpField(out, MetaType::ShortString, properties_[cpUserId]);
if (prop_ & Message::UserId)
writeAmqpField(out, MetaType::ShortString, properties_[Message::UserId]);
if (prop_ & cpAppId)
writeAmqpField(out, MetaType::ShortString, properties_[cpAppId]);
if (prop_ & Message::AppId)
writeAmqpField(out, MetaType::ShortString, properties_[Message::AppId]);
if (prop_ & cpClusterID)
writeAmqpField(out, MetaType::ShortString, properties_[cpClusterID]);
if (prop_ & Message::ClusterID)
writeAmqpField(out, MetaType::ShortString, properties_[Message::ClusterID]);
return buffer_.size();
}
@ -355,12 +355,12 @@ void Content::setBodySize(qlonglong size)
bodySize_ = size;
}
void Content::setProperty(Property prop, const QVariant &value)
void Content::setProperty(Message::Property prop, const QVariant &value)
{
properties_[prop] = value;
}
QVariant Content::property(Property prop) const
QVariant Content::property(Message::Property prop) const
{
return properties_.value(prop);
}
@ -377,47 +377,47 @@ void Content::readPayload(QDataStream &in)
in >> bodySize_;
qint16 flags_ = 0;
in >> flags_;
if (flags_ & cpContentType)
properties_[cpContentType] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::ContentType)
properties_[Message::ContentType] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpContentEncoding)
properties_[cpContentEncoding] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::ContentEncoding)
properties_[Message::ContentEncoding] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpHeaders)
properties_[cpHeaders] = readAmqpField(in, MetaType::Hash);
if (flags_ & Message::Headers)
properties_[Message::Headers] = readAmqpField(in, MetaType::Hash);
if (flags_ & cpDeliveryMode)
properties_[cpDeliveryMode] = readAmqpField(in, MetaType::ShortShortUint);
if (flags_ & Message::DeliveryMode)
properties_[Message::DeliveryMode] = readAmqpField(in, MetaType::ShortShortUint);
if (flags_ & cpPriority)
properties_[cpPriority] = readAmqpField(in, MetaType::ShortShortUint);
if (flags_ & Message::Priority)
properties_[Message::Priority] = readAmqpField(in, MetaType::ShortShortUint);
if (flags_ & cpCorrelationId)
properties_[cpCorrelationId] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::CorrelationId)
properties_[Message::CorrelationId] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpReplyTo)
properties_[cpReplyTo] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::ReplyTo)
properties_[Message::ReplyTo] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpExpiration)
properties_[cpExpiration] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::Expiration)
properties_[Message::Expiration] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpMessageId)
properties_[cpMessageId] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::MessageId)
properties_[Message::MessageId] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpTimestamp)
properties_[cpTimestamp] = readAmqpField(in, MetaType::Timestamp);
if (flags_ & Message::Timestamp)
properties_[Message::Timestamp] = readAmqpField(in, MetaType::Timestamp);
if (flags_ & cpType)
properties_[cpType] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::Type)
properties_[Message::Type] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpUserId)
properties_[cpUserId] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::UserId)
properties_[Message::UserId] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpAppId)
properties_[cpAppId] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::AppId)
properties_[Message::AppId] = readAmqpField(in, MetaType::ShortString);
if (flags_ & cpClusterID)
properties_[cpClusterID] = readAmqpField(in, MetaType::ShortString);
if (flags_ & Message::ClusterID)
properties_[Message::ClusterID] = readAmqpField(in, MetaType::ShortString);
}
//////////////////////////////////////////////////////////////////////////

View File

@ -6,6 +6,7 @@
#include <QVariant>
#include "amqp_global.h"
#include "amqp_message.h"
/**
* Library namespace
@ -219,22 +220,22 @@ namespace Frame
* short short long long short remainder...
* @endcode
*
* | Property | Description |
* | ------------------ | -------------------------------------- |
* | cpContentType | MIME content type |
* | cpContentEncoding | MIME content encoding |
* | cpHeaders | message header field table |
* | cpDeliveryMode | nonpersistent (1) or persistent (2) |
* | cpPriority | message priority, 0 to 9 |
* | cpCorrelationId | application correlation identifier |
* | cpReplyTo | address to reply to |
* | cpExpiration | message expiration specification |
* | cpMessageId | application message identifier |
* | cpTimestamp | message timestamp |
* | cpType | message type name |
* | cpUserId | creating user id |
* | cpAppId | creating application id |
* | cpClusterID | cluster ID |
* | 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 |
*
* Default property:
* @sa setProperty
@ -243,28 +244,6 @@ namespace Frame
class QAMQP_EXPORT Content : public Base
{
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.
* @detailed Construct frame content header class for sending.
@ -296,13 +275,13 @@ namespace Frame
* @param prop Any default content header property
* @param value Associated data
*/
void setProperty(Property prop, const QVariant &value);
void setProperty(Message::Property prop, const QVariant &value);
/*
* Return associated with property value
* @param prop Any default content header property
*/
QVariant property(Property prop) const;
QVariant property(Message::Property prop) const;
qlonglong bodySize() const;
void setBodySize(qlonglong size);
@ -313,7 +292,7 @@ namespace Frame
short methodClass_;
qint16 id_;
mutable QByteArray buffer_;
QHash<int, QVariant> properties_;
Message::PropertyHash properties_;
qlonglong bodySize_;
private:

View File

@ -88,10 +88,10 @@ void QueuePrivate::_q_content(const Frame::Content &frame)
}
currentMessage.d->leftSize = frame.bodySize();
QHash<int, QVariant>::ConstIterator it;
QHash<int, QVariant>::ConstIterator itEnd = frame.properties_.constEnd();
Message::PropertyHash::ConstIterator it;
Message::PropertyHash::ConstIterator itEnd = frame.properties_.constEnd();
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)
currentMessage.d->headers = (it.value()).toHash();
currentMessage.d->properties[property] = it.value();