summaryrefslogtreecommitdiff
path: root/qpid/cpp/src
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2013-09-23 13:25:32 +0000
committerGordon Sim <gsim@apache.org>2013-09-23 13:25:32 +0000
commit91edb93e2362fc717091c07127145ba7f5a559a5 (patch)
treeeae305bc9415e9814aa3f2750d8dab35ffca9ebb /qpid/cpp/src
parentb07719f653b27c348774fae87020ab142fb10b42 (diff)
downloadqpid-python-91edb93e2362fc717091c07127145ba7f5a559a5.tar.gz
QPID-5153: Implement Encoding::getPropertyAsString() for 1.0 format message
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1525584 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
-rw-r--r--qpid/cpp/src/qpid/broker/amqp/Message.cpp69
-rw-r--r--qpid/cpp/src/qpid/messaging/amqp/AddressHelper.cpp2
2 files changed, 65 insertions, 6 deletions
diff --git a/qpid/cpp/src/qpid/broker/amqp/Message.cpp b/qpid/cpp/src/qpid/broker/amqp/Message.cpp
index 572eea3881..cf134a894d 100644
--- a/qpid/cpp/src/qpid/broker/amqp/Message.cpp
+++ b/qpid/cpp/src/qpid/broker/amqp/Message.cpp
@@ -31,6 +31,7 @@
#include "qpid/log/Statement.h"
#include "qpid/framing/Buffer.h"
#include <string.h>
+#include <boost/lexical_cast.hpp>
namespace qpid {
namespace broker {
@@ -79,8 +80,51 @@ uint8_t Message::getPriority() const
else return priority.get();
}
-std::string Message::getPropertyAsString(const std::string& /*key*/) const { return empty; }
-std::string Message::getAnnotationAsString(const std::string& /*key*/) const { return empty; }
+namespace {
+class StringRetriever : public MapHandler
+{
+ public:
+ StringRetriever(const std::string& k) : key(k) {}
+ void handleBool(const qpid::amqp::CharSequence& actualKey, bool actualValue) { process(actualKey, actualValue); }
+ void handleUint8(const qpid::amqp::CharSequence& actualKey, uint8_t actualValue) { process(actualKey, actualValue); }
+ void handleUint16(const qpid::amqp::CharSequence& actualKey, uint16_t actualValue) { process(actualKey, actualValue); }
+ void handleUint32(const qpid::amqp::CharSequence& actualKey, uint32_t actualValue) { process(actualKey, actualValue); }
+ void handleUint64(const qpid::amqp::CharSequence& actualKey, uint64_t actualValue) { process(actualKey, actualValue); }
+ void handleInt8(const qpid::amqp::CharSequence& actualKey, int8_t actualValue) { process(actualKey, actualValue); }
+ void handleInt16(const qpid::amqp::CharSequence& actualKey, int16_t actualValue) { process(actualKey, actualValue); }
+ void handleInt32(const qpid::amqp::CharSequence& actualKey, int32_t actualValue) { process(actualKey, actualValue); }
+ void handleInt64(const qpid::amqp::CharSequence& actualKey, int64_t actualValue) { process(actualKey, actualValue); }
+ void handleFloat(const qpid::amqp::CharSequence& actualKey, float actualValue) { process(actualKey, actualValue); }
+ void handleDouble(const qpid::amqp::CharSequence& actualKey, double actualValue) { process(actualKey, actualValue); }
+ void handleVoid(const qpid::amqp::CharSequence&) { /*nothing to do*/ }
+ void handleString(const qpid::amqp::CharSequence& actualKey, const qpid::amqp::CharSequence& actualValue, const qpid::amqp::CharSequence& /*encoding*/)
+ {
+ if (isRequestedKey(actualKey)) value = std::string(actualValue.data, actualValue.size);
+ }
+ std::string getValue() const { return value; }
+ private:
+ const std::string key;
+ std::string value;
+
+ template <typename T> void process(const qpid::amqp::CharSequence& actualKey, T actualValue)
+ {
+ if (isRequestedKey(actualKey)) value = boost::lexical_cast<std::string>(actualValue);
+ }
+
+ bool isRequestedKey(const qpid::amqp::CharSequence& actualKey)
+ {
+ //TODO: avoid allocating new string by just iterating over chars
+ return key == std::string(actualKey.data, actualKey.size);
+ }
+};
+}
+
+std::string Message::getPropertyAsString(const std::string& key) const
+{
+ StringRetriever sr(key);
+ processProperties(sr);
+ return sr.getValue();
+}
namespace {
class PropertyAdapter : public Reader {
@@ -135,12 +179,27 @@ namespace {
state(KEY)
{}
};
+
+void processMapData(const CharSequence& source, MapHandler& handler)
+{
+ qpid::amqp::Decoder d(source.data, source.size);
+ PropertyAdapter adapter(handler);
+ d.read(adapter);
+
+}
}
void Message::processProperties(MapHandler& mh) const {
- qpid::amqp::Decoder d(applicationProperties.data, applicationProperties.size);
- PropertyAdapter mha(mh);
- d.read(mha);
+ processMapData(applicationProperties, mh);
+}
+
+std::string Message::getAnnotationAsString(const std::string& key) const
+{
+ StringRetriever sr(key);
+ processMapData(messageAnnotations, sr);
+ if (sr.getValue().empty()) processMapData(deliveryAnnotations, sr);
+ return sr.getValue();
+
}
//getContentSize() is primarily used in stats about the number of
diff --git a/qpid/cpp/src/qpid/messaging/amqp/AddressHelper.cpp b/qpid/cpp/src/qpid/messaging/amqp/AddressHelper.cpp
index beac50cdac..2a35442ed7 100644
--- a/qpid/cpp/src/qpid/messaging/amqp/AddressHelper.cpp
+++ b/qpid/cpp/src/qpid/messaging/amqp/AddressHelper.cpp
@@ -688,7 +688,7 @@ void AddressHelper::setNodeProperties(pn_terminus_t* terminus)
putLifetimePolicy(data, toLifetimePolicy(i->second.asString()));
} else {
pn_data_put_symbol(data, convert(i->first));
- pn_data_put_string(data, convert(i->second.asString()));
+ write(data, i->second);
}
}
pn_data_exit(data);