00001 #ifndef QPID_AMQP_0_10_BUILT_IN_TYPES_H
00002 #define QPID_AMQP_0_10_BUILT_IN_TYPES_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qpid/Serializer.h"
00025 #include "qpid/framing/Uuid.h"
00026 #include "qpid/sys/Time.h"
00027 #include "Decimal.h"
00028 #include "SerializableString.h"
00029 #include <boost/array.hpp>
00030 #include <boost/range/iterator_range.hpp>
00031 #include <string>
00032 #include <ostream>
00033 #include <vector>
00034 #include <stdint.h>
00035
00038 namespace qpid {
00039
00040 namespace framing {
00041 class SequenceNumber;
00042 class SequenceSet;
00043 }
00044
00045 namespace amqp_0_10 {
00046
00050 template <class T, int Unique=0> struct Wrapper {
00051 T value;
00052 Wrapper() {}
00053 Wrapper(const T& x) : value(x) {}
00054 Wrapper& operator=(const T& x) { value=x; return *this; }
00055 operator T&() { return value; }
00056 operator const T&() const { return value; }
00057 template <class S> void serialize(S& s) { s(value); }
00058 };
00059
00060 template<class T>
00061 inline std::ostream& operator<<(std::ostream& o, const Wrapper<T>& w) {
00062 return o << w.value;
00063 }
00064
00066 struct Void { template <class S> void serialize(S&) {} };
00067 inline std::ostream& operator<<(std::ostream& o, const Void&) { return o; }
00068
00070 struct Bit : public Wrapper<bool> {
00071 Bit(bool b=false) : Wrapper<bool>(b) {}
00072 using Wrapper<bool>::operator=;
00073 template <class S> void serialize(S& s) { s.split(*this); }
00074 template <class S> void encode(S&) const { }
00075 template <class S> void decode(S&) { *this = true; }
00076 };
00077
00078 inline std::ostream& operator<<(std::ostream& o, const Bit& b) {
00079 return o << bool(b);
00080 }
00081
00082
00083 typedef bool Boolean;
00084 typedef char Char;
00085 typedef int8_t Int8;
00086 typedef int16_t Int16;
00087 typedef int32_t Int32;
00088 typedef int64_t Int64;
00089 typedef uint8_t Uint8;
00090 typedef uint16_t Uint16;
00091 typedef uint32_t Uint32;
00092 typedef uint64_t Uint64;
00093 typedef Wrapper<uint32_t> CharUtf32;
00094
00095 template <size_t N> struct Bin : public boost::array<char, N> {
00096 template <class S> void serialize(S& s) { s.raw(this->begin(), this->size()); }
00097 };
00098
00099 template <size_t N> std::ostream& operator<<(std::ostream& o, const Bin<N>& b) {
00100 return o << boost::make_iterator_range(b.begin(), b.end());
00101 }
00102
00103 template <> struct Bin<1> : public boost::array<char, 1> {
00104 Bin(char c=0) { this->front() = c; }
00105 operator char() { return this->front(); }
00106 template <class S> void serialize(S& s) { s(front()); }
00107 };
00108
00109 typedef Bin<1> Bin8;
00110 typedef Bin<128> Bin1024;
00111 typedef Bin<16> Bin128;
00112 typedef Bin<2> Bin16;
00113 typedef Bin<32> Bin256;
00114 typedef Bin<4> Bin32;
00115 typedef Bin<5> Bin40;
00116 typedef Bin<64> Bin512;
00117 typedef Bin<8> Bin64;
00118 typedef Bin<9> Bin72;
00119
00120 typedef double Double;
00121 typedef float Float;
00122 typedef framing::SequenceNumber SequenceNo;
00123 using framing::Uuid;
00124 typedef sys::AbsTime Datetime;
00125
00126 typedef Decimal<Uint8, Int32> Dec32;
00127 typedef Decimal<Uint8, Int64> Dec64;
00128
00129
00130
00131 typedef SerializableString<Uint8, Uint8> Vbin8;
00132 typedef SerializableString<char, Uint8, 1> Str8Latin;
00133 typedef SerializableString<char, Uint8> Str8;
00134 typedef SerializableString<Uint16, Uint8> Str8Utf16;
00135
00136 typedef SerializableString<Uint8, Uint16> Vbin16;
00137 typedef SerializableString<char, Uint16, 1> Str16Latin;
00138 typedef SerializableString<char, Uint16> Str16;
00139 typedef SerializableString<Uint16, Uint16> Str16Utf16;
00140
00141 typedef SerializableString<Uint8, Uint32> Vbin32;
00142
00143 typedef framing::SequenceSet SequenceSet;
00144
00145
00146 class Map;
00147 class Struct32;
00148 class List;
00149 class UnknownType;
00150
00151 template <class T> struct ArrayDomain;
00152 typedef ArrayDomain<UnknownType> Array;
00153
00154
00155 struct ByteRanges { template <class S> void serialize(S&) {} };
00156 struct List { template <class S> void serialize(S&) {} };
00157
00158
00159 inline std::ostream& operator<<(std::ostream& o, const ByteRanges&) { return o; }
00160 inline std::ostream& operator<<(std::ostream& o, const SequenceSet&) { return o; }
00161 inline std::ostream& operator<<(std::ostream& o, const List&) { return o; }
00162
00163 enum SegmentType { CONTROL, COMMAND, HEADER, BODY };
00164
00165 inline SerializeAs<SegmentType, uint8_t> serializable(SegmentType& st) {
00166 return SerializeAs<SegmentType, uint8_t>(st);
00167 }
00168
00169
00170 }}
00171
00172 #endif