move property definition/access to Message
MessageProperties is currently defined in Frame::Content, which makes it cumbersome to use when working directly with a Message itself. I attempted to make this easier by using typedefs, but it's become pretty obvious that it belongs in the Message class itself.
This commit is contained in:
parent
dec9ef72d3
commit
5c6cd23e10
|
|
@ -7,21 +7,6 @@
|
|||
|
||||
#include "amqp_global.h"
|
||||
|
||||
#define AMQP_BASIC_CONTENT_TYPE_FLAG (1 << 15)
|
||||
#define AMQP_BASIC_CONTENT_ENCODING_FLAG (1 << 14)
|
||||
#define AMQP_BASIC_HEADERS_FLAG (1 << 13)
|
||||
#define AMQP_BASIC_DELIVERY_MODE_FLAG (1 << 12)
|
||||
#define AMQP_BASIC_PRIORITY_FLAG (1 << 11)
|
||||
#define AMQP_BASIC_CORRELATION_ID_FLAG (1 << 10)
|
||||
#define AMQP_BASIC_REPLY_TO_FLAG (1 << 9)
|
||||
#define AMQP_BASIC_EXPIRATION_FLAG (1 << 8)
|
||||
#define AMQP_BASIC_MESSAGE_ID_FLAG (1 << 7)
|
||||
#define AMQP_BASIC_TIMESTAMP_FLAG (1 << 6)
|
||||
#define AMQP_BASIC_TYPE_FLAG (1 << 5)
|
||||
#define AMQP_BASIC_USER_ID_FLAG (1 << 4)
|
||||
#define AMQP_BASIC_APP_ID_FLAG (1 << 3)
|
||||
#define AMQP_BASIC_CLUSTER_ID_FLAG (1 << 2)
|
||||
|
||||
/**
|
||||
* Library namespace
|
||||
* @namespace QAMQP
|
||||
|
|
|
|||
|
|
@ -14,6 +14,21 @@
|
|||
#define AMQP_FRAME_MAX 131072
|
||||
#define AMQP_FRAME_MIN_SIZE 4096
|
||||
|
||||
#define AMQP_BASIC_CONTENT_TYPE_FLAG (1 << 15)
|
||||
#define AMQP_BASIC_CONTENT_ENCODING_FLAG (1 << 14)
|
||||
#define AMQP_BASIC_HEADERS_FLAG (1 << 13)
|
||||
#define AMQP_BASIC_DELIVERY_MODE_FLAG (1 << 12)
|
||||
#define AMQP_BASIC_PRIORITY_FLAG (1 << 11)
|
||||
#define AMQP_BASIC_CORRELATION_ID_FLAG (1 << 10)
|
||||
#define AMQP_BASIC_REPLY_TO_FLAG (1 << 9)
|
||||
#define AMQP_BASIC_EXPIRATION_FLAG (1 << 8)
|
||||
#define AMQP_BASIC_MESSAGE_ID_FLAG (1 << 7)
|
||||
#define AMQP_BASIC_TIMESTAMP_FLAG (1 << 6)
|
||||
#define AMQP_BASIC_TYPE_FLAG (1 << 5)
|
||||
#define AMQP_BASIC_USER_ID_FLAG (1 << 4)
|
||||
#define AMQP_BASIC_APP_ID_FLAG (1 << 3)
|
||||
#define AMQP_BASIC_CLUSTER_ID_FLAG (1 << 2)
|
||||
|
||||
#define QAMQP_VERSION "0.3.0"
|
||||
|
||||
#define AMQP_CONNECTION_FORCED 320
|
||||
|
|
@ -32,6 +47,7 @@
|
|||
|
||||
namespace QAMQP {
|
||||
|
||||
|
||||
enum Error {
|
||||
NoError = 0,
|
||||
ContentTooLargeError = 311,
|
||||
|
|
|
|||
|
|
@ -62,12 +62,22 @@ QByteArray Message::payload() const
|
|||
return d->payload;
|
||||
}
|
||||
|
||||
MessageProperties Message::properties() const
|
||||
{
|
||||
return d->properties;
|
||||
}
|
||||
|
||||
Frame::TableField Message::headers() const
|
||||
{
|
||||
return d->headers;
|
||||
}
|
||||
|
||||
bool Message::hasProperty(Property property) const
|
||||
{
|
||||
return d->properties.contains(property);
|
||||
}
|
||||
|
||||
void Message::setProperty(Property property, const QVariant &value)
|
||||
{
|
||||
d->properties.insert(property, value);
|
||||
}
|
||||
|
||||
QVariant Message::property(Property property, const QVariant &defaultValue) const
|
||||
{
|
||||
return d->properties.value(property, defaultValue);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,28 @@ public:
|
|||
Message &operator=(const Message &other);
|
||||
~Message();
|
||||
|
||||
enum Property {
|
||||
ContentType = AMQP_BASIC_CONTENT_TYPE_FLAG,
|
||||
ContentEncoding = AMQP_BASIC_CONTENT_ENCODING_FLAG,
|
||||
Headers = AMQP_BASIC_HEADERS_FLAG,
|
||||
DeliveryMode = AMQP_BASIC_DELIVERY_MODE_FLAG,
|
||||
Priority = AMQP_BASIC_PRIORITY_FLAG,
|
||||
CorrelationId = AMQP_BASIC_CORRELATION_ID_FLAG,
|
||||
ReplyTo = AMQP_BASIC_REPLY_TO_FLAG,
|
||||
Expiration = AMQP_BASIC_EXPIRATION_FLAG,
|
||||
MessageId = AMQP_BASIC_MESSAGE_ID_FLAG,
|
||||
Timestamp = AMQP_BASIC_TIMESTAMP_FLAG,
|
||||
Type = AMQP_BASIC_TYPE_FLAG,
|
||||
UserId = AMQP_BASIC_USER_ID_FLAG,
|
||||
AppId = AMQP_BASIC_APP_ID_FLAG,
|
||||
ClusterID = AMQP_BASIC_CLUSTER_ID_FLAG
|
||||
};
|
||||
Q_DECLARE_FLAGS(Properties, Property)
|
||||
|
||||
bool hasProperty(Property property) const;
|
||||
void setProperty(Property property, const QVariant &value);
|
||||
QVariant property(Property property, const QVariant &defaultValue = QString()) const;
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
qlonglong deliveryTag() const;
|
||||
|
|
@ -27,7 +49,6 @@ public:
|
|||
QString exchangeName() const;
|
||||
QString routingKey() const;
|
||||
QByteArray payload() const;
|
||||
MessageProperties properties() const;
|
||||
Frame::TableField headers() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -18,11 +18,9 @@ public:
|
|||
bool redelivered;
|
||||
QString exchangeName;
|
||||
QString routingKey;
|
||||
|
||||
QByteArray payload;
|
||||
MessageProperties properties;
|
||||
QHash<Message::Property, QVariant> properties;
|
||||
Frame::TableField headers;
|
||||
|
||||
int leftSize;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ void QueuePrivate::_q_content(const Frame::Content &frame)
|
|||
QHash<int, QVariant>::ConstIterator it;
|
||||
QHash<int, QVariant>::ConstIterator itEnd = frame.properties_.constEnd();
|
||||
for (it = frame.properties_.constBegin(); it != itEnd; ++it)
|
||||
currentMessage.d->properties[MessageProperty(it.key())] = it.value();
|
||||
currentMessage.d->properties[static_cast<Message::Property>(it.key())] = it.value();
|
||||
}
|
||||
|
||||
void QueuePrivate::_q_body(const Frame::ContentBody &frame)
|
||||
|
|
|
|||
|
|
@ -399,8 +399,8 @@ void tst_QAMQPQueue::verifyContentEncodingIssue33()
|
|||
|
||||
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived())));
|
||||
Message message = queue->dequeue();
|
||||
QString contentType =
|
||||
message.properties().value(Frame::Content::cpContentEncoding).toString();
|
||||
QVERIFY(message.hasProperty(Message::ContentEncoding));
|
||||
QString contentType = message.property(Message::ContentEncoding).toString();
|
||||
QCOMPARE(contentType, QLatin1String("fakeContentEncoding"));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue