00001 #ifndef QPID_FRAMING_AMQHEADERBODY_H
00002 #define QPID_FRAMING_AMQHEADERBODY_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "amqp_types.h"
00025 #include "AMQBody.h"
00026 #include "Buffer.h"
00027 #include "qpid/framing/DeliveryProperties.h"
00028 #include "qpid/framing/MessageProperties.h"
00029 #include "qpid/framing/DeliveryProperties010.h"
00030 #include "qpid/framing/MessageProperties010.h"
00031 #include <iostream>
00032
00033 #include <boost/optional.hpp>
00034
00035
00036 namespace qpid {
00037 namespace framing {
00038
00039 enum DeliveryMode { TRANSIENT = 1, PERSISTENT = 2};
00040
00041 class AMQHeaderBody : public AMQBody
00042 {
00043 template <class T> struct OptProps { boost::optional<T> props; };
00044 template <class Base, class T>
00045 struct PropSet : public Base, public OptProps<T> {
00046 uint32_t size() const {
00047 const boost::optional<T>& p=this->OptProps<T>::props;
00048 return (p ? p->size() : 0) + Base::size();
00049 }
00050 void encode(Buffer& buffer) const {
00051 const boost::optional<T>& p=this->OptProps<T>::props;
00052 if (p) p->encode(buffer);
00053 Base::encode(buffer);
00054 }
00055 bool decode(Buffer& buffer, uint32_t size, uint16_t type) {
00056 boost::optional<T>& p=this->OptProps<T>::props;
00057 if (type == T::TYPE) {
00058 p=T();
00059 p->decodeStructBody(buffer, size);
00060 return true;
00061 }
00062 else
00063 return Base::decode(buffer, size, type);
00064 }
00065 void print(std::ostream& out) const {
00066 const boost::optional<T>& p=this->OptProps<T>::props;
00067 if (p) out << *p;
00068 Base::print(out);
00069 }
00070 };
00071
00072 struct Empty {
00073 uint32_t size() const { return 0; }
00074 void encode(Buffer&) const {};
00075 bool decode(Buffer&, uint32_t, uint16_t) const { return false; };
00076 void print(std::ostream&) const {}
00077 };
00078
00079
00080 typedef PropSet< PropSet< PropSet<PropSet<Empty, DeliveryProperties>,
00081 MessageProperties>,
00082 DeliveryProperties010>,
00083 MessageProperties010> Properties;
00084
00085 Properties properties;
00086
00087 public:
00088
00089 inline uint8_t type() const { return HEADER_BODY; }
00090
00091 uint32_t size() const;
00092 void encode(Buffer& buffer) const;
00093 void decode(Buffer& buffer, uint32_t size);
00094 uint64_t getContentLength() const;
00095 void print(std::ostream& out) const;
00096 void accept(AMQBodyConstVisitor&) const;
00097
00098 template <class T> T* get(bool create) {
00099 boost::optional<T>& p=properties.OptProps<T>::props;
00100 if (create && !p) p=T();
00101 return p.get_ptr();
00102 }
00103
00104 template <class T> const T* get() const {
00105 return properties.OptProps<T>::props.get_ptr();
00106 }
00107 };
00108
00109 }}
00110
00111
00112
00113 #endif