TransportHeader.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "dds/DCPS/Serializer.h"
00009 #include "EntryExit.h"
00010
00011 #include <algorithm>
00012
00013 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00014
00015 namespace OpenDDS {
00016 namespace DCPS {
00017
00018 ACE_INLINE
00019 TransportHeader::TransportHeader()
00020 : byte_order_(ACE_CDR_BYTE_ORDER),
00021 first_fragment_(false),
00022 last_fragment_(false),
00023 reserved_(0),
00024 length_(0),
00025 sequence_(),
00026 source_(0)
00027 {
00028 DBG_ENTRY_LVL("TransportHeader","TransportHeader",6);
00029
00030 std::copy(&DCPS_PROTOCOL[0], &DCPS_PROTOCOL[6], this->protocol_);
00031 }
00032
00033 ACE_INLINE
00034 TransportHeader::TransportHeader(const TransportHeader::no_init_t&)
00035 {
00036 }
00037
00038 ACE_INLINE
00039 TransportHeader::TransportHeader(ACE_Message_Block& buffer)
00040 {
00041 DBG_ENTRY_LVL("TransportHeader","TransportHeader",6);
00042 this->init(&buffer);
00043 }
00044
00045 ACE_INLINE
00046 TransportHeader&
00047 TransportHeader::operator=(ACE_Message_Block& buffer)
00048 {
00049 DBG_ENTRY_LVL("TransportHeader","operator=",6);
00050 this->init(&buffer);
00051 return *this;
00052 }
00053
00054 ACE_INLINE
00055 size_t
00056 TransportHeader::max_marshaled_size()
00057 {
00058
00059 TransportHeader hdr(no_init);
00060 return sizeof(hdr.protocol_) +
00061 1 +
00062 sizeof(hdr.reserved_) +
00063 sizeof(hdr.length_) +
00064 sizeof(hdr.sequence_) +
00065 sizeof(hdr.source_);
00066 }
00067
00068 ACE_INLINE
00069 bool
00070 TransportHeader::swap_bytes() const
00071 {
00072 DBG_ENTRY_LVL("TransportHeader","swap_bytes",6);
00073
00074 return this->byte_order_ != ACE_CDR_BYTE_ORDER;
00075 }
00076
00077 ACE_INLINE
00078 bool
00079 TransportHeader::valid() const
00080 {
00081 DBG_ENTRY_LVL("TransportHeader","valid",6);
00082
00083
00084
00085 return std::equal(&DCPS_PROTOCOL[0], &DCPS_PROTOCOL[6], this->protocol_);
00086 }
00087
00088 ACE_INLINE
00089 bool
00090 TransportHeader::init(ACE_Message_Block* buffer)
00091 {
00092 DBG_ENTRY_LVL("TransportHeader","init",6);
00093
00094 Serializer reader(buffer);
00095
00096 if (!reader.read_octet_array(this->protocol_, sizeof(this->protocol_)))
00097 return false;
00098
00099 ACE_CDR::Octet flags;
00100 if (!(reader >> ACE_InputCDR::to_octet(flags)))
00101 return false;
00102
00103 this->byte_order_= flags & (1 << BYTE_ORDER_FLAG);
00104 this->first_fragment_ = flags & (1 << FIRST_FRAGMENT_FLAG);
00105 this->last_fragment_ = flags & (1 << LAST_FRAGMENT_FLAG);
00106
00107 if (!(reader >> ACE_InputCDR::to_octet(this->reserved_)))
00108 return false;
00109
00110 reader.swap_bytes(swap_bytes());
00111
00112 return (reader >> this->length_) &&
00113 (reader >> this->sequence_) &&
00114 (reader >> this->source_);
00115 }
00116
00117 }
00118 }
00119
00120 OPENDDS_END_VERSIONED_NAMESPACE_DECL