TransportHeader.inl

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

Generated on Fri Feb 12 20:05:28 2016 for OpenDDS by  doxygen 1.4.7