00001
00002
00003
00004
00005
00006
00007
00008 #include <ace/Message_Block.h>
00009 #include <ace/CDR_Stream.h>
00010 #include "Serializer.h"
00011
00012 namespace OpenDDS {
00013 namespace DCPS {
00014
00015
00016
00017
00018 ACE_INLINE size_t
00019 Serializer::doread(char* dest, size_t size, bool swap, size_t offset)
00020 {
00021
00022
00023
00024 if (this->current_ == 0) {
00025 this->good_bit_ = false;
00026 return size;
00027 }
00028
00029
00030
00031
00032
00033 const size_t len = this->current_->length();
00034 register size_t remainder = (size - offset > len) ? size - offset - len : 0;
00035
00036
00037
00038
00039 register size_t initial = size - offset - remainder;
00040
00041
00042
00043
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
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
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
00087
00088 return offset + initial;
00089 }
00090
00091 ACE_INLINE void
00092 Serializer::buffer_read(char* dest, size_t size, bool swap)
00093 {
00094 register size_t offset = 0;
00095
00096 while (size > offset) {
00097 offset = this->doread(dest, size, swap, offset);
00098 }
00099 }
00100
00101
00102
00103
00104 ACE_INLINE size_t
00105 Serializer::dowrite(const char* src, size_t size, bool swap, size_t offset)
00106 {
00107
00108
00109
00110 if (this->current_ == 0) {
00111 this->good_bit_ = false;
00112 return size;
00113 }
00114
00115
00116
00117
00118
00119 const size_t spc = this->current_->space();
00120 register size_t remainder = (size - offset > spc) ? size - offset - spc : 0;
00121
00122
00123
00124
00125 register size_t initial = size - offset - remainder;
00126
00127
00128
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
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
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
00173
00174 return offset + initial;
00175 }
00176
00177 ACE_INLINE void
00178 Serializer::buffer_write(const char* src, size_t size, bool swap)
00179 {
00180 register size_t offset = 0;
00181
00182 while (size > offset) {
00183 offset = this->dowrite(src, size, swap, offset);
00184 }
00185 }
00186
00187 ACE_INLINE void
00188 Serializer::swap_bytes(bool do_swap)
00189 {
00190 this->swap_bytes_ = do_swap;
00191 }
00192
00193 ACE_INLINE bool
00194 Serializer::swap_bytes() const
00195 {
00196 return this->swap_bytes_;
00197 }
00198
00199 ACE_INLINE Serializer::Alignment
00200 Serializer::alignment() const
00201 {
00202 return this->alignment_;
00203 }
00204
00205 ACE_INLINE bool
00206 Serializer::good_bit() const
00207 {
00208 return this->good_bit_;
00209 }
00210
00211 ACE_INLINE bool
00212 Serializer::skip(ACE_CDR::UShort n, int size)
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 }
00234
00235 ACE_INLINE void
00236 Serializer::read_array(char* x, size_t size, ACE_CDR::ULong length)
00237 {
00238 this->read_array(x, size, length, this->swap_bytes_);
00239 }
00240
00241 ACE_INLINE void
00242 Serializer::read_array(char* x, size_t size,
00243 ACE_CDR::ULong length, bool swap)
00244 {
00245 if (!swap || size == 1) {
00246
00247
00248
00249
00250 this->buffer_read(x, size * length, false);
00251
00252 } else {
00253
00254
00255
00256
00257
00258 while (length-- > 0) {
00259 this->buffer_read(x, size, true);
00260 x += size;
00261 }
00262 }
00263 }
00264
00265 ACE_INLINE void
00266 Serializer::write_array(const char* x, size_t size, ACE_CDR::ULong length)
00267 {
00268 this->write_array(x, size, length, this->swap_bytes_);
00269 }
00270
00271 ACE_INLINE void
00272 Serializer::write_array(const char* x, size_t size,
00273 ACE_CDR::ULong length, bool swap)
00274 {
00275 if (!swap || size == 1) {
00276
00277
00278
00279 this->buffer_write(x, size * length, false);
00280
00281 } else {
00282
00283
00284
00285
00286
00287
00288
00289 while (length-- > 0) {
00290 this->buffer_write(x, size, true);
00291 x += size;
00292 }
00293 }
00294 }
00295
00296 ACE_INLINE bool
00297 Serializer::read_boolean_array(ACE_CDR::Boolean* x, ACE_CDR::ULong length)
00298 {
00299 this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Boolean), length);
00300 return this->good_bit();
00301 }
00302
00303 ACE_INLINE bool
00304 Serializer::read_char_array(ACE_CDR::Char* x, ACE_CDR::ULong length)
00305 {
00306 this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Char), length);
00307 return this->good_bit();
00308 }
00309
00310 ACE_INLINE bool
00311 Serializer::read_wchar_array(ACE_CDR::WChar* x, ACE_CDR::ULong length)
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 }
00320
00321 ACE_INLINE bool
00322 Serializer::read_octet_array(ACE_CDR::Octet* x, ACE_CDR::ULong length)
00323 {
00324 this->read_array(reinterpret_cast<char*>(x), sizeof(ACE_CDR::Octet), length);
00325 return this->good_bit();
00326 }
00327
00328 ACE_INLINE bool
00329 Serializer::read_short_array(ACE_CDR::Short* x, ACE_CDR::ULong length)
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 }
00335
00336 ACE_INLINE bool
00337 Serializer::read_ushort_array(ACE_CDR::UShort* x, ACE_CDR::ULong length)
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 }
00343
00344 ACE_INLINE bool
00345 Serializer::read_long_array(ACE_CDR::Long* x, ACE_CDR::ULong length)
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 }
00351
00352 ACE_INLINE bool
00353 Serializer::read_ulong_array(ACE_CDR::ULong* x, ACE_CDR::ULong length)
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 }
00359
00360 ACE_INLINE bool
00361 Serializer::read_longlong_array(ACE_CDR::LongLong* x, ACE_CDR::ULong length)
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 }
00367
00368 ACE_INLINE bool
00369 Serializer::read_ulonglong_array(ACE_CDR::ULongLong* x, ACE_CDR::ULong length)
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 }
00375
00376 ACE_INLINE bool
00377 Serializer::read_float_array(ACE_CDR::Float* x, ACE_CDR::ULong length)
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 }
00383
00384 ACE_INLINE bool
00385 Serializer::read_double_array(ACE_CDR::Double* x, ACE_CDR::ULong length)
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 }
00391
00392 ACE_INLINE bool
00393 Serializer::read_longdouble_array(ACE_CDR::LongDouble* x, ACE_CDR::ULong length)
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 }
00399
00400 ACE_INLINE bool
00401 Serializer::write_boolean_array(const ACE_CDR::Boolean* x,
00402 ACE_CDR::ULong length)
00403 {
00404 this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Boolean), length);
00405 return this->good_bit();
00406 }
00407
00408 ACE_INLINE bool
00409 Serializer::write_char_array(const ACE_CDR::Char* x, ACE_CDR::ULong length)
00410 {
00411 this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Char), length);
00412 return this->good_bit();
00413 }
00414
00415 ACE_INLINE bool
00416 Serializer::write_wchar_array(const ACE_CDR::WChar* x, ACE_CDR::ULong length)
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 }
00425
00426 ACE_INLINE bool
00427 Serializer::write_octet_array(const ACE_CDR::Octet* x, ACE_CDR::ULong length)
00428 {
00429 this->write_array(reinterpret_cast<const char*>(x), sizeof(ACE_CDR::Octet), length);
00430 return this->good_bit();
00431 }
00432
00433 ACE_INLINE bool
00434 Serializer::write_short_array(const ACE_CDR::Short* x, ACE_CDR::ULong length)
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 }
00440
00441 ACE_INLINE bool
00442 Serializer::write_ushort_array(const ACE_CDR::UShort* x, ACE_CDR::ULong length)
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 }
00448
00449 ACE_INLINE bool
00450 Serializer::write_long_array(const ACE_CDR::Long* x, ACE_CDR::ULong length)
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 }
00456
00457 ACE_INLINE bool
00458 Serializer::write_ulong_array(const ACE_CDR::ULong* x, ACE_CDR::ULong length)
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 }
00464
00465 ACE_INLINE bool
00466 Serializer::write_longlong_array(const ACE_CDR::LongLong* x,
00467 ACE_CDR::ULong length)
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 }
00473
00474 ACE_INLINE bool
00475 Serializer::write_ulonglong_array(const ACE_CDR::ULongLong* x,
00476 ACE_CDR::ULong length)
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 }
00482
00483 ACE_INLINE bool
00484 Serializer::write_float_array(const ACE_CDR::Float* x, ACE_CDR::ULong length)
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 }
00490
00491 ACE_INLINE bool
00492 Serializer::write_double_array(const ACE_CDR::Double* x, ACE_CDR::ULong length)
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 }
00498
00499 ACE_INLINE bool
00500 Serializer::write_longdouble_array(const ACE_CDR::LongDouble* x,
00501 ACE_CDR::ULong length)
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 }
00507
00508 ACE_INLINE int
00509 Serializer::align_r(size_t al)
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 }
00516
00517 ACE_INLINE int
00518 Serializer::align_w(size_t al)
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 }
00545
00546
00547 ACE_INLINE void
00548 Serializer::align_cont_r()
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 }
00560
00561 ACE_INLINE void
00562 Serializer::align_cont_w()
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 }
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583 ACE_INLINE bool
00584 operator<<(Serializer& s, ACE_CDR::Char x)
00585 {
00586 s.buffer_write(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Char), s.swap_bytes());
00587 return s.good_bit();
00588 }
00589
00590 ACE_INLINE bool
00591 operator<<(Serializer& s, ACE_CDR::Short x)
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 }
00597
00598 ACE_INLINE bool
00599 operator<<(Serializer& s, ACE_CDR::UShort x)
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 }
00605
00606 ACE_INLINE bool
00607 operator<<(Serializer& s, ACE_CDR::Long x)
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 }
00613
00614 ACE_INLINE bool
00615 operator<<(Serializer& s, ACE_CDR::ULong x)
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 }
00621
00622 ACE_INLINE bool
00623 operator<<(Serializer& s, ACE_CDR::LongLong x)
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 }
00629
00630 ACE_INLINE bool
00631 operator<<(Serializer& s, ACE_CDR::ULongLong x)
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 }
00637
00638 ACE_INLINE bool
00639 operator<<(Serializer& s, ACE_CDR::LongDouble x)
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 }
00645
00646 ACE_INLINE bool
00647 operator<<(Serializer& s, ACE_CDR::Float x)
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 }
00653
00654 ACE_INLINE bool
00655 operator<<(Serializer& s, ACE_CDR::Double x)
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 }
00661
00662 ACE_INLINE bool
00663 operator<<(Serializer& s, const ACE_CDR::Char* x)
00664 {
00665 if (x != 0) {
00666
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 }
00678
00679 ACE_INLINE bool
00680 operator<<(Serializer& s, const ACE_CDR::WChar* x)
00681 {
00682
00683 if (x != 0) {
00684
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]) {
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 }
00707
00708 ACE_INLINE bool
00709 operator<<(Serializer& s, ACE_OutputCDR::from_boolean x)
00710 {
00711 s.buffer_write(reinterpret_cast<char*>(&x.val_), sizeof(ACE_CDR::Boolean), s.swap_bytes());
00712 return s.good_bit();
00713 }
00714
00715 ACE_INLINE bool
00716 operator<<(Serializer& s, ACE_OutputCDR::from_char x)
00717 {
00718 s.buffer_write(reinterpret_cast<char*>(&x.val_), sizeof(ACE_CDR::Char), false);
00719 return s.good_bit();
00720 }
00721
00722 ACE_INLINE bool
00723 operator<<(Serializer& s, ACE_OutputCDR::from_wchar x)
00724 {
00725
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_) {
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 }
00740
00741 ACE_INLINE bool
00742 operator<<(Serializer& s, ACE_OutputCDR::from_octet x)
00743 {
00744 s.buffer_write(reinterpret_cast<char*>(&x.val_), sizeof(ACE_CDR::Octet), false);
00745 return s.good_bit();
00746 }
00747
00748 ACE_INLINE bool
00749 operator<<(Serializer& s, ACE_OutputCDR::from_string x)
00750 {
00751
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 }
00765
00766 ACE_INLINE bool
00767 operator<<(Serializer& s, ACE_OutputCDR::from_wstring x)
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 }
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783 ACE_INLINE bool
00784 operator>>(Serializer& s, ACE_CDR::Char& x)
00785 {
00786 s.buffer_read(reinterpret_cast<char*>(&x), sizeof(ACE_CDR::Char), s.swap_bytes());
00787 return s.good_bit();
00788 }
00789
00790 ACE_INLINE bool
00791 operator>>(Serializer& s, ACE_CDR::Short& x)
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 }
00797
00798 ACE_INLINE bool
00799 operator>>(Serializer& s, ACE_CDR::UShort& x)
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 }
00805
00806 ACE_INLINE bool
00807 operator>>(Serializer& s, ACE_CDR::Long& x)
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 }
00813
00814 ACE_INLINE bool
00815 operator>>(Serializer& s, ACE_CDR::ULong& x)
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 }
00821
00822 ACE_INLINE bool
00823 operator>>(Serializer& s, ACE_CDR::LongLong& x)
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 }
00829
00830 ACE_INLINE bool
00831 operator>>(Serializer& s, ACE_CDR::ULongLong& x)
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 }
00837
00838 ACE_INLINE bool
00839 operator>>(Serializer& s, ACE_CDR::LongDouble& x)
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 }
00845
00846 ACE_INLINE bool
00847 operator>>(Serializer& s, ACE_CDR::Float& x)
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 }
00853
00854 ACE_INLINE bool
00855 operator>>(Serializer& s, ACE_CDR::Double& x)
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 }
00861
00862 ACE_INLINE bool
00863 operator>>(Serializer& s, ACE_CDR::Char*& x)
00864 {
00865 s.read_string(x);
00866 return s.good_bit();
00867 }
00868
00869 ACE_INLINE bool
00870 operator>>(Serializer& s, ACE_CDR::WChar*& x)
00871 {
00872 s.read_string(x);
00873 return s.good_bit();
00874 }
00875
00876 ACE_INLINE bool
00877 operator>>(Serializer& s, ACE_InputCDR::to_boolean x)
00878 {
00879 s.buffer_read(reinterpret_cast<char*>(&x.ref_), sizeof(ACE_CDR::Boolean), s.swap_bytes());
00880 return s.good_bit();
00881 }
00882
00883 ACE_INLINE bool
00884 operator>>(Serializer& s, ACE_InputCDR::to_char x)
00885 {
00886 s.buffer_read(reinterpret_cast<char*>(&x.ref_), sizeof(ACE_CDR::Char), s.swap_bytes());
00887 return s.good_bit();
00888 }
00889
00890 ACE_INLINE bool
00891 operator>>(Serializer& s, ACE_InputCDR::to_wchar x)
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 }
00908
00909 ACE_INLINE bool
00910 operator>>(Serializer& s, ACE_InputCDR::to_octet x)
00911 {
00912 s.buffer_read(reinterpret_cast<char*>(&x.ref_), sizeof(ACE_CDR::Octet), false);
00913 return s.good_bit();
00914 }
00915
00916 ACE_INLINE bool
00917 operator>>(Serializer& s, ACE_InputCDR::to_string x)
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 }
00923
00924 ACE_INLINE bool
00925 operator>>(Serializer& s, ACE_InputCDR::to_wstring x)
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 }
00931
00932
00933
00934 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::Short& )
00935 {
00936 return sizeof(ACE_CDR::Short);
00937 }
00938
00939 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::UShort& )
00940 {
00941 return sizeof(ACE_CDR::UShort);
00942 }
00943
00944 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::Long& )
00945 {
00946 return sizeof(ACE_CDR::Long);
00947 }
00948
00949 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::ULong& )
00950 {
00951 return sizeof(ACE_CDR::ULong);
00952 }
00953
00954 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::LongLong& )
00955 {
00956 return sizeof(ACE_CDR::LongLong);
00957 }
00958
00959 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::ULongLong& )
00960 {
00961 return sizeof(ACE_CDR::ULongLong);
00962 }
00963
00964 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::LongDouble& )
00965 {
00966 return sizeof(ACE_CDR::LongDouble);
00967 }
00968
00969 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::Float& )
00970 {
00971 return sizeof(ACE_CDR::Float);
00972 }
00973
00974 ACE_INLINE size_t gen_max_marshaled_size(const ACE_CDR::Double& )
00975 {
00976 return sizeof(ACE_CDR::Double);
00977 }
00978
00979
00980 ACE_INLINE size_t gen_max_marshaled_size(const ACE_OutputCDR::from_boolean )
00981 {
00982 return sizeof(ACE_CDR::Char);
00983 }
00984
00985 ACE_INLINE size_t gen_max_marshaled_size(const ACE_OutputCDR::from_char )
00986 {
00987 return sizeof(ACE_CDR::Char);
00988 }
00989
00990 ACE_INLINE size_t gen_max_marshaled_size(const ACE_OutputCDR::from_wchar )
00991 {
00992 return Serializer::WCHAR_SIZE + 1;
00993 }
00994
00995 ACE_INLINE size_t gen_max_marshaled_size(const ACE_OutputCDR::from_octet )
00996 {
00997 return sizeof(ACE_CDR::Char);
00998 }
00999
01000
01001 ACE_INLINE size_t max_marshaled_size_boolean()
01002 {
01003 return sizeof(ACE_CDR::Char);
01004 }
01005
01006 ACE_INLINE size_t max_marshaled_size_char()
01007 {
01008 return sizeof(ACE_CDR::Char);
01009 }
01010
01011 ACE_INLINE size_t max_marshaled_size_wchar()
01012 {
01013 return Serializer::WCHAR_SIZE + 1;
01014 }
01015
01016 ACE_INLINE size_t max_marshaled_size_octet()
01017 {
01018 return sizeof(ACE_CDR::Char);
01019 }
01020
01021 ACE_INLINE size_t max_marshaled_size_ulong()
01022 {
01023 return sizeof(ACE_CDR::ULong);
01024 }
01025
01026 ACE_INLINE void find_size_ulong(size_t& size, size_t& padding)
01027 {
01028 const size_t sz = sizeof(ACE_CDR::ULong);
01029 if ((size + padding) % sz) {
01030 padding += sz - ((size + padding) % sz);
01031 }
01032 size += sz;
01033 }
01034
01035 }
01036 }