LCOV - code coverage report
Current view: top level - DCPS/RTPS - MessageParser.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 42 0.0 %
Date: 2023-04-30 01:32:43 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Distributed under the OpenDDS License.
       3             :  * See: http://www.opendds.org/license.html
       4             :  */
       5             : 
       6             : #include "MessageParser.h"
       7             : 
       8             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
       9             : 
      10             : namespace OpenDDS {
      11             : namespace RTPS {
      12             : 
      13             : using DCPS::Encoding;
      14             : 
      15             : namespace {
      16             :   const Encoding encoding_plain_native(Encoding::KIND_XCDR1);
      17             : }
      18             : 
      19           0 : MessageParser::MessageParser(const ACE_Message_Block& in)
      20           0 :   : in_(in.duplicate())
      21           0 :   , ser_(in_.get(), encoding_plain_native)
      22           0 :   , header_()
      23           0 :   , sub_()
      24           0 :   , smContentStart_(0)
      25           0 : {}
      26             : 
      27           0 : MessageParser::MessageParser(const DDS::OctetSeq& in)
      28           0 :   : fromSeq_(reinterpret_cast<const char*>(in.get_buffer()), in.length())
      29           0 :   , ser_(&fromSeq_, encoding_plain_native)
      30           0 :   , header_()
      31           0 :   , sub_()
      32           0 :   , smContentStart_(0)
      33             : {
      34           0 :   fromSeq_.wr_ptr(fromSeq_.size());
      35           0 : }
      36             : 
      37           0 : bool MessageParser::parseHeader()
      38             : {
      39           0 :   return ser_ >> header_;
      40             : }
      41             : 
      42           0 : bool MessageParser::parseSubmessageHeader()
      43             : {
      44           0 :   if(!(ser_ >> ACE_InputCDR::to_octet(sub_.submessageId)) ||
      45           0 :     !(ser_ >> ACE_InputCDR::to_octet(sub_.flags))) {
      46           0 :     return false;
      47             :   }
      48             : 
      49           0 :   ser_.swap_bytes(ACE_CDR_BYTE_ORDER != (sub_.flags & FLAG_E));
      50           0 :   if(!(ser_ >> sub_.submessageLength)) {
      51           0 :     return false;
      52             :   }
      53           0 :   smContentStart_ = ser_.length();
      54           0 :   return sub_.submessageLength <= ser_.length();
      55             : }
      56             : 
      57           0 : bool MessageParser::hasNextSubmessage() const
      58             : {
      59           0 :   if(sub_.submessageLength == 0) {
      60           0 :     if(sub_.submessageId != PAD && sub_.submessageId != INFO_TS) {
      61           0 :       return false;
      62             :     }
      63           0 :     return ser_.length();
      64             :   }
      65           0 :   return smContentStart_ > sub_.submessageLength;
      66             : }
      67             : 
      68           0 : bool MessageParser::skipToNextSubmessage()
      69             : {
      70           0 :   const size_t read = smContentStart_ - ser_.length();
      71           0 :   return ser_.skip(static_cast<unsigned short>(sub_.submessageLength - read));
      72             : }
      73             : 
      74           0 : bool MessageParser::skipSubmessageContent()
      75             : {
      76           0 :   if(sub_.submessageLength) {
      77           0 :     const size_t read = smContentStart_ - ser_.length();
      78           0 :     return ser_.skip(static_cast<unsigned short>(sub_.submessageLength - read));
      79           0 :   } else if (sub_.submessageId == PAD || sub_.submessageId == INFO_TS) {
      80           0 :     return true;
      81             :   } else {
      82           0 :     return ser_.skip(static_cast<unsigned short>(ser_.length()));
      83             :   }
      84             : }
      85             : 
      86             : }
      87             : }
      88             : 
      89             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16