00001 #ifndef QPID_AMQP_0_10_FRAMEHEADER_H
00002 #define QPID_AMQP_0_10_FRAMEHEADER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "qpid/amqp_0_10/built_in_types.h"
00026 #include <boost/shared_array.hpp>
00027 #include <string.h>
00028 #include <assert.h>
00029 #include <iosfwd>
00030
00031 namespace qpid {
00032 namespace amqp_0_10 {
00033
00034 enum FrameFlags { FIRST_SEGMENT=8, LAST_SEGMENT=4, FIRST_FRAME=2, LAST_FRAME=1 };
00035
00036 class FrameHeader {
00037 public:
00038 static const size_t SIZE=12;
00039 static uint8_t trackFor(SegmentType type) { return type == 0 ? 0 : 1; }
00040
00041 FrameHeader(uint8_t flags_=0, SegmentType type_=SegmentType(), uint16_t size_=0, uint8_t track_=0, uint16_t channel_=0)
00042 : flags(flags_), type(type_), size(size_), track(track_), channel(channel_)
00043 {}
00044
00045 uint8_t getFlags() const { return flags; }
00046 SegmentType getType() const { return type; }
00048 uint16_t getSize() const { return size; }
00050 uint16_t getDataSize() const { return size - SIZE; }
00051 uint8_t getTrack() const { return track; }
00052 uint16_t getChannel() const { return channel; }
00053
00054 void setFlags(uint8_t flags_) { flags=flags_; }
00056 void setType(SegmentType type_) { type=type_; track=trackFor(type); }
00058 void setSize(uint16_t size_) { size = size_; }
00060 void setDataSize(uint16_t size_) { size = size_+SIZE; }
00061 void setChannel(uint8_t channel_) { channel=channel_; }
00062
00063 bool allFlags(uint8_t f) const { return (flags & f) == f; }
00064 bool anyFlags(uint8_t f) const { return (flags & f); }
00065
00066 void raiseFlags(uint8_t f) { flags |= f; }
00067 void clearFlags(uint8_t f) { flags &= ~f; }
00068
00069 bool isComplete() const { return allFlags(FIRST_FRAME | LAST_FRAME); }
00070
00071 bool operator==(const FrameHeader&) const;
00072
00073 template <class S> void serialize(S& s) {
00074 uint8_t pad8=0; uint32_t pad32=0;
00075 s(flags)(type)(size)(pad8)(track)(channel)(pad32);
00076 }
00077
00078 private:
00079 uint8_t flags;
00080 SegmentType type;
00081 uint16_t size;
00082 uint8_t track;
00083 uint16_t channel;
00084 };
00085
00086 std::ostream& operator<<(std::ostream&, const FrameHeader&);
00087
00088 }}
00089
00090 #endif