@@ -151,6 +151,85 @@ std::string Message::getPropertyAsString(const std::string& key) const
151151 return sr.getValue ();
152152}
153153
154+ namespace {
155+ class PropertyPrinter : public MapHandler
156+ {
157+ public:
158+ std::stringstream out;
159+
160+ PropertyPrinter () : first(true ) {}
161+ void handleVoid (const CharSequence&) {}
162+ void handleBool (const CharSequence& key, bool value) { handle (key, value); }
163+ void handleUint8 (const CharSequence& key, uint8_t value) { handle (key, value); }
164+ void handleUint16 (const CharSequence& key, uint16_t value) { handle (key, value); }
165+ void handleUint32 (const CharSequence& key, uint32_t value) { handle (key, value); }
166+ void handleUint64 (const CharSequence& key, uint64_t value) { handle (key, value); }
167+ void handleInt8 (const CharSequence& key, int8_t value) { handle (key, value); }
168+ void handleInt16 (const CharSequence& key, int16_t value) { handle (key, value); }
169+ void handleInt32 (const CharSequence& key, int32_t value) { handle (key, value); }
170+ void handleInt64 (const CharSequence& key, int64_t value) { handle (key, value); }
171+ void handleFloat (const CharSequence& key, float value) { handle (key, value); }
172+ void handleDouble (const CharSequence& key, double value) { handle (key, value); }
173+ void handleString (const CharSequence& key, const CharSequence& value, const CharSequence& /* encoding*/ )
174+ {
175+ handle (key, value.str ());
176+ }
177+ std::string str () { return out.str (); }
178+ bool print (const std::string& key, const std::string& value, bool prependComma) {
179+ if (prependComma) out << " , " ;
180+ if (!value.empty ()) {
181+ out << key << " =" << value;
182+ return true ;
183+ } else {
184+ return false ;
185+ }
186+ }
187+ template <typename T> bool print_ (const std::string& key, T value, bool prependComma) {
188+ if (prependComma) out << " , " ;
189+ if (value) {
190+ out << key << " =" << value;
191+ return true ;
192+ } else {
193+ return false ;
194+ }
195+ }
196+
197+ private:
198+ bool first;
199+
200+ template <typename T> void handle (const CharSequence& key, T value)
201+ {
202+ if (first) {
203+ first = false ;
204+ } else {
205+ out << " , " ;
206+ }
207+ out << key.str () << " =" << value;
208+ }
209+ };
210+ }
211+
212+ std::string Message::printProperties () const
213+ {
214+ PropertyPrinter r;
215+ bool comma = false ;
216+ comma = r.print (" subject" , getSubject (), comma);
217+ comma = r.print (" message-id" , getMessageId ().str (), comma);
218+ comma = r.print (" correlation-id" , getCorrelationId ().str (), comma);
219+ comma = r.print (" user-id" , getUserId (), comma);
220+ comma = r.print (" to" , getTo (), comma);
221+ comma = r.print (" reply-to" , getReplyTo (), comma);
222+ comma = r.print_ (" priority" , (uint32_t ) getPriority (), comma);
223+ comma = r.print_ (" durable" , isPersistent (), comma);
224+ uint64_t ttl (0 );
225+ getTtl (ttl);
226+ comma = r.print_ (" ttl" , ttl, comma);
227+ r.out << " , application-properties={" ;
228+ processProperties (r);
229+ r.out << " }" ;
230+ return r.str ();
231+ }
232+
154233namespace {
155234 class PropertyAdapter : public Reader {
156235 MapHandler& handler;
0 commit comments