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/CommonImportExport.h"
00030 #include <iostream>
00031
00032 #include <boost/optional.hpp>
00033
00034
00035 namespace qpid {
00036 namespace framing {
00037
00038 enum DeliveryMode { TRANSIENT = 1, PERSISTENT = 2};
00039
00040 class AMQHeaderBody : public AMQBody
00041 {
00042 template <class T> struct OptProps { boost::optional<T> props; };
00043 template <class Base, class T>
00044 struct PropSet : public Base, public OptProps<T> {
00045 uint32_t encodedSize() const {
00046 const boost::optional<T>& p=this->OptProps<T>::props;
00047 return (p ? p->encodedSize() : 0) + Base::encodedSize();
00048 }
00049 void encode(Buffer& buffer) const {
00050 const boost::optional<T>& p=this->OptProps<T>::props;
00051 if (p) p->encode(buffer);
00052 Base::encode(buffer);
00053 }
00054 bool decode(Buffer& buffer, uint32_t size, uint16_t type) {
00055 boost::optional<T>& p=this->OptProps<T>::props;
00056 if (type == T::TYPE) {
00057 p=T();
00058 p->decodeStructBody(buffer, size);
00059 return true;
00060 }
00061 else
00062 return Base::decode(buffer, size, type);
00063 }
00064 void print(std::ostream& out) const {
00065 const boost::optional<T>& p=this->OptProps<T>::props;
00066 if (p) out << *p;
00067 Base::print(out);
00068 }
00069 };
00070
00071 struct Empty {
00072 uint32_t encodedSize() const { return 0; }
00073 void encode(Buffer&) const {};
00074 bool decode(Buffer&, uint32_t, uint16_t) const { return false; };
00075 void print(std::ostream&) const {}
00076 };
00077
00078
00079 typedef PropSet<PropSet<Empty, DeliveryProperties>, MessageProperties> Properties;
00080
00081 Properties properties;
00082
00083 public:
00084
00085 inline uint8_t type() const { return HEADER_BODY; }
00086
00087 QPID_COMMON_EXTERN uint32_t encodedSize() const;
00088 QPID_COMMON_EXTERN void encode(Buffer& buffer) const;
00089 QPID_COMMON_EXTERN void decode(Buffer& buffer, uint32_t size);
00090 QPID_COMMON_EXTERN uint64_t getContentLength() const;
00091 QPID_COMMON_EXTERN void print(std::ostream& out) const;
00092 QPID_COMMON_EXTERN void accept(AMQBodyConstVisitor&) const;
00093
00094 template <class T> T* get(bool create) {
00095 boost::optional<T>& p=properties.OptProps<T>::props;
00096 if (create && !p) p=T();
00097 return p.get_ptr();
00098 }
00099
00100 template <class T> const T* get() const {
00101 return properties.OptProps<T>::props.get_ptr();
00102 }
00103
00104 boost::intrusive_ptr<AMQBody> clone() const { return BodyFactory::copy(*this); }
00105 };
00106
00107 }}
00108
00109
00110
00111 #endif