LCOV - code coverage report
Current view: top level - DCPS - Serializer.inl (source / functions) Hit Total Coverage
Test: coverage.info Lines: 574 725 79.2 %
Date: 2023-04-30 01:32:43 Functions: 134 154 87.0 %

          Line data    Source code
       1             : /*
       2             :  * Distributed under the OpenDDS License.
       3             :  * See: http://www.opendds.org/license.html
       4             :  */
       5             : 
       6             : #include "Serializer.h"
       7             : #include "debug.h"
       8             : 
       9             : #include <ace/Message_Block.h>
      10             : #include <ace/OS_NS_string.h>
      11             : #include <ace/Log_Msg.h>
      12             : 
      13             : #include <algorithm>
      14             : 
      15             : #include <cstring>
      16             : 
      17             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      18             : 
      19             : namespace OpenDDS {
      20             : namespace DCPS {
      21             : 
      22             : ACE_INLINE
      23       13858 : void align(size_t& value, size_t by)
      24             : {
      25       13858 :   value = (value + by - 1) & ~(by - 1);
      26       13858 : }
      27             : 
      28             : ACE_INLINE
      29        2546 : Encoding::Kind Encoding::kind() const
      30             : {
      31        2546 :   return kind_;
      32             : }
      33             : 
      34             : ACE_INLINE
      35        2762 : void Encoding::kind(Kind value)
      36             : {
      37        2762 :   zero_init_padding(true);
      38             : 
      39        2762 :   switch (value) {
      40        2650 :   case KIND_XCDR1:
      41        2650 :     alignment(ALIGN_CDR);
      42        2650 :     xcdr_version(XCDR_VERSION_1);
      43        2650 :     break;
      44             : 
      45          24 :   case KIND_XCDR2:
      46          24 :     alignment(ALIGN_XCDR2);
      47          24 :     xcdr_version(XCDR_VERSION_2);
      48          24 :     break;
      49             : 
      50          88 :   case KIND_UNALIGNED_CDR:
      51          88 :     alignment(ALIGN_NONE);
      52          88 :     xcdr_version(XCDR_VERSION_NONE);
      53          88 :     break;
      54             : 
      55           0 :   default:
      56           0 :     ACE_ERROR((LM_ERROR,
      57             :       ACE_TEXT("(%P|%t) ERROR: Encoding::kind: Invalid Argument: %u\n"), value));
      58             :   }
      59             : 
      60        2762 :   kind_ = value;
      61        2762 : }
      62             : 
      63             : ACE_INLINE
      64        2601 : Endianness Encoding::endianness() const
      65             : {
      66        2601 :   return endianness_;
      67             : }
      68             : 
      69             : ACE_INLINE
      70         109 : void Encoding::endianness(Endianness value)
      71             : {
      72         109 :   endianness_ = value;
      73         109 : }
      74             : 
      75             : ACE_INLINE
      76       17459 : Encoding::Alignment Encoding::alignment() const
      77             : {
      78       17459 :   return alignment_;
      79             : }
      80             : 
      81             : ACE_INLINE
      82        2762 : void Encoding::alignment(Alignment value)
      83             : {
      84        2762 :   alignment_ = value;
      85        2762 : }
      86             : 
      87             : ACE_INLINE
      88         508 : bool Encoding::zero_init_padding() const
      89             : {
      90         508 :   return zero_init_padding_;
      91             : }
      92             : 
      93             : ACE_INLINE
      94        2762 : void Encoding::zero_init_padding(bool value)
      95             : {
      96        2762 :   zero_init_padding_ = value;
      97        2762 : }
      98             : 
      99             : ACE_INLINE
     100        1301 : bool Encoding::skip_sequence_dheader() const
     101             : {
     102        1301 :   return skip_sequence_dheader_;
     103             : }
     104             : 
     105             : ACE_INLINE
     106           1 : void Encoding::skip_sequence_dheader(bool value)
     107             : {
     108           1 :   skip_sequence_dheader_ = value;
     109           1 : }
     110             : 
     111             : ACE_INLINE
     112       35372 : size_t Encoding::max_align() const
     113             : {
     114       35372 :   return static_cast<size_t>(alignment_);
     115             : }
     116             : 
     117             : ACE_INLINE
     118       13899 : void Encoding::align(size_t& value, size_t by) const
     119             : {
     120       13899 :   const size_t max_alignment = max_align();
     121       13899 :   if (max_alignment) {
     122       13853 :     DCPS::align(value, (std::min)(max_alignment, by));
     123             :   }
     124       13899 : }
     125             : 
     126             : ACE_INLINE
     127       13165 : Encoding::XcdrVersion Encoding::xcdr_version() const
     128             : {
     129       13165 :   return xcdr_version_;
     130             : }
     131             : 
     132             : ACE_INLINE
     133        2762 : void Encoding::xcdr_version(XcdrVersion value)
     134             : {
     135        2762 :   xcdr_version_ = value;
     136        2762 : }
     137             : 
     138             : ACE_INLINE
     139           3 : bool Encoding::is_encapsulated(Kind kind)
     140             : {
     141           3 :   switch (kind) {
     142           2 :   case KIND_XCDR1:
     143             :   case KIND_XCDR2:
     144           2 :     return true;
     145           1 :   case KIND_UNALIGNED_CDR:
     146           1 :     return false;
     147           0 :   default:
     148           0 :     ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Encoding::is_encapsulated: ")
     149             :       ACE_TEXT("Invalid Argument: %u\n"), kind));
     150           0 :     return false;
     151             :   }
     152             : }
     153             : 
     154             : ACE_INLINE
     155           2 : bool Encoding::is_encapsulated() const
     156             : {
     157           2 :   return is_encapsulated(kind_);
     158             : }
     159             : 
     160             : ACE_INLINE
     161           0 : EncapsulationHeader::Kind EncapsulationHeader::kind() const
     162             : {
     163           0 :   return kind_;
     164             : }
     165             : 
     166             : ACE_INLINE
     167          11 : void EncapsulationHeader::kind(Kind value)
     168             : {
     169          11 :   kind_ = value;
     170          11 : }
     171             : 
     172             : ACE_INLINE
     173           2 : bool EncapsulationHeader::is_good() const
     174             : {
     175           2 :   return kind_ != KIND_INVALID;
     176             : }
     177             : 
     178             : ACE_INLINE
     179           0 : ACE_UINT16 EncapsulationHeader::options() const
     180             : {
     181           0 :   return options_;
     182             : }
     183             : 
     184             : ACE_INLINE
     185           0 : void EncapsulationHeader::options(ACE_CDR::UShort value)
     186             : {
     187           0 :   options_ = value;
     188           0 : }
     189             : 
     190             : ACE_INLINE
     191             : bool serialized_size(const Encoding& /*encoding*/, size_t& size,
     192             :   const EncapsulationHeader& /*value*/)
     193             : {
     194             :   size += EncapsulationHeader::serialized_size;
     195             :   return true;
     196             : }
     197             : 
     198             : ACE_INLINE
     199       50955 : const Encoding& Serializer::encoding() const
     200             : {
     201       50955 :   return encoding_;
     202             : }
     203             : 
     204             : ACE_INLINE
     205        2590 : void Serializer::encoding(const Encoding& value)
     206             : {
     207        2590 :   encoding_ = value;
     208        2590 :   swap_bytes_ = value.endianness() != ENDIAN_NATIVE;
     209        2590 : }
     210             : 
     211             : ACE_INLINE
     212           1 : void Serializer::endianness(Endianness value)
     213             : {
     214           1 :   Encoding enc = encoding();
     215           1 :   enc.endianness(value);
     216           1 :   encoding(enc);
     217           1 : }
     218             : 
     219             : ACE_INLINE
     220           1 : Endianness Serializer::endianness() const
     221             : {
     222           1 :   return encoding_.endianness();
     223             : }
     224             : 
     225             : // NOTE: I use the ternary operators in here for conditionals to help
     226             : //       the compiler inline the code -- and it does end up fairly
     227             : //       tight...
     228             : ACE_INLINE size_t
     229       18791 : Serializer::doread(char* dest, size_t size, bool swap, size_t offset)
     230             : {
     231             :   //
     232             :   // Ensure we work only with buffer data.
     233             :   //
     234       18791 :   if (current_ == 0) {
     235           0 :     good_bit_ = false;
     236           0 :     return size;
     237             :   }
     238             : 
     239             :   //
     240             :   // Determine how much data will remain to be read after the current
     241             :   // buffer has been entirely read.
     242             :   //
     243       18791 :   const size_t len = current_->length();
     244       18791 :   const size_t remainder = (size - offset > len) ? size - offset - len : 0;
     245             : 
     246             :   //
     247             :   // Derive how much data we need to read from the current buffer.
     248             :   //
     249       18791 :   const size_t initial = size - offset - remainder;
     250             : 
     251             :   //
     252             :   // Copy or swap the source data from the current buffer into the
     253             :   // destination.
     254             :   //
     255             :   swap
     256       18791 :     ? swapcpy(dest + remainder, current_->rd_ptr(), initial)
     257       15656 :     : smemcpy(dest + offset, current_->rd_ptr(), initial);
     258       18791 :   current_->rd_ptr(initial);
     259             : 
     260             :   // Update the logical reading position in the stream.
     261       18791 :   rpos_ += initial;
     262             : 
     263             :   //   smemcpy
     264             :   //
     265             :   //   dest            b1   b2   b3        offset   remainder   initial
     266             :   //   xxxxxxxx        01   23   4567xx
     267             :   //                   ^                   0        6           2
     268             :   //   01xxxxxx        01   23   4567xx
     269             :   //                        ^              2        4           2
     270             :   //   0123xxxx        01   23   4567xx
     271             :   //                             ^         4        0           4
     272             :   //   01234567        01   23   4567xx
     273             :   //                                 ^
     274             : 
     275             :   //   swapcpy
     276             :   //
     277             :   //   dest            b1   b2   b3        offset   remainder   initial
     278             :   //   xxxxxxxx        01   23   4567xx
     279             :   //                   ^                   0        6           2
     280             :   //   xxxxxx10        01   23   4567xx
     281             :   //                        ^              2        4           2
     282             :   //   xxxx3210        01   23   4567xx
     283             :   //                             ^         4        0           4
     284             :   //   76543210        01   23   4567xx
     285             :   //                                 ^
     286             : 
     287             :   //
     288             :   // Move to the next chained block if this one is spent.
     289             :   //
     290       18791 :   if (current_->length() == 0) {
     291         607 :     if (encoding().alignment()) {
     292         567 :       align_cont_r();
     293             :     } else {
     294          40 :       current_ = current_->cont();
     295             :     }
     296             :   }
     297             : 
     298             :   //
     299             :   // Return the current location in the read.
     300             :   //
     301       18791 :   return offset + initial;
     302             : }
     303             : 
     304             : ACE_INLINE void
     305       18769 : Serializer::buffer_read(char* dest, size_t size, bool swap)
     306             : {
     307       18769 :   size_t offset = 0;
     308             : 
     309       37560 :   while (size > offset) {
     310       18791 :     offset = doread(dest, size, swap, offset);
     311             :   }
     312       18769 : }
     313             : 
     314             : // NOTE: I use the ternary operators in here for conditionals to help
     315             : //       the compiler inline the code -- and it does end up fairly
     316             : //       tight...
     317             : ACE_INLINE size_t
     318        5684 : Serializer::dowrite(const char* src, size_t size, bool swap, size_t offset)
     319             : {
     320             :   //
     321             :   // Ensure we work only with buffer data.
     322             :   //
     323        5684 :   if (current_ == 0) {
     324           0 :     good_bit_ = false;
     325           0 :     return size;
     326             :   }
     327             : 
     328             :   //
     329             :   // Determine how much data will remain to be written after the current
     330             :   // buffer has been entirely filled.
     331             :   //
     332        5684 :   const size_t spc = current_->space();
     333        5684 :   const size_t remainder = (size - offset > spc) ? size - offset - spc : 0;
     334             : 
     335             :   //
     336             :   // Derive how much data we need to write to the current buffer.
     337             :   //
     338        5684 :   const size_t initial = size - offset - remainder;
     339             : 
     340             :   //
     341             :   // Copy or swap the source data into the current buffer.
     342             :   //
     343             :   swap
     344        5684 :     ? swapcpy(current_->wr_ptr(), src + remainder, initial)
     345        3528 :     : smemcpy(current_->wr_ptr(), src + offset, initial);
     346        5684 :   current_->wr_ptr(initial);
     347             : 
     348             :   // Update the logical writing position in the stream.
     349        5684 :   wpos_ += initial;
     350             : 
     351             :   //   smemcpy
     352             :   //
     353             :   //   src             b1   b2   b3        offset   remainder   initial
     354             :   //   01234567        xx   xx   xxxxxx
     355             :   //                   ^                   0        6           2
     356             :   //                   01   xx   xxxxxx
     357             :   //                        ^              2        4           2
     358             :   //                   01   23   xxxxxx
     359             :   //                             ^         4        0           4
     360             :   //                   01   23   4567xx
     361             :   //                                 ^
     362             : 
     363             :   //   swapcpy
     364             :   //
     365             :   //   src             b1   b2   b3        offset   remainder   initial
     366             :   //   01234567        xx   xx   xxxxxx
     367             :   //                   ^                   0        6           2
     368             :   //                   76   xx   xxxxxx
     369             :   //                        ^              2        4           2
     370             :   //                   76   54   xxxxxx
     371             :   //                             ^         4        0           4
     372             :   //                   76   54   3210xx
     373             :   //                                 ^
     374             : 
     375             :   //
     376             :   // Move to the next chained block if this one is spent.
     377             :   //
     378        5684 :   if (current_->space() == 0) {
     379         257 :     if (encoding().alignment()) {
     380         250 :       align_cont_w();
     381             :     } else {
     382           7 :       current_ = current_->cont();
     383             :     }
     384             :   }
     385             : 
     386             :   //
     387             :   // Return the current location in the write.
     388             :   //
     389        5684 :   return offset + initial;
     390             : }
     391             : 
     392             : ACE_INLINE void
     393        5661 : Serializer::buffer_write(const char* src, size_t size, bool swap)
     394             : {
     395        5661 :   size_t offset = 0;
     396             : 
     397       11345 :   while (size > offset) {
     398        5684 :     offset = dowrite(src, size, swap, offset);
     399             :   }
     400        5661 : }
     401             : 
     402             : ACE_INLINE
     403          96 : void Serializer::swap_bytes(bool do_swap)
     404             : {
     405          96 :   Encoding enc = encoding_;
     406          96 :   enc.endianness(do_swap ? ENDIAN_NONNATIVE : ENDIAN_NATIVE);
     407          96 :   encoding(enc);
     408          96 : }
     409             : 
     410             : ACE_INLINE bool
     411       17241 : Serializer::swap_bytes() const
     412             : {
     413       17241 :   return swap_bytes_;
     414             : }
     415             : 
     416             : ACE_INLINE
     417       16590 : Encoding::Alignment Serializer::alignment() const
     418             : {
     419       16590 :   return encoding().alignment();
     420             : }
     421             : 
     422             : ACE_INLINE
     423             : void Serializer::alignment(Encoding::Alignment value)
     424             : {
     425             :   Encoding enc = encoding_;
     426             :   enc.alignment(value);
     427             :   encoding(enc);
     428             : }
     429             : 
     430             : ACE_INLINE bool
     431       41599 : Serializer::good_bit() const
     432             : {
     433       41599 :   return good_bit_;
     434             : }
     435             : 
     436             : ACE_INLINE size_t
     437         411 : Serializer::length() const
     438             : {
     439         411 :   return good_bit_ && current_ ? current_->total_length() : 0;
     440             : }
     441             : 
     442             : ACE_INLINE bool
     443       16219 : Serializer::skip(size_t n, int size)
     444             : {
     445       16219 :   if (size > 1 && !align_r((std::min)(size_t(size), encoding().max_align()))) {
     446           0 :     return false;
     447             :   }
     448             : 
     449       16253 :   for (size_t len = static_cast<size_t>(n * size); len;) {
     450        6453 :     if (!current_) {
     451           1 :       good_bit_ = false;
     452           1 :       return false;
     453             :     }
     454        6452 :     const size_t cur_len = current_->length();
     455        6452 :     if (cur_len <= len) {
     456          34 :       len -= cur_len;
     457          34 :       current_->rd_ptr(current_->wr_ptr());
     458          34 :       align_cont_r();
     459             :     } else {
     460        6418 :       current_->rd_ptr(len);
     461        6418 :       break;
     462             :     }
     463             :   }
     464             : 
     465       16218 :   if (good_bit_) {
     466       16217 :     rpos_ += n * size;
     467             :   }
     468       16218 :   return good_bit();
     469             : }
     470             : 
     471             : ACE_INLINE void
     472        2482 : Serializer::read_array(char* x, size_t size, ACE_CDR::ULong length)
     473             : {
     474        2482 :   read_array(x, size, length, swap_bytes_);
     475        2482 : }
     476             : 
     477             : ACE_INLINE void
     478        2482 : Serializer::read_array(char* x, size_t size,
     479             :                        ACE_CDR::ULong length, bool swap)
     480             : {
     481        2482 :   if (!swap || size == 1) {
     482             :     //
     483             :     // No swap, copy direct.  This silently corrupts the data if there is
     484             :     // padding in the buffer.
     485             :     //
     486        2417 :     buffer_read(x, size * length, false);
     487             : 
     488             :   } else {
     489             :     //
     490             :     // Swapping _must_ be done at 'size' boundaries, so we need to spin
     491             :     // through the array element by element.  This silently corrupts the
     492             :     // data if there is padding in the buffer.
     493             :     //
     494         185 :     while (length-- > 0) {
     495         120 :       buffer_read(x, size, true);
     496         120 :       x += size;
     497             :     }
     498             :   }
     499        2482 : }
     500             : 
     501             : ACE_INLINE void
     502         718 : Serializer::write_array(const char* x, size_t size, ACE_CDR::ULong length)
     503             : {
     504         718 :   write_array(x, size, length, swap_bytes_);
     505         718 : }
     506             : 
     507             : ACE_INLINE void
     508         718 : Serializer::write_array(const char* x, size_t size,
     509             :                         ACE_CDR::ULong length, bool swap)
     510             : {
     511         718 :   if (!swap || size == 1) {
     512             :     //
     513             :     // No swap, copy direct.
     514             :     //
     515         612 :     buffer_write(x, size * length, false);
     516             : 
     517             :   } else {
     518             :     //
     519             :     // Swapping _must_ be done at 'size' boundaries, so we need to spin
     520             :     // through the array element by element.
     521             :     // NOTE: This assumes that there is _no_ padding between the array
     522             :     //       elements.  If this is not the case, do not use this
     523             :     //       method.
     524             :     //
     525         306 :     while (length-- > 0) {
     526         200 :       buffer_write(x, size, true);
     527         200 :       x += size;
     528             :     }
     529             :   }
     530         718 : }
     531             : 
     532             : ACE_INLINE bool
     533           5 : Serializer::read_boolean_array(ACE_CDR::Boolean* x, ACE_CDR::ULong length)
     534             : {
     535           5 :   read_array(reinterpret_cast<char*>(x), boolean_cdr_size, length);
     536           5 :   return good_bit();
     537             : }
     538             : 
     539             : ACE_INLINE bool
     540        1052 : Serializer::read_char_array(ACE_CDR::Char* x, ACE_CDR::ULong length)
     541             : {
     542        1052 :   read_array(reinterpret_cast<char*>(x), char8_cdr_size, length);
     543        1052 :   return good_bit();
     544             : }
     545             : 
     546             : ACE_INLINE bool
     547           5 : Serializer::read_wchar_array(ACE_CDR::WChar* x, ACE_CDR::ULong length)
     548             : {
     549          20 :   for (ACE_CDR::ULong i = 0; i < length; ++i) {
     550          15 :     if (!((*this) >> ACE_InputCDR::to_wchar(x[i]))) {
     551           0 :       break;
     552             :     }
     553             :   }
     554           5 :   return good_bit();
     555             : }
     556             : 
     557             : ACE_INLINE bool
     558        1056 : Serializer::read_octet_array(ACE_CDR::Octet* x, ACE_CDR::ULong length)
     559             : {
     560        1056 :   read_array(reinterpret_cast<char*>(x), byte_cdr_size, length);
     561        1056 :   return good_bit();
     562             : }
     563             : 
     564             : #if OPENDDS_HAS_EXPLICIT_INTS
     565             : ACE_INLINE
     566           5 : bool Serializer::read_int8_array(ACE_CDR::Int8* x, ACE_CDR::ULong length)
     567             : {
     568           5 :   read_array(reinterpret_cast<char*>(x), int8_cdr_size, length);
     569           5 :   return good_bit();
     570             : }
     571             : 
     572             : ACE_INLINE
     573           5 : bool Serializer::read_uint8_array(ACE_CDR::UInt8* x, ACE_CDR::ULong length)
     574             : {
     575           5 :   read_array(reinterpret_cast<char*>(x), uint8_cdr_size, length);
     576           5 :   return good_bit();
     577             : }
     578             : #endif
     579             : 
     580             : ACE_INLINE bool
     581           5 : Serializer::read_short_array(ACE_CDR::Short* x, ACE_CDR::ULong length)
     582             : {
     583           5 :   if (!align_r(int16_cdr_size)) {
     584           0 :     return false;
     585             :   }
     586           5 :   read_array(reinterpret_cast<char*>(x), int16_cdr_size, length);
     587           5 :   return good_bit();
     588             : }
     589             : 
     590             : ACE_INLINE bool
     591           5 : Serializer::read_ushort_array(ACE_CDR::UShort* x, ACE_CDR::ULong length)
     592             : {
     593           5 :   if (!align_r(uint16_cdr_size)) {
     594           0 :     return false;
     595             :   }
     596           5 :   read_array(reinterpret_cast<char*>(x), uint16_cdr_size, length);
     597           5 :   return good_bit();
     598             : }
     599             : 
     600             : ACE_INLINE bool
     601         312 : Serializer::read_long_array(ACE_CDR::Long* x, ACE_CDR::ULong length)
     602             : {
     603         312 :   if (!align_r(int32_cdr_size)) {
     604           0 :     return false;
     605             :   }
     606         312 :   read_array(reinterpret_cast<char*>(x), int32_cdr_size, length);
     607         312 :   return good_bit();
     608             : }
     609             : 
     610             : ACE_INLINE bool
     611          12 : Serializer::read_ulong_array(ACE_CDR::ULong* x, ACE_CDR::ULong length)
     612             : {
     613          12 :   if (!align_r(uint32_cdr_size)) {
     614           0 :     return false;
     615             :   }
     616          12 :   read_array(reinterpret_cast<char*>(x), uint32_cdr_size, length);
     617          12 :   return good_bit();
     618             : }
     619             : 
     620             : ACE_INLINE bool
     621           5 : Serializer::read_longlong_array(ACE_CDR::LongLong* x, ACE_CDR::ULong length)
     622             : {
     623           5 :   if (!align_r(int64_cdr_size)) {
     624           0 :     return false;
     625             :   }
     626           5 :   read_array(reinterpret_cast<char*>(x), int64_cdr_size, length);
     627           5 :   return good_bit();
     628             : }
     629             : 
     630             : ACE_INLINE bool
     631           5 : Serializer::read_ulonglong_array(ACE_CDR::ULongLong* x, ACE_CDR::ULong length)
     632             : {
     633           5 :   if (!align_r(uint64_cdr_size)) {
     634           0 :     return false;
     635             :   }
     636           5 :   read_array(reinterpret_cast<char*>(x), uint64_cdr_size, length);
     637           5 :   return good_bit();
     638             : }
     639             : 
     640             : ACE_INLINE bool
     641           5 : Serializer::read_float_array(ACE_CDR::Float* x, ACE_CDR::ULong length)
     642             : {
     643           5 :   if (!align_r(float32_cdr_size)) {
     644           0 :     return false;
     645             :   }
     646           5 :   read_array(reinterpret_cast<char*>(x), float32_cdr_size, length);
     647           5 :   return good_bit();
     648             : }
     649             : 
     650             : ACE_INLINE bool
     651           5 : Serializer::read_double_array(ACE_CDR::Double* x, ACE_CDR::ULong length)
     652             : {
     653           5 :   if (!align_r(float64_cdr_size)) {
     654           0 :     return false;
     655             :   }
     656           5 :   read_array(reinterpret_cast<char*>(x), float64_cdr_size, length);
     657           5 :   return good_bit();
     658             : }
     659             : 
     660             : ACE_INLINE bool
     661           5 : Serializer::read_longdouble_array(ACE_CDR::LongDouble* x, ACE_CDR::ULong length)
     662             : {
     663           5 :   if (!align_r(float128_cdr_size)) {
     664           0 :     return false;
     665             :   }
     666           5 :   read_array(reinterpret_cast<char*>(x), float128_cdr_size, length);
     667           5 :   return good_bit();
     668             : }
     669             : 
     670             : ACE_INLINE bool
     671          12 : Serializer::write_boolean_array(const ACE_CDR::Boolean* x,
     672             :                                 ACE_CDR::ULong length)
     673             : {
     674          12 :   write_array(reinterpret_cast<const char*>(x), boolean_cdr_size, length);
     675          12 :   return good_bit();
     676             : }
     677             : 
     678             : ACE_INLINE bool
     679          12 : Serializer::write_char_array(const ACE_CDR::Char* x, ACE_CDR::ULong length)
     680             : {
     681          12 :   write_array(reinterpret_cast<const char*>(x), char8_cdr_size, length);
     682          12 :   return good_bit();
     683             : }
     684             : 
     685             : ACE_INLINE bool
     686          12 : Serializer::write_wchar_array(const ACE_CDR::WChar* x, ACE_CDR::ULong length)
     687             : {
     688          48 :   for (ACE_CDR::ULong i = 0; i < length; ++i) {
     689          36 :     if (!((*this) << ACE_OutputCDR::from_wchar(x[i]))) {
     690           0 :       break;
     691             :     }
     692             :   }
     693          12 :   return good_bit();
     694             : }
     695             : 
     696             : ACE_INLINE bool
     697         559 : Serializer::write_octet_array(const ACE_CDR::Octet* x, ACE_CDR::ULong length)
     698             : {
     699         559 :   write_array(reinterpret_cast<const char*>(x), byte_cdr_size, length);
     700         559 :   return good_bit();
     701             : }
     702             : 
     703             : #if OPENDDS_HAS_EXPLICIT_INTS
     704             : ACE_INLINE
     705          15 : bool Serializer::write_int8_array(const ACE_CDR::Int8* x, ACE_CDR::ULong length)
     706             : {
     707          15 :   write_array(reinterpret_cast<const char*>(x), int8_cdr_size, length);
     708          15 :   return good_bit();
     709             : }
     710             : 
     711             : ACE_INLINE
     712          12 : bool Serializer::write_uint8_array(const ACE_CDR::UInt8* x, ACE_CDR::ULong length)
     713             : {
     714          12 :   write_array(reinterpret_cast<const char*>(x), uint8_cdr_size, length);
     715          12 :   return good_bit();
     716             : }
     717             : #endif
     718             : 
     719             : ACE_INLINE bool
     720          12 : Serializer::write_short_array(const ACE_CDR::Short* x, ACE_CDR::ULong length)
     721             : {
     722          12 :   if (!align_w(int16_cdr_size)) {
     723           0 :     return false;
     724             :   }
     725          12 :   write_array(reinterpret_cast<const char*>(x), int16_cdr_size, length);
     726          12 :   return good_bit();
     727             : }
     728             : 
     729             : ACE_INLINE bool
     730          12 : Serializer::write_ushort_array(const ACE_CDR::UShort* x, ACE_CDR::ULong length)
     731             : {
     732          12 :   if (!align_w(uint16_cdr_size)) {
     733           0 :     return false;
     734             :   }
     735          12 :   write_array(reinterpret_cast<const char*>(x), uint16_cdr_size, length);
     736          12 :   return good_bit();
     737             : }
     738             : 
     739             : ACE_INLINE bool
     740          22 : Serializer::write_long_array(const ACE_CDR::Long* x, ACE_CDR::ULong length)
     741             : {
     742          22 :   if (!align_w(int32_cdr_size)) {
     743           0 :     return false;
     744             :   }
     745          22 :   write_array(reinterpret_cast<const char*>(x), int32_cdr_size, length);
     746          22 :   return good_bit();
     747             : }
     748             : 
     749             : ACE_INLINE bool
     750          14 : Serializer::write_ulong_array(const ACE_CDR::ULong* x, ACE_CDR::ULong length)
     751             : {
     752          14 :   if (!align_w(uint32_cdr_size)) {
     753           0 :     return false;
     754             :   }
     755          14 :   write_array(reinterpret_cast<const char*>(x), uint32_cdr_size, length);
     756          14 :   return good_bit();
     757             : }
     758             : 
     759             : ACE_INLINE bool
     760          12 : Serializer::write_longlong_array(const ACE_CDR::LongLong* x,
     761             :                                  ACE_CDR::ULong length)
     762             : {
     763          12 :   if (!align_w(int64_cdr_size)) {
     764           0 :     return false;
     765             :   }
     766          12 :   write_array(reinterpret_cast<const char*>(x), int64_cdr_size, length);
     767          12 :   return good_bit();
     768             : }
     769             : 
     770             : ACE_INLINE bool
     771          12 : Serializer::write_ulonglong_array(const ACE_CDR::ULongLong* x,
     772             :                                   ACE_CDR::ULong length)
     773             : {
     774          12 :   if (!align_w(uint64_cdr_size)) {
     775           0 :     return false;
     776             :   }
     777          12 :   write_array(reinterpret_cast<const char*>(x), uint64_cdr_size, length);
     778          12 :   return good_bit();
     779             : }
     780             : 
     781             : ACE_INLINE bool
     782          12 : Serializer::write_float_array(const ACE_CDR::Float* x, ACE_CDR::ULong length)
     783             : {
     784          12 :   if (!align_w(float32_cdr_size)) {
     785           0 :     return false;
     786             :   }
     787          12 :   write_array(reinterpret_cast<const char*>(x), float32_cdr_size, length);
     788          12 :   return good_bit();
     789             : }
     790             : 
     791             : ACE_INLINE bool
     792          12 : Serializer::write_double_array(const ACE_CDR::Double* x, ACE_CDR::ULong length)
     793             : {
     794          12 :   if (!align_w(float64_cdr_size)) {
     795           0 :     return false;
     796             :   }
     797          12 :   write_array(reinterpret_cast<const char*>(x), float64_cdr_size, length);
     798          12 :   return good_bit();
     799             : }
     800             : 
     801             : ACE_INLINE bool
     802           0 : Serializer::write_longdouble_array(const ACE_CDR::LongDouble* x,
     803             :                                    ACE_CDR::ULong length)
     804             : {
     805           0 :   if (!align_w(float128_cdr_size)) {
     806           0 :     return false;
     807             :   }
     808           0 :   write_array(reinterpret_cast<const char*>(x), float128_cdr_size, length);
     809           0 :   return good_bit();
     810             : }
     811             : 
     812             : ACE_INLINE
     813       12682 : bool Serializer::align_r(size_t al)
     814             : {
     815       12682 :   if (!alignment()) {
     816         172 :     return true;
     817             :   }
     818       12510 :   if (!current_) {
     819           0 :     good_bit_ = false;
     820           0 :     return false;
     821             :   }
     822       12510 :   al = (std::min)(al, encoding().max_align());
     823             :   const size_t len =
     824       12510 :     (al - ptrdiff_t(current_->rd_ptr()) + align_rshift_) % al;
     825             : 
     826       12510 :   return skip(static_cast<ACE_CDR::UShort>(len));
     827             : }
     828             : 
     829             : ACE_INLINE
     830        3908 : bool Serializer::align_w(size_t al)
     831             : {
     832        3908 :   if (!alignment()) {
     833         122 :     return true;
     834             :   }
     835        3786 :   if (!current_) {
     836           0 :     good_bit_ = false;
     837           0 :     return false;
     838             :   }
     839        3786 :   al = (std::min)(al, encoding().max_align());
     840             :   size_t len =
     841        3786 :     (al - ptrdiff_t(current_->wr_ptr()) + align_wshift_) % al;
     842        3786 :   while (len) {
     843         508 :     if (!current_) {
     844           0 :       good_bit_ = false;
     845           0 :       break;
     846             :     }
     847         508 :     const size_t cur_spc = current_->space();
     848         508 :     if (cur_spc <= len) {
     849           0 :       len -= cur_spc;
     850           0 :       if (encoding().zero_init_padding()) {
     851           0 :         smemcpy(current_->wr_ptr(), ALIGN_PAD, cur_spc);
     852             :       }
     853           0 :       current_->wr_ptr(cur_spc);
     854           0 :       wpos_ += cur_spc;
     855           0 :       align_cont_w();
     856             :     } else {
     857         508 :       if (encoding().zero_init_padding()) {
     858         508 :         smemcpy(current_->wr_ptr(), ALIGN_PAD, len);
     859             :       }
     860         508 :       current_->wr_ptr(len);
     861         508 :       wpos_ += len;
     862         508 :       break;
     863             :     }
     864             :   }
     865        3786 :   return good_bit_;
     866             : }
     867             : 
     868             : ACE_INLINE unsigned char
     869        5133 : Serializer::offset(char* index, size_t start, size_t align)
     870             : {
     871        5133 :   return static_cast<unsigned char>((ptrdiff_t(index) - start) % align);
     872             : }
     873             : 
     874             : ACE_INLINE void
     875         601 : Serializer::align_cont_r()
     876             : {
     877         601 :   const size_t max_align = encoding().max_align();
     878             :   const size_t thisblock =
     879         601 :     max_align ? (ptrdiff_t(current_->rd_ptr()) - align_rshift_) % max_align : 0;
     880             : 
     881         601 :   current_ = current_->cont();
     882             : 
     883         601 :   if (current_ && max_align) {
     884          37 :     align_rshift_ = offset(current_->rd_ptr(), thisblock, max_align);
     885             :   }
     886         601 : }
     887             : 
     888             : ACE_INLINE void
     889         250 : Serializer::align_cont_w()
     890             : {
     891         250 :   const size_t max_align = encoding().max_align();
     892             :   const size_t thisblock =
     893         250 :     max_align ? (ptrdiff_t(current_->wr_ptr()) - align_wshift_) % max_align : 0;
     894             : 
     895         250 :   current_ = current_->cont();
     896             : 
     897         250 :   if (current_ && max_align) {
     898          26 :     align_wshift_ = offset(current_->wr_ptr(), thisblock, max_align);
     899             :   }
     900         250 : }
     901             : 
     902             : ACE_INLINE
     903         275 : bool Serializer::skip_delimiter()
     904             : {
     905         275 :   if (encoding().xcdr_version() == Encoding::XCDR_VERSION_2) {
     906         164 :     return skip(uint32_cdr_size);
     907             :   }
     908         111 :   return true;
     909             : }
     910             : 
     911             : ACE_INLINE
     912        2709 : bool Serializer::read_delimiter(size_t& size)
     913             : {
     914        2709 :   if (encoding().xcdr_version() == Encoding::XCDR_VERSION_2) {
     915             :     ACE_CDR::ULong dheader;
     916        2709 :     if (*this >> dheader) {
     917        2709 :       size = dheader;
     918        2709 :       return true;
     919             :     }
     920             :   }
     921           0 :   return false;
     922             : }
     923             : 
     924             : ACE_INLINE
     925         754 : bool Serializer::write_delimiter(size_t size)
     926             : {
     927         754 :   if (encoding().xcdr_version() == Encoding::XCDR_VERSION_2) {
     928         754 :     return *this << static_cast<ACE_CDR::ULong>(size - uint32_cdr_size);
     929             :   }
     930           0 :   return true;
     931             : }
     932             : 
     933             : ACE_INLINE
     934           0 : bool Serializer::write_list_end_parameter_id()
     935             : {
     936           0 :   if (encoding().xcdr_version() == Encoding::XCDR_VERSION_1) {
     937           0 :     return align_w(xcdr1_pid_alignment) && *this << pid_list_end && *this << ACE_CDR::UShort(0);
     938             :   }
     939           0 :   return true;
     940             : }
     941             : 
     942             : //
     943             : // The following insertion operators are done in the style of the
     944             : // ACE_CDR insertion operators instead of a stream abstraction.  This
     945             : // is done to allow their use in the same way as existing ACE_CDR
     946             : // inserters, rather than as a true stream abstraction (which would
     947             : // return the argument stream).
     948             : //
     949             : 
     950             : ACE_INLINE bool
     951          46 : operator<<(Serializer& s, ACE_CDR::Char x)
     952             : {
     953          46 :   s.buffer_write(reinterpret_cast<char*>(&x), char8_cdr_size, s.swap_bytes());
     954          46 :   return s.good_bit();
     955             : }
     956             : 
     957             : ACE_INLINE bool
     958          16 : operator<<(Serializer& s, ACE_CDR::Short x)
     959             : {
     960          16 :   if (!s.align_w(int16_cdr_size)) {
     961           0 :     return false;
     962             :   }
     963          16 :   s.buffer_write(reinterpret_cast<char*>(&x), int16_cdr_size, s.swap_bytes());
     964          16 :   return s.good_bit();
     965             : }
     966             : 
     967             : ACE_INLINE bool
     968         198 : operator<<(Serializer& s, ACE_CDR::UShort x)
     969             : {
     970         198 :   if (!s.align_w(uint16_cdr_size)) {
     971           0 :     return false;
     972             :   }
     973         198 :   s.buffer_write(reinterpret_cast<char*>(&x), uint16_cdr_size, s.swap_bytes());
     974         198 :   return s.good_bit();
     975             : }
     976             : 
     977             : ACE_INLINE bool
     978         614 : operator<<(Serializer& s, ACE_CDR::Long x)
     979             : {
     980         614 :   if (!s.align_w(int32_cdr_size)) {
     981           0 :     return false;
     982             :   }
     983         614 :   s.buffer_write(reinterpret_cast<char*>(&x), int32_cdr_size, s.swap_bytes());
     984         614 :   return s.good_bit();
     985             : }
     986             : 
     987             : ACE_INLINE bool
     988        2865 : operator<<(Serializer& s, ACE_CDR::ULong x)
     989             : {
     990        2865 :   if (!s.align_w(uint32_cdr_size)) {
     991           0 :     return false;
     992             :   }
     993        2865 :   s.buffer_write(reinterpret_cast<char*>(&x), uint32_cdr_size, s.swap_bytes());
     994        2865 :   return s.good_bit();
     995             : }
     996             : 
     997             : ACE_INLINE bool
     998          11 : operator<<(Serializer& s, ACE_CDR::LongLong x)
     999             : {
    1000          11 :   if (!s.align_w(int64_cdr_size)) {
    1001           0 :     return false;
    1002             :   }
    1003          11 :   s.buffer_write(reinterpret_cast<char*>(&x), int64_cdr_size, s.swap_bytes());
    1004          11 :   return s.good_bit();
    1005             : }
    1006             : 
    1007             : ACE_INLINE bool
    1008          17 : operator<<(Serializer& s, ACE_CDR::ULongLong x)
    1009             : {
    1010          17 :   if (!s.align_w(uint64_cdr_size)) {
    1011           0 :     return false;
    1012             :   }
    1013          17 :   s.buffer_write(reinterpret_cast<char*>(&x), uint64_cdr_size, s.swap_bytes());
    1014          17 :   return s.good_bit();
    1015             : }
    1016             : 
    1017             : ACE_INLINE bool
    1018          10 : operator<<(Serializer& s, ACE_CDR::Float x)
    1019             : {
    1020          10 :   if (!s.align_w(float32_cdr_size)) {
    1021           0 :     return false;
    1022             :   }
    1023          10 :   s.buffer_write(reinterpret_cast<char*>(&x), float32_cdr_size, s.swap_bytes());
    1024          10 :   return s.good_bit();
    1025             : }
    1026             : 
    1027             : ACE_INLINE bool
    1028          22 : operator<<(Serializer& s, ACE_CDR::Double x)
    1029             : {
    1030          22 :   if (!s.align_w(float64_cdr_size)) {
    1031           0 :     return false;
    1032             :   }
    1033          22 :   s.buffer_write(reinterpret_cast<char*>(&x), float64_cdr_size, s.swap_bytes());
    1034          22 :   return s.good_bit();
    1035             : }
    1036             : 
    1037             : ACE_INLINE bool
    1038           0 : operator<<(Serializer& s, ACE_CDR::LongDouble x)
    1039             : {
    1040           0 :   if (!s.align_w(float128_cdr_size)) {
    1041           0 :     return false;
    1042             :   }
    1043           0 :   s.buffer_write(reinterpret_cast<char*>(&x), float128_cdr_size, s.swap_bytes());
    1044           0 :   return s.good_bit();
    1045             : }
    1046             : 
    1047             : ACE_INLINE bool
    1048         289 : operator<<(Serializer& s, const ACE_CDR::Char* x)
    1049             : {
    1050         289 :   if (x != 0) {
    1051             :     // Include the null termination in the serialized data.
    1052         289 :     const ACE_CDR::ULong stringlen =
    1053         289 :       1 + static_cast<ACE_CDR::ULong>(std::strlen(x));
    1054         289 :     s << stringlen;
    1055         289 :     s.buffer_write(reinterpret_cast<const char*>(x), stringlen, false);
    1056             : 
    1057             :   } else {
    1058           0 :     s << ACE_CDR::ULong(0);
    1059             :   }
    1060             : 
    1061         289 :   return s.good_bit();
    1062             : }
    1063             : 
    1064             : ACE_INLINE bool
    1065          34 : operator<<(Serializer& s, const ACE_CDR::WChar* x)
    1066             : {
    1067          34 :   if (x != 0) {
    1068             :     // Do not include the null terminatator in the serialized data.
    1069          34 :     const ACE_CDR::ULong length = static_cast<ACE_CDR::ULong>(ACE_OS::strlen(x));
    1070          34 :     s << ACE_CDR::ULong(length * char16_cdr_size);
    1071             : 
    1072             : #if ACE_SIZEOF_WCHAR == 2
    1073             :     s.write_array(reinterpret_cast<const char*>(x), char16_cdr_size, length,
    1074             :       s.swap_bytes());
    1075             : #else
    1076         136 :     for (size_t i = 0; i < length && s.good_bit(); ++i) {
    1077         102 :       const ACE_UINT16 as_utf16 = static_cast<ACE_UINT16>(x[i]);
    1078         102 :       if (as_utf16 != x[i]) { // not currently handling surrogates
    1079           0 :         s.good_bit_ = false;
    1080           0 :         break;
    1081             :       }
    1082         102 :       s.buffer_write(reinterpret_cast<const char*>(&as_utf16), char16_cdr_size,
    1083         102 :         s.swap_bytes());
    1084             :     }
    1085             : #endif
    1086             :   } else {
    1087           0 :     s << ACE_CDR::ULong(0);
    1088             :   }
    1089             : 
    1090          34 :   return s.good_bit();
    1091             : }
    1092             : 
    1093             : #ifdef NONNATIVE_LONGDOUBLE
    1094             : ACE_INLINE bool
    1095             : operator<<(Serializer& s, long double x)
    1096             : {
    1097             :   if (!s.align_w(float128_cdr_size)) {
    1098             :     return false;
    1099             :   }
    1100             :   ACE_CDR::LongDouble ld;
    1101             :   ACE_CDR_LONG_DOUBLE_ASSIGNMENT(ld, x);
    1102             :   return s << ld;
    1103             : }
    1104             : #endif
    1105             : 
    1106             : ACE_INLINE bool
    1107          25 : operator<<(Serializer& s, ACE_OutputCDR::from_boolean x)
    1108             : {
    1109          25 :   s.buffer_write(reinterpret_cast<char*>(&x.val_), boolean_cdr_size, false);
    1110          25 :   return s.good_bit();
    1111             : }
    1112             : 
    1113             : ACE_INLINE bool
    1114          14 : operator<<(Serializer& s, ACE_OutputCDR::from_char x)
    1115             : {
    1116          14 :   s.buffer_write(reinterpret_cast<char*>(&x.val_), char8_cdr_size, false);
    1117          14 :   return s.good_bit();
    1118             : }
    1119             : 
    1120             : ACE_INLINE bool
    1121          47 : operator<<(Serializer& s, ACE_OutputCDR::from_wchar x)
    1122             : {
    1123          47 :   if (!s.align_w(char16_cdr_size)) {
    1124           0 :     return false;
    1125             :   }
    1126             : #if ACE_SIZEOF_WCHAR == 2
    1127             :   s.buffer_write(reinterpret_cast<char*>(&x.val_), char16_cdr_size, s.swap_bytes());
    1128             : #else
    1129          47 :   const ACE_UINT16 as_utf16 = static_cast<ACE_UINT16>(x.val_);
    1130          47 :   if (as_utf16 != x.val_) { // not currently handling surrogates
    1131           0 :     if (DCPS_debug_level) {
    1132           0 :       ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ")
    1133             :         ACE_TEXT("operator<<(Serializer&, ACE_OutputCDR::from_wchar): ")
    1134             :         ACE_TEXT("failure to convert UTF-32 to UTF-16.\n")));
    1135             :     }
    1136           0 :     s.good_bit_ = false;
    1137             :   } else {
    1138          47 :     s.buffer_write(reinterpret_cast<const char*>(&as_utf16), char16_cdr_size,
    1139          47 :       s.swap_bytes());
    1140             :   }
    1141             : #endif
    1142          47 :   return s.good_bit();
    1143             : }
    1144             : 
    1145             : ACE_INLINE bool
    1146           0 : operator<<(Serializer& s, const String& x)
    1147             : {
    1148           0 :   return s << x.c_str();
    1149             : }
    1150             : 
    1151             : ACE_INLINE bool
    1152           0 : operator<<(Serializer& s, Serializer::FromBoundedString<char> x)
    1153             : {
    1154           0 :   return (x.bound_ == 0 || x.str_.size() <= x.bound_) && s << x.str_;
    1155             : }
    1156             : 
    1157             : #ifdef DDS_HAS_WCHAR
    1158             : ACE_INLINE bool
    1159           0 : operator<<(Serializer& s, const WString& x)
    1160             : {
    1161           0 :   return s << x.c_str();
    1162             : }
    1163             : 
    1164             : ACE_INLINE bool
    1165           0 : operator<<(Serializer& s, Serializer::FromBoundedString<wchar_t> x)
    1166             : {
    1167           0 :   return (x.bound_ == 0 || x.str_.size() <= x.bound_) && s << x.str_;
    1168             : }
    1169             : #endif /* DDS_HAS_WCHAR */
    1170             : 
    1171             : ACE_INLINE bool
    1172         545 : operator<<(Serializer& s, ACE_OutputCDR::from_octet x)
    1173             : {
    1174         545 :   s.buffer_write(reinterpret_cast<char*>(&x.val_), byte_cdr_size, false);
    1175         545 :   return s.good_bit();
    1176             : }
    1177             : 
    1178             : ACE_INLINE bool
    1179           2 : operator<<(Serializer& s, ACE_OutputCDR::from_string x)
    1180             : {
    1181             :   // Include the null termination in the serialized data.
    1182           2 :   ACE_CDR::ULong stringlen = 0;
    1183           2 :   if (x.val_ != 0) {
    1184           2 :     stringlen = 1 + static_cast<ACE_CDR::ULong>(ACE_OS::strlen(x.val_));
    1185           2 :     s << stringlen;
    1186           2 :     s.buffer_write(reinterpret_cast<char*>(x.val_), stringlen, false);
    1187             :   } else {
    1188           0 :     s << ACE_CDR::ULong(0);
    1189             :   }
    1190           2 :   return s.good_bit() && ((x.bound_ == 0) || (stringlen - 1 <= x.bound_));
    1191             : }
    1192             : 
    1193             : ACE_INLINE bool
    1194             : operator<<(Serializer& s, ACE_OutputCDR::from_wstring x)
    1195             : {
    1196             :   s << x.val_;
    1197             :   const ACE_CDR::ULong stringlen =
    1198             :     x.bound_ ? static_cast<ACE_CDR::ULong>(ACE_OS::strlen(x.val_)) : 0;
    1199             :   return s.good_bit() && ((x.bound_ == 0) || (stringlen <= x.bound_));
    1200             : }
    1201             : 
    1202             : #if OPENDDS_HAS_EXPLICIT_INTS
    1203             : ACE_INLINE
    1204          11 : bool operator<<(Serializer& s, ACE_OutputCDR::from_uint8 x)
    1205             : {
    1206          11 :   s.buffer_write(reinterpret_cast<const char*>(&x.val_), uint8_cdr_size, false);
    1207          11 :   return s.good_bit();
    1208             : }
    1209             : 
    1210             : ACE_INLINE
    1211          15 : bool operator<<(Serializer& s, ACE_OutputCDR::from_int8 x)
    1212             : {
    1213          15 :   s.buffer_write(reinterpret_cast<const char*>(&x.val_), int8_cdr_size, false);
    1214          15 :   return s.good_bit();
    1215             : }
    1216             : #endif
    1217             : 
    1218             : //
    1219             : // The following extraction operators are done in the style of the
    1220             : // ACE_CDR extraction operators instead of a stream abstraction.  This
    1221             : // is done to allow their use in the same way as existing ACE_CDR
    1222             : // extractors, rather than as a true stream abstraction (which would
    1223             : // return the argument stream).
    1224             : //
    1225             : 
    1226             : ACE_INLINE bool
    1227         226 : operator>>(Serializer& s, ACE_CDR::Char& x)
    1228             : {
    1229         226 :   s.buffer_read(reinterpret_cast<char*>(&x), char8_cdr_size, s.swap_bytes());
    1230         226 :   return s.good_bit();
    1231             : }
    1232             : 
    1233             : ACE_INLINE bool
    1234          23 : operator>>(Serializer& s, ACE_CDR::Short& x)
    1235             : {
    1236          23 :   if (!s.align_r(int16_cdr_size)) {
    1237           0 :     return false;
    1238             :   }
    1239          23 :   s.buffer_read(reinterpret_cast<char*>(&x), int16_cdr_size, s.swap_bytes());
    1240          23 :   return s.good_bit();
    1241             : }
    1242             : 
    1243             : ACE_INLINE bool
    1244        1958 : operator>>(Serializer& s, ACE_CDR::UShort& x)
    1245             : {
    1246        1958 :   if (!s.align_r(uint16_cdr_size)) {
    1247           0 :     return false;
    1248             :   }
    1249        1958 :   s.buffer_read(reinterpret_cast<char*>(&x), uint16_cdr_size, s.swap_bytes());
    1250        1958 :   return s.good_bit();
    1251             : }
    1252             : 
    1253             : ACE_INLINE bool
    1254         560 : operator>>(Serializer& s, ACE_CDR::Long& x)
    1255             : {
    1256         560 :   if (!s.align_r(int32_cdr_size)) {
    1257           0 :     return false;
    1258             :   }
    1259         560 :   s.buffer_read(reinterpret_cast<char*>(&x), int32_cdr_size, s.swap_bytes());
    1260         560 :   return s.good_bit();
    1261             : }
    1262             : 
    1263             : ACE_INLINE bool
    1264        7952 : operator>>(Serializer& s, ACE_CDR::ULong& x)
    1265             : {
    1266        7952 :   if (!s.align_r(uint32_cdr_size)) {
    1267           0 :     return false;
    1268             :   }
    1269        7952 :   s.buffer_read(reinterpret_cast<char*>(&x), uint32_cdr_size, s.swap_bytes());
    1270        7952 :   return s.good_bit();
    1271             : }
    1272             : 
    1273             : ACE_INLINE bool
    1274          15 : operator>>(Serializer& s, ACE_CDR::LongLong& x)
    1275             : {
    1276          15 :   if (!s.align_r(int64_cdr_size)) {
    1277           0 :     return false;
    1278             :   }
    1279          15 :   s.buffer_read(reinterpret_cast<char*>(&x), int64_cdr_size, s.swap_bytes());
    1280          15 :   return s.good_bit();
    1281             : }
    1282             : 
    1283             : ACE_INLINE bool
    1284          20 : operator>>(Serializer& s, ACE_CDR::ULongLong& x)
    1285             : {
    1286          20 :   if (!s.align_r(uint64_cdr_size)) {
    1287           0 :     return false;
    1288             :   }
    1289          20 :   s.buffer_read(reinterpret_cast<char*>(&x), uint64_cdr_size, s.swap_bytes());
    1290          20 :   return s.good_bit();
    1291             : }
    1292             : 
    1293             : ACE_INLINE bool
    1294          15 : operator>>(Serializer& s, ACE_CDR::Float& x)
    1295             : {
    1296          15 :   if (!s.align_r(float32_cdr_size)) {
    1297           0 :     return false;
    1298             :   }
    1299          15 :   s.buffer_read(reinterpret_cast<char*>(&x), float32_cdr_size, s.swap_bytes());
    1300          15 :   return s.good_bit();
    1301             : }
    1302             : 
    1303             : ACE_INLINE bool
    1304          15 : operator>>(Serializer& s, ACE_CDR::Double& x)
    1305             : {
    1306          15 :   if (!s.align_r(float64_cdr_size)) {
    1307           0 :     return false;
    1308             :   }
    1309          15 :   s.buffer_read(reinterpret_cast<char*>(&x), float64_cdr_size, s.swap_bytes());
    1310          15 :   return s.good_bit();
    1311             : }
    1312             : 
    1313             : ACE_INLINE bool
    1314          15 : operator>>(Serializer& s, ACE_CDR::LongDouble& x)
    1315             : {
    1316          15 :   if (!s.align_r(float128_cdr_size)) {
    1317           0 :     return false;
    1318             :   }
    1319          15 :   s.buffer_read(reinterpret_cast<char*>(&x), float128_cdr_size, s.swap_bytes());
    1320          15 :   return s.good_bit();
    1321             : }
    1322             : 
    1323             : ACE_INLINE bool
    1324          21 : operator>>(Serializer& s, ACE_CDR::Char*& x)
    1325             : {
    1326          21 :   s.read_string(x);
    1327          21 :   return s.good_bit();
    1328             : }
    1329             : 
    1330             : ACE_INLINE bool
    1331          25 : operator>>(Serializer& s, ACE_CDR::WChar*& x)
    1332             : {
    1333          25 :   s.read_string(x);
    1334          25 :   return s.good_bit();
    1335             : }
    1336             : 
    1337             : #ifdef NONNATIVE_LONGDOUBLE
    1338             : ACE_INLINE bool
    1339             : operator>>(Serializer& s, long double& x)
    1340             : {
    1341             :   if (!s.align_r(float128_cdr_size)) {
    1342             :     return false;
    1343             :   }
    1344             :   ACE_CDR::LongDouble ld;
    1345             :   if (s >> ld) {
    1346             :     x = ld;
    1347             :     return true;
    1348             :   }
    1349             :   return false;
    1350             : }
    1351             : #endif
    1352             : 
    1353             : ACE_INLINE bool
    1354        2365 : operator>>(Serializer& s, ACE_InputCDR::to_boolean x)
    1355             : {
    1356        2365 :   s.buffer_read(reinterpret_cast<char*>(&x.ref_), boolean_cdr_size, s.swap_bytes());
    1357        2365 :   return s.good_bit();
    1358             : }
    1359             : 
    1360             : ACE_INLINE bool
    1361          15 : operator>>(Serializer& s, ACE_InputCDR::to_char x)
    1362             : {
    1363          15 :   s.buffer_read(reinterpret_cast<char*>(&x.ref_), char8_cdr_size, s.swap_bytes());
    1364          15 :   return s.good_bit();
    1365             : }
    1366             : 
    1367             : ACE_INLINE bool
    1368          30 : operator>>(Serializer& s, ACE_InputCDR::to_wchar x)
    1369             : {
    1370          30 :   if (!s.align_r(char16_cdr_size)) {
    1371           0 :     return false;
    1372             :   }
    1373             : #if ACE_SIZEOF_WCHAR == 2
    1374             :   s.buffer_read(reinterpret_cast<char*>(&x.ref_), char16_cdr_size,
    1375             :     s.swap_bytes());
    1376             : #else
    1377             :   ACE_UINT16 as_utf16;
    1378          30 :   s.buffer_read(reinterpret_cast<char*>(&as_utf16), char16_cdr_size,
    1379          30 :     s.swap_bytes());
    1380          30 :   x.ref_ = as_utf16;
    1381             : #endif
    1382          30 :   return s.good_bit();
    1383             : }
    1384             : 
    1385             : ACE_INLINE bool
    1386        2895 : operator>>(Serializer& s, ACE_InputCDR::to_octet x)
    1387             : {
    1388        2895 :   s.buffer_read(reinterpret_cast<char*>(&x.ref_), byte_cdr_size, false);
    1389        2895 :   return s.good_bit();
    1390             : }
    1391             : 
    1392             : ACE_INLINE bool
    1393           0 : operator>>(Serializer& s, ACE_InputCDR::to_string x)
    1394             : {
    1395           0 :   const size_t length = s.read_string(const_cast<char*&>(x.val_));
    1396           0 :   if (s.good_bit() && (x.bound_ != 0) && (length > x.bound_)) {
    1397           0 :     s.set_construction_status(Serializer::BoundConstructionFailure);
    1398           0 :     return false;
    1399             :   }
    1400           0 :   return s.good_bit();
    1401             : }
    1402             : 
    1403             : ACE_INLINE bool
    1404             : operator>>(Serializer& s, ACE_InputCDR::to_wstring x)
    1405             : {
    1406             :   const size_t length = s.read_string(const_cast<ACE_CDR::WChar*&>(x.val_));
    1407             :   if (s.good_bit() && (x.bound_ != 0) && (length > x.bound_)) {
    1408             :     s.set_construction_status(Serializer::BoundConstructionFailure);
    1409             :     return false;
    1410             :   }
    1411             :   return s.good_bit();
    1412             : }
    1413             : 
    1414             : #if OPENDDS_HAS_EXPLICIT_INTS
    1415             : ACE_INLINE
    1416          15 : bool operator>>(Serializer& s, ACE_InputCDR::to_uint8 x)
    1417             : {
    1418          15 :   s.buffer_read(reinterpret_cast<char*>(&x.ref_), uint8_cdr_size, false);
    1419          15 :   return s.good_bit();
    1420             : }
    1421             : 
    1422             : ACE_INLINE
    1423          32 : bool operator>>(Serializer& s, ACE_InputCDR::to_int8 x)
    1424             : {
    1425          32 :   s.buffer_read(reinterpret_cast<char*>(&x.ref_), int8_cdr_size, false);
    1426          32 :   return s.good_bit();
    1427             : }
    1428             : #endif
    1429             : 
    1430             : ACE_INLINE bool
    1431        1026 : operator>>(Serializer& s, String& x)
    1432             : {
    1433        1026 :   char* buf = 0;
    1434        1026 :   const size_t length = s.read_string(buf);
    1435        1026 :   if (!s.good_bit()) {
    1436           1 :     return false;
    1437             :   }
    1438        1025 :   x.assign(buf, length);
    1439        1025 :   s.free_string(buf);
    1440        1025 :   return true;
    1441             : }
    1442             : 
    1443             : ACE_INLINE bool
    1444        1026 : operator>>(Serializer& s, Serializer::ToBoundedString<char> x)
    1445             : {
    1446        1026 :   if (s >> x.str_) {
    1447        1025 :     if ((x.bound_ != 0) && (x.str_.size() > x.bound_)) {
    1448           0 :       s.set_construction_status(Serializer::BoundConstructionFailure);
    1449           0 :       return false;
    1450             :     }
    1451        1025 :     return true;
    1452             :   }
    1453           1 :   return false;
    1454             : }
    1455             : 
    1456             : #ifdef DDS_HAS_WCHAR
    1457             : ACE_INLINE bool
    1458           0 : operator>>(Serializer& s, WString& x)
    1459             : {
    1460           0 :   ACE_CDR::WChar* buf = 0;
    1461           0 :   const size_t length = s.read_string(buf);
    1462           0 :   if (!s.good_bit()) {
    1463           0 :     return false;
    1464             :   }
    1465           0 :   x.assign(buf, length);
    1466           0 :   s.free_string(buf);
    1467           0 :   return true;
    1468             : }
    1469             : 
    1470             : ACE_INLINE bool
    1471           0 : operator>>(Serializer& s, Serializer::ToBoundedString<wchar_t> x)
    1472             : {
    1473           0 :   if (s >> x.str_) {
    1474           0 :     if ((x.bound_ != 0) && (x.str_.size() > x.bound_)) {
    1475           0 :       s.set_construction_status(Serializer::BoundConstructionFailure);
    1476           0 :       return false;
    1477             :     }
    1478           0 :     return true;
    1479             :   }
    1480           0 :   return false;
    1481             : }
    1482             : #endif /* DDS_HAS_WCHAR */
    1483             : 
    1484             : //----------------------------------------------------------------------------
    1485             : // predefined type methods
    1486             : 
    1487             : ACE_INLINE
    1488          32 : bool primitive_serialized_size(
    1489             :   const Encoding& encoding, size_t& size,
    1490             :   const ACE_CDR::Short& /*value*/, size_t count)
    1491             : {
    1492          32 :   encoding.align(size, int16_cdr_size);
    1493          32 :   size += int16_cdr_size * count;
    1494          32 :   return true;
    1495             : }
    1496             : 
    1497             : ACE_INLINE
    1498        1819 : bool primitive_serialized_size(
    1499             :   const Encoding& encoding, size_t& size,
    1500             :   const ACE_CDR::UShort& /*value*/, size_t count)
    1501             : {
    1502        1819 :   encoding.align(size, uint16_cdr_size);
    1503        1819 :   size += uint16_cdr_size * count;
    1504        1819 :   return true;
    1505             : }
    1506             : 
    1507             : ACE_INLINE
    1508        1394 : bool primitive_serialized_size(
    1509             :   const Encoding& encoding, size_t& size,
    1510             :   const ACE_CDR::Long& /*value*/, size_t count)
    1511             : {
    1512        1394 :   encoding.align(size, int32_cdr_size);
    1513        1394 :   size += int32_cdr_size * count;
    1514        1394 :   return true;
    1515             : }
    1516             : 
    1517             : ACE_INLINE
    1518        1734 : bool primitive_serialized_size(
    1519             :   const Encoding& encoding, size_t& size,
    1520             :   const ACE_CDR::ULong& /*value*/, size_t count)
    1521             : {
    1522        1734 :   encoding.align(size, uint32_cdr_size);
    1523        1734 :   size += uint32_cdr_size * count;
    1524        1734 :   return true;
    1525             : }
    1526             : 
    1527             : ACE_INLINE
    1528          25 : bool primitive_serialized_size(
    1529             :   const Encoding& encoding, size_t& size,
    1530             :   const ACE_CDR::LongLong& /*value*/, size_t count)
    1531             : {
    1532          25 :   encoding.align(size, int64_cdr_size);
    1533          25 :   size += int64_cdr_size * count;
    1534          25 :   return true;
    1535             : }
    1536             : 
    1537             : ACE_INLINE
    1538          25 : bool primitive_serialized_size(
    1539             :   const Encoding& encoding, size_t& size,
    1540             :   const ACE_CDR::ULongLong& /*value*/, size_t count)
    1541             : {
    1542          25 :   encoding.align(size, uint64_cdr_size);
    1543          25 :   size += uint64_cdr_size * count;
    1544          25 :   return true;
    1545             : }
    1546             : 
    1547             : ACE_INLINE
    1548          23 : bool primitive_serialized_size(
    1549             :   const Encoding& encoding, size_t& size,
    1550             :   const ACE_CDR::Float& /*value*/, size_t count)
    1551             : {
    1552          23 :   encoding.align(size, float32_cdr_size);
    1553          23 :   size += float32_cdr_size * count;
    1554          23 :   return true;
    1555             : }
    1556             : 
    1557             : ACE_INLINE
    1558          23 : bool primitive_serialized_size(
    1559             :   const Encoding& encoding, size_t& size,
    1560             :   const ACE_CDR::Double& /*value*/, size_t count)
    1561             : {
    1562          23 :   encoding.align(size, float64_cdr_size);
    1563          23 :   size += float64_cdr_size * count;
    1564          23 :   return true;
    1565             : }
    1566             : 
    1567             : ACE_INLINE
    1568           0 : bool primitive_serialized_size(
    1569             :   const Encoding& encoding, size_t& size,
    1570             :   const ACE_CDR::LongDouble& /*value*/, size_t count)
    1571             : {
    1572           0 :   encoding.align(size, float128_cdr_size);
    1573           0 :   size += float128_cdr_size * count;
    1574           0 :   return true;
    1575             : }
    1576             : 
    1577             : // predefined type method disambiguators.
    1578             : ACE_INLINE
    1579           0 : bool primitive_serialized_size(
    1580             :   const Encoding& /*encoding*/, size_t& size,
    1581             :   const ACE_OutputCDR::from_boolean /*value*/, size_t count)
    1582             : {
    1583           0 :   size += boolean_cdr_size * count;
    1584           0 :   return true;
    1585             : }
    1586             : 
    1587             : ACE_INLINE
    1588           0 : bool primitive_serialized_size(
    1589             :   const Encoding& /*encoding*/, size_t& size,
    1590             :   const ACE_OutputCDR::from_char /*value*/, size_t count)
    1591             : {
    1592           0 :   size += char8_cdr_size * count;
    1593           0 :   return true;
    1594             : }
    1595             : 
    1596             : ACE_INLINE
    1597           0 : bool primitive_serialized_size(
    1598             :   const Encoding& encoding, size_t& size,
    1599             :   const ACE_OutputCDR::from_wchar /*value*/, size_t count)
    1600             : {
    1601           0 :   encoding.align(size, char16_cdr_size);
    1602           0 :   size += char16_cdr_size * count;
    1603           0 :   return true;
    1604             : }
    1605             : 
    1606             : ACE_INLINE
    1607         699 : bool primitive_serialized_size(
    1608             :   const Encoding& /*encoding*/, size_t& size,
    1609             :   const ACE_OutputCDR::from_octet /*value*/, size_t count)
    1610             : {
    1611         699 :   size += byte_cdr_size * count;
    1612         699 :   return true;
    1613             : }
    1614             : 
    1615             : #if OPENDDS_HAS_EXPLICIT_INTS
    1616             : ACE_INLINE
    1617           0 : bool primitive_serialized_size(
    1618             :   const Encoding& /*encoding*/, size_t& size,
    1619             :   const ACE_OutputCDR::from_uint8 /*value*/, size_t count)
    1620             : {
    1621           0 :   size += uint8_cdr_size * count;
    1622           0 :   return true;
    1623             : }
    1624             : 
    1625             : ACE_INLINE
    1626           0 : bool primitive_serialized_size(
    1627             :   const Encoding& /*encoding*/, size_t& size,
    1628             :   const ACE_OutputCDR::from_int8 /*value*/, size_t count)
    1629             : {
    1630           0 :   size += int8_cdr_size * count;
    1631           0 :   return true;
    1632             : }
    1633             : #endif
    1634             : 
    1635             : // predefined type method explicit disambiguators.
    1636             : 
    1637             : ACE_INLINE
    1638          28 : void primitive_serialized_size_boolean(const Encoding& /*encoding*/, size_t& size,
    1639             :   size_t count)
    1640             : {
    1641          28 :   size += boolean_cdr_size * count;
    1642          28 : }
    1643             : 
    1644             : ACE_INLINE
    1645          28 : void primitive_serialized_size_char(const Encoding& /*encoding*/, size_t& size,
    1646             :   size_t count)
    1647             : {
    1648          28 :   size += char8_cdr_size * count;
    1649          28 : }
    1650             : 
    1651             : ACE_INLINE
    1652          25 : void primitive_serialized_size_wchar(const Encoding& encoding, size_t& size,
    1653             :   size_t count)
    1654             : {
    1655          25 :   encoding.align(size, char16_cdr_size);
    1656          25 :   size += char16_cdr_size * count;
    1657          25 : }
    1658             : 
    1659             : ACE_INLINE
    1660        4509 : void primitive_serialized_size_octet(const Encoding& /*encoding*/, size_t& size,
    1661             :   size_t count)
    1662             : {
    1663        4509 :   size += byte_cdr_size * count;
    1664        4509 : }
    1665             : 
    1666             : ACE_INLINE
    1667        8159 : void primitive_serialized_size_ulong(const Encoding& encoding, size_t& size,
    1668             :   size_t count)
    1669             : {
    1670        8159 :   encoding.align(size, uint32_cdr_size);
    1671        8159 :   size += uint32_cdr_size * count;
    1672        8159 : }
    1673             : 
    1674             : #if OPENDDS_HAS_EXPLICIT_INTS
    1675             : ACE_INLINE
    1676          25 : void primitive_serialized_size_uint8(const Encoding& /*encoding*/, size_t& size,
    1677             :   size_t count)
    1678             : {
    1679          25 :   size += uint8_cdr_size * count;
    1680          25 : }
    1681             : 
    1682             : ACE_INLINE
    1683          36 : void primitive_serialized_size_int8(const Encoding& /*encoding*/, size_t& size,
    1684             :   size_t count)
    1685             : {
    1686          36 :   size += int8_cdr_size * count;
    1687          36 : }
    1688             : #endif
    1689             : 
    1690             : ACE_INLINE
    1691        4610 : void serialized_size_delimiter(const Encoding& encoding, size_t& size)
    1692             : {
    1693        4610 :   if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2) {
    1694        4610 :     primitive_serialized_size_ulong(encoding, size);
    1695             :   }
    1696        4610 : }
    1697             : 
    1698             : ACE_INLINE
    1699         604 : void serialized_size_parameter_id(
    1700             :   const Encoding& encoding, size_t& size, size_t& running_size)
    1701             : {
    1702         604 :   const Encoding::XcdrVersion xcdr = encoding.xcdr_version();
    1703         604 :   if (xcdr == Encoding::XCDR_VERSION_1) {
    1704           0 :     encoding.align(size, xcdr1_pid_alignment);
    1705           0 :     size += uint16_cdr_size * 2;
    1706             :     // TODO(iguessthislldo): Extended PID
    1707             : 
    1708             :     // Save and Zero Size to Reset the Alignment
    1709           0 :     running_size += size;
    1710           0 :     size = 0;
    1711         604 :   } else if (xcdr == Encoding::XCDR_VERSION_2) {
    1712         604 :     if (running_size != 0 && size != 1 && size != 2 && size != 4 && size != 8) {
    1713         191 :       size += uint32_cdr_size; // nextint
    1714             :     }
    1715         604 :     encoding.align(size, uint32_cdr_size);
    1716         604 :     size += uint32_cdr_size; // emheader
    1717         604 :     running_size += size;
    1718         604 :     size = 0;
    1719             :   }
    1720         604 : }
    1721             : 
    1722             : ACE_INLINE
    1723         311 : void serialized_size_list_end_parameter_id(
    1724             :   const Encoding& encoding, size_t& size, size_t& running_size)
    1725             : {
    1726         311 :   if (encoding.xcdr_version() == Encoding::XCDR_VERSION_1) {
    1727             :     /*
    1728             :      * TODO(iguessthislldo): See how DDSXTY14-23 is resolved.
    1729             :      * https://github.com/OpenDDS/OpenDDS/pull/1722#discussion_r447165924
    1730             :      */
    1731           0 :     encoding.align(size, xcdr1_pid_alignment);
    1732           0 :     size += uint16_cdr_size * 2;
    1733             : 
    1734             :     // Restore Saved Totals from Alignment Resets
    1735           0 :     size += running_size;
    1736         311 :   } else if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2) {
    1737         311 :     if (running_size != 0 && size != 1 && size != 2 && size != 4 && size != 8) {
    1738         197 :       size += uint32_cdr_size; // nextint
    1739             :     }
    1740         311 :     size += running_size;
    1741             :   }
    1742         311 : }
    1743             : 
    1744             : ACE_INLINE
    1745           0 : Serializer::ConstructionStatus Serializer::get_construction_status() const
    1746             : {
    1747           0 :   return construction_status_;
    1748             : }
    1749             : 
    1750             : ACE_INLINE
    1751           1 : void Serializer::set_construction_status(ConstructionStatus cs)
    1752             : {
    1753           1 :   construction_status_ = cs;
    1754           1 : }
    1755             : 
    1756             : ACE_INLINE
    1757         287 : Serializer::RdState Serializer::rdstate() const
    1758             : {
    1759         287 :   RdState state(align_rshift_, rpos_);
    1760         287 :   return state;
    1761             : }
    1762             : 
    1763             : ACE_INLINE
    1764         636 : void Serializer::rdstate(const RdState& state)
    1765             : {
    1766         636 :   align_rshift_ = state.align_rshift;
    1767         636 :   rpos_ = state.rpos;
    1768         636 : }
    1769             : 
    1770             : } // namespace DCPS
    1771             : } // namespace OpenDDS
    1772             : 
    1773             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16