summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/qpid/broker/amqp/Message.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/src/qpid/broker/amqp/Message.cpp')
-rw-r--r--qpid/cpp/src/qpid/broker/amqp/Message.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/qpid/cpp/src/qpid/broker/amqp/Message.cpp b/qpid/cpp/src/qpid/broker/amqp/Message.cpp
index 857ca2c313..2e19c9a9ad 100644
--- a/qpid/cpp/src/qpid/broker/amqp/Message.cpp
+++ b/qpid/cpp/src/qpid/broker/amqp/Message.cpp
@@ -152,6 +152,85 @@ std::string Message::getPropertyAsString(const std::string& key) const
}
namespace {
+class PropertyPrinter : public MapHandler
+{
+ public:
+ std::stringstream out;
+
+ PropertyPrinter() : first(true) {}
+ void handleVoid(const CharSequence&) {}
+ void handleBool(const CharSequence& key, bool value) { handle(key, value); }
+ void handleUint8(const CharSequence& key, uint8_t value) { handle(key, value); }
+ void handleUint16(const CharSequence& key, uint16_t value) { handle(key, value); }
+ void handleUint32(const CharSequence& key, uint32_t value) { handle(key, value); }
+ void handleUint64(const CharSequence& key, uint64_t value) { handle(key, value); }
+ void handleInt8(const CharSequence& key, int8_t value) { handle(key, value); }
+ void handleInt16(const CharSequence& key, int16_t value) { handle(key, value); }
+ void handleInt32(const CharSequence& key, int32_t value) { handle(key, value); }
+ void handleInt64(const CharSequence& key, int64_t value) { handle(key, value); }
+ void handleFloat(const CharSequence& key, float value) { handle(key, value); }
+ void handleDouble(const CharSequence& key, double value) { handle(key, value); }
+ void handleString(const CharSequence& key, const CharSequence& value, const CharSequence& /*encoding*/)
+ {
+ handle(key, value.str());
+ }
+ std::string str() { return out.str(); }
+ bool print(const std::string& key, const std::string& value, bool prependComma) {
+ if (prependComma) out << ", ";
+ if (!value.empty()) {
+ out << key << "=" << value;
+ return true;
+ } else {
+ return false;
+ }
+ }
+ template <typename T> bool print_(const std::string& key, T value, bool prependComma) {
+ if (prependComma) out << ", ";
+ if (value) {
+ out << key << "=" << value;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private:
+ bool first;
+
+ template <typename T> void handle(const CharSequence& key, T value)
+ {
+ if (first) {
+ first = false;
+ } else {
+ out << ", ";
+ }
+ out << key.str() << "=" << value;
+ }
+};
+}
+
+std::string Message::printProperties() const
+{
+ PropertyPrinter r;
+ bool comma = false;
+ comma = r.print("subject", getSubject(), comma);
+ comma = r.print("message-id", getMessageId().str(), comma);
+ comma = r.print("correlation-id", getCorrelationId().str(), comma);
+ comma = r.print("user-id", getUserId(), comma);
+ comma = r.print("to", getTo(), comma);
+ comma = r.print("reply-to", getReplyTo(), comma);
+ comma = r.print_("priority", (uint32_t) getPriority(), comma);
+ comma = r.print_("durable", isPersistent(), comma);
+ uint64_t ttl(0);
+ getTtl(ttl);
+ comma = r.print_("ttl", ttl, comma);
+ r.out << ", application-properties={";
+ processProperties(r);
+ r.out << "}";
+ return r.str();
+}
+
+namespace {
class PropertyAdapter : public Reader {
MapHandler& handler;
CharSequence key;