LCOV - code coverage report
Current view: top level - DCPS/transport/framework - TransportHeader.inl (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 13 0.0 %
Date: 2023-04-30 01:32:43 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *
       4             :  * Distributed under the OpenDDS License.
       5             :  * See: http://www.opendds.org/license.html
       6             :  */
       7             : 
       8             : #include "dds/DCPS/Serializer.h"
       9             : #include "EntryExit.h"
      10             : 
      11             : #include <algorithm>
      12             : 
      13             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      14             : 
      15             : namespace OpenDDS {
      16             : namespace DCPS {
      17             : 
      18             : ACE_INLINE
      19           0 : TransportHeader::TransportHeader()
      20           0 :   : byte_order_(ACE_CDR_BYTE_ORDER)
      21           0 :   , first_fragment_(false)
      22           0 :   , last_fragment_(false)
      23           0 :   , reserved_(0)
      24           0 :   , length_(0)
      25           0 :   , sequence_()
      26           0 :   , source_(0)
      27             : {
      28             :   DBG_ENTRY_LVL("TransportHeader","TransportHeader",6);
      29             : 
      30           0 :   std::copy(&DCPS_PROTOCOL[0], &DCPS_PROTOCOL[6], this->protocol_);
      31           0 : }
      32             : 
      33             : ACE_INLINE
      34             : TransportHeader::TransportHeader(ACE_Message_Block& buffer)
      35             :   : byte_order_(ACE_CDR_BYTE_ORDER)
      36             :   , first_fragment_(false)
      37             :   , last_fragment_(false)
      38             :   , reserved_(0)
      39             :   , length_(0)
      40             :   , sequence_()
      41             :   , source_(0)
      42             : {
      43             :   DBG_ENTRY_LVL("TransportHeader","TransportHeader",6);
      44             :   this->init(&buffer);
      45             : }
      46             : 
      47             : ACE_INLINE
      48             : TransportHeader&
      49             : TransportHeader::operator=(ACE_Message_Block& buffer)
      50             : {
      51             :   DBG_ENTRY_LVL("TransportHeader","operator=",6);
      52             :   this->init(&buffer);
      53             :   return *this;
      54             : }
      55             : 
      56             : ACE_INLINE
      57           0 : size_t TransportHeader::get_max_serialized_size()
      58             : {
      59             :   // Representation takes no extra space for encoding.
      60           0 :   const TransportHeader* hdr = 0;
      61             :   return sizeof(hdr->protocol_) +
      62             :          1 /*flags*/ +
      63             :          sizeof(hdr->reserved_) +
      64             :          sizeof(hdr->length_) +
      65             :          sizeof(hdr->sequence_) +
      66           0 :          sizeof(hdr->source_);
      67             : }
      68             : 
      69             : ACE_INLINE
      70             : bool
      71             : TransportHeader::swap_bytes() const
      72             : {
      73             :   DBG_ENTRY_LVL("TransportHeader","swap_bytes",6);
      74             : 
      75             :   return this->byte_order_ != ACE_CDR_BYTE_ORDER;
      76             : }
      77             : 
      78             : ACE_INLINE
      79             : bool
      80             : TransportHeader::valid() const
      81             : {
      82             :   DBG_ENTRY_LVL("TransportHeader","valid",6);
      83             : 
      84             :   // Currently we do not support compatibility with other
      85             :   // versions of the protocol:
      86             :   return std::equal(&DCPS_PROTOCOL[0], &DCPS_PROTOCOL[6], this->protocol_);
      87             : }
      88             : 
      89             : ACE_INLINE
      90             : bool
      91             : TransportHeader::init(ACE_Message_Block* buffer)
      92             : {
      93             :   DBG_ENTRY_LVL("TransportHeader","init",6);
      94             : 
      95             :   Serializer reader(buffer, Encoding::KIND_UNALIGNED_CDR);
      96             : 
      97             :   if (!reader.read_octet_array(this->protocol_, sizeof(this->protocol_)))
      98             :     return false;
      99             : 
     100             :   ACE_CDR::Octet flags;
     101             :   if (!(reader >> ACE_InputCDR::to_octet(flags)))
     102             :     return false;
     103             : 
     104             :   this->byte_order_= flags & (1 << BYTE_ORDER_FLAG);
     105             :   this->first_fragment_ = flags & (1 << FIRST_FRAGMENT_FLAG);
     106             :   this->last_fragment_ = flags & (1 << LAST_FRAGMENT_FLAG);
     107             : 
     108             :   if (!(reader >> ACE_InputCDR::to_octet(this->reserved_)))
     109             :     return false;
     110             : 
     111             :   reader.swap_bytes(swap_bytes());
     112             : 
     113             :   return (reader >> this->length_) &&
     114             :          (reader >> this->sequence_) &&
     115             :          (reader >> this->source_);
     116             : }
     117             : 
     118             : }
     119             : }
     120             : 
     121             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16