OpenDDS  Snapshot(2023/04/28-20:55)
TransportHeader.inl
Go to the documentation of this file.
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 
14 
15 namespace OpenDDS {
16 namespace DCPS {
17 
20  : byte_order_(ACE_CDR_BYTE_ORDER)
21  , first_fragment_(false)
22  , last_fragment_(false)
23  , reserved_(0)
24  , length_(0)
25  , sequence_()
26  , source_(0)
27 {
28  DBG_ENTRY_LVL("TransportHeader","TransportHeader",6);
29 
31 }
32 
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 
50 {
51  DBG_ENTRY_LVL("TransportHeader","operator=",6);
52  this->init(&buffer);
53  return *this;
54 }
55 
58 {
59  // Representation takes no extra space for encoding.
60  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  sizeof(hdr->source_);
67 }
68 
70 bool
72 {
73  DBG_ENTRY_LVL("TransportHeader","swap_bytes",6);
74 
75  return this->byte_order_ != ACE_CDR_BYTE_ORDER;
76 }
77 
79 bool
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 
90 bool
92 {
93  DBG_ENTRY_LVL("TransportHeader","init",6);
94 
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 
ACE_Byte Octet
bool swap_bytes() const
Determine if the serializer should swap bytes.
bool valid() const
Determine if this is a valid packet header.
static size_t get_max_serialized_size()
Similar to IDL compiler generated methods.
#define ACE_CDR_BYTE_ORDER
bool read_octet_array(ACE_CDR::Octet *x, ACE_CDR::ULong length)
Definition: Serializer.inl:558
static const ACE_CDR::Octet DCPS_PROTOCOL[6]
ACE_CDR::Octet reserved_
Reserved for future use (provides padding for preamble).
TransportHeader()
Default constructor.
Class to serialize and deserialize data for DDS.
Definition: Serializer.h:369
ACE_CDR::Octet protocol_[6]
The protocol of the packet being transmitted.
Defines class that represents a transport packet header.
void swap_bytes(bool do_swap)
Definition: Serializer.inl:403
bool byte_order_
Flags: marshaled as a single byte (ACE_CDR::Octet)
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
DDS::ReturnCode_t copy(DDS::DynamicData_ptr dest, DDS::DynamicData_ptr src)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
bool init(ACE_Message_Block *buffer)
Demarshal transport packet from ACE_Message_Block.
TransportHeader & operator=(ACE_Message_Block &buffer)
Assignment from an ACE_Message_Block.
#define ACE_INLINE
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28