OpenDDS::DCPS::Serializer Class Reference

Class to serialize and deserialize data for DDS. More...

#include <Serializer.h>

List of all members.

Public Types

 ALIGN_NONE
 ALIGN_INITIALIZE
 ALIGN_CDR
enum  Alignment { ALIGN_NONE, ALIGN_INITIALIZE, ALIGN_CDR }

Public Member Functions

 Serializer (ACE_Message_Block *chain, bool swap_bytes=false, Alignment align=ALIGN_NONE)
virtual ~Serializer ()
void swap_bytes (bool do_swap)
 Establish byte swaping behavior.
bool swap_bytes () const
 Examine byte swaping behavior.
Alignment alignment () const
 Examine alignment behavior.
void reset_alignment ()
 Reset aligment as if a new instance were created.
bool good_bit () const
 Examine the state of the stream abstraction.
void read_string (ACE_CDR::Char *&dest, ACE_CDR::Char *str_alloc(ACE_CDR::ULong)=CORBA::string_alloc, void str_free(ACE_CDR::Char *)=CORBA::string_free)
 Read a narrow string.
void read_string (ACE_CDR::WChar *&dest, ACE_CDR::WChar *str_alloc(ACE_CDR::ULong)=CORBA::wstring_alloc, void str_free(ACE_CDR::WChar *)=CORBA::wstring_free)
 Read a wide string.
bool skip (ACE_CDR::UShort n, int size=1)
void buffer_read (char *dest, size_t size, bool swap)
 Read from the chain into a destination buffer.
bool read_boolean_array (ACE_CDR::Boolean *x, ACE_CDR::ULong length)
bool read_char_array (ACE_CDR::Char *x, ACE_CDR::ULong length)
bool read_wchar_array (ACE_CDR::WChar *x, ACE_CDR::ULong length)
bool read_octet_array (ACE_CDR::Octet *x, ACE_CDR::ULong length)
bool read_short_array (ACE_CDR::Short *x, ACE_CDR::ULong length)
bool read_ushort_array (ACE_CDR::UShort *x, ACE_CDR::ULong length)
bool read_long_array (ACE_CDR::Long *x, ACE_CDR::ULong length)
bool read_ulong_array (ACE_CDR::ULong *x, ACE_CDR::ULong length)
bool read_longlong_array (ACE_CDR::LongLong *x, ACE_CDR::ULong length)
bool read_ulonglong_array (ACE_CDR::ULongLong *x, ACE_CDR::ULong length)
bool read_float_array (ACE_CDR::Float *x, ACE_CDR::ULong length)
bool read_double_array (ACE_CDR::Double *x, ACE_CDR::ULong length)
bool read_longdouble_array (ACE_CDR::LongDouble *x, ACE_CDR::ULong length)
bool write_boolean_array (const ACE_CDR::Boolean *x, ACE_CDR::ULong length)
bool write_char_array (const ACE_CDR::Char *x, ACE_CDR::ULong length)
bool write_wchar_array (const ACE_CDR::WChar *x, ACE_CDR::ULong length)
bool write_octet_array (const ACE_CDR::Octet *x, ACE_CDR::ULong length)
bool write_short_array (const ACE_CDR::Short *x, ACE_CDR::ULong length)
bool write_ushort_array (const ACE_CDR::UShort *x, ACE_CDR::ULong length)
bool write_long_array (const ACE_CDR::Long *x, ACE_CDR::ULong length)
bool write_ulong_array (const ACE_CDR::ULong *x, ACE_CDR::ULong length)
bool write_longlong_array (const ACE_CDR::LongLong *x, ACE_CDR::ULong length)
bool write_ulonglong_array (const ACE_CDR::ULongLong *x, ACE_CDR::ULong length)
bool write_float_array (const ACE_CDR::Float *x, ACE_CDR::ULong length)
bool write_double_array (const ACE_CDR::Double *x, ACE_CDR::ULong length)
bool write_longdouble_array (const ACE_CDR::LongDouble *x, ACE_CDR::ULong length)

Static Public Member Functions

static bool use_rti_serialization ()
static void set_use_rti_serialization (bool should_use)

Static Public Attributes

static const size_t WCHAR_SIZE = 2
static const bool SWAP_BE = false

Private Member Functions

void read_array (char *x, size_t size, ACE_CDR::ULong length)
void read_array (char *x, size_t size, ACE_CDR::ULong length, bool swap)
void buffer_write (const char *src, size_t size, bool swap)
 Write to the chain from a source buffer.
void write_array (const char *x, size_t size, ACE_CDR::ULong length)
void write_array (const char *x, size_t size, ACE_CDR::ULong length, bool swap)
int align_r (size_t alignment)
int align_w (size_t alignment)
void smemcpy (char *to, const char *from, size_t n)
void swapcpy (char *to, const char *from, size_t n)
size_t doread (char *dest, size_t size, bool swap, size_t offset)
 Implementation of the actual read from the chain.
size_t dowrite (const char *dest, size_t size, bool swap, size_t offset)
 Implementation of the actual write to the chain.
void align_cont_r ()
 Update alignment state when a cont() chain is followed during a read.
void align_cont_w ()
 Update alignment state when a cont() chain is followed during a write.

Private Attributes

ACE_Message_Block * current_
 Currently active message block in chain.
bool swap_bytes_
 Indicates whether bytes will be swapped for this stream.
bool good_bit_
 Indicates the current state of the stream abstraction.
Alignment alignment_
 Current alignment mode, see Alignment enum above.
unsigned char align_rshift_
unsigned char align_wshift_

Static Private Attributes

static const size_t MAX_ALIGN = 8
static const char ALIGN_PAD [MAX_ALIGN] = {0}
static bool use_rti_serialization_

Friends

OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::Char x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::Short x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::UShort x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::Long x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::ULong x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::LongLong x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::ULongLong x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::LongDouble x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::Float x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_CDR::Double x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, const ACE_CDR::Char *x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, const ACE_CDR::WChar *x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_OutputCDR::from_boolean x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_OutputCDR::from_char x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_OutputCDR::from_wchar x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_OutputCDR::from_octet x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_OutputCDR::from_string x)
OpenDDS_Dcps_Export bool operator<< (Serializer &s, ACE_OutputCDR::from_wstring x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::Char &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::Short &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::UShort &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::Long &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::ULong &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::LongLong &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::ULongLong &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::LongDouble &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::Float &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::Double &x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::Char *&x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_CDR::WChar *&x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_InputCDR::to_boolean x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_InputCDR::to_char x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_InputCDR::to_wchar x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_InputCDR::to_octet x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_InputCDR::to_string x)
OpenDDS_Dcps_Export bool operator>> (Serializer &s, ACE_InputCDR::to_wstring x)


Detailed Description

Class to serialize and deserialize data for DDS.

This class provides a mechanism to insert and extract data to and from an ACE_Message_Block chain that represents the data which can be transported on the wire to other DDS service participants.

Definition at line 38 of file Serializer.h.


Member Enumeration Documentation

enum OpenDDS::DCPS::Serializer::Alignment

Enumerator:
ALIGN_NONE 
ALIGN_INITIALIZE 
ALIGN_CDR 

Definition at line 41 of file Serializer.h.

00041                  {
00042     ALIGN_NONE,           // no alignment needed
00043     ALIGN_INITIALIZE,     // align to CDR rules and zero-out padding
00044     ALIGN_CDR             // align to CDR rules with uninitialized padding
00045 #ifdef ACE_INITIALIZE_MEMORY_BEFORE_USE
00046       = ALIGN_INITIALIZE  // if the above macro is set, always init padding
00047 #endif
00048   };


Constructor & Destructor Documentation

OpenDDS::DCPS::Serializer::Serializer ( ACE_Message_Block *  chain,
bool  swap_bytes = false,
Alignment  align = ALIGN_NONE 
) [explicit]

Constructor with a message block chain. This installs the message block chain and sets the current block to the first in the chain. Memory management is the responsibility of the owner of this object, and is not performed internally. Ownership of the message block chain is retained by the owner of this object and the lifetime of the chain must be longer than the use of this object.

Bytes are swapped when either reading or writing from the message chain if the swap_bytes argument is true. It is the responsibility of the owner of this object to determine whether this should be performed or not.

Definition at line 25 of file Serializer.cpp.

00027   : current_(chain)
00028   , swap_bytes_(swap_bytes)
00029   , good_bit_(true)
00030   , alignment_(align)
00031   , align_rshift_(chain ? ptrdiff_t(chain->rd_ptr()) % MAX_ALIGN : 0)
00032   , align_wshift_(chain ? ptrdiff_t(chain->wr_ptr()) % MAX_ALIGN : 0)
00033 {
00034 }

OpenDDS::DCPS::Serializer::~Serializer (  )  [virtual]

Definition at line 36 of file Serializer.cpp.

00037 {
00038 }


Member Function Documentation

ACE_INLINE void OpenDDS::DCPS::Serializer::align_cont_r (  )  [private]

Update alignment state when a cont() chain is followed during a read.

Definition at line 548 of file Serializer.inl.

References align_rshift_, current_, and MAX_ALIGN.

Referenced by doread(), and skip().

00549 {
00550   const size_t thisblock =
00551     (ptrdiff_t(this->current_->rd_ptr()) - this->align_rshift_) % MAX_ALIGN;
00552 
00553   this->current_ = this->current_->cont();
00554 
00555   if (this->current_) {
00556     this->align_rshift_ =
00557       (ptrdiff_t(this->current_->rd_ptr()) - thisblock) % MAX_ALIGN;
00558   }
00559 }

ACE_INLINE void OpenDDS::DCPS::Serializer::align_cont_w (  )  [private]

Update alignment state when a cont() chain is followed during a write.

Definition at line 562 of file Serializer.inl.

References align_wshift_, current_, and MAX_ALIGN.

Referenced by align_w(), and dowrite().

00563 {
00564   const size_t thisblock =
00565     (ptrdiff_t(this->current_->wr_ptr()) - this->align_wshift_) % MAX_ALIGN;
00566 
00567   this->current_ = this->current_->cont();
00568 
00569   if (this->current_) {
00570     this->align_wshift_ =
00571       (ptrdiff_t(this->current_->wr_ptr()) - thisblock) % MAX_ALIGN;
00572   }
00573 }

ACE_INLINE int OpenDDS::DCPS::Serializer::align_r ( size_t  alignment  )  [private]

Align for reading: moves current_->rd_ptr() past the alignment padding. Alignments of 2, 4, or 8 are supported by CDR and this implementation.

Definition at line 509 of file Serializer.inl.

References skip().

Referenced by OpenDDS::DCPS::operator>>(), read_double_array(), read_float_array(), read_long_array(), read_longdouble_array(), read_longlong_array(), read_short_array(), read_string(), read_ulong_array(), read_ulonglong_array(), read_ushort_array(), and skip().

00510 {
00511   const size_t len =
00512     (al - ptrdiff_t(this->current_->rd_ptr()) + this->align_rshift_) % al;
00513   this->skip(static_cast<ACE_CDR::UShort>(len));
00514   return 0;
00515 }

ACE_INLINE int OpenDDS::DCPS::Serializer::align_w ( size_t  alignment  )  [private]

Align for writing: moves current_->wr_ptr() past the padding, possibly zero-filling the pad bytes (based on the alignment_ setting). Alignments of 2, 4, or 8 are supported by CDR and this implementation.

Definition at line 518 of file Serializer.inl.

References align_cont_w(), ALIGN_INITIALIZE, ALIGN_PAD, current_, good_bit_, and smemcpy().

Referenced by OpenDDS::DCPS::operator<<(), write_double_array(), write_float_array(), write_long_array(), write_longdouble_array(), write_longlong_array(), write_short_array(), write_ulong_array(), write_ulonglong_array(), and write_ushort_array().

00519 {
00520   size_t len =
00521     (al - ptrdiff_t(this->current_->wr_ptr()) + this->align_wshift_) % al;
00522   while (len) {
00523     if (!this->current_) {
00524       this->good_bit_ = false;
00525       break;
00526     }
00527     const size_t cur_spc = this->current_->space();
00528     if (cur_spc <= len) {
00529       len -= cur_spc;
00530       if (this->alignment_ == ALIGN_INITIALIZE) {
00531         this->smemcpy(this->current_->wr_ptr(), ALIGN_PAD, cur_spc);
00532       }
00533       this->current_->wr_ptr(cur_spc);
00534       this->align_cont_w();
00535     } else {
00536       if (this->alignment_ == ALIGN_INITIALIZE) {
00537         this->smemcpy(this->current_->wr_ptr(), ALIGN_PAD, len);
00538       }
00539       this->current_->wr_ptr(len);
00540       break;
00541     }
00542   }
00543   return 0;
00544 }

ACE_INLINE Serializer::Alignment OpenDDS::DCPS::Serializer::alignment (  )  const

Examine alignment behavior.

Definition at line 200 of file Serializer.inl.

References alignment_.

Referenced by OpenDDS::DCPS::operator<<(), OpenDDS::DCPS::operator>>(), read_double_array(), read_float_array(), read_long_array(), read_longdouble_array(), read_longlong_array(), read_short_array(), read_ulong_array(), read_ulonglong_array(), read_ushort_array(), write_double_array(), write_float_array(), write_long_array(), write_longdouble_array(), write_longlong_array(), write_short_array(), write_ulong_array(), write_ulonglong_array(), and write_ushort_array().

00201 {
00202   return this->alignment_;
00203 }

ACE_INLINE void OpenDDS::DCPS::Serializer::buffer_read ( char *  dest,
size_t  size,
bool  swap 
)

Read from the chain into a destination buffer.

Definition at line 92 of file Serializer.inl.

References doread().

Referenced by mb_copy(), OpenDDS::DCPS::operator>>(), read_array(), and read_string().

00093 {
00094   register size_t offset = 0;
00095 
00096   while (size > offset) {
00097     offset = this->doread(dest, size, swap, offset);
00098   }
00099 }

ACE_INLINE void OpenDDS::DCPS::Serializer::buffer_write ( const char *  src,
size_t  size,
bool  swap 
) [private]

Write to the chain from a source buffer.

Definition at line 178 of file Serializer.inl.

References dowrite().

Referenced by OpenDDS::DCPS::operator<<(), and write_array().

00179 {
00180   register size_t offset = 0;
00181 
00182   while (size > offset) {
00183     offset = this->dowrite(src, size, swap, offset);
00184   }
00185 }

ACE_INLINE size_t OpenDDS::DCPS::Serializer::doread ( char *  dest,
size_t  size,
bool  swap,
size_t  offset 
) [private]

Implementation of the actual read from the chain.

Definition at line 19 of file Serializer.inl.

References align_cont_r(), ALIGN_NONE, current_, good_bit_, and swapcpy().

Referenced by buffer_read().

00020 {
00021   //
00022   // Ensure we work only with buffer data.
00023   //
00024   if (this->current_ == 0) {
00025     this->good_bit_ = false;
00026     return size;
00027   }
00028 
00029   //
00030   // Determine how much data will remain to be read after the current
00031   // buffer has been entirely read.
00032   //
00033   const size_t len = this->current_->length();
00034   register size_t remainder = (size - offset > len) ? size - offset - len : 0;
00035 
00036   //
00037   // Derive how much data we need to read from the current buffer.
00038   //
00039   register size_t initial = size - offset - remainder;
00040 
00041   //
00042   // Copy or swap the source data from the current buffer into the
00043   // destination.
00044   //
00045   swap
00046     ? this->swapcpy(dest + remainder, this->current_->rd_ptr(), initial)
00047     : this->smemcpy(dest + offset, this->current_->rd_ptr(), initial);
00048   this->current_->rd_ptr(initial);
00049 
00050   //   smemcpy
00051   //
00052   //   dest            b1   b2   b3        offset   remainder   initial
00053   //   xxxxxxxx        01   23   4567xx
00054   //                   ^                   0        6           2
00055   //   01xxxxxx        01   23   4567xx
00056   //                        ^              2        4           2
00057   //   0123xxxx        01   23   4567xx
00058   //                             ^         4        0           4
00059   //   01234567        01   23   4567xx
00060   //                                 ^
00061 
00062   //   swapcpy
00063   //
00064   //   dest            b1   b2   b3        offset   remainder   initial
00065   //   xxxxxxxx        01   23   4567xx
00066   //                   ^                   0        6           2
00067   //   xxxxxx10        01   23   4567xx
00068   //                        ^              2        4           2
00069   //   xxxx3210        01   23   4567xx
00070   //                             ^         4        0           4
00071   //   76543210        01   23   4567xx
00072   //                                 ^
00073 
00074   //
00075   // Move to the next chained block if this one is spent.
00076   //
00077   if (this->current_->length() == 0) {
00078 
00079     if (this->alignment_ == ALIGN_NONE) {
00080       this->current_ = this->current_->cont();
00081     } else {
00082       this->align_cont_r();
00083     }
00084   }
00085   //
00086   // Return the current location in the read.
00087   //
00088   return offset + initial;
00089 }

ACE_INLINE size_t OpenDDS::DCPS::Serializer::dowrite ( const char *  dest,
size_t  size,
bool  swap,
size_t  offset 
) [private]

Implementation of the actual write to the chain.

Definition at line 105 of file Serializer.inl.

References align_cont_w(), ALIGN_NONE, current_, good_bit_, and swapcpy().

Referenced by buffer_write().

00106 {
00107   //
00108   // Ensure we work only with buffer data.
00109   //
00110   if (this->current_ == 0) {
00111     this->good_bit_ = false;
00112     return size;
00113   }
00114 
00115   //
00116   // Determine how much data will remain to be written after the current
00117   // buffer has been entirely filled.
00118   //
00119   const size_t spc = this->current_->space();
00120   register size_t remainder = (size - offset > spc) ? size - offset - spc : 0;
00121 
00122   //
00123   // Derive how much data we need to write to the current buffer.
00124   //
00125   register size_t initial = size - offset - remainder;
00126 
00127   //
00128   // Copy or swap the source data into the current buffer.
00129   //
00130   swap
00131     ? this->swapcpy(this->current_->wr_ptr(), src + remainder, initial)
00132     : this->smemcpy(this->current_->wr_ptr(), src + offset, initial);
00133   this->current_->wr_ptr(initial);
00134 
00135   //   smemcpy
00136   //
00137   //   src             b1   b2   b3        offset   remainder   initial
00138   //   01234567        xx   xx   xxxxxx
00139   //                   ^                   0        6           2
00140   //                   01   xx   xxxxxx
00141   //                        ^              2        4           2
00142   //                   01   23   xxxxxx
00143   //                             ^         4        0           4
00144   //                   01   23   4567xx
00145   //                                 ^
00146 
00147   //   swapcpy
00148   //
00149   //   src             b1   b2   b3        offset   remainder   initial
00150   //   01234567        xx   xx   xxxxxx
00151   //                   ^                   0        6           2
00152   //                   76   xx   xxxxxx
00153   //                        ^              2        4           2
00154   //                   76   54   xxxxxx
00155   //                             ^         4        0           4
00156   //                   76   54   3210xx
00157   //                                 ^
00158 
00159   //
00160   // Move to the next chained block if this one is spent.
00161   //
00162   if (this->current_->space() == 0) {
00163 
00164     if (this->alignment_ == ALIGN_NONE) {
00165       this->current_ = this->current_->cont();
00166     } else {
00167       this->align_cont_w();
00168     }
00169   }
00170 
00171   //
00172   // Return the current location in the write.
00173   //
00174   return offset + initial;
00175 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::good_bit (  )  const

Examine the state of the stream abstraction.

Definition at line 206 of file Serializer.inl.

References good_bit_.

Referenced by OpenDDS::DCPS::DataSampleHeader::init(), OpenDDS::DCPS::operator<<(), OpenDDS::FaceTypes::operator>>(), OpenDDS::DCPS::operator>>(), read_boolean_array(), read_char_array(), read_double_array(), read_float_array(), read_long_array(), read_longdouble_array(), read_longlong_array(), read_octet_array(), read_short_array(), read_ulong_array(), read_ulonglong_array(), read_ushort_array(), read_wchar_array(), write_boolean_array(), write_char_array(), write_double_array(), write_float_array(), write_long_array(), write_longdouble_array(), write_longlong_array(), write_octet_array(), write_short_array(), write_ulong_array(), write_ulonglong_array(), write_ushort_array(), and write_wchar_array().

00207 {
00208   return this->good_bit_;
00209 }

ACE_INLINE void OpenDDS::DCPS::Serializer::read_array ( char *  x,
size_t  size,
ACE_CDR::ULong  length,
bool  swap 
) [private]

Definition at line 242 of file Serializer.inl.

References buffer_read().

00244 {
00245   if (!swap || size == 1) {
00246     //
00247     // No swap, copy direct.  This silently corrupts the data if there is
00248     // padding in the buffer.
00249     //
00250     this->buffer_read(x, size * length, false);
00251 
00252   } else {
00253     //
00254     // Swapping _must_ be done at 'size' boundaries, so we need to spin
00255     // through the array element by element.  This silently corrupts the
00256     // data if there is padding in the buffer.
00257     //
00258     while (length-- > 0) {
00259       this->buffer_read(x, size, true);
00260       x += size;
00261     }
00262   }
00263 }

ACE_INLINE void OpenDDS::DCPS::Serializer::read_array ( char *  x,
size_t  size,
ACE_CDR::ULong  length 
) [private]

Read an array of values from the chain. NOTE: This assumes that the buffer contains elements that are properly aligned. The buffer must have padding if the elements are not naturally aligned; or this routine should not be used.

Definition at line 236 of file Serializer.inl.

Referenced by read_boolean_array(), read_char_array(), read_double_array(), read_float_array(), read_long_array(), read_longdouble_array(), read_longlong_array(), read_octet_array(), read_short_array(), read_string(), read_ulong_array(), read_ulonglong_array(), and read_ushort_array().

00237 {
00238   this->read_array(x, size, length, this->swap_bytes_);
00239 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_boolean_array ( ACE_CDR::Boolean *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 297 of file Serializer.inl.

References good_bit(), and read_array().

00298 {
00299   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Boolean), length);
00300   return this->good_bit();
00301 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_char_array ( ACE_CDR::Char *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 304 of file Serializer.inl.

References good_bit(), and read_array().

Referenced by read_string().

00305 {
00306   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Char), length);
00307   return this->good_bit();
00308 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_double_array ( ACE_CDR::Double *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 385 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00386 {
00387   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::Double));
00388   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Double), length);
00389   return this->good_bit();
00390 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_float_array ( ACE_CDR::Float *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 377 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00378 {
00379   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::Float));
00380   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Float), length);
00381   return this->good_bit();
00382 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_long_array ( ACE_CDR::Long *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 345 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00346 {
00347   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::Long));
00348   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Long), length);
00349   return this->good_bit();
00350 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_longdouble_array ( ACE_CDR::LongDouble *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 393 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00394 {
00395   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(8);
00396   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::LongDouble), length);
00397   return this->good_bit();
00398 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_longlong_array ( ACE_CDR::LongLong *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 361 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00362 {
00363   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::LongLong));
00364   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::LongLong), length);
00365   return this->good_bit();
00366 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_octet_array ( ACE_CDR::Octet *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 322 of file Serializer.inl.

References good_bit(), and read_array().

Referenced by OpenDDS::DCPS::TransportHeader::init(), and OpenDDS::DCPS::UdpTransport::passive_connection().

00323 {
00324   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Octet), length);
00325   return this->good_bit();
00326 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_short_array ( ACE_CDR::Short *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 329 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00330 {
00331   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::Short));
00332   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Short), length);
00333   return this->good_bit();
00334 }

void OpenDDS::DCPS::Serializer::read_string ( ACE_CDR::WChar *&  dest,
ACE_CDR::WChar *  str_alloc(ACE_CDR::ULong) = CORBA::wstring_alloc,
void   str_free(ACE_CDR::WChar *) = CORBA::wstring_free 
)

Read a wide string.

Definition at line 149 of file Serializer.cpp.

References ALIGN_NONE, align_r(), alignment_, buffer_read(), current_, good_bit_, read_array(), SWAP_BE, and WCHAR_SIZE.

00152 {
00153   this->alignment_ == ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::ULong));
00154   //
00155   // Ensure no bad values leave the routine.
00156   //
00157   str_free(dest);
00158   dest = 0;
00159 
00160   //
00161   // Extract the string length.
00162   //
00163   ACE_CDR::ULong bytecount = 0;
00164   this->buffer_read(reinterpret_cast<char*>(&bytecount),
00165                     sizeof(ACE_CDR::ULong), this->swap_bytes());
00166 
00167   if (!this->good_bit_) {
00168     return;
00169   }
00170 
00171   //
00172   // NOTE: Maintain the ACE implementation where the length check is
00173   //       done here before the allocation even though it will be
00174   //       checked during the actual read as well.
00175   //
00176   if (bytecount <= this->current_->total_length()) {
00177 
00178     const ACE_CDR::ULong length = bytecount / WCHAR_SIZE;
00179 
00180     dest = str_alloc(length);
00181 
00182     if (dest == 0) {
00183       this->good_bit_ = false;
00184       return;
00185     }
00186 
00187 #if ACE_SIZEOF_WCHAR == 2
00188     this->read_array(reinterpret_cast<char*>(dest), WCHAR_SIZE, length, SWAP_BE);
00189 #else
00190     for (size_t i = 0; i < length && this->good_bit_; ++i) {
00191       ACE_UINT16 as_utf16;
00192       this->buffer_read(reinterpret_cast<char*>(&as_utf16), WCHAR_SIZE, SWAP_BE);
00193       if (this->good_bit_) {
00194         dest[i] = as_utf16;
00195       }
00196     }
00197 #endif
00198 
00199     if (this->good_bit_) {
00200       //
00201       // Null terminate the string.
00202       //
00203       dest[length] = L'\0';
00204 
00205     } else {
00206       str_free(dest);
00207       dest = 0;
00208     }
00209   }
00210 }

void OpenDDS::DCPS::Serializer::read_string ( ACE_CDR::Char *&  dest,
ACE_CDR::Char *  str_alloc(ACE_CDR::ULong) = CORBA::string_alloc,
void   str_free(ACE_CDR::Char *) = CORBA::string_free 
)

Read a narrow string.

Definition at line 101 of file Serializer.cpp.

References ALIGN_NONE, align_r(), alignment_, buffer_read(), current_, good_bit_, and read_char_array().

Referenced by OpenDDS::FaceTypes::operator>>(), and OpenDDS::DCPS::operator>>().

00104 {
00105   this->alignment_ == ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::ULong));
00106   //
00107   // Ensure no bad values leave the routine.
00108   //
00109   str_free(dest);
00110   dest = 0;
00111 
00112   //
00113   // Extract the string length.
00114   //
00115   ACE_CDR::ULong length; // includes the null
00116   this->buffer_read(reinterpret_cast<char*>(&length), sizeof(ACE_CDR::ULong), this->swap_bytes());
00117 
00118   if (!this->good_bit_) {
00119     return;
00120   }
00121 
00122   //
00123   // NOTE: Maintain the ACE implementation where the length check is
00124   //       done here before the allocation even though it will be
00125   //       checked during the actual read as well.
00126   //
00127   if (length <= this->current_->total_length()) {
00128 
00129     dest = str_alloc(length - 1);
00130 
00131     if (dest == 0) {
00132       this->good_bit_ = false;
00133 
00134     } else {
00135       //
00136       // Extract the string.
00137       //
00138       this->read_char_array(dest, length);
00139     }
00140 
00141     if (!this->good_bit_) {
00142       str_free(dest);
00143       dest = 0;
00144     }
00145   }
00146 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_ulong_array ( ACE_CDR::ULong *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 353 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00354 {
00355   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::ULong));
00356   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::ULong), length);
00357   return this->good_bit();
00358 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_ulonglong_array ( ACE_CDR::ULongLong *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 369 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00370 {
00371   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::ULongLong));
00372   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::ULongLong), length);
00373   return this->good_bit();
00374 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_ushort_array ( ACE_CDR::UShort *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 337 of file Serializer.inl.

References ALIGN_NONE, align_r(), alignment(), good_bit(), and read_array().

00338 {
00339   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_r(sizeof(ACE_CDR::UShort));
00340   this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::UShort), length);
00341   return this->good_bit();
00342 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::read_wchar_array ( ACE_CDR::WChar *  x,
ACE_CDR::ULong  length 
)

The buffer x must be large enough to contain length elements. Return false on failure and true on success.

Definition at line 311 of file Serializer.inl.

References good_bit().

00312 {
00313   for (ACE_CDR::ULong i = 0; i < length; ++i) {
00314     if (!((*this) >> ACE_InputCDR::to_wchar(x[i]))) {
00315       break;
00316     }
00317   }
00318   return this->good_bit();
00319 }

void OpenDDS::DCPS::Serializer::reset_alignment (  ) 

Reset aligment as if a new instance were created.

Definition at line 41 of file Serializer.cpp.

References align_rshift_, align_wshift_, current_, and MAX_ALIGN.

Referenced by OpenDDS::DCPS::DataReaderImpl_T< MessageType >::dds_demarshal(), and OpenDDS::DCPS::DataWriterImpl_T< MessageType >::dds_marshal().

00042 {
00043   align_rshift_ = current_ ? ptrdiff_t(current_->rd_ptr()) % MAX_ALIGN : 0;
00044   align_wshift_ = current_ ? ptrdiff_t(current_->wr_ptr()) % MAX_ALIGN : 0;
00045 }

void OpenDDS::DCPS::Serializer::set_use_rti_serialization ( bool  should_use  )  [static]

Definition at line 213 of file Serializer.cpp.

References use_rti_serialization_.

Referenced by OpenDDS::DCPS::Service_Participant::load_common_configuration(), and OpenDDS::DCPS::Service_Participant::parse_args().

00214 {
00215   use_rti_serialization_ = should_use;
00216 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::skip ( ACE_CDR::UShort  n,
int  size = 1 
)

Skip the logical rd_ptr() over a given number of bytes = n * size. If alignment is enabled, skips any padding to align to 'size' before skipping the n * size bytes. This is used by the RTPS protocol to allow reading messages from future versions of the spec which may have additional optional fields.

Definition at line 212 of file Serializer.inl.

References align_cont_r(), ALIGN_NONE, align_r(), current_, and MAX_ALIGN.

Referenced by align_r(), OpenDDS::RTPS::Spdp::SpdpTransport::handle_input(), OpenDDS::DCPS::RtpsSampleHeader::init(), and OpenDDS::DCPS::FilterEvaluator::SerializedForEval::lookup().

00213 {
00214   if (size > 1 && this->alignment_ != ALIGN_NONE) {
00215     this->align_r(size_t(size) > MAX_ALIGN ? MAX_ALIGN : size_t(size));
00216   }
00217   for (size_t len = static_cast<size_t>(n * size); len;) {
00218     if (!this->current_) {
00219       this->good_bit_ = false;
00220       return false;
00221     }
00222     const size_t cur_len = this->current_->length();
00223     if (cur_len <= len) {
00224       len -= cur_len;
00225       this->current_->rd_ptr(this->current_->wr_ptr());
00226       this->align_cont_r();
00227     } else {
00228       this->current_->rd_ptr(len);
00229       break;
00230     }
00231   }
00232   return this->good_bit();
00233 }

void OpenDDS::DCPS::Serializer::smemcpy ( char *  to,
const char *  from,
size_t  n 
) [private]

Efficient straight copy for quad words and shorter. This is an instance method to match the swapcpy semantics.

Definition at line 48 of file Serializer.cpp.

Referenced by align_w().

00049 {
00050     (void) ACE_OS::memcpy(
00051       reinterpret_cast<void*>(to),
00052       reinterpret_cast<const void*>(from),
00053       n);
00054 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::swap_bytes (  )  const

Examine byte swaping behavior.

Definition at line 194 of file Serializer.inl.

References swap_bytes_.

00195 {
00196   return this->swap_bytes_;
00197 }

ACE_INLINE void OpenDDS::DCPS::Serializer::swap_bytes ( bool  do_swap  ) 

Establish byte swaping behavior.

Definition at line 188 of file Serializer.inl.

References swap_bytes_.

Referenced by OpenDDS::RTPS::Spdp::SpdpTransport::handle_input(), OpenDDS::DCPS::TransportHeader::init(), OpenDDS::DCPS::DataSampleHeader::init(), OpenDDS::DCPS::operator<<(), and OpenDDS::DCPS::operator>>().

00189 {
00190   this->swap_bytes_ = do_swap;
00191 }

void OpenDDS::DCPS::Serializer::swapcpy ( char *  to,
const char *  from,
size_t  n 
) [private]

Efficient swaping copy for quad words and shorter. This is an instance method to allow clearing the good_bit_ on error.

Definition at line 57 of file Serializer.cpp.

References good_bit_.

Referenced by doread(), and dowrite().

00058 {
00059   // Unroll the loop...
00060   switch (n) {               // 2   4   8   16
00061   case 16:
00062     to[ 15] = from[ n - 16]; // x   x   x    0
00063   case 15:
00064     to[ 14] = from[ n - 15]; // x   x   x    1
00065   case 14:
00066     to[ 13] = from[ n - 14]; // x   x   x    2
00067   case 13:
00068     to[ 12] = from[ n - 13]; // x   x   x    3
00069   case 12:
00070     to[ 11] = from[ n - 12]; // x   x   x    4
00071   case 11:
00072     to[ 10] = from[ n - 11]; // x   x   x    5
00073   case 10:
00074     to[  9] = from[ n - 10]; // x   x   x    6
00075   case  9:
00076     to[  8] = from[ n -  9]; // x   x   x    7
00077   case  8:
00078     to[  7] = from[ n -  8]; // x   x   0    8
00079   case  7:
00080     to[  6] = from[ n -  7]; // x   x   1    9
00081   case  6:
00082     to[  5] = from[ n -  6]; // x   x   2   10
00083   case  5:
00084     to[  4] = from[ n -  5]; // x   x   3   11
00085   case  4:
00086     to[  3] = from[ n -  4]; // x   0   4   12
00087   case  3:
00088     to[  2] = from[ n -  3]; // x   1   5   13
00089   case  2:
00090     to[  1] = from[ n -  2]; // 0   2   6   14
00091   case  1:
00092     to[  0] = from[ n -  1]; // 1   3   7   15
00093   case  0:
00094     return;
00095   default:
00096     this->good_bit_ = false;
00097   }
00098 }

bool OpenDDS::DCPS::Serializer::use_rti_serialization (  )  [static]

Definition at line 219 of file Serializer.cpp.

References use_rti_serialization_.

Referenced by OpenDDS::DCPS::DataReaderImpl_T< MessageType >::dds_demarshal(), OpenDDS::DCPS::DataWriterImpl_T< MessageType >::dds_marshal(), and OpenDDS::DCPS::DataReaderImpl_T< MessageType >::lookup_instance().

00220 {
00221   return use_rti_serialization_;
00222 }

ACE_INLINE void OpenDDS::DCPS::Serializer::write_array ( const char *  x,
size_t  size,
ACE_CDR::ULong  length,
bool  swap 
) [private]

Definition at line 272 of file Serializer.inl.

References buffer_write().

00274 {
00275   if (!swap || size == 1) {
00276     //
00277     // No swap, copy direct.
00278     //
00279     this->buffer_write(x, size * length, false);
00280 
00281   } else {
00282     //
00283     // Swapping _must_ be done at 'size' boundaries, so we need to spin
00284     // through the array element by element.
00285     // NOTE: This assumes that there is _no_ padding between the array
00286     //       elements.  If this is not the case, do not use this
00287     //       method.
00288     //
00289     while (length-- > 0) {
00290       this->buffer_write(x, size, true);
00291       x += size;
00292     }
00293   }
00294 }

ACE_INLINE void OpenDDS::DCPS::Serializer::write_array ( const char *  x,
size_t  size,
ACE_CDR::ULong  length 
) [private]

Write an array of values to the chain. NOTE: This assumes that there is _no_ padding between the array elements. If this is not the case, do not use this method. If padding exists in the array, it will be written when _not_ swapping, and will _not_ be written when swapping, resulting in corrupted data.

Definition at line 266 of file Serializer.inl.

Referenced by OpenDDS::DCPS::operator<<(), write_boolean_array(), write_char_array(), write_double_array(), write_float_array(), write_long_array(), write_longdouble_array(), write_longlong_array(), write_octet_array(), write_short_array(), write_ulong_array(), write_ulonglong_array(), and write_ushort_array().

00267 {
00268   this->write_array(x, size, length, this->swap_bytes_);
00269 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_boolean_array ( const ACE_CDR::Boolean *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 401 of file Serializer.inl.

References good_bit(), and write_array().

00403 {
00404   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Boolean), length);
00405   return this->good_bit();
00406 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_char_array ( const ACE_CDR::Char *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 409 of file Serializer.inl.

References good_bit(), and write_array().

00410 {
00411   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Char), length);
00412   return this->good_bit();
00413 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_double_array ( const ACE_CDR::Double *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 492 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00493 {
00494   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(sizeof(ACE_CDR::Double));
00495   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Double), length);
00496   return this->good_bit();
00497 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_float_array ( const ACE_CDR::Float *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 484 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00485 {
00486   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(sizeof(ACE_CDR::Float));
00487   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Float), length);
00488   return this->good_bit();
00489 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_long_array ( const ACE_CDR::Long *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 450 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00451 {
00452   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(sizeof(ACE_CDR::Long));
00453   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Long), length);
00454   return this->good_bit();
00455 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_longdouble_array ( const ACE_CDR::LongDouble *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 500 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00502 {
00503   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(8);
00504   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::LongDouble), length);
00505   return this->good_bit();
00506 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_longlong_array ( const ACE_CDR::LongLong *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 466 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00468 {
00469   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(sizeof(ACE_CDR::LongLong));
00470   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::LongLong), length);
00471   return this->good_bit();
00472 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_octet_array ( const ACE_CDR::Octet *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 427 of file Serializer.inl.

References good_bit(), and write_array().

Referenced by OpenDDS::DCPS::RtpsUdpSendStrategy::marshal_transport_header(), and OpenDDS::DCPS::operator<<().

00428 {
00429   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Octet), length);
00430   return this->good_bit();
00431 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_short_array ( const ACE_CDR::Short *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 434 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00435 {
00436   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(sizeof(ACE_CDR::Short));
00437   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Short), length);
00438   return this->good_bit();
00439 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_ulong_array ( const ACE_CDR::ULong *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 458 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00459 {
00460   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(sizeof(ACE_CDR::ULong));
00461   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::ULong), length);
00462   return this->good_bit();
00463 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_ulonglong_array ( const ACE_CDR::ULongLong *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 475 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00477 {
00478   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(sizeof(ACE_CDR::ULongLong));
00479   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::ULongLong), length);
00480   return this->good_bit();
00481 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_ushort_array ( const ACE_CDR::UShort *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 442 of file Serializer.inl.

References ALIGN_NONE, align_w(), alignment(), good_bit(), and write_array().

00443 {
00444   this->alignment() == Serializer::ALIGN_NONE ? 0 : this->align_w(sizeof(ACE_CDR::UShort));
00445   this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::UShort), length);
00446   return this->good_bit();
00447 }

ACE_INLINE bool OpenDDS::DCPS::Serializer::write_wchar_array ( const ACE_CDR::WChar *  x,
ACE_CDR::ULong  length 
)

Note: the portion written starts at x and ends at x + length. The length is *NOT* stored into the CDR stream.

Definition at line 416 of file Serializer.inl.

References good_bit().

00417 {
00418   for (ACE_CDR::ULong i = 0; i < length; ++i) {
00419     if (!((*this) << ACE_OutputCDR::from_wchar(x[i]))) {
00420       break;
00421     }
00422   }
00423   return this->good_bit();
00424 }


Friends And Related Function Documentation

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_OutputCDR::from_wstring  x 
) [friend]

Definition at line 767 of file Serializer.inl.

00768 {
00769   s << x.val_;
00770   const ACE_CDR::ULong stringlen =
00771     x.bound_ ? static_cast<ACE_CDR::ULong>(ACE_OS::strlen(x.val_)) : 0;
00772   return s.good_bit() && ((x.bound_ == 0) || (stringlen <= x.bound_));
00773 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_OutputCDR::from_string  x 
) [friend]

Definition at line 749 of file Serializer.inl.

00750 {
00751   // Include the null termination in the serialized data.
00752   ACE_CDR::ULong stringlen = 0;
00753 
00754   if (x.val_ != 0) {
00755     stringlen = 1 + static_cast<ACE_CDR::ULong>(ACE_OS::strlen(x.val_));
00756     s << stringlen;
00757     s.buffer_write(reinterpret_cast<char*>(x.val_), stringlen, false);
00758 
00759   } else {
00760     s << ACE_CDR::ULong(0);
00761   }
00762 
00763   return s.good_bit() && ((x.bound_ == 0) || (stringlen - 1 <= x.bound_));
00764 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_OutputCDR::from_octet  x 
) [friend]

Definition at line 742 of file Serializer.inl.

00743 {
00744   s.buffer_write(reinterpret_cast<char*>(&x.val_), sizeof(ACE_CDR::Octet), false);
00745   return s.good_bit();
00746 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_OutputCDR::from_wchar  x 
) [friend]

Definition at line 723 of file Serializer.inl.

00724 {
00725   // CDR wchar format: 1 octet for # of bytes in wchar, followed by those bytes
00726   static const ACE_CDR::Octet wchar_bytes = Serializer::WCHAR_SIZE;
00727   s.buffer_write(reinterpret_cast<const char*>(&wchar_bytes), 1, false);
00728 #if ACE_SIZEOF_WCHAR == 2
00729   s.buffer_write(reinterpret_cast<char*>(&x.val_), Serializer::WCHAR_SIZE, Serializer::SWAP_BE);
00730 #else
00731   const ACE_UINT16 as_utf16 = static_cast<ACE_UINT16>(x.val_);
00732   if (as_utf16 != x.val_) { // not currently handling surrogates
00733     s.good_bit_ = false;
00734   } else {
00735     s.buffer_write(reinterpret_cast<const char*>(&as_utf16), Serializer::WCHAR_SIZE, Serializer::SWAP_BE);
00736   }
00737 #endif
00738   return s.good_bit();
00739 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_OutputCDR::from_char  x 
) [friend]

Definition at line 716 of file Serializer.inl.

00717 {
00718   s.buffer_write(reinterpret_cast<char*>(&x.val_), sizeof(ACE_CDR::Char), false);
00719   return s.good_bit();
00720 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_OutputCDR::from_boolean  x 
) [friend]

Definition at line 709 of file Serializer.inl.

00710 {
00711   s.buffer_write(reinterpret_cast<char*>(&x.val_), sizeof(ACE_CDR::Boolean), s.swap_bytes());
00712   return s.good_bit();
00713 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
const ACE_CDR::WChar *  x 
) [friend]

Definition at line 680 of file Serializer.inl.

00681 {
00682   //NOTE: Serializing wchar/wstring uses UTF-16BE
00683   if (x != 0) {
00684     // Do not include the null terminatator in the serialized data.
00685     const ACE_CDR::ULong length = static_cast<ACE_CDR::ULong>(ACE_OS::strlen(x));
00686     s << ACE_CDR::ULong(length * Serializer::WCHAR_SIZE);
00687 
00688 #if ACE_SIZEOF_WCHAR == 2
00689     s.write_array(reinterpret_cast<const char*>(x), Serializer::WCHAR_SIZE,
00690                   length, Serializer::SWAP_BE);
00691 #else
00692     for (size_t i = 0; i < length && s.good_bit(); ++i) {
00693       const ACE_UINT16 as_utf16 = static_cast<ACE_UINT16>(x[i]);
00694       if (as_utf16 != x[i]) { // not currently handling surrogates
00695         s.good_bit_ = false;
00696         break;
00697       }
00698       s.buffer_write(reinterpret_cast<const char*>(&as_utf16), Serializer::WCHAR_SIZE, Serializer::SWAP_BE);
00699     }
00700 #endif
00701   } else {
00702     s << ACE_CDR::ULong(0);
00703   }
00704 
00705   return s.good_bit();
00706 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
const ACE_CDR::Char *  x 
) [friend]

Definition at line 663 of file Serializer.inl.

00664 {
00665   if (x != 0) {
00666     // Include the null termination in the serialized data.
00667     const ACE_CDR::ULong stringlen =
00668       1 + static_cast<ACE_CDR::ULong>(ACE_OS::strlen(x));
00669     s << stringlen;
00670     s.buffer_write(reinterpret_cast<const char*>(x), stringlen, false);
00671 
00672   } else {
00673     s << ACE_CDR::ULong(0);
00674   }
00675 
00676   return s.good_bit();
00677 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::Double  x 
) [friend]

Definition at line 655 of file Serializer.inl.

00656 {
00657   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(sizeof(ACE_CDR::Double));
00658   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Double), s.swap_bytes());
00659   return s.good_bit();
00660 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::Float  x 
) [friend]

Definition at line 647 of file Serializer.inl.

00648 {
00649   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(sizeof(ACE_CDR::Float));
00650   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Float), s.swap_bytes());
00651   return s.good_bit();
00652 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::LongDouble  x 
) [friend]

Definition at line 639 of file Serializer.inl.

00640 {
00641   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(8);
00642   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::LongDouble), s.swap_bytes());
00643   return s.good_bit();
00644 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::ULongLong  x 
) [friend]

Definition at line 631 of file Serializer.inl.

00632 {
00633   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(sizeof(ACE_CDR::ULongLong));
00634   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::ULongLong), s.swap_bytes());
00635   return s.good_bit();
00636 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::LongLong  x 
) [friend]

Definition at line 623 of file Serializer.inl.

00624 {
00625   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(sizeof(ACE_CDR::LongLong));
00626   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::LongLong), s.swap_bytes());
00627   return s.good_bit();
00628 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::ULong  x 
) [friend]

Definition at line 615 of file Serializer.inl.

00616 {
00617   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(sizeof(ACE_CDR::ULong));
00618   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::ULong), s.swap_bytes());
00619   return s.good_bit();
00620 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::Long  x 
) [friend]

Definition at line 607 of file Serializer.inl.

00608 {
00609   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(sizeof(ACE_CDR::Long));
00610   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Long), s.swap_bytes());
00611   return s.good_bit();
00612 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::UShort  x 
) [friend]

Definition at line 599 of file Serializer.inl.

00600 {
00601   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(sizeof(ACE_CDR::UShort));
00602   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::UShort), s.swap_bytes());
00603   return s.good_bit();
00604 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::Short  x 
) [friend]

Definition at line 591 of file Serializer.inl.

00592 {
00593   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_w(sizeof(ACE_CDR::Short));
00594   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Short), s.swap_bytes());
00595   return s.good_bit();
00596 }

OpenDDS_Dcps_Export bool operator<< ( Serializer s,
ACE_CDR::Char  x 
) [friend]

Definition at line 584 of file Serializer.inl.

00585 {
00586   s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Char), s.swap_bytes());
00587   return s.good_bit();
00588 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_InputCDR::to_wstring  x 
) [friend]

Definition at line 925 of file Serializer.inl.

00926 {
00927   s.read_string(const_cast<ACE_CDR::WChar*&>(x.val_));
00928   return s.good_bit()
00929          && ((x.bound_ == 0) || (ACE_OS::strlen(x.val_) <= x.bound_));
00930 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_InputCDR::to_string  x 
) [friend]

Definition at line 917 of file Serializer.inl.

00918 {
00919   s.read_string(const_cast<char*&>(x.val_));
00920   return s.good_bit()
00921          && ((x.bound_ == 0) || (ACE_OS::strlen(x.val_) <= x.bound_));
00922 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_InputCDR::to_octet  x 
) [friend]

Definition at line 910 of file Serializer.inl.

00911 {
00912   s.buffer_read(reinterpret_cast<char*>(&x.ref_), sizeof(ACE_CDR::Octet), false);
00913   return s.good_bit();
00914 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_InputCDR::to_wchar  x 
) [friend]

Definition at line 891 of file Serializer.inl.

00892 {
00893   ACE_CDR::Octet len;
00894   s.buffer_read(reinterpret_cast<char*>(&len), 1, false);
00895   if (len != Serializer::WCHAR_SIZE) {
00896     s.good_bit_ = false;
00897   } else {
00898 #if ACE_SIZEOF_WCHAR == 2
00899     s.buffer_read(reinterpret_cast<char*>(&x.ref_), Serializer::WCHAR_SIZE, Serializer::SWAP_BE);
00900 #else
00901     ACE_UINT16 as_utf16;
00902     s.buffer_read(reinterpret_cast<char*>(&as_utf16), Serializer::WCHAR_SIZE, Serializer::SWAP_BE);
00903     x.ref_ = as_utf16;
00904 #endif
00905   }
00906   return s.good_bit();
00907 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_InputCDR::to_char  x 
) [friend]

Definition at line 884 of file Serializer.inl.

00885 {
00886   s.buffer_read(reinterpret_cast<char*>(&x.ref_), sizeof(ACE_CDR::Char), s.swap_bytes());
00887   return s.good_bit();
00888 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_InputCDR::to_boolean  x 
) [friend]

Definition at line 877 of file Serializer.inl.

00878 {
00879   s.buffer_read(reinterpret_cast<char*>(&x.ref_), sizeof(ACE_CDR::Boolean), s.swap_bytes());
00880   return s.good_bit();
00881 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::WChar *&  x 
) [friend]

Definition at line 870 of file Serializer.inl.

00871 {
00872   s.read_string(x);
00873   return s.good_bit();
00874 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::Char *&  x 
) [friend]

Definition at line 863 of file Serializer.inl.

00864 {
00865   s.read_string(x);
00866   return s.good_bit();
00867 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::Double &  x 
) [friend]

Definition at line 855 of file Serializer.inl.

00856 {
00857   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(sizeof(ACE_CDR::Double));
00858   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Double), s.swap_bytes());
00859   return s.good_bit();
00860 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::Float &  x 
) [friend]

Definition at line 847 of file Serializer.inl.

00848 {
00849   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(sizeof(ACE_CDR::Float));
00850   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Float), s.swap_bytes());
00851   return s.good_bit();
00852 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::LongDouble &  x 
) [friend]

Definition at line 839 of file Serializer.inl.

00840 {
00841   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(8);
00842   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::LongDouble), s.swap_bytes());
00843   return s.good_bit();
00844 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::ULongLong &  x 
) [friend]

Definition at line 831 of file Serializer.inl.

00832 {
00833   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(sizeof(ACE_CDR::ULongLong));
00834   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::ULongLong), s.swap_bytes());
00835   return s.good_bit();
00836 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::LongLong &  x 
) [friend]

Definition at line 823 of file Serializer.inl.

00824 {
00825   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(sizeof(ACE_CDR::LongLong));
00826   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::LongLong), s.swap_bytes());
00827   return s.good_bit();
00828 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::ULong &  x 
) [friend]

Definition at line 815 of file Serializer.inl.

00816 {
00817   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(sizeof(ACE_CDR::ULong));
00818   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::ULong), s.swap_bytes());
00819   return s.good_bit();
00820 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::Long &  x 
) [friend]

Definition at line 807 of file Serializer.inl.

00808 {
00809   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(sizeof(ACE_CDR::Long));
00810   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Long), s.swap_bytes());
00811   return s.good_bit();
00812 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::UShort &  x 
) [friend]

Definition at line 799 of file Serializer.inl.

00800 {
00801   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(sizeof(ACE_CDR::UShort));
00802   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::UShort), s.swap_bytes());
00803   return s.good_bit();
00804 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::Short &  x 
) [friend]

Definition at line 791 of file Serializer.inl.

00792 {
00793   s.alignment() == Serializer::ALIGN_NONE ? 0 : s.align_r(sizeof(ACE_CDR::Short));
00794   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Short), s.swap_bytes());
00795   return s.good_bit();
00796 }

OpenDDS_Dcps_Export bool operator>> ( Serializer s,
ACE_CDR::Char &  x 
) [friend]

Definition at line 784 of file Serializer.inl.

00785 {
00786   s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Char), s.swap_bytes());
00787   return s.good_bit();
00788 }


Member Data Documentation

const char OpenDDS::DCPS::Serializer::ALIGN_PAD = {0} [static, private]

Definition at line 299 of file Serializer.h.

Referenced by align_w().

unsigned char OpenDDS::DCPS::Serializer::align_rshift_ [private]

Number of bytes off of max alignment (8) that the current_ block's rd_ptr() started at.

Definition at line 292 of file Serializer.h.

Referenced by align_cont_r(), and reset_alignment().

unsigned char OpenDDS::DCPS::Serializer::align_wshift_ [private]

Number of bytes off of max alignment (8) that the current_ block's wr_ptr() started at.

Definition at line 296 of file Serializer.h.

Referenced by align_cont_w(), and reset_alignment().

Alignment OpenDDS::DCPS::Serializer::alignment_ [private]

Current alignment mode, see Alignment enum above.

Definition at line 288 of file Serializer.h.

Referenced by alignment(), and read_string().

ACE_Message_Block* OpenDDS::DCPS::Serializer::current_ [private]

Currently active message block in chain.

Definition at line 279 of file Serializer.h.

Referenced by align_cont_r(), align_cont_w(), align_w(), doread(), dowrite(), read_string(), reset_alignment(), and skip().

bool OpenDDS::DCPS::Serializer::good_bit_ [private]

Indicates the current state of the stream abstraction.

Definition at line 285 of file Serializer.h.

Referenced by align_w(), doread(), dowrite(), good_bit(), OpenDDS::DCPS::operator<<(), OpenDDS::DCPS::operator>>(), read_string(), and swapcpy().

const size_t OpenDDS::DCPS::Serializer::MAX_ALIGN = 8 [static, private]

Definition at line 298 of file Serializer.h.

Referenced by align_cont_r(), align_cont_w(), reset_alignment(), and skip().

const bool OpenDDS::DCPS::Serializer::SWAP_BE = false [static]

Definition at line 311 of file Serializer.h.

Referenced by OpenDDS::DCPS::operator<<(), OpenDDS::DCPS::operator>>(), and read_string().

bool OpenDDS::DCPS::Serializer::swap_bytes_ [private]

Indicates whether bytes will be swapped for this stream.

Definition at line 282 of file Serializer.h.

Referenced by swap_bytes().

bool OpenDDS::DCPS::Serializer::use_rti_serialization_ [static, private]

Definition at line 300 of file Serializer.h.

Referenced by set_use_rti_serialization(), and use_rti_serialization().

const size_t OpenDDS::DCPS::Serializer::WCHAR_SIZE = 2 [static]

Definition at line 303 of file Serializer.h.

Referenced by OpenDDS::DCPS::gen_max_marshaled_size(), OpenDDS::DCPS::max_marshaled_size_wchar(), OpenDDS::DCPS::operator<<(), OpenDDS::DCPS::operator>>(), and read_string().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:24 2016 for OpenDDS by  doxygen 1.4.7