1 #include "ace/CDR_Stream.h"
2 #include "ace/SString.h"
3 #include "ace/Truncate.h"
6 #if !defined (__ACE_INLINE__)
7 # include "ace/CDR_Stream.inl"
8 #endif /* ! __ACE_INLINE__ */
10 // ****************************************************************
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 size_t ACE_OutputCDR::wchar_maxbytes_
= sizeof (ACE_CDR::WChar
);
16 ACE_OutputCDR::ACE_OutputCDR (size_t size
,
18 ACE_Allocator
*buffer_allocator
,
19 ACE_Allocator
*data_block_allocator
,
20 ACE_Allocator
*message_block_allocator
,
21 size_t memcpy_tradeoff
,
22 ACE_CDR::Octet major_version
,
23 ACE_CDR::Octet minor_version
)
24 : start_ ((size
? size
: (size_t) ACE_CDR::DEFAULT_BUFSIZE
) + ACE_CDR::MAX_ALIGNMENT
,
25 ACE_Message_Block::MB_DATA
,
32 ACE_Time_Value::max_time
,
34 message_block_allocator
),
35 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
36 current_alignment_ (0),
37 #endif /* ACE_LACKS_CDR_ALIGNMENT */
38 current_is_writable_ (true),
39 do_byte_swap_ (byte_order
!= ACE_CDR_BYTE_ORDER
),
41 memcpy_tradeoff_ (memcpy_tradeoff
),
42 major_version_ (major_version
),
43 minor_version_ (minor_version
),
48 ACE_CDR::mb_align (&this->start_
);
49 this->current_
= &this->start_
;
51 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
52 ACE_NEW (this->monitor_
,
53 ACE::Monitor_Control::Size_Monitor
);
54 this->monitor_
->receive (this->total_length ());
55 #endif /* ACE_HAS_MONITOR_POINTS==1 */
58 ACE_OutputCDR::ACE_OutputCDR (char *data
,
61 ACE_Allocator
*buffer_allocator
,
62 ACE_Allocator
*data_block_allocator
,
63 ACE_Allocator
*message_block_allocator
,
64 size_t memcpy_tradeoff
,
65 ACE_CDR::Octet major_version
,
66 ACE_CDR::Octet minor_version
)
68 ACE_Message_Block::MB_DATA
,
75 ACE_Time_Value::max_time
,
77 message_block_allocator
),
78 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
79 current_alignment_ (0),
80 #endif /* ACE_LACKS_CDR_ALIGNMENT */
81 current_is_writable_ (true),
82 do_byte_swap_ (byte_order
!= ACE_CDR_BYTE_ORDER
),
84 memcpy_tradeoff_ (memcpy_tradeoff
),
85 major_version_ (major_version
),
86 minor_version_ (minor_version
),
90 // We cannot trust the buffer to be properly aligned
91 ACE_CDR::mb_align (&this->start_
);
92 this->current_
= &this->start_
;
94 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
95 ACE_NEW (this->monitor_
,
96 ACE::Monitor_Control::Size_Monitor
);
97 this->monitor_
->receive (this->total_length ());
98 #endif /* ACE_HAS_MONITOR_POINTS==1 */
101 ACE_OutputCDR::ACE_OutputCDR (ACE_Data_Block
*data_block
,
103 ACE_Allocator
*message_block_allocator
,
104 size_t memcpy_tradeoff
,
105 ACE_CDR::Octet major_version
,
106 ACE_CDR::Octet minor_version
)
107 : start_ (data_block
,
108 ACE_Message_Block::DONT_DELETE
,
109 message_block_allocator
),
110 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
111 current_alignment_ (0),
112 #endif /* ACE_LACKS_CDR_ALIGNMENT */
113 current_is_writable_ (true),
114 do_byte_swap_ (byte_order
!= ACE_CDR_BYTE_ORDER
),
116 memcpy_tradeoff_ (memcpy_tradeoff
),
117 major_version_ (major_version
),
118 minor_version_ (minor_version
),
119 char_translator_ (0),
120 wchar_translator_ (0)
122 // We cannot trust the buffer to be properly aligned
123 ACE_CDR::mb_align (&this->start_
);
124 this->current_
= &this->start_
;
126 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
127 ACE_NEW (this->monitor_
,
128 ACE::Monitor_Control::Size_Monitor
);
129 this->monitor_
->receive (this->total_length ());
130 #endif /* ACE_HAS_MONITOR_POINTS==1 */
133 ACE_OutputCDR::ACE_OutputCDR (ACE_Message_Block
*data
,
135 size_t memcpy_tradeoff
,
136 ACE_CDR::Octet major_version
,
137 ACE_CDR::Octet minor_version
)
138 : start_ (data
->data_block ()->duplicate ()),
139 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
140 current_alignment_ (0),
141 #endif /* ACE_LACKS_CDR_ALIGNMENT */
142 current_is_writable_ (true),
143 do_byte_swap_ (byte_order
!= ACE_CDR_BYTE_ORDER
),
145 memcpy_tradeoff_ (memcpy_tradeoff
),
146 major_version_ (major_version
),
147 minor_version_ (minor_version
),
148 char_translator_ (0),
149 wchar_translator_ (0)
151 // We cannot trust the buffer to be properly aligned
152 ACE_CDR::mb_align (&this->start_
);
153 this->current_
= &this->start_
;
155 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
156 ACE_NEW (this->monitor_
,
157 ACE::Monitor_Control::Size_Monitor
);
158 this->monitor_
->receive (this->total_length ());
159 #endif /* ACE_HAS_MONITOR_POINTS==1 */
163 ACE_OutputCDR::wchar_maxbytes (size_t maxbytes
)
165 ACE_OutputCDR::wchar_maxbytes_
= maxbytes
;
169 ACE_OutputCDR::wchar_maxbytes ()
171 return ACE_OutputCDR::wchar_maxbytes_
;
175 ACE_OutputCDR::grow_and_adjust (size_t size
,
179 if (!this->current_is_writable_
180 || this->current_
->cont () == 0
181 || this->current_
->cont ()->size () < size
+ ACE_CDR::MAX_ALIGNMENT
)
183 // Calculate the new buffer's length; if growing for encode, we
184 // don't grow in "small" chunks because of the cost.
185 size_t cursize
= this->current_
->size ();
186 if (this->current_
->cont () != 0)
187 cursize
= this->current_
->cont ()->size ();
188 size_t minsize
= size
;
190 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
191 minsize
+= ACE_CDR::MAX_ALIGNMENT
;
192 #endif /* ACE_LACKS_CDR_ALIGNMENT */
194 // Make sure that there is enough room for <minsize> bytes, but
195 // also make it bigger than whatever our current size is.
196 if (minsize
< cursize
)
199 size_t const newsize
= ACE_CDR::next_size (minsize
);
201 this->good_bit_
= false;
202 ACE_Message_Block
* tmp
= 0;
204 ACE_Message_Block (newsize
,
205 ACE_Message_Block::MB_DATA
,
208 this->current_
->data_block ()->allocator_strategy (),
211 ACE_Time_Value::zero
,
212 ACE_Time_Value::max_time
,
213 this->current_
->data_block ()->data_block_allocator ()),
216 // Message block initialization may fail while the construction
217 // succeds. Since as a matter of policy, ACE may throw no
218 // exceptions, we have to do a separate check like this.
219 if (tmp
!= 0 && tmp
->size () < newsize
)
226 this->good_bit_
= true;
228 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
229 // The new block must start with the same alignment as the
230 // previous block finished.
231 ptrdiff_t const tmpalign
=
232 reinterpret_cast<ptrdiff_t> (tmp
->rd_ptr ()) % ACE_CDR::MAX_ALIGNMENT
;
233 ptrdiff_t const curalign
=
234 static_cast<ptrdiff_t> (this->current_alignment_
) % ACE_CDR::MAX_ALIGNMENT
;
235 ptrdiff_t offset
= curalign
- tmpalign
;
237 offset
+= ACE_CDR::MAX_ALIGNMENT
;
238 tmp
->rd_ptr (static_cast<size_t> (offset
));
239 tmp
->wr_ptr (tmp
->rd_ptr ());
240 #endif /* ACE_LACKS_CDR_ALIGNMENT */
242 // grow the chain and set the current block.
243 tmp
->cont (this->current_
->cont ());
244 this->current_
->cont (tmp
);
246 this->current_
= this->current_
->cont ();
247 this->current_is_writable_
= true;
249 return this->adjust (size
, align
, buf
);
253 ACE_OutputCDR::write_wchar (ACE_CDR::WChar x
)
255 if (this->wchar_translator_
!= 0)
256 return (this->good_bit_
= this->wchar_translator_
->write_wchar (*this, x
));
257 if (ACE_OutputCDR::wchar_maxbytes_
== 0)
260 return (this->good_bit_
= false);
262 if (static_cast<ACE_CDR::Short
> (major_version_
) == 1
263 && static_cast<ACE_CDR::Short
> (minor_version_
) == 2)
266 static_cast<ACE_CDR::Octet
> (ACE_OutputCDR::wchar_maxbytes_
);
267 if (this->write_1 (&len
))
269 if (ACE_OutputCDR::wchar_maxbytes_
== sizeof(ACE_CDR::WChar
))
271 this->write_octet_array (
272 reinterpret_cast<const ACE_CDR::Octet
*> (&x
),
273 static_cast<ACE_CDR::ULong
> (len
));
275 if (ACE_OutputCDR::wchar_maxbytes_
== 2)
277 ACE_CDR::Short sx
= static_cast<ACE_CDR::Short
> (x
);
279 this->write_octet_array (
280 reinterpret_cast<const ACE_CDR::Octet
*> (&sx
),
281 static_cast<ACE_CDR::ULong
> (len
));
285 ACE_CDR::Octet ox
= static_cast<ACE_CDR::Octet
> (x
);
287 this->write_octet_array (
288 reinterpret_cast<const ACE_CDR::Octet
*> (&ox
),
289 static_cast<ACE_CDR::ULong
> (len
));
293 else if (static_cast<ACE_CDR::Short
> (minor_version_
) == 0)
294 { // wchar is not allowed with GIOP 1.0.
296 return (this->good_bit_
= false);
298 if (ACE_OutputCDR::wchar_maxbytes_
== sizeof (ACE_CDR::WChar
))
300 void const * const temp
= &x
;
302 this->write_4 (reinterpret_cast<const ACE_CDR::ULong
*> (temp
));
304 else if (ACE_OutputCDR::wchar_maxbytes_
== 2)
306 ACE_CDR::Short sx
= static_cast<ACE_CDR::Short
> (x
);
307 return this->write_2 (reinterpret_cast<const ACE_CDR::UShort
*> (&sx
));
309 ACE_CDR::Octet ox
= static_cast<ACE_CDR::Octet
> (x
);
310 return this->write_1 (reinterpret_cast<const ACE_CDR::Octet
*> (&ox
));
314 ACE_OutputCDR::write_string (ACE_CDR::ULong len
,
315 const ACE_CDR::Char
*x
)
317 // @@ This is a slight violation of "Optimize for the common case",
318 // i.e. normally the translator will be 0, but OTOH the code is
319 // smaller and should be better for the cache ;-) ;-)
320 if (this->char_translator_
!= 0)
321 return this->char_translator_
->write_string (*this, len
, x
);
325 if (this->write_ulong (len
+ 1))
326 return this->write_char_array (x
, len
+ 1);
330 // Be nice to programmers: treat nulls as empty strings not
331 // errors. (OMG-IDL supports languages that don't use the C/C++
332 // notion of null v. empty strings; nulls aren't part of the OMG-IDL
334 if (this->write_ulong (1))
335 return this->write_char (0);
338 return (this->good_bit_
= false);
342 ACE_OutputCDR::write_string (const ACE_CString
&x
)
344 // @@ Leave this method in here, not the `.i' file so that we don't
345 // have to unnecessarily pull in the `ace/SString.h' header.
346 return this->write_string (static_cast<ACE_CDR::ULong
> (x
.length ()),
351 ACE_OutputCDR::write_wstring (ACE_CDR::ULong len
,
352 const ACE_CDR::WChar
*x
)
354 // @@ This is a slight violation of "Optimize for the common case",
355 // i.e. normally the translator will be 0, but OTOH the code is
356 // smaller and should be better for the cache ;-) ;-)
357 // What do we do for GIOP 1.2???
358 if (this->wchar_translator_
!= 0)
359 return this->wchar_translator_
->write_wstring (*this, len
, x
);
360 if (ACE_OutputCDR::wchar_maxbytes_
== 0)
363 return (this->good_bit_
= false);
366 if (static_cast<ACE_CDR::Short
> (this->major_version_
) == 1
367 && static_cast<ACE_CDR::Short
> (this->minor_version_
) == 2)
371 //In GIOP 1.2 the length field contains the number of bytes
372 //the wstring occupies rather than number of wchars
373 //Taking sizeof might not be a good way! This is a temporary fix.
374 ACE_CDR::Boolean good_ulong
=
376 ACE_Utils::truncate_cast
<ACE_CDR::ULong
> (
377 ACE_OutputCDR::wchar_maxbytes_
* len
));
381 return this->write_wchar_array (x
, len
);
386 //In GIOP 1.2 zero length wstrings are legal
387 return this->write_ulong (0);
394 if (this->write_ulong (len
+ 1))
395 return this->write_wchar_array (x
, len
+ 1);
397 else if (this->write_ulong (1))
398 return this->write_wchar (0);
399 return (this->good_bit_
= false);
403 ACE_OutputCDR::write_octet_array_mb (const ACE_Message_Block
* mb
)
405 // If the buffer is small and it fits in the current message
406 // block it is be cheaper just to copy the buffer.
407 for (const ACE_Message_Block
* i
= mb
;
411 size_t const length
= i
->length ();
413 // If the mb does not own its data we are forced to make a copy.
414 if (ACE_BIT_ENABLED (i
->flags (),
415 ACE_Message_Block::DONT_DELETE
))
417 if (! this->write_array (i
->rd_ptr (),
419 ACE_CDR::OCTET_ALIGN
,
420 static_cast<ACE_CDR::ULong
> (length
)))
421 return (this->good_bit_
= false);
425 if (length
< this->memcpy_tradeoff_
426 && this->current_
->wr_ptr () + length
< this->current_
->end ())
428 if (! this->write_array (i
->rd_ptr (),
430 ACE_CDR::OCTET_ALIGN
,
431 static_cast<ACE_CDR::ULong
> (length
)))
432 return (this->good_bit_
= false);
436 ACE_Message_Block
* cont
= 0;
437 this->good_bit_
= false;
438 ACE_NEW_RETURN (cont
,
439 ACE_Message_Block (i
->data_block ()->duplicate ()),
441 this->good_bit_
= true;
443 if (this->current_
->cont () != 0)
444 ACE_Message_Block::release (this->current_
->cont ());
445 cont
->rd_ptr (i
->rd_ptr ());
446 cont
->wr_ptr (i
->wr_ptr ());
448 this->current_
->cont (cont
);
449 this->current_
= cont
;
450 this->current_is_writable_
= false;
451 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
452 this->current_alignment_
=
453 (this->current_alignment_
+ cont
->length ()) % ACE_CDR::MAX_ALIGNMENT
;
454 #endif /* ACE_LACKS_CDR_ALIGNMENT */
461 ACE_OutputCDR::write_1 (const ACE_CDR::Octet
*x
)
464 if (this->adjust (1, buf
) == 0)
466 *reinterpret_cast<ACE_CDR::Octet
*> (buf
) = *x
;
474 ACE_OutputCDR::write_2 (const ACE_CDR::UShort
*x
)
477 if (this->adjust (ACE_CDR::SHORT_SIZE
, buf
) == 0)
479 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
480 *reinterpret_cast<ACE_CDR::UShort
*> (buf
) = *x
;
483 if (!this->do_byte_swap_
)
485 *reinterpret_cast<ACE_CDR::UShort
*> (buf
) = *x
;
490 ACE_CDR::swap_2 (reinterpret_cast<const char*> (x
), buf
);
493 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
500 ACE_OutputCDR::write_4 (const ACE_CDR::ULong
*x
)
503 if (this->adjust (ACE_CDR::LONG_SIZE
, buf
) == 0)
505 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
506 *reinterpret_cast<ACE_CDR::ULong
*> (buf
) = *x
;
509 if (!this->do_byte_swap_
)
511 *reinterpret_cast<ACE_CDR::ULong
*> (buf
) = *x
;
516 ACE_CDR::swap_4 (reinterpret_cast<const char*> (x
), buf
);
519 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
526 ACE_OutputCDR::write_8 (const ACE_CDR::ULongLong
*x
)
530 if (this->adjust (ACE_CDR::LONGLONG_SIZE
, buf
) == 0)
532 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
533 *reinterpret_cast<ACE_CDR::ULongLong
*> (buf
) = *x
;
536 if (!this->do_byte_swap_
)
538 *reinterpret_cast<ACE_CDR::ULongLong
*> (buf
) = *x
;
543 ACE_CDR::swap_8 (reinterpret_cast<const char*> (x
), buf
);
546 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
553 ACE_OutputCDR::write_16 (const ACE_CDR::LongDouble
*x
)
556 if (this->adjust (ACE_CDR::LONGDOUBLE_SIZE
,
557 ACE_CDR::LONGDOUBLE_ALIGN
,
560 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
561 *reinterpret_cast<ACE_CDR::LongDouble
*> (buf
) = *x
;
564 if (!this->do_byte_swap_
)
566 *reinterpret_cast<ACE_CDR::LongDouble
*> (buf
) = *x
;
571 ACE_CDR::swap_16 (reinterpret_cast<const char*> (x
), buf
);
574 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
581 ACE_OutputCDR::write_wchar_array_i (const ACE_CDR::WChar
*x
,
582 ACE_CDR::ULong length
)
587 size_t const align
= (ACE_OutputCDR::wchar_maxbytes_
== 2) ?
588 ACE_CDR::SHORT_ALIGN
:
589 ACE_CDR::OCTET_ALIGN
;
591 if (this->adjust (ACE_OutputCDR::wchar_maxbytes_
* length
, align
, buf
) == 0)
593 if (ACE_OutputCDR::wchar_maxbytes_
== 2)
595 ACE_CDR::UShort
*sb
= reinterpret_cast<ACE_CDR::UShort
*> (buf
);
596 for (size_t i
= 0; i
< length
; ++i
)
597 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
598 sb
[i
] = static_cast<ACE_CDR::UShort
> (x
[i
]);
600 if (!this->do_byte_swap_
)
601 sb
[i
] = static_cast<ACE_CDR::UShort
> (x
[i
]);
604 ACE_CDR::UShort sx
= static_cast<ACE_CDR::UShort
> (x
[i
]);
605 ACE_CDR::swap_2 (reinterpret_cast<char *> (&sx
), &buf
[i
* 2]);
607 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
611 for (size_t i
= 0; i
< length
; ++i
)
612 buf
[i
] = static_cast<char> (x
[i
]);
614 return this->good_bit_
;
621 ACE_OutputCDR::write_array (const void *x
,
624 ACE_CDR::ULong length
)
629 if (this->adjust (size
* length
, align
, buf
) == 0)
631 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
632 ACE_OS::memcpy (buf
, x
, size
*length
);
635 if (!this->do_byte_swap_
|| size
== 1)
637 ACE_OS::memcpy (buf
, x
, size
*length
);
642 const char *source
= reinterpret_cast<const char *> (x
);
646 ACE_CDR::swap_2_array (source
, buf
, length
);
649 ACE_CDR::swap_4_array (source
, buf
, length
);
652 ACE_CDR::swap_8_array (source
, buf
, length
);
655 ACE_CDR::swap_16_array (source
, buf
, length
);
658 // TODO: print something?
659 this->good_bit_
= false;
663 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
665 this->good_bit_
= false;
671 ACE_OutputCDR::write_boolean_array (const ACE_CDR::Boolean
* x
,
672 ACE_CDR::ULong length
)
674 // It is hard to optimize this, the spec requires that on the wire
675 // booleans be represented as a byte with value 0 or 1, but in
676 // memory it is possible (though very unlikely) that a boolean has
677 // a non-zero value (different from 1).
678 // We resort to a simple loop.
679 ACE_CDR::Boolean
const * const end
= x
+ length
;
681 for (ACE_CDR::Boolean
const * i
= x
;
682 i
!= end
&& this->good_bit ();
684 (void) this->write_boolean (*i
);
686 return this->good_bit ();
690 ACE_OutputCDR::write_long_placeholder ()
693 if (this->adjust (ACE_CDR::LONG_SIZE
, buf
) == 0)
694 *reinterpret_cast<ACE_CDR::ULong
*> (buf
) = 0;
701 ACE_OutputCDR::write_short_placeholder ()
704 if (this->adjust (ACE_CDR::SHORT_SIZE
, buf
) == 0)
705 *reinterpret_cast<ACE_CDR::UShort
*> (buf
) = 0;
712 ACE_OutputCDR::write_boolean_placeholder ()
715 if (this->adjust (ACE_CDR::OCTET_SIZE
, buf
) == 0)
716 *reinterpret_cast<ACE_CDR::Boolean
*> (buf
) = 0;
723 ACE_OutputCDR::write_char_placeholder ()
726 if (this->adjust (ACE_CDR::OCTET_SIZE
, buf
) == 0)
727 *reinterpret_cast<ACE_CDR::Char
*> (buf
) = 0;
734 ACE_OutputCDR::write_octet_placeholder ()
737 if (this->adjust (ACE_CDR::OCTET_SIZE
, buf
) == 0)
738 *reinterpret_cast<ACE_CDR::Octet
*> (buf
) = 0;
745 ACE_OutputCDR::write_longlong_placeholder ()
748 if (this->adjust (ACE_CDR::LONGLONG_SIZE
, buf
) == 0)
749 *reinterpret_cast<ACE_CDR::ULongLong
*> (buf
) = 0;
756 ACE_OutputCDR::write_float_placeholder ()
759 if (this->adjust (ACE_CDR::LONG_SIZE
, buf
) == 0)
760 *reinterpret_cast<ACE_CDR::ULong
*> (buf
) = 0;
767 ACE_OutputCDR::write_double_placeholder ()
770 if (this->adjust (ACE_CDR::LONGLONG_SIZE
, buf
) == 0)
771 *reinterpret_cast<ACE_CDR::ULongLong
*> (buf
) = 0;
778 ACE_OutputCDR::replace (ACE_CDR::Long x
, char* loc
)
780 if (this->find (loc
) == 0)
783 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
784 *reinterpret_cast<ACE_CDR::Long
*> (loc
) = x
;
786 if (!this->do_byte_swap_
)
788 *reinterpret_cast<ACE_CDR::Long
*> (loc
) = x
;
792 ACE_CDR::swap_4 (reinterpret_cast<const char*> (&x
), loc
);
794 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
800 ACE_OutputCDR::replace (ACE_CDR::ULong x
, char* loc
)
802 if (this->find (loc
) == 0)
805 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
806 *reinterpret_cast<ACE_CDR::ULong
*> (loc
) = x
;
808 if (!this->do_byte_swap_
)
810 *reinterpret_cast<ACE_CDR::ULong
*> (loc
) = x
;
814 ACE_CDR::swap_4 (reinterpret_cast<const char*> (&x
), loc
);
816 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
822 ACE_OutputCDR::replace (ACE_CDR::Short x
, char* loc
)
824 if (this->find (loc
) == 0)
827 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
828 *reinterpret_cast<ACE_CDR::Short
*> (loc
) = x
;
830 if (!this->do_byte_swap_
)
832 *reinterpret_cast<ACE_CDR::Short
*> (loc
) = x
;
836 ACE_CDR::swap_2 (reinterpret_cast<const char*> (&x
), loc
);
838 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
844 ACE_OutputCDR::replace (ACE_CDR::UShort x
, char* loc
)
846 if (this->find (loc
) == 0)
849 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
850 *reinterpret_cast<ACE_CDR::UShort
*> (loc
) = x
;
852 if (!this->do_byte_swap_
)
854 *reinterpret_cast<ACE_CDR::UShort
*> (loc
) = x
;
858 ACE_CDR::swap_2 (reinterpret_cast<const char*> (&x
), loc
);
860 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
866 ACE_OutputCDR::replace (ACE_CDR::Boolean x
, char* loc
)
868 if (this->find (loc
) == 0)
871 *reinterpret_cast<ACE_CDR::Boolean
*> (loc
) = x
;
877 ACE_OutputCDR::replace (ACE_CDR::Char x
, char* loc
)
879 if (this->find (loc
) == 0)
882 *reinterpret_cast<ACE_CDR::Char
*> (loc
) = x
;
888 ACE_OutputCDR::replace (ACE_CDR::Octet x
, char* loc
)
890 if (this->find (loc
) == 0)
893 *reinterpret_cast<ACE_CDR::Octet
*> (loc
) = x
;
899 ACE_OutputCDR::replace (ACE_CDR::LongLong x
, char* loc
)
901 if (this->find (loc
) == 0)
904 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
905 *reinterpret_cast<ACE_CDR::LongLong
*> (loc
) = x
;
907 if (!this->do_byte_swap_
)
909 *reinterpret_cast<ACE_CDR::LongLong
*> (loc
) = x
;
913 ACE_CDR::swap_8 (reinterpret_cast<const char*> (&x
), loc
);
915 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
921 ACE_OutputCDR::replace (ACE_CDR::ULongLong x
, char* loc
)
923 if (this->find (loc
) == 0)
926 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
927 *reinterpret_cast<ACE_CDR::ULongLong
*> (loc
) = x
;
929 if (!this->do_byte_swap_
)
931 *reinterpret_cast<ACE_CDR::ULongLong
*> (loc
) = x
;
935 ACE_CDR::swap_8 (reinterpret_cast<const char*> (&x
), loc
);
937 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
943 ACE_OutputCDR::replace (ACE_CDR::Float x
, char* loc
)
945 if (this->find (loc
) == 0)
948 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
949 *reinterpret_cast<ACE_CDR::Float
*> (loc
) = x
;
951 if (!this->do_byte_swap_
)
953 *reinterpret_cast<ACE_CDR::Float
*> (loc
) = x
;
957 ACE_CDR::swap_4 (reinterpret_cast<const char*> (&x
), loc
);
959 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
965 ACE_OutputCDR::replace (ACE_CDR::Double x
, char* loc
)
967 if (this->find (loc
) == 0)
970 #if !defined (ACE_ENABLE_SWAP_ON_WRITE)
971 *reinterpret_cast<ACE_CDR::Double
*> (loc
) = x
;
973 if (!this->do_byte_swap_
)
975 *reinterpret_cast<ACE_CDR::Double
*> (loc
) = x
;
979 ACE_CDR::swap_8 (reinterpret_cast<const char*> (&x
), loc
);
981 #endif /* ACE_ENABLE_SWAP_ON_WRITE */
987 ACE_OutputCDR::consolidate ()
989 // Optimize by only doing something if we need to
990 if (this->current_
!= &this->start_
)
992 // Set the number of bytes in the top-level block, reallocating
993 // if necessary. The rd_ptr and wr_ptr remain at the original offsets
994 // into the buffer, even if it is reallocated.
995 // Return an error if the allocation failed.
996 size_t const newsize
=
997 ACE_CDR::first_size (this->total_length ()
998 + ACE_CDR::MAX_ALIGNMENT
);
999 if (this->start_
.size (newsize
) < 0)
1004 // Consolidate the chain into the first block. NOTE that
1005 // ACE_CDR::consolidate can not be used since we don't want to
1006 // overwrite what is already in the first block. We just append it since
1007 // the read and write pointers weren't affected by the resizing above.
1008 // We also don't have to worry about alignment since the start block is
1010 // NOTE also we know there is a continuation since we checked for it
1011 // above. There is therefore no reason to check for a 0 continuation
1013 ACE_Message_Block
*cont
= this->start_
.cont ();
1014 for (const ACE_Message_Block
* i
= cont
; i
!= 0; i
= i
->cont ())
1016 this->start_
.copy (i
->rd_ptr (), i
->length ());
1019 // Release the old blocks that were consolidated and reset the
1020 // current_ and current_is_writable_ to reflect the single used block.
1021 ACE_Message_Block::release (cont
);
1022 this->start_
.cont (0);
1023 this->current_
= &this->start_
;
1024 this->current_is_writable_
= true;
1032 ACE_OutputCDR::find (char* loc
)
1034 ACE_Message_Block
* mb
= 0;
1035 for (mb
= &this->start_
; mb
!= 0; mb
= mb
->cont ())
1037 if (loc
<= mb
->wr_ptr () && loc
>= mb
->rd_ptr ())
1046 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1049 ACE_OutputCDR::register_monitor (const char *id
)
1051 this->monitor_
->name (id
);
1052 this->monitor_
->add_to_registry ();
1056 ACE_OutputCDR::unregister_monitor ()
1058 this->monitor_
->remove_from_registry ();
1061 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1063 // ****************************************************************
1065 ACE_InputCDR::ACE_InputCDR (const char *buf
,
1068 ACE_CDR::Octet major_version
,
1069 ACE_CDR::Octet minor_version
)
1070 : start_ (buf
, bufsiz
),
1071 do_byte_swap_ (byte_order
!= ACE_CDR_BYTE_ORDER
),
1073 major_version_ (major_version
),
1074 minor_version_ (minor_version
),
1075 char_translator_ (0),
1076 wchar_translator_ (0)
1078 this->start_
.wr_ptr (bufsiz
);
1080 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1081 ACE_NEW (this->monitor_
,
1082 ACE::Monitor_Control::Size_Monitor
);
1083 this->monitor_
->receive (bufsiz
);
1084 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1087 ACE_InputCDR::ACE_InputCDR (size_t bufsiz
,
1089 ACE_CDR::Octet major_version
,
1090 ACE_CDR::Octet minor_version
)
1092 do_byte_swap_ (byte_order
!= ACE_CDR_BYTE_ORDER
),
1094 major_version_ (major_version
),
1095 minor_version_ (minor_version
),
1096 char_translator_ (0),
1097 wchar_translator_ (0)
1099 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1100 ACE_NEW (this->monitor_
,
1101 ACE::Monitor_Control::Size_Monitor
);
1102 this->monitor_
->receive (bufsiz
);
1103 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1106 ACE_InputCDR::ACE_InputCDR (const ACE_Message_Block
*data
,
1108 ACE_CDR::Octet major_version
,
1109 ACE_CDR::Octet minor_version
,
1111 : start_ (0, ACE_Message_Block::MB_DATA
, 0, 0, 0, lock
),
1113 major_version_ (major_version
),
1114 minor_version_ (minor_version
),
1115 char_translator_ (0),
1116 wchar_translator_ (0)
1118 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1119 ACE_NEW (this->monitor_
,
1120 ACE::Monitor_Control::Size_Monitor
);
1121 this->monitor_
->receive (this->start_
.total_size ());
1122 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1124 this->reset (data
, byte_order
);
1127 ACE_InputCDR::ACE_InputCDR (ACE_Data_Block
*data
,
1128 ACE_Message_Block::Message_Flags flag
,
1130 ACE_CDR::Octet major_version
,
1131 ACE_CDR::Octet minor_version
)
1132 : start_ (data
, flag
),
1133 do_byte_swap_ (byte_order
!= ACE_CDR_BYTE_ORDER
),
1135 major_version_ (major_version
),
1136 minor_version_ (minor_version
),
1137 char_translator_ (0),
1138 wchar_translator_ (0)
1140 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1141 ACE_NEW (this->monitor_
,
1142 ACE::Monitor_Control::Size_Monitor
);
1143 this->monitor_
->receive (data
->size ());
1144 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1147 ACE_InputCDR::ACE_InputCDR (ACE_Data_Block
*data
,
1148 ACE_Message_Block::Message_Flags flag
,
1152 ACE_CDR::Octet major_version
,
1153 ACE_CDR::Octet minor_version
)
1154 : start_ (data
, flag
),
1155 do_byte_swap_ (byte_order
!= ACE_CDR_BYTE_ORDER
),
1157 major_version_ (major_version
),
1158 minor_version_ (minor_version
),
1159 char_translator_ (0),
1160 wchar_translator_ (0)
1162 // Set the read pointer
1163 this->start_
.rd_ptr (rd_pos
);
1165 // Set the write pointer after doing a sanity check.
1166 char* wrpos
= this->start_
.base () + wr_pos
;
1168 if (this->start_
.end () >= wrpos
)
1170 this->start_
.wr_ptr (wr_pos
);
1173 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1174 ACE_NEW (this->monitor_
,
1175 ACE::Monitor_Control::Size_Monitor
);
1176 this->monitor_
->receive (data
->size ());
1177 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1180 ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR
& rhs
,
1182 ACE_CDR::Long offset
)
1183 : start_ (rhs
.start_
,
1184 ACE_CDR::MAX_ALIGNMENT
),
1185 do_byte_swap_ (rhs
.do_byte_swap_
),
1187 major_version_ (rhs
.major_version_
),
1188 minor_version_ (rhs
.minor_version_
),
1189 char_translator_ (rhs
.char_translator_
),
1190 wchar_translator_ (rhs
.wchar_translator_
)
1192 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
1193 // Align the base pointer assuming that the incoming stream is also
1194 // aligned the way we are aligned
1195 char *incoming_start
= ACE_ptr_align_binary (rhs
.start_
.base (),
1196 ACE_CDR::MAX_ALIGNMENT
);
1198 char *incoming_start
= rhs
.start_
.base ();
1199 #endif /* ACE_LACKS_CDR_ALIGNMENT */
1201 const size_t newpos
=
1202 (rhs
.start_
.rd_ptr() - incoming_start
) + offset
;
1204 if (newpos
<= this->start_
.space ()
1205 && newpos
+ size
<= this->start_
.space ())
1207 this->start_
.rd_ptr (newpos
);
1208 this->start_
.wr_ptr (newpos
+ size
);
1212 this->good_bit_
= false;
1215 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1216 ACE_NEW (this->monitor_
,
1217 ACE::Monitor_Control::Size_Monitor
);
1218 this->monitor_
->receive (this->start_
.total_size ());
1219 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1222 ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR
& rhs
,
1224 : start_ (rhs
.start_
,
1225 ACE_CDR::MAX_ALIGNMENT
),
1226 do_byte_swap_ (rhs
.do_byte_swap_
),
1228 major_version_ (rhs
.major_version_
),
1229 minor_version_ (rhs
.minor_version_
),
1230 char_translator_ (rhs
.char_translator_
),
1231 wchar_translator_ (rhs
.wchar_translator_
)
1233 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
1234 // Align the base pointer assuming that the incoming stream is also
1235 // aligned the way we are aligned
1236 char *incoming_start
= ACE_ptr_align_binary (rhs
.start_
.base (),
1237 ACE_CDR::MAX_ALIGNMENT
);
1239 char *incoming_start
= rhs
.start_
.base ();
1240 #endif /* ACE_LACKS_CDR_ALIGNMENT */
1242 const size_t newpos
=
1243 rhs
.start_
.rd_ptr() - incoming_start
;
1245 if (newpos
<= this->start_
.space ()
1246 && newpos
+ size
<= this->start_
.space ())
1248 // Notice that ACE_Message_Block::duplicate may leave the
1249 // wr_ptr() with a higher value than what we actually want.
1250 this->start_
.rd_ptr (newpos
);
1251 this->start_
.wr_ptr (newpos
+ size
);
1253 ACE_CDR::Octet byte_order
= 0;
1254 (void) this->read_octet (byte_order
);
1255 this->do_byte_swap_
= (byte_order
!= ACE_CDR_BYTE_ORDER
);
1259 this->good_bit_
= false;
1262 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1263 ACE_NEW (this->monitor_
,
1264 ACE::Monitor_Control::Size_Monitor
);
1265 this->monitor_
->receive (this->start_
.total_size ());
1266 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1269 ACE_InputCDR::ACE_InputCDR (const ACE_InputCDR
& rhs
)
1270 : start_ (rhs
.start_
,
1271 ACE_CDR::MAX_ALIGNMENT
),
1272 do_byte_swap_ (rhs
.do_byte_swap_
),
1274 major_version_ (rhs
.major_version_
),
1275 minor_version_ (rhs
.minor_version_
),
1276 char_translator_ (rhs
.char_translator_
),
1277 wchar_translator_ (rhs
.wchar_translator_
)
1279 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
1280 char *buf
= ACE_ptr_align_binary (rhs
.start_
.base (),
1281 ACE_CDR::MAX_ALIGNMENT
);
1283 char *buf
= rhs
.start_
.base ();
1284 #endif /* ACE_LACKS_CDR_ALIGNMENT */
1286 size_t rd_offset
= rhs
.start_
.rd_ptr () - buf
;
1287 size_t wr_offset
= rhs
.start_
.wr_ptr () - buf
;
1288 this->start_
.rd_ptr (rd_offset
);
1289 this->start_
.wr_ptr (wr_offset
);
1291 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1292 ACE_NEW (this->monitor_
,
1293 ACE::Monitor_Control::Size_Monitor
);
1294 this->monitor_
->receive (this->start_
.total_size ());
1295 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1298 ACE_InputCDR::ACE_InputCDR (ACE_InputCDR::Transfer_Contents x
)
1299 : start_ (x
.rhs_
.start_
.data_block ()),
1300 do_byte_swap_ (x
.rhs_
.do_byte_swap_
),
1302 major_version_ (x
.rhs_
.major_version_
),
1303 minor_version_ (x
.rhs_
.minor_version_
),
1304 char_translator_ (x
.rhs_
.char_translator_
),
1305 wchar_translator_ (x
.rhs_
.wchar_translator_
)
1307 this->start_
.rd_ptr (x
.rhs_
.start_
.rd_ptr ());
1308 this->start_
.wr_ptr (x
.rhs_
.start_
.wr_ptr ());
1310 ACE_Data_Block
* db
= this->start_
.data_block ()->clone_nocopy ();
1311 (void) x
.rhs_
.start_
.replace_data_block (db
);
1313 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1314 ACE_NEW (this->monitor_
,
1315 ACE::Monitor_Control::Size_Monitor
);
1316 this->monitor_
->receive (this->start_
.total_size ());
1317 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1321 ACE_InputCDR::operator= (const ACE_InputCDR
& rhs
)
1325 this->start_
.data_block (rhs
.start_
.data_block ()->duplicate ());
1326 this->start_
.rd_ptr (rhs
.start_
.rd_ptr ());
1327 this->start_
.wr_ptr (rhs
.start_
.wr_ptr ());
1328 this->do_byte_swap_
= rhs
.do_byte_swap_
;
1329 this->good_bit_
= true;
1330 this->char_translator_
= rhs
.char_translator_
;
1331 this->major_version_
= rhs
.major_version_
;
1332 this->minor_version_
= rhs
.minor_version_
;
1335 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1336 this->monitor_
->receive (this->start_
.total_size ());
1337 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1342 ACE_InputCDR::ACE_InputCDR (const ACE_OutputCDR
& rhs
,
1343 ACE_Allocator
* buffer_allocator
,
1344 ACE_Allocator
* data_block_allocator
,
1345 ACE_Allocator
* message_block_allocator
)
1346 : start_ (rhs
.total_length () + ACE_CDR::MAX_ALIGNMENT
,
1347 ACE_Message_Block::MB_DATA
,
1353 ACE_Time_Value::zero
,
1354 ACE_Time_Value::max_time
,
1355 data_block_allocator
,
1356 message_block_allocator
),
1357 do_byte_swap_ (rhs
.do_byte_swap_
),
1359 major_version_ (rhs
.major_version_
),
1360 minor_version_ (rhs
.minor_version_
),
1361 char_translator_ (rhs
.char_translator_
),
1362 wchar_translator_ (rhs
.wchar_translator_
)
1364 ACE_CDR::mb_align (&this->start_
);
1365 for (const ACE_Message_Block
*i
= rhs
.begin ();
1369 this->start_
.copy (i
->rd_ptr (), i
->length ());
1372 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1373 ACE_NEW (this->monitor_
,
1374 ACE::Monitor_Control::Size_Monitor
);
1375 this->monitor_
->receive (this->start_
.total_size ());
1376 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1380 ACE_InputCDR::skip_wchar ()
1382 if (static_cast<ACE_CDR::Short
> (major_version_
) == 1
1383 && static_cast<ACE_CDR::Short
> (minor_version_
) == 2)
1386 if (this->read_1 (&len
))
1387 return this->skip_bytes (static_cast<size_t> (len
));
1392 void * const temp
= &x
;
1393 if (ACE_OutputCDR::wchar_maxbytes_
== 2)
1394 return this->read_2 (reinterpret_cast<ACE_CDR::UShort
*> (temp
));
1396 return this->read_4 (reinterpret_cast<ACE_CDR::ULong
*> (temp
));
1399 return (this->good_bit_
= false);
1403 ACE_InputCDR::read_wchar (ACE_CDR::WChar
& x
)
1405 if (this->wchar_translator_
!= 0)
1407 this->good_bit_
= this->wchar_translator_
->read_wchar (*this,x
);
1408 return this->good_bit_
;
1410 if (ACE_OutputCDR::wchar_maxbytes_
== 0)
1413 return (this->good_bit_
= false);
1416 if (ACE_OutputCDR::wchar_maxbytes_
== sizeof (ACE_CDR::WChar
))
1418 if (static_cast<ACE_CDR::Short
> (major_version_
) == 1
1419 && static_cast<ACE_CDR::Short
> (minor_version_
) == 2)
1423 if (this->read_1 (&len
))
1424 return this->read_array
1425 (reinterpret_cast<ACE_CDR::Octet
*> (&x
),
1426 static_cast<ACE_CDR::ULong
> (len
),
1427 ACE_CDR::OCTET_ALIGN
,
1431 return (this->good_bit_
= false);
1434 void * const temp
= &x
;
1435 if (sizeof (ACE_CDR::WChar
) == 2)
1436 return this->read_2 (reinterpret_cast<ACE_CDR::UShort
*> (temp
));
1438 return this->read_4 (reinterpret_cast<ACE_CDR::ULong
*> (temp
));
1441 if (static_cast<ACE_CDR::Short
> (major_version_
) == 1
1442 && static_cast<ACE_CDR::Short
> (minor_version_
) == 2)
1446 if (this->read_1 (&len
))
1451 if (this->read_array
1452 (reinterpret_cast<ACE_CDR::Octet
*> (&sx
),
1453 static_cast<ACE_CDR::ULong
> (len
),
1454 ACE_CDR::OCTET_ALIGN
,
1457 x
= static_cast<ACE_CDR::WChar
> (sx
);
1464 if (this->read_array
1465 (reinterpret_cast<ACE_CDR::Octet
*> (&ox
),
1466 static_cast<ACE_CDR::ULong
> (len
),
1467 ACE_CDR::OCTET_ALIGN
,
1470 x
= static_cast<ACE_CDR::WChar
> (ox
);
1478 if (ACE_OutputCDR::wchar_maxbytes_
== 2)
1481 if (this->read_2 (reinterpret_cast<ACE_CDR::UShort
*> (&sx
)))
1483 x
= static_cast<ACE_CDR::WChar
> (sx
);
1490 if (this->read_1 (&ox
))
1492 x
= static_cast<ACE_CDR::WChar
> (ox
);
1498 return (this->good_bit_
= false);
1502 ACE_InputCDR::read_string (ACE_CDR::Char
*&x
)
1504 // @@ This is a slight violation of "Optimize for the common case",
1505 // i.e. normally the translator will be 0, but OTOH the code is
1506 // smaller and should be better for the cache ;-) ;-)
1507 if (this->char_translator_
!= 0)
1509 this->good_bit_
= this->char_translator_
->read_string (*this, x
);
1510 return this->good_bit_
;
1513 ACE_CDR::ULong len
= 0;
1515 if (!this->read_ulong (len
))
1518 // A check for the length being too great is done later in the
1519 // call to read_char_array but we want to have it done before
1520 // the memory is allocated.
1521 if (len
> 0 && len
<= this->length())
1523 #if defined (ACE_HAS_ALLOC_HOOKS)
1524 ACE_ALLOCATOR_RETURN (x
,
1525 static_cast<ACE_CDR::Char
*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::Char
) * (len
))),
1531 #endif /* ACE_HAS_ALLOC_HOOKS */
1533 std::unique_ptr
<ACE_CDR::Char
[]> safe_data (x
);
1535 if (this->read_char_array (x
, len
))
1537 (void) safe_data
.release ();
1543 // Convert any null strings to empty strings since empty
1544 // strings can cause crashes. (See bug 58.)
1545 #if defined (ACE_HAS_ALLOC_HOOKS)
1546 ACE_ALLOCATOR_RETURN (x
,
1547 static_cast<ACE_CDR::Char
*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::Char
) * (1))),
1553 #endif /* ACE_HAS_ALLOC_HOOKS */
1555 ACE_OS::strcpy (const_cast<char *&> (x
), "");
1560 return (this->good_bit_
= false);
1564 ACE_InputCDR::read_string (ACE_CString
&x
)
1566 ACE_CDR::Char
* data
= nullptr;
1567 if (this->read_string (data
))
1569 std::unique_ptr
<ACE_CDR::Char
[]> safe_data (data
);
1575 return (this->good_bit_
= false);
1579 ACE_InputCDR::read_wstring (ACE_CDR::WChar
*& x
)
1581 // @@ This is a slight violation of "Optimize for the common case",
1582 // i.e. normally the translator will be 0, but OTOH the code is
1583 // smaller and should be better for the cache ;-) ;-)
1584 if (this->wchar_translator_
!= 0)
1586 this->good_bit_
= this->wchar_translator_
->read_wstring (*this, x
);
1587 return this->good_bit_
;
1589 if (ACE_OutputCDR::wchar_maxbytes_
== 0)
1592 return (this->good_bit_
= false);
1595 ACE_CDR::ULong len
= 0;
1597 if (!this->read_ulong (len
))
1602 // A check for the length being too great is done later in the
1603 // call to read_char_array but we want to have it done before
1604 // the memory is allocated.
1605 if (len
> 0 && len
<= this->length ())
1607 std::unique_ptr
<ACE_CDR::WChar
[]> safe_data
;
1609 if (static_cast<ACE_CDR::Short
> (this->major_version_
) == 1
1610 && static_cast<ACE_CDR::Short
> (this->minor_version_
) == 2)
1613 ACE_Utils::truncate_cast
<ACE_CDR::ULong
> (
1614 ACE_OutputCDR::wchar_maxbytes_
);
1616 //allocating one extra for the null character needed by applications
1617 #if defined (ACE_HAS_ALLOC_HOOKS)
1618 ACE_ALLOCATOR_RETURN (x
,
1619 static_cast<ACE_CDR::WChar
*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::WChar
) * (len
+ 1))),
1623 ACE_CDR::WChar
[len
+ 1],
1625 #endif /* ACE_HAS_ALLOC_HOOKS */
1627 safe_data
.reset (x
);
1629 if (this->read_wchar_array (x
, len
))
1631 //Null character used by applications to find the end of
1633 //Is this okay with the GIOP 1.2 spec??
1636 (void) safe_data
.release ();
1643 #if defined (ACE_HAS_ALLOC_HOOKS)
1644 ACE_ALLOCATOR_RETURN (x
,
1645 static_cast<ACE_CDR::WChar
*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::WChar
) * (len
))),
1649 ACE_CDR::WChar
[len
],
1651 #endif /* ACE_HAS_ALLOC_HOOKS */
1653 safe_data
.reset (x
);
1655 if (this->read_wchar_array (x
, len
))
1657 (void) safe_data
.release ();
1665 // Convert any null strings to empty strings since empty
1666 // strings can cause crashes. (See bug 58.)
1667 #if defined (ACE_HAS_ALLOC_HOOKS)
1668 ACE_ALLOCATOR_RETURN (x
,
1669 static_cast<ACE_CDR::WChar
*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::WChar
) * (1))),
1675 #endif /* ACE_HAS_ALLOC_HOOKS */
1681 this->good_bit_
= false;
1686 // As of C++11 std::string guarantees contiguous memory storage.
1687 // That provides the opportunity to optimize CDR streaming.
1689 ACE_InputCDR::read_string (std::string
& x
)
1691 // @@ This is a slight violation of "Optimize for the common case",
1692 // i.e. normally the translator will be 0, but OTOH the code is
1693 // smaller and should be better for the cache ;-) ;-)
1694 if (this->char_translator_
!= 0)
1696 this->good_bit_
= this->char_translator_
->read_string (*this, x
);
1697 return this->good_bit_
;
1700 ACE_CDR::ULong len
= 0;
1702 if (!this->read_ulong (len
))
1705 // A check for the length being too great is done later in the
1706 // call to read_char_array but we want to have it done before
1707 // the memory is allocated.
1708 if (len
> 0 && len
<= this->length())
1712 x
.resize (len
-1); // no need to include the terminating '\0' here
1714 catch (const std::bad_alloc
&)
1719 if (len
== 0 || this->read_char_array (&x
[0], len
-1))
1721 return this->skip_char (); // skip the terminating '\0'
1725 this->good_bit_
= false;
1730 #if !defined(ACE_LACKS_STD_WSTRING)
1732 ACE_InputCDR::read_wstring (std::wstring
& x
)
1734 // @@ This is a slight violation of "Optimize for the common case",
1735 // i.e. normally the translator will be 0, but OTOH the code is
1736 // smaller and should be better for the cache ;-) ;-)
1737 if (this->wchar_translator_
!= 0)
1739 this->good_bit_
= this->wchar_translator_
->read_wstring (*this, x
);
1740 return this->good_bit_
;
1742 if (ACE_OutputCDR::wchar_maxbytes_
== 0)
1745 return (this->good_bit_
= false);
1748 ACE_CDR::ULong len
= 0;
1750 if (!this->read_ulong (len
))
1755 // A check for the length being too great is done later in the
1756 // call to read_char_array but we want to have it done before
1757 // the memory is allocated.
1758 if (len
> 0 && len
<= this->length ())
1760 if (static_cast<ACE_CDR::Short
> (this->major_version_
) == 1
1761 && static_cast<ACE_CDR::Short
> (this->minor_version_
) == 2)
1764 ACE_Utils::truncate_cast
<ACE_CDR::ULong
> (
1765 ACE_OutputCDR::wchar_maxbytes_
);
1771 catch (const std::bad_alloc
&)
1776 if (this->read_wchar_array (&x
[0], len
))
1785 x
.resize (len
-1); // no need to include the terminating '\0' here
1787 catch (const std::bad_alloc
&)
1792 if (len
== 1 || this->read_wchar_array (&x
[0], len
-1))
1794 return this->skip_wchar (); // skip the terminating '\0'
1804 this->good_bit_
= false;
1811 ACE_InputCDR::read_array (void* x
,
1814 ACE_CDR::ULong length
)
1820 if (this->adjust (size
* length
, align
, buf
) == 0)
1822 #if defined (ACE_DISABLE_SWAP_ON_READ)
1823 ACE_OS::memcpy (x
, buf
, size
*length
);
1825 if (!this->do_byte_swap_
|| size
== 1)
1826 ACE_OS::memcpy (x
, buf
, size
*length
);
1829 char *target
= reinterpret_cast<char*> (x
);
1833 ACE_CDR::swap_2_array (buf
, target
, length
);
1836 ACE_CDR::swap_4_array (buf
, target
, length
);
1839 ACE_CDR::swap_8_array (buf
, target
, length
);
1842 ACE_CDR::swap_16_array (buf
, target
, length
);
1845 // TODO: print something?
1846 this->good_bit_
= false;
1850 #endif /* ACE_DISABLE_SWAP_ON_READ */
1851 return this->good_bit_
;
1857 ACE_InputCDR::read_wchar_array_i (ACE_CDR::WChar
* x
,
1858 ACE_CDR::ULong length
)
1863 size_t const align
= (ACE_OutputCDR::wchar_maxbytes_
== 2) ?
1864 ACE_CDR::SHORT_ALIGN
:
1865 ACE_CDR::OCTET_ALIGN
;
1867 if (this->adjust (ACE_OutputCDR::wchar_maxbytes_
* length
, align
, buf
) == 0)
1869 if (ACE_OutputCDR::wchar_maxbytes_
== 2)
1871 ACE_CDR::UShort
*sb
= reinterpret_cast<ACE_CDR::UShort
*> (buf
);
1872 for (size_t i
= 0; i
< length
; ++i
)
1873 #if defined (ACE_DISABLE_SWAP_ON_READ)
1874 x
[i
] = static_cast<ACE_CDR::WChar
> (sb
[i
]);
1876 if (!this->do_byte_swap_
)
1877 x
[i
] = static_cast<ACE_CDR::WChar
> (sb
[i
]);
1881 ACE_CDR::swap_2 (&buf
[i
* 2], reinterpret_cast<char *> (&sx
));
1882 x
[i
] = static_cast<ACE_CDR::WChar
> (sx
);
1884 #endif /* ACE_DISABLE_SWAP_ON_READ */
1888 for (size_t i
= 0; i
< length
; ++i
)
1889 x
[i
] = static_cast<ACE_CDR::Octet
> (buf
[i
]);
1891 return this->good_bit_
;
1898 ACE_InputCDR::read_boolean_array (ACE_CDR::Boolean
*x
,
1899 ACE_CDR::ULong length
)
1901 // Make sure the length of the array isn't greater than the length of
1903 if (length
> this->length ())
1905 this->good_bit_
= false;
1909 // It is hard to optimize this, the spec requires that on the wire
1910 // booleans be represented as a byte with value 0 or 1, but in
1911 // memory it is possible (though very unlikely) that a boolean has
1912 // a non-zero value (different from 1).
1913 // We resort to a simple loop.
1914 for (ACE_CDR::ULong i
= 0; i
!= length
&& this->good_bit_
; ++i
)
1915 (void) this->read_boolean (x
[i
]);
1917 return this->good_bit_
;
1921 ACE_InputCDR::read_1 (ACE_CDR::Octet
*x
)
1923 if (this->rd_ptr () < this->wr_ptr ())
1925 *x
= *reinterpret_cast<ACE_CDR::Octet
*> (this->rd_ptr ());
1926 this->start_
.rd_ptr (1);
1930 this->good_bit_
= false;
1935 ACE_InputCDR::read_2 (ACE_CDR::UShort
*x
)
1938 if (this->adjust (ACE_CDR::SHORT_SIZE
, buf
) == 0)
1940 #if !defined (ACE_DISABLE_SWAP_ON_READ)
1941 if (!this->do_byte_swap_
)
1942 *x
= *reinterpret_cast<ACE_CDR::UShort
*> (buf
);
1944 ACE_CDR::swap_2 (buf
, reinterpret_cast<char*> (x
));
1946 *x
= *reinterpret_cast<ACE_CDR::UShort
*> (buf
);
1947 #endif /* ACE_DISABLE_SWAP_ON_READ */
1950 this->good_bit_
= false;
1955 ACE_InputCDR::read_4 (ACE_CDR::ULong
*x
)
1958 if (this->adjust (ACE_CDR::LONG_SIZE
, buf
) == 0)
1960 #if !defined (ACE_DISABLE_SWAP_ON_READ)
1961 if (!this->do_byte_swap_
)
1962 *x
= *reinterpret_cast<ACE_CDR::ULong
*> (buf
);
1964 ACE_CDR::swap_4 (buf
, reinterpret_cast<char*> (x
));
1966 *x
= *reinterpret_cast<ACE_CDR::ULong
*> (buf
);
1967 #endif /* ACE_DISABLE_SWAP_ON_READ */
1970 this->good_bit_
= false;
1975 ACE_InputCDR::read_8 (ACE_CDR::ULongLong
*x
)
1979 if (this->adjust (ACE_CDR::LONGLONG_SIZE
, buf
) == 0)
1981 #if !defined (ACE_DISABLE_SWAP_ON_READ)
1982 if (!this->do_byte_swap_
)
1983 *x
= *reinterpret_cast<ACE_CDR::ULongLong
*> (buf
);
1985 ACE_CDR::swap_8 (buf
, reinterpret_cast<char *> (x
));
1987 *x
= *reinterpret_cast<ACE_CDR::ULongLong
*> (buf
);
1988 #endif /* ACE_DISABLE_SWAP_ON_READ */
1992 this->good_bit_
= false;
1997 ACE_InputCDR::read_16 (ACE_CDR::LongDouble
*x
)
2000 if (this->adjust (ACE_CDR::LONGDOUBLE_SIZE
,
2001 ACE_CDR::LONGDOUBLE_ALIGN
,
2004 #if !defined (ACE_DISABLE_SWAP_ON_READ)
2005 if (!this->do_byte_swap_
)
2006 *x
= *reinterpret_cast<ACE_CDR::LongDouble
*> (buf
);
2008 ACE_CDR::swap_16 (buf
, reinterpret_cast<char*> (x
));
2010 *x
= *reinterpret_cast<ACE_CDR::LongDouble
*> (buf
);
2011 #endif /* ACE_DISABLE_SWAP_ON_READ */
2015 this->good_bit_
= false;
2020 ACE_InputCDR::skip_string ()
2022 ACE_CDR::ULong len
= 0;
2023 if (this->read_ulong (len
))
2025 if (static_cast<ACE_CDR::ULong
> (~0u) == len
)
2027 // Indirection, next Long in stream is signed offset to actual
2028 // string location (backwards in same stream from here).
2029 ACE_CDR::Long offset
= 0;
2030 if (this->read_long (offset
))
2035 else if (this->rd_ptr () + len
<= this->wr_ptr ())
2040 this->good_bit_
= false;
2046 ACE_InputCDR::skip_wstring ()
2048 ACE_CDR::ULong len
= 0;
2049 ACE_CDR::Boolean continue_skipping
= read_ulong (len
);
2051 if (continue_skipping
&& len
!= 0)
2053 if (static_cast<ACE_CDR::Short
> (this->major_version_
) == 1
2054 && static_cast<ACE_CDR::Short
> (this->minor_version_
) == 2)
2055 continue_skipping
= this->skip_bytes ((size_t)len
);
2057 while (continue_skipping
&& len
--)
2058 continue_skipping
= this->skip_wchar ();
2060 return continue_skipping
;
2064 ACE_InputCDR::skip_bytes (size_t len
)
2066 if (this->rd_ptr () + len
<= this->wr_ptr ())
2071 this->good_bit_
= false;
2076 ACE_InputCDR::grow (size_t newsize
)
2078 if (ACE_CDR::grow (&this->start_
, newsize
) == -1)
2081 ACE_CDR::mb_align (&this->start_
);
2082 this->start_
.wr_ptr (newsize
);
2084 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
2085 if (newsize
> this->start_
.total_size ())
2087 this->monitor_
->receive (newsize
);
2089 #endif /* ACE_HAS_MONITOR_POINTS==1 */
2095 ACE_InputCDR::reset (const ACE_Message_Block
* data
,
2098 this->reset_byte_order (byte_order
);
2099 ACE_CDR::consolidate (&this->start_
, data
);
2101 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
2102 this->monitor_
->receive (this->start_
.total_size ());
2103 #endif /* ACE_HAS_MONITOR_POINTS==1 */
2107 ACE_InputCDR::steal_from (ACE_InputCDR
&cdr
)
2109 this->do_byte_swap_
= cdr
.do_byte_swap_
;
2110 this->start_
.data_block (cdr
.start_
.data_block ()->duplicate ());
2112 // If the message block had a DONT_DELETE flags, just clear it off..
2113 this->start_
.clr_self_flags (ACE_Message_Block::DONT_DELETE
);
2114 this->start_
.rd_ptr (cdr
.start_
.rd_ptr ());
2116 this->start_
.wr_ptr (cdr
.start_
.wr_ptr ());
2117 this->major_version_
= cdr
.major_version_
;
2118 this->minor_version_
= cdr
.minor_version_
;
2119 cdr
.reset_contents ();
2121 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
2122 this->monitor_
->receive (this->start_
.total_size ());
2123 #endif /* ACE_HAS_MONITOR_POINTS==1 */
2127 ACE_InputCDR::exchange_data_blocks (ACE_InputCDR
&cdr
)
2129 // Exchange byte orders
2130 int const byte_order
= cdr
.do_byte_swap_
;
2131 cdr
.do_byte_swap_
= this->do_byte_swap_
;
2132 this->do_byte_swap_
= byte_order
;
2134 // Get the destination read and write pointers
2135 size_t const drd_pos
=
2136 cdr
.start_
.rd_ptr () - cdr
.start_
.base ();
2137 size_t const dwr_pos
=
2138 cdr
.start_
.wr_ptr () - cdr
.start_
.base ();
2140 // Get the source read & write pointers
2141 size_t const srd_pos
=
2142 this->start_
.rd_ptr () - this->start_
.base ();
2143 size_t const swr_pos
=
2144 this->start_
.wr_ptr () - this->start_
.base ();
2146 // Exchange data_blocks. Dont release any of the data blocks.
2147 ACE_Data_Block
*dnb
=
2148 this->start_
.replace_data_block (cdr
.start_
.data_block ());
2149 cdr
.start_
.replace_data_block (dnb
);
2151 // Exchange the flags information..
2152 ACE_Message_Block::Message_Flags df
= cdr
.start_
.self_flags ();
2153 ACE_Message_Block::Message_Flags sf
= this->start_
.self_flags ();
2155 cdr
.start_
.clr_self_flags (df
);
2156 this->start_
.clr_self_flags (sf
);
2158 cdr
.start_
.set_self_flags (sf
);
2159 this->start_
.set_self_flags (df
);
2161 // Reset the <cdr> pointers to zero before it is set again.
2162 cdr
.start_
.reset ();
2163 this->start_
.reset ();
2165 // Set the read and write pointers.
2166 if (cdr
.start_
.size () >= srd_pos
)
2168 cdr
.start_
.rd_ptr (srd_pos
);
2171 if (cdr
.start_
.size () >= swr_pos
)
2173 cdr
.start_
.wr_ptr (swr_pos
);
2176 if (this->start_
.size () >= drd_pos
)
2178 this->start_
.rd_ptr (drd_pos
);
2181 if (this->start_
.size () >= dwr_pos
)
2183 this->start_
.wr_ptr (dwr_pos
);
2186 ACE_CDR::Octet
const dmajor
= cdr
.major_version_
;
2187 ACE_CDR::Octet
const dminor
= cdr
.minor_version_
;
2189 // Exchange the GIOP version info
2190 cdr
.major_version_
= this->major_version_
;
2191 cdr
.minor_version_
= this->minor_version_
;
2193 this->major_version_
= dmajor
;
2194 this->minor_version_
= dminor
;
2196 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
2197 this->monitor_
->receive (this->start_
.total_size ());
2198 #endif /* ACE_HAS_MONITOR_POINTS==1 */
2202 ACE_InputCDR::clone_from (ACE_InputCDR
&cdr
)
2204 this->do_byte_swap_
= cdr
.do_byte_swap_
;
2206 // Get the read & write pointer positions in the incoming CDR
2208 char *rd_ptr
= cdr
.start_
.rd_ptr ();
2209 char *wr_ptr
= cdr
.start_
.wr_ptr ();
2211 // Now reset the incoming CDR stream
2212 cdr
.start_
.reset ();
2214 // As we have reset the stream, try to align the underlying message
2215 // block in the incoming stream
2216 ACE_CDR::mb_align (&cdr
.start_
);
2218 // Get the read & write pointer positions again
2219 char *nrd_ptr
= cdr
.start_
.rd_ptr ();
2220 char *nwr_ptr
= cdr
.start_
.wr_ptr ();
2222 // Actual length of the stream is..
2223 // @todo: This will look idiotic, but we dont seem to have much of a
2224 // choice. How do we calculate the length of the incoming stream?
2225 // Calling the method before calling reset () would give us the
2226 // wrong length of the stream that needs copying. So we do the
2227 // calulation like this
2228 // (1) We get the <rd_ptr> and <wr_ptr> positions of the incoming
2230 // (2) Then we reset the <incoming> stream and then align it.
2231 // (3) We get the <rd_ptr> and <wr_ptr> positions again. (Points #1
2232 // thru #3 has been done already)
2233 // (4) The difference in the <rd_ptr> and <wr_ptr> positions gives
2234 // us the following, the actual bytes traversed by the <rd_ptr> and
2236 // (5) The bytes traversed by the <wr_ptr> is the actual length of
2239 // Actual bytes traversed
2240 size_t rd_bytes
= rd_ptr
- nrd_ptr
;
2241 size_t wr_bytes
= wr_ptr
- nwr_ptr
;
2243 ACE_CDR::mb_align (&this->start_
);
2245 ACE_Data_Block
*db
= this->start_
.data_block ();
2247 // If the size of the data that needs to be copied are higher than
2248 // what is available, then do a reallocation.
2249 if (wr_bytes
> (this->start_
.size () - ACE_CDR::MAX_ALIGNMENT
))
2251 // @@NOTE: We need to probably add another method to the message
2252 // block interface to simplify this
2253 db
= cdr
.start_
.data_block ()->clone_nocopy ();
2255 if (db
== 0 || db
->size ((wr_bytes
) +
2256 ACE_CDR::MAX_ALIGNMENT
) == -1)
2259 // Replace our data block by using the incoming CDR stream.
2260 db
= this->start_
.replace_data_block (db
);
2262 // Align the start_ message block.
2263 ACE_CDR::mb_align (&this->start_
);
2265 // Clear the DONT_DELETE flag if it has been set
2266 this->start_
.clr_self_flags (ACE_Message_Block::DONT_DELETE
);
2270 (void) ACE_OS::memcpy (this->start_
.wr_ptr (),
2271 cdr
.start_
.rd_ptr (),
2274 // Set the read pointer position to the same point as that was in
2276 this->start_
.rd_ptr (rd_bytes
);
2277 this->start_
.wr_ptr (wr_bytes
);
2279 // We have changed the read & write pointers for the incoming
2280 // stream. Set them back to the positions that they were before..
2281 cdr
.start_
.rd_ptr (rd_bytes
);
2282 cdr
.start_
.wr_ptr (wr_bytes
);
2284 this->major_version_
= cdr
.major_version_
;
2285 this->minor_version_
= cdr
.minor_version_
;
2287 // Copy the char/wchar translators
2288 this->char_translator_
= cdr
.char_translator_
;
2289 this->wchar_translator_
= cdr
.wchar_translator_
;
2291 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
2292 this->monitor_
->receive (this->start_
.total_size ());
2293 #endif /* ACE_HAS_MONITOR_POINTS==1 */
2299 ACE_InputCDR::steal_contents ()
2301 ACE_Message_Block
* block
= this->start_
.clone ();
2302 this->start_
.data_block (block
->data_block ()->clone ());
2304 // If at all our message had a DONT_DELETE flag set, just clear it
2306 this->start_
.clr_self_flags (ACE_Message_Block::DONT_DELETE
);
2308 ACE_CDR::mb_align (&this->start_
);
2310 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
2311 this->monitor_
->receive (this->start_
.total_size ());
2312 #endif /* ACE_HAS_MONITOR_POINTS==1 */
2318 ACE_InputCDR::reset_contents ()
2320 this->start_
.data_block (this->start_
.data_block ()->clone_nocopy ());
2322 // Reset the flags...
2323 this->start_
.clr_self_flags (ACE_Message_Block::DONT_DELETE
);
2325 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
2326 this->monitor_
->receive (this->start_
.total_size ());
2327 #endif /* ACE_HAS_MONITOR_POINTS==1 */
2330 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
2333 ACE_InputCDR::register_monitor (const char *id
)
2335 this->monitor_
->name (id
);
2336 this->monitor_
->add_to_registry ();
2340 ACE_InputCDR::unregister_monitor ()
2342 this->monitor_
->remove_from_registry ();
2345 #endif /* ACE_HAS_MONITOR_POINTS==1 */
2347 // --------------------------------------------------------------
2350 ACE_Char_Codeset_Translator::read_string (ACE_InputCDR
&cdr
,
2353 ACE_CDR::Char
*buf
= 0;
2354 ACE_CDR::Boolean
const marshal_flag
= this->read_string (cdr
, buf
);
2356 ACE::strdelete (buf
);
2357 return marshal_flag
;
2360 // --------------------------------------------------------------
2362 #if !defined(ACE_LACKS_STD_WSTRING)
2364 ACE_WChar_Codeset_Translator::read_wstring (ACE_InputCDR
&cdr
,
2367 ACE_CDR::WChar
*buf
= 0;
2368 ACE_CDR::Boolean
const marshal_flag
= this->read_wstring (cdr
, buf
);
2370 ACE::strdelete (buf
);
2371 return marshal_flag
;
2375 // --------------------------------------------------------------
2378 operator<< (ACE_OutputCDR
&os
, const ACE_CString
&x
)
2380 os
.write_string (x
);
2381 return os
.good_bit ();
2385 operator>> (ACE_InputCDR
&is
, ACE_CString
&x
)
2388 return is
.good_bit ();
2391 #if defined (GEN_OSTREAM_OPS)
2394 operator<< (std::ostream
&os
, ACE_OutputCDR::from_boolean x
)
2396 return (x
.val_
? os
<< "true" : os
<< "false");
2400 operator<< (std::ostream
&os
, ACE_OutputCDR::from_char x
)
2402 return os
<< '\'' << x
.val_
<< '\'';
2406 operator<< (std::ostream
&os
, ACE_OutputCDR::from_wchar x
)
2408 os
.setf (ios_base::showbase
);
2409 os
.setf (ios_base::hex
, ios_base::basefield
);
2411 os
.unsetf (ios_base::showbase
);
2412 os
.setf (ios_base::dec
, ios_base::basefield
);
2417 operator<< (std::ostream
&os
, ACE_OutputCDR::from_octet x
)
2419 // Same format (hex) and no risk of overflow.
2420 ACE_CDR::WChar w
= static_cast<ACE_CDR::WChar
> (x
.val_
);
2421 ACE_OutputCDR::from_wchar
tmp (w
);
2425 #endif /* GEN_OSTREAM_OPS */
2427 ACE_END_VERSIONED_NAMESPACE_DECL