diff --git a/src/amqp_frame.h b/src/amqp_frame.h index 4940054..058262b 100644 --- a/src/amqp_frame.h +++ b/src/amqp_frame.h @@ -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 diff --git a/src/amqp_global.h b/src/amqp_global.h index 2ca17ed..13eb40b 100644 --- a/src/amqp_global.h +++ b/src/amqp_global.h @@ -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, diff --git a/src/amqp_message.cpp b/src/amqp_message.cpp index 5b8f628..f0c8088 100644 --- a/src/amqp_message.cpp +++ b/src/amqp_message.cpp @@ -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); +} diff --git a/src/amqp_message.h b/src/amqp_message.h index eb89ed0..de2cfc7 100644 --- a/src/amqp_message.h +++ b/src/amqp_message.h @@ -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: diff --git a/src/amqp_message_p.h b/src/amqp_message_p.h index 638c8f7..f26467d 100644 --- a/src/amqp_message_p.h +++ b/src/amqp_message_p.h @@ -18,11 +18,9 @@ public: bool redelivered; QString exchangeName; QString routingKey; - QByteArray payload; - MessageProperties properties; + QHash properties; Frame::TableField headers; - int leftSize; }; diff --git a/src/amqp_queue.cpp b/src/amqp_queue.cpp index daf7bc3..ff9382d 100644 --- a/src/amqp_queue.cpp +++ b/src/amqp_queue.cpp @@ -91,7 +91,7 @@ void QueuePrivate::_q_content(const Frame::Content &frame) QHash::ConstIterator it; QHash::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(it.key())] = it.value(); } void QueuePrivate::_q_body(const Frame::ContentBody &frame) diff --git a/tests/auto/qamqpqueue/tst_qamqpqueue.cpp b/tests/auto/qamqpqueue/tst_qamqpqueue.cpp index 3ccac9c..150518d 100644 --- a/tests/auto/qamqpqueue/tst_qamqpqueue.cpp +++ b/tests/auto/qamqpqueue/tst_qamqpqueue.cpp @@ -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")); }