summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/framing/AMQHeaderBody.h
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-08-28 19:38:17 +0000
committerGordon Sim <gsim@apache.org>2007-08-28 19:38:17 +0000
commit9e10f4ea3b2f8ab6650f635cada48e4735ca20d7 (patch)
tree26ad3b8dffa17fa665fe7a033a7c8092839df011 /cpp/src/qpid/framing/AMQHeaderBody.h
parent6b09696b216c090b512c6af92bf7976ae3407add (diff)
downloadqpid-python-9e10f4ea3b2f8ab6650f635cada48e4735ca20d7.tar.gz
Updated message.transfer encoding to use header and content segments (including new structs).
Unified more between the basic and message classes messages. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@570538 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/framing/AMQHeaderBody.h')
-rw-r--r--cpp/src/qpid/framing/AMQHeaderBody.h95
1 files changed, 81 insertions, 14 deletions
diff --git a/cpp/src/qpid/framing/AMQHeaderBody.h b/cpp/src/qpid/framing/AMQHeaderBody.h
index 894936060c..76bd60559e 100644
--- a/cpp/src/qpid/framing/AMQHeaderBody.h
+++ b/cpp/src/qpid/framing/AMQHeaderBody.h
@@ -22,6 +22,12 @@
#include "AMQBody.h"
#include "Buffer.h"
#include "BasicHeaderProperties.h"
+#include "qpid/framing/DeliveryProperties.h"
+#include "qpid/framing/MessageProperties.h"
+#include <iostream>
+#include <vector>
+#include <boost/variant.hpp>
+#include <boost/variant/get.hpp>
#ifndef _AMQHeaderBody_
#define _AMQHeaderBody_
@@ -31,24 +37,85 @@ namespace framing {
class AMQHeaderBody : public AMQBody
{
- BasicHeaderProperties properties;
- uint16_t weight;
- uint64_t contentSize;
- public:
- AMQHeaderBody(int classId);
+ typedef std::vector< boost::variant<BasicHeaderProperties, DeliveryProperties, MessageProperties> > PropertyList;
+
+ PropertyList properties;
+
+ template <class T> void decode(T t, Buffer& b, uint32_t size) {
+ t.decode(b, size);
+ properties.push_back(t);
+ }
+
+ class Encode : public boost::static_visitor<> {
+ Buffer& buffer;
+ public:
+ Encode(Buffer& b) : buffer(b) {}
+
+ template <class T> void operator()(T& t) const {
+ buffer.putLong(t.size() + 2/*typecode*/);
+ buffer.putShort(T::TYPE);
+ t.encode(buffer);
+ }
+ };
+
+ class CalculateSize : public boost::static_visitor<> {
+ uint32_t size;
+ public:
+ CalculateSize() : size(0) {}
+
+ template <class T> void operator()(T& t) {
+ size += t.size();
+ }
+
+ uint32_t totalSize() {
+ return size;
+ }
+ };
+
+ class Print : public boost::static_visitor<> {
+ std::ostream& out;
+ public:
+ Print(std::ostream& o) : out(o) {}
+
+ template <class T> void operator()(T& t) {
+ out << t;
+ }
+ };
+
+public:
+
AMQHeaderBody();
+ ~AMQHeaderBody();
inline uint8_t type() const { return HEADER_BODY; }
- BasicHeaderProperties* getProperties(){ return &properties; }
- const BasicHeaderProperties* getProperties() const { return &properties; }
- inline uint64_t getContentSize() const { return contentSize; }
- inline void setContentSize(uint64_t _size) { contentSize = _size; }
- virtual ~AMQHeaderBody();
- virtual uint32_t size() const;
- virtual void encode(Buffer& buffer) const;
- virtual void decode(Buffer& buffer, uint32_t size);
- virtual void print(std::ostream& out) const;
+
+ uint32_t size() const;
+ void encode(Buffer& buffer) const;
+ void decode(Buffer& buffer, uint32_t size);
+ uint64_t getContentLength() const;
+ void print(std::ostream& out) const;
void accept(AMQBodyConstVisitor& v) const { v.visit(*this); }
+
+ template <class T> T* get(bool create) {
+ for (PropertyList::iterator i = properties.begin(); i != properties.end(); i++) {
+ T* p = boost::get<T>(&(*i));
+ if (p) return p;
+ }
+ if (create) {
+ properties.push_back(T());
+ return boost::get<T>(&(properties.back()));
+ } else {
+ return 0;
+ }
+ }
+
+ template <class T> const T* get() const {
+ for (PropertyList::const_iterator i = properties.begin(); i != properties.end(); i++) {
+ const T* p = boost::get<T>(&(*i));
+ if (p) return p;
+ }
+ return 0;
+ }
};
}