3 //=============================================================================
7 * ACE Common Data Representation (CDR) marshaling and demarshaling
10 * This implementation was inspired in the CDR class in SunSoft's
11 * IIOP engine, but has a completely different implementation and a
12 * different interface too.
14 * The current implementation assumes that the host has 1-byte,
15 * 2-byte and 4-byte integral types, and that it has single
16 * precision and double precision IEEE floats.
17 * Those assumptions are pretty good these days, with Crays being
18 * the only known exception.
22 * ACE_LACKS_CDR_ALIGNMENT
23 * @author Arvind S. Krishna <arvindk@dre.vanderbilt.edu>
25 * CDR stream ignores alignment when marshaling data. Use this option
26 * only when ACE_DISABLE_SWAP_ON_READ can be enabled. This option requires
27 * ACE CDR engine to do both marshaling and demarshaling.
29 * @author TAO version by Aniruddha Gokhale <gokhale@cs.wustl.edu>
30 * @author Carlos O'Ryan <coryan@cs.wustl.edu>
31 * @author ACE version by Jeff Parsons <parsons@cs.wustl.edu>
32 * @author Istvan Buki <istvan.buki@euronet.be>
33 * @author Codeset translation by Jim Rogers <jrogers@viasoft.com>
35 //=============================================================================
37 #ifndef ACE_CDR_STREAM_H
38 #define ACE_CDR_STREAM_H
40 #include /**/ "ace/pre.h"
42 #include "ace/CDR_Base.h"
44 #if !defined (ACE_LACKS_PRAGMA_ONCE)
46 #endif /* ACE_LACKS_PRAGMA_ONCE */
48 #include "ace/SStringfwd.h"
49 #include "ace/Message_Block.h"
51 #if defined (GEN_OSTREAM_OPS)
52 #include "ace/streams.h"
53 #endif /* GEN_OSTREAM_OPS */
55 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
56 #include "Monitor_Size.h"
57 #endif /* ACE_HAS_MONITOR_POINTS==1 */
60 #include <string_view>
62 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
64 class ACE_Char_Codeset_Translator
;
65 class ACE_WChar_Codeset_Translator
;
70 * @class ACE_OutputCDR
72 * @brief A CDR stream for marshalling data, most often for transmission to
73 * another system which may or may not have the same byte order.
75 * This class is based on the the CORBA spec for Java (98-02-29),
76 * java class omg.org.CORBA.portable.OutputStream. It diverts in
78 * @li Operations taking arrays don't have offsets, because in C++
79 * it is easier to describe an array starting from x+offset.
80 * @li Operations return an error status, because exceptions are
81 * not widely available in C++ (yet).
83 class ACE_Export ACE_OutputCDR
87 * The Codeset translators need access to some private members to
88 * efficiently marshal arrays
89 * For reading from an output CDR stream.
91 friend class ACE_Char_Codeset_Translator
;
92 friend class ACE_WChar_Codeset_Translator
;
93 friend class ACE_InputCDR
;
96 * Default constructor; allows one to set byte ordering, allocators, and
99 * @param size Causes constructor to preallocate @a size bytes; if
100 * @a size is 0 it allocates the default size.
102 * @param byte_order The byte order that data will have within this
103 * object. Unless otherwise specified, the byte order
104 * will be the order native to the hardware this is
105 * executed on. To force the marshalled data to have
106 * a specific order, specify one of the values defined
107 * in ACE_CDR::Byte_Order.
108 * @note The @c ACE_ENABLE_SWAP_ON_WRITE config macro
109 * must be set for any local byte swapping to occur
110 * as data is inserted into an ACE_OutputCDR object.
112 ACE_OutputCDR (size_t size
= 0,
113 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
114 ACE_Allocator
* buffer_allocator
= 0,
115 ACE_Allocator
* data_block_allocator
= 0,
116 ACE_Allocator
* message_block_allocator
= 0,
117 size_t memcpy_tradeoff
= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
,
118 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
119 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
121 /// Build a CDR stream with an initial buffer, it will *not* remove
122 /// @a data, since it did not allocated it. It's important to be careful
123 /// with the alignment of @a data.
125 * Create an output stream from an arbitrary buffer, care must be
126 * exercised with alignment, because this constructor will align if
127 * needed. In this case @a data will not point to the start of the
128 * output stream. @c begin()->rd_ptr() points to the start of the
129 * output stream. See @c ACE_ptr_align_binary() to properly align a
130 * pointer and use ACE_CDR::MAX_ALIGNMENT for the correct alignment.
132 ACE_OutputCDR (char *data
,
134 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
135 ACE_Allocator
* buffer_allocator
= 0,
136 ACE_Allocator
* data_block_allocator
= 0,
137 ACE_Allocator
* message_block_allocator
= 0,
138 size_t memcpy_tradeoff
= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
,
139 ACE_CDR::Octet giop_major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
140 ACE_CDR::Octet giop_minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
142 /// Build a CDR stream with an initial data block, it will *not* remove
143 /// @a data_block, since it did not allocated it. It's important to be
144 /// careful with the alignment of @a data_block.
146 * Create an output stream from an arbitrary data block, care must be
147 * exercised with alignment, because this constructor will align if
148 * needed. In this case @a data_block will not point to the
149 * start of the output stream. begin()->rd_ptr() points to the start
150 * off the output stream. See ACE_ptr_align_binary() to properly align a
151 * pointer and use ACE_CDR::MAX_ALIGNMENT for the correct alignment.
153 ACE_OutputCDR (ACE_Data_Block
*data_block
,
154 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
155 ACE_Allocator
* message_block_allocator
= 0,
156 size_t memcpy_tradeoff
= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
,
157 ACE_CDR::Octet giop_major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
158 ACE_CDR::Octet giop_minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
160 /// Build a CDR stream with an initial Message_Block chain, it will
161 /// *not* remove @a data, since it did not allocate it.
162 ACE_OutputCDR (ACE_Message_Block
*data
,
163 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
164 size_t memcpy_tradeoff
= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
,
165 ACE_CDR::Octet giop_major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
166 ACE_CDR::Octet giop_minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
172 * Disambiguate overload when inserting booleans, octets, chars, and
175 //@{ @name Helper classes
177 struct ACE_Export from_boolean
179 explicit from_boolean (ACE_CDR::Boolean b
);
180 ACE_CDR::Boolean val_
;
183 struct ACE_Export from_octet
185 explicit from_octet (ACE_CDR::Octet o
);
189 struct ACE_Export from_char
191 explicit from_char (ACE_CDR::Char c
);
195 struct ACE_Export from_wchar
197 explicit from_wchar (ACE_CDR::WChar wc
);
201 struct ACE_Export from_int8
203 explicit from_int8 (ACE_CDR::Int8 val
);
207 struct ACE_Export from_uint8
209 explicit from_uint8 (ACE_CDR::UInt8 val
);
213 struct ACE_Export from_string
215 from_string (ACE_CDR::Char
* s
,
217 ACE_CDR::Boolean nocopy
= 0);
218 from_string (const ACE_CDR::Char
* s
,
220 ACE_CDR::Boolean nocopy
= 0);
222 ACE_CDR::ULong bound_
;
223 ACE_CDR::Boolean nocopy_
;
226 struct ACE_Export from_wstring
228 from_wstring (ACE_CDR::WChar
* ws
,
230 ACE_CDR::Boolean nocopy
= 0);
231 from_wstring (const ACE_CDR::WChar
* ws
,
233 ACE_CDR::Boolean nocopy
= 0);
234 ACE_CDR::WChar
*val_
;
235 ACE_CDR::ULong bound_
;
236 ACE_CDR::Boolean nocopy_
;
239 struct ACE_Export from_std_string
241 from_std_string (const std::string
&s
,
243 const std::string
&val_
;
244 ACE_CDR::ULong bound_
;
247 #if !defined(ACE_LACKS_STD_WSTRING)
248 struct ACE_Export from_std_wstring
250 from_std_wstring (const std::wstring
&ws
,
252 const std::wstring
&val_
;
253 ACE_CDR::ULong bound_
;
259 * @{ @name Write operations
260 * Return 0 on failure and 1 on success.
262 ACE_CDR::Boolean
write_boolean (ACE_CDR::Boolean x
);
263 ACE_CDR::Boolean
write_char (ACE_CDR::Char x
);
264 ACE_CDR::Boolean
write_wchar (ACE_CDR::WChar x
);
265 ACE_CDR::Boolean
write_octet (ACE_CDR::Octet x
);
266 ACE_CDR::Boolean
write_short (ACE_CDR::Short x
);
267 ACE_CDR::Boolean
write_ushort (ACE_CDR::UShort x
);
268 ACE_CDR::Boolean
write_long (ACE_CDR::Long x
);
269 ACE_CDR::Boolean
write_ulong (ACE_CDR::ULong x
);
270 ACE_CDR::Boolean
write_longlong (const ACE_CDR::LongLong
&x
);
271 ACE_CDR::Boolean
write_ulonglong (const ACE_CDR::ULongLong
&x
);
272 ACE_CDR::Boolean
write_float (ACE_CDR::Float x
);
273 ACE_CDR::Boolean
write_double (const ACE_CDR::Double
&x
);
274 ACE_CDR::Boolean
write_longdouble (const ACE_CDR::LongDouble
&x
);
275 ACE_CDR::Boolean
write_fixed (const ACE_CDR::Fixed
&x
);
276 ACE_CDR::Boolean
write_int8 (ACE_CDR::Int8 x
);
277 ACE_CDR::Boolean
write_uint8 (ACE_CDR::UInt8 x
);
279 /// For string we offer methods that accept a precomputed length.
280 ACE_CDR::Boolean
write_string (const ACE_CDR::Char
*x
);
281 ACE_CDR::Boolean
write_string (ACE_CDR::ULong len
,
282 const ACE_CDR::Char
*x
);
283 ACE_CDR::Boolean
write_string (const ACE_CString
&x
);
284 ACE_CDR::Boolean
write_wstring (const ACE_CDR::WChar
*x
);
285 ACE_CDR::Boolean
write_wstring (ACE_CDR::ULong length
,
286 const ACE_CDR::WChar
*x
);
287 ACE_CDR::Boolean
write_string (const std::string
&x
);
288 ACE_CDR::Boolean
write_string_view (const std::string_view
&x
);
289 #if !defined(ACE_LACKS_STD_WSTRING)
290 ACE_CDR::Boolean
write_wstring (const std::wstring
&x
);
295 /// @note the portion written starts at @a x and ends
296 /// at @a x + @a length.
297 /// The length is *NOT* stored into the CDR stream.
298 //@{ @name Array write operations
299 ACE_CDR::Boolean
write_boolean_array (const ACE_CDR::Boolean
*x
,
300 ACE_CDR::ULong length
);
301 ACE_CDR::Boolean
write_char_array (const ACE_CDR::Char
*x
,
302 ACE_CDR::ULong length
);
303 ACE_CDR::Boolean
write_wchar_array (const ACE_CDR::WChar
* x
,
304 ACE_CDR::ULong length
);
305 ACE_CDR::Boolean
write_octet_array (const ACE_CDR::Octet
* x
,
306 ACE_CDR::ULong length
);
307 ACE_CDR::Boolean
write_short_array (const ACE_CDR::Short
*x
,
308 ACE_CDR::ULong length
);
309 ACE_CDR::Boolean
write_ushort_array (const ACE_CDR::UShort
*x
,
310 ACE_CDR::ULong length
);
311 ACE_CDR::Boolean
write_long_array (const ACE_CDR::Long
*x
,
312 ACE_CDR::ULong length
);
313 ACE_CDR::Boolean
write_ulong_array (const ACE_CDR::ULong
*x
,
314 ACE_CDR::ULong length
);
315 ACE_CDR::Boolean
write_longlong_array (const ACE_CDR::LongLong
* x
,
316 ACE_CDR::ULong length
);
317 ACE_CDR::Boolean
write_ulonglong_array (const ACE_CDR::ULongLong
*x
,
318 ACE_CDR::ULong length
);
319 ACE_CDR::Boolean
write_float_array (const ACE_CDR::Float
*x
,
320 ACE_CDR::ULong length
);
321 ACE_CDR::Boolean
write_double_array (const ACE_CDR::Double
*x
,
322 ACE_CDR::ULong length
);
323 ACE_CDR::Boolean
write_longdouble_array (const ACE_CDR::LongDouble
* x
,
324 ACE_CDR::ULong length
);
325 ACE_CDR::Boolean
write_int8_array (const ACE_CDR::Int8
*x
, ACE_CDR::ULong length
);
326 ACE_CDR::Boolean
write_uint8_array (const ACE_CDR::UInt8
*x
, ACE_CDR::ULong length
);
328 /// Write an octet array contained inside a MB, this can be optimized
329 /// to minimize copies.
330 ACE_CDR::Boolean
write_octet_array_mb (const ACE_Message_Block
* mb
);
334 * @{ @name Placeholder/replace operations
335 * Facilitates writing a placeholder into a CDR stream to be replaced
336 * later with a different value.
338 * @note An example use for this facility is:
341 ... // insert values...
342 char *pos = strm.write_long_placeholder ();
343 ... // insert more values
344 ACE_CDR::Long real_val; // Somehow assign the "correct" value
345 strm.replace (real_val, pos); // Replace earlier placeholder
350 * Write a placeholder into the stream. The placeholder's pointer
351 * is returned so it may later be passed as the @a loc argument to
353 * These methods align the stream's write pointer properly prior to
354 * writing the placeholder.
356 * @retval Pointer to the placeholder; 0 if there is not enough space
357 * in the stream and memory could not be allocated.
359 char* write_long_placeholder ();
360 char* write_short_placeholder ();
361 char* write_boolean_placeholder ();
362 char* write_char_placeholder ();
363 char* write_longlong_placeholder ();
364 char* write_octet_placeholder ();
365 char* write_float_placeholder ();
366 char* write_double_placeholder ();
369 * Writes a new value into a specific location. This is commonly
370 * used to update a prior "placeholder" location in the stream.
371 * The specified location is assumed to have proper CDR alignment for the
372 * type to insert. This requirement is satisfied by using one of the
373 * placeholder-writing methods to align the stream for the anticipated
374 * value and obtain the correct location.
375 * Treatment of @a x with respect to byte swapping is the same as for when
376 * any value is inserted.
378 * @param x The value to insert into the specified location.
379 * @param loc The location at which to insert @a x. @a loc must be a valid
380 * position within the stream's current set of message blocks.
382 * @sa write_long_placeholder(), write_short_placeholder ()
384 ACE_CDR::Boolean
replace (ACE_CDR::Long x
, char* loc
);
385 ACE_CDR::Boolean
replace (ACE_CDR::ULong x
, char* loc
);
386 ACE_CDR::Boolean
replace (ACE_CDR::Short x
, char* loc
);
387 ACE_CDR::Boolean
replace (ACE_CDR::UShort x
, char* loc
);
388 ACE_CDR::Boolean
replace (ACE_CDR::Boolean x
, char* loc
);
389 ACE_CDR::Boolean
replace (ACE_CDR::Char x
, char* loc
);
390 ACE_CDR::Boolean
replace (ACE_CDR::LongLong x
, char* loc
);
391 ACE_CDR::Boolean
replace (ACE_CDR::ULongLong x
, char* loc
);
392 ACE_CDR::Boolean
replace (ACE_CDR::Octet x
, char* loc
);
393 ACE_CDR::Boolean
replace (ACE_CDR::Float x
, char* loc
);
394 ACE_CDR::Boolean
replace (ACE_CDR::Double x
, char* loc
);
398 * Return 0 on failure and 1 on success.
400 //@{ @name Append contents of own CDR stream to another
401 ACE_CDR::Boolean
append_boolean (ACE_InputCDR
&);
402 ACE_CDR::Boolean
append_char (ACE_InputCDR
&);
403 ACE_CDR::Boolean
append_wchar (ACE_InputCDR
&);
404 ACE_CDR::Boolean
append_octet (ACE_InputCDR
&);
405 ACE_CDR::Boolean
append_short (ACE_InputCDR
&);
406 ACE_CDR::Boolean
append_ushort (ACE_InputCDR
&);
407 ACE_CDR::Boolean
append_long (ACE_InputCDR
&);
408 ACE_CDR::Boolean
append_ulong (ACE_InputCDR
&);
409 ACE_CDR::Boolean
append_longlong (ACE_InputCDR
&);
410 ACE_CDR::Boolean
append_ulonglong (ACE_InputCDR
&);
411 ACE_CDR::Boolean
append_float (ACE_InputCDR
&);
412 ACE_CDR::Boolean
append_double (ACE_InputCDR
&);
413 ACE_CDR::Boolean
append_longdouble (ACE_InputCDR
&);
414 ACE_CDR::Boolean
append_fixed (ACE_InputCDR
&);
416 ACE_CDR::Boolean
append_wstring (ACE_InputCDR
&);
417 ACE_CDR::Boolean
append_string (ACE_InputCDR
&);
420 /// Returns @c false if an error has occurred.
422 * @note The only expected error is to run out of memory.
424 bool good_bit () const;
426 /// Reuse the CDR stream to write on the old buffer.
429 /// Add the length of each message block in the chain.
430 size_t total_length () const;
433 * Return the start of the message block chain for this CDR stream.
434 * @note The complete CDR stream is represented by a chain of
437 const ACE_Message_Block
*begin () const;
439 /// Return the last message in the chain that is is use.
440 const ACE_Message_Block
*end () const;
442 /// Return the <current_> message block in chain.
443 const ACE_Message_Block
*current () const;
445 /// Replace the message block chain with a single message block.
447 * Upon successful completion, there will be a single message block
448 * containing the data from the complete message block chain.
450 * @note The only expected error is to run out of memory.
455 * Access the underlying buffer (read only). @note This
456 * method only returns a pointer to the first block in the
459 const char *buffer () const;
462 * Return the size of first message block in the block chain. @note This
463 * method only returns information about the first block in the
466 size_t length () const;
469 * Utility function to allow the user more flexibility.
470 * Pads the stream up to the nearest @a alignment byte boundary.
471 * Argument MUST be a power of 2.
472 * Returns 0 on success and -1 on failure.
474 int align_write_ptr (size_t alignment
);
476 /// Access the codeset translators. They can be null!
477 ACE_Char_Codeset_Translator
*char_translator () const;
478 ACE_WChar_Codeset_Translator
*wchar_translator () const;
480 /// Set the char codeset translator.
481 void char_translator (ACE_Char_Codeset_Translator
*);
482 /// Set the wchar codeset translator.
483 void wchar_translator (ACE_WChar_Codeset_Translator
*);
485 /// set the global size of serialized wchars. This may be different
486 /// than the size of a wchar_t.
487 static void wchar_maxbytes (size_t max_bytes
);
489 /// access the serialized size of wchars.
490 static size_t wchar_maxbytes ();
493 * Return alignment of the wr_ptr(), with respect to the start of
494 * the CDR stream. This is not the same as the alignment of
497 size_t current_alignment () const;
499 void current_alignment (size_t current_alignment
);
502 * Returns (in @a buf) the next position in the buffer aligned to
503 * @a size, it advances the Message_Block wr_ptr past the data
504 * (i.e., @a buf + @a size). If necessary it grows the Message_Block
505 * buffer. Sets the good_bit to false and returns a -1 on failure.
507 int adjust (size_t size
,
510 /// As above, but now the size and alignment requirements may be
512 int adjust (size_t size
,
516 /// Returns true if this stream is writing in non-native byte order
517 /// and false otherwise. For example, it would be true if either
518 /// ACE_ENABLE_SWAP_ON_WRITE is defined or a specific byte order was
519 /// specified for this stream.
520 bool do_byte_swap () const;
522 /// Returns the byte order this stream is marshaling data in. Will be one
523 /// of the values in ACE_CDR::Byte_Order.
524 int byte_order () const;
526 /// For use by a gateway, which creates the output stream for the
527 /// reply to the client in its native byte order, but which must
528 /// send the reply in the byte order of the target's reply to the
530 void reset_byte_order (int byte_order
);
532 /// Set GIOP version info
533 void set_version (ACE_CDR::Octet major
, ACE_CDR::Octet minor
);
535 /// Set the underlying GIOP version..
536 void get_version (ACE_CDR::Octet
&major
, ACE_CDR::Octet
&minor
);
538 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
539 /// Register and unregister our buffer size monitor.
540 void register_monitor (const char* id
);
541 void unregister_monitor ();
542 #endif /* ACE_HAS_MONITOR_POINTS==1 */
545 // Find the message block in the chain of message blocks
546 // that the provide location locates.
547 ACE_Message_Block
* find (char* loc
);
549 ACE_OutputCDR (const ACE_OutputCDR
&) = delete;
550 ACE_OutputCDR
& operator= (const ACE_OutputCDR
&) = delete;
551 ACE_OutputCDR (ACE_OutputCDR
&&) = delete;
552 ACE_OutputCDR
& operator= (ACE_OutputCDR
&&) = delete;
554 ACE_CDR::Boolean
write_1 (const ACE_CDR::Octet
*x
);
555 ACE_CDR::Boolean
write_2 (const ACE_CDR::UShort
*x
);
556 ACE_CDR::Boolean
write_4 (const ACE_CDR::ULong
*x
);
557 ACE_CDR::Boolean
write_8 (const ACE_CDR::ULongLong
*x
);
558 ACE_CDR::Boolean
write_16 (const ACE_CDR::LongDouble
*x
);
561 * write an array of @a length elements, each of @a size bytes and the
562 * start aligned at a multiple of @a align. The elements are assumed
563 * to be packed with the right alignment restrictions. It is mostly
564 * designed for buffers of the basic types.
566 * This operation uses @c memcpy; as explained above it is expected
567 * that using assignment is faster that @c memcpy for one element,
568 * but for several elements @c memcpy should be more efficient, it
569 * could be interesting to find the break even point and optimize
570 * for that case, but that would be too platform dependent.
572 ACE_CDR::Boolean
write_array (const void *x
,
575 ACE_CDR::ULong length
);
578 ACE_CDR::Boolean
write_wchar_array_i (const ACE_CDR::WChar
* x
,
579 ACE_CDR::ULong length
);
583 * Grow the CDR stream. When it returns @a buf contains a pointer to
584 * memory in the CDR stream, with at least @a size bytes ahead of it
585 * and aligned to an @a align boundary. It moved the <wr_ptr> to <buf
588 int grow_and_adjust (size_t size
,
593 /// The start of the chain of message blocks.
594 ACE_Message_Block start_
;
596 /// The current block in the chain where we are writing.
597 ACE_Message_Block
*current_
;
599 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
601 * The current alignment as measured from the start of the buffer.
602 * Usually this coincides with the alignment of the buffer in
603 * memory, but, when we chain another buffer this "quasi invariant"
605 * The current_alignment is used to readjust the buffer following
606 * the stolen message block.
608 size_t current_alignment_
;
609 #endif /* ACE_LACKS_CDR_ALIGNMENT */
612 * Is the current block writable. When we steal a buffer from the
613 * user and just chain it into the message block we are not supposed
614 * to write on it, even if it is past the start and end of the
617 bool current_is_writable_
;
620 * If not zero swap bytes at writing so the created CDR stream byte
621 * order does *not* match the machine byte order. The motivation
622 * for such a beast is that in some setting a few (fast) machines
623 * can be serving hundreds of slow machines with the opposite byte
624 * order, so it makes sense (as a load balancing device) to put the
625 * responsibility in the writers.
627 * @warning THIS IS NOT A STANDARD IN CORBA, USE AT YOUR OWN RISK
631 /// Set to false when an error ocurrs.
634 /// Break-even point for copying.
635 size_t const memcpy_tradeoff_
;
637 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
638 ACE::Monitor_Control::Size_Monitor
*monitor_
;
639 #endif /* ACE_HAS_MONITOR_POINTS==1 */
642 /// GIOP version information
643 ACE_CDR::Octet major_version_
;
644 ACE_CDR::Octet minor_version_
;
646 /// If not nil, invoke for translation of character and string data.
647 ACE_Char_Codeset_Translator
*char_translator_
;
648 ACE_WChar_Codeset_Translator
*wchar_translator_
;
651 * Some wide char codesets may be defined with a maximum number
652 * of bytes that is smaller than the size of a wchar_t. This means
653 * that the CDR cannot simply memcpy a block of wchars to and from
654 * the stream, but must instead realign the bytes appropriately.
655 * In cases when wchar i/o is not allowed, such as with GIOP 1.0,
656 * or not having a native wchar codeset defined, the maxbytes is
657 * set to zero, indicating no wchar data is allowed.
659 static size_t wchar_maxbytes_
;
663 // ****************************************************************
666 * @class ACE_InputCDR
668 * @brief A CDR stream for demarshalling CDR-encoded data.
670 * This class is based on the the CORBA spec for Java (98-02-29),
671 * java class omg.org.CORBA.portable.InputStream. It diverts in a
673 * @li Operations to retrieve basic types take parameters by
675 * @li Operations taking arrays don't have offsets, because in C++
676 * it is easier to describe an array starting from x+offset.
677 * @li Operations return an error status, because exceptions are
678 * not widely available in C++ (yet).
680 class ACE_Export ACE_InputCDR
683 // The translators need privileged access to efficiently demarshal
685 friend class ACE_Char_Codeset_Translator
;
686 friend class ACE_WChar_Codeset_Translator
;
689 * Create an input stream from an arbitrary buffer. The buffer must
690 * be properly aligned because this constructor will *not* work if
691 * the buffer is aligned unproperly.See ACE_ptr_align_binary() for
692 * instructions on how to align a pointer properly and use
693 * ACE_CDR::MAX_ALIGNMENT for the correct alignment.
695 ACE_InputCDR (const char *buf
,
697 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
698 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
699 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
701 /// Create an empty input stream. The caller is responsible for
702 /// putting the right data and providing the right alignment.
703 ACE_InputCDR (size_t bufsiz
,
704 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
705 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
706 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
708 /// Create an input stream from an ACE_Message_Block
710 * The alignment of the @a data block is carried into the new
711 * ACE_InputCDR object. This constructor either increments the
712 * @a data reference count, or copies the data (if it's a compound
713 * message block) so the caller can release the block immediately
716 ACE_InputCDR (const ACE_Message_Block
*data
,
717 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
718 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
719 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
,
722 /// Create an input stream from an ACE_Data_Block. The @a flag
723 /// indicates whether the @a data can be deleted by the CDR stream
725 ACE_InputCDR (ACE_Data_Block
*data
,
726 ACE_Message_Block::Message_Flags flag
= 0,
727 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
728 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
729 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
731 /// Create an input stream from an ACE_Data_Block. It also sets the
732 /// read and write pointers at the desired positions. This would be
733 /// helpful if the applications desires to create a new CDR stream
734 /// from a semi-processed datablock.
735 ACE_InputCDR (ACE_Data_Block
*data
,
736 ACE_Message_Block::Message_Flags flag
,
737 size_t read_pointer_position
,
738 size_t write_pointer_position
,
739 int byte_order
= ACE_CDR::BYTE_ORDER_NATIVE
,
740 ACE_CDR::Octet major_version
= ACE_CDR_GIOP_MAJOR_VERSION
,
741 ACE_CDR::Octet minor_version
= ACE_CDR_GIOP_MINOR_VERSION
);
744 * These make a copy of the current stream state, but do not copy
745 * the internal buffer, so the same stream can be read multiple
748 ACE_InputCDR (const ACE_InputCDR
& rhs
);
750 ACE_InputCDR
& operator= (const ACE_InputCDR
& rhs
);
752 /// When interpreting indirected TypeCodes it is useful to make a
753 /// "copy" of the stream starting in the new position.
754 ACE_InputCDR (const ACE_InputCDR
& rhs
,
756 ACE_CDR::Long offset
);
758 /// This creates an encapsulated stream, the first byte must be (per
759 /// the spec) the byte order of the encapsulation.
760 ACE_InputCDR (const ACE_InputCDR
& rhs
,
763 /// Create an input CDR from an output CDR.
764 ACE_InputCDR (const ACE_OutputCDR
& rhs
,
765 ACE_Allocator
* buffer_allocator
= 0,
766 ACE_Allocator
* data_block_allocator
= 0,
767 ACE_Allocator
* message_block_allocator
= 0);
769 /// Helper class to transfer the contents from one input CDR to
770 /// another without requiring any extra memory allocations, data
771 /// copies or too many temporaries.
772 struct ACE_Export Transfer_Contents
774 Transfer_Contents (ACE_InputCDR
&rhs
);
778 /// Transfer the contents from @a rhs to a new CDR
779 ACE_InputCDR (Transfer_Contents rhs
);
782 virtual ~ACE_InputCDR ();
784 /// Disambiguate overloading when extracting octets, chars,
785 /// booleans, and bounded strings
786 //@{ @name Helper classes
788 struct ACE_Export to_boolean
790 explicit to_boolean (ACE_CDR::Boolean
&b
);
791 ACE_CDR::Boolean
&ref_
;
794 struct ACE_Export to_char
796 explicit to_char (ACE_CDR::Char
&c
);
800 struct ACE_Export to_wchar
802 explicit to_wchar (ACE_CDR::WChar
&wc
);
803 ACE_CDR::WChar
&ref_
;
806 struct ACE_Export to_octet
808 explicit to_octet (ACE_CDR::Octet
&o
);
809 ACE_CDR::Octet
&ref_
;
812 struct ACE_Export to_int8
814 explicit to_int8 (ACE_CDR::Int8
&ref
);
818 struct ACE_Export to_uint8
820 explicit to_uint8 (ACE_CDR::UInt8
&ref
);
821 ACE_CDR::UInt8
&ref_
;
824 struct ACE_Export to_string
827 * @deprecated The constructor taking a non-const string is now
828 * deprecated (C++ mapping 00-01-02), but we keep it
829 * around for backward compatibility.
831 to_string (ACE_CDR::Char
*&s
,
833 to_string (const ACE_CDR::Char
*&s
,
835 const ACE_CDR::Char
*&val_
;
836 ACE_CDR::ULong bound_
;
839 struct ACE_Export to_wstring
841 /// The constructor taking a non-const wstring is
842 /// now deprecated (C++ mapping 00-01-02), but we
843 /// keep it around for backward compatibility.
844 to_wstring (ACE_CDR::WChar
*&ws
,
846 to_wstring (const ACE_CDR::WChar
*&ws
,
848 const ACE_CDR::WChar
*&val_
;
849 ACE_CDR::ULong bound_
;
852 /// Helper classes for extracting bounded strings into std::string/wstring.
853 struct ACE_Export to_std_string
855 to_std_string (std::string
&s
,
858 ACE_CDR::ULong bound_
;
861 #if !defined(ACE_LACKS_STD_WSTRING)
862 struct ACE_Export to_std_wstring
864 to_std_wstring (std::wstring
&ws
,
867 ACE_CDR::ULong bound_
;
869 #endif /* ACE_LACKS_STD_WSTRING */
873 * Return @c false on failure and @c true on success.
875 //@{ @name Read basic IDL types
876 ACE_CDR::Boolean
read_boolean (ACE_CDR::Boolean
& x
);
877 ACE_CDR::Boolean
read_char (ACE_CDR::Char
&x
);
878 ACE_CDR::Boolean
read_wchar (ACE_CDR::WChar
& x
);
879 ACE_CDR::Boolean
read_octet (ACE_CDR::Octet
& x
);
880 ACE_CDR::Boolean
read_short (ACE_CDR::Short
&x
);
881 ACE_CDR::Boolean
read_ushort (ACE_CDR::UShort
&x
);
882 ACE_CDR::Boolean
read_long (ACE_CDR::Long
&x
);
883 ACE_CDR::Boolean
read_ulong (ACE_CDR::ULong
&x
);
884 ACE_CDR::Boolean
read_longlong (ACE_CDR::LongLong
& x
);
885 ACE_CDR::Boolean
read_ulonglong (ACE_CDR::ULongLong
& x
);
886 ACE_CDR::Boolean
read_float (ACE_CDR::Float
&x
);
887 ACE_CDR::Boolean
read_double (ACE_CDR::Double
&x
);
888 ACE_CDR::Boolean
read_longdouble (ACE_CDR::LongDouble
&x
);
889 ACE_CDR::Boolean
read_fixed (ACE_CDR::Fixed
&x
);
890 ACE_CDR::Boolean
read_int8 (ACE_CDR::Int8
&x
);
891 ACE_CDR::Boolean
read_uint8 (ACE_CDR::UInt8
&x
);
893 ACE_CDR::Boolean
read_string (ACE_CDR::Char
*&x
);
894 ACE_CDR::Boolean
read_string (ACE_CString
&x
);
895 ACE_CDR::Boolean
read_wstring (ACE_CDR::WChar
*& x
);
896 ACE_CDR::Boolean
read_string (std::string
& x
);
897 #if !defined(ACE_LACKS_STD_WSTRING)
898 ACE_CDR::Boolean
read_wstring (std::wstring
& x
);
903 * The buffer @a x must be large enough to contain @a length
905 * Return @c false on failure and @c true on success.
907 //@{ @name Read basic IDL types arrays
908 ACE_CDR::Boolean
read_boolean_array (ACE_CDR::Boolean
* x
,
909 ACE_CDR::ULong length
);
910 ACE_CDR::Boolean
read_char_array (ACE_CDR::Char
*x
,
911 ACE_CDR::ULong length
);
912 ACE_CDR::Boolean
read_wchar_array (ACE_CDR::WChar
* x
,
913 ACE_CDR::ULong length
);
914 ACE_CDR::Boolean
read_octet_array (ACE_CDR::Octet
* x
,
915 ACE_CDR::ULong length
);
916 ACE_CDR::Boolean
read_short_array (ACE_CDR::Short
*x
,
917 ACE_CDR::ULong length
);
918 ACE_CDR::Boolean
read_ushort_array (ACE_CDR::UShort
*x
,
919 ACE_CDR::ULong length
);
920 ACE_CDR::Boolean
read_long_array (ACE_CDR::Long
*x
,
921 ACE_CDR::ULong length
);
922 ACE_CDR::Boolean
read_ulong_array (ACE_CDR::ULong
*x
,
923 ACE_CDR::ULong length
);
924 ACE_CDR::Boolean
read_longlong_array (ACE_CDR::LongLong
* x
,
925 ACE_CDR::ULong length
);
926 ACE_CDR::Boolean
read_ulonglong_array (ACE_CDR::ULongLong
* x
,
927 ACE_CDR::ULong length
);
928 ACE_CDR::Boolean
read_float_array (ACE_CDR::Float
*x
,
929 ACE_CDR::ULong length
);
930 ACE_CDR::Boolean
read_double_array (ACE_CDR::Double
*x
,
931 ACE_CDR::ULong length
);
932 ACE_CDR::Boolean
read_longdouble_array (ACE_CDR::LongDouble
* x
,
933 ACE_CDR::ULong length
);
934 ACE_CDR::Boolean
read_int8_array (ACE_CDR::Int8
*x
, ACE_CDR::ULong length
);
935 ACE_CDR::Boolean
read_uint8_array (ACE_CDR::UInt8
*x
, ACE_CDR::ULong length
);
939 * Return @c false on failure and @c true on success.
941 //@{ @name Skip elements
942 ACE_CDR::Boolean
skip_boolean ();
943 ACE_CDR::Boolean
skip_char ();
944 ACE_CDR::Boolean
skip_wchar ();
945 ACE_CDR::Boolean
skip_octet ();
946 ACE_CDR::Boolean
skip_short ();
947 ACE_CDR::Boolean
skip_ushort ();
948 ACE_CDR::Boolean
skip_long ();
949 ACE_CDR::Boolean
skip_ulong ();
950 ACE_CDR::Boolean
skip_longlong ();
951 ACE_CDR::Boolean
skip_ulonglong ();
952 ACE_CDR::Boolean
skip_float ();
953 ACE_CDR::Boolean
skip_double ();
954 ACE_CDR::Boolean
skip_longdouble ();
955 ACE_CDR::Boolean
skip_fixed ();
959 * The next field must be a string, this method skips it. It is
960 * useful in parsing a TypeCode.
961 * @return @c false on failure and @c true on success.
963 ACE_CDR::Boolean
skip_wstring ();
964 ACE_CDR::Boolean
skip_string ();
966 /// Skip @a n bytes in the CDR stream.
968 * @return @c false on failure and @c true on success.
970 ACE_CDR::Boolean
skip_bytes (size_t n
);
972 /// returns @c false if a problem has been detected.
973 bool good_bit () const;
976 * @return The start of the message block chain for this CDR
979 * @note In the current implementation the chain has length 1, but
980 * we are planning to change that.
982 const ACE_Message_Block
* start () const;
984 // = The following functions are useful to read the contents of the
985 // CDR stream from a socket or file.
988 * Grow the internal buffer, reset @c rd_ptr to the first byte in
989 * the new buffer that is properly aligned, and set @c wr_ptr to @c
990 * rd_ptr @c + @c newsize
992 int grow (size_t newsize
);
995 * After reading and partially parsing the contents the user can
996 * detect a change in the byte order, this method will let him/her
999 void reset_byte_order (int byte_order
);
1001 /// Re-initialize the CDR stream, copying the contents of the chain
1002 /// of message_blocks starting from @a data.
1003 void reset (const ACE_Message_Block
*data
,
1006 /// Steal the contents from the current CDR.
1007 ACE_Message_Block
*steal_contents ();
1009 /// Steal the contents of @a cdr and make a shallow copy into this
1011 void steal_from (ACE_InputCDR
&cdr
);
1013 /// Exchange data blocks with the caller of this method. The read
1014 /// and write pointers are also exchanged.
1016 * @note We now do only with the start_ message block.
1018 void exchange_data_blocks (ACE_InputCDR
&cdr
);
1020 /// Copy the data portion from the @a cdr to this cdr and return the
1021 /// data content (ie. the ACE_Data_Block) from this CDR to the
1024 * @note The caller is responsible for managing the memory of the
1025 * returned ACE_Data_Block.
1027 ACE_Data_Block
* clone_from (ACE_InputCDR
&cdr
);
1029 /// Re-initialize the CDR stream, forgetting about the old contents
1030 /// of the stream and allocating a new buffer (from the allocators).
1031 void reset_contents ();
1033 /// Returns the current position for the @c rd_ptr.
1036 /// Returns the current position for the @c wr_ptr.
1039 /// Return how many bytes are left in the stream.
1040 size_t length () const;
1043 * Utility function to allow the user more flexibility.
1044 * Skips up to the nearest @a alignment-byte boundary.
1045 * Argument MUST be a power of 2.
1047 * @return 0 on success and -1 on failure.
1049 int align_read_ptr (size_t alignment
);
1051 /// If @c true then this stream is writing in non-native byte order.
1052 /// This is only meaningful if ACE_ENABLE_SWAP_ON_WRITE is defined.
1053 bool do_byte_swap () const;
1055 /// If @c do_byte_swap() returns @c false, this returns
1056 /// ACE_CDR_BYTE_ORDER else it returns !ACE_CDR_BYTE_ORDER.
1057 int byte_order () const;
1059 /// Access the codeset translators. They can be nil!
1060 ACE_Char_Codeset_Translator
*char_translator () const;
1061 ACE_WChar_Codeset_Translator
*wchar_translator () const;
1063 /// Set the codeset translators.
1064 void char_translator (ACE_Char_Codeset_Translator
*);
1065 void wchar_translator (ACE_WChar_Codeset_Translator
*);
1068 * Returns (in @a buf) the next position in the buffer aligned to
1069 * @a size. It advances the Message_Block @c rd_ptr past the data
1070 * (i.e., @c buf @c + @c size). Sets the good_bit to @c false and
1071 * returns a -1 on failure.
1073 int adjust (size_t size
,
1076 /// As above, but now the size and alignment requirements may be
1078 int adjust (size_t size
,
1082 /// Set the underlying GIOP version..
1083 void set_version (ACE_CDR::Octet major
, ACE_CDR::Octet minor
);
1085 /// Set the underlying GIOP version..
1086 void get_version (ACE_CDR::Octet
&major
, ACE_CDR::Octet
&minor
);
1088 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1089 /// Register and unregister our buffer size monitor.
1090 void register_monitor (const char* id
);
1091 void unregister_monitor ();
1092 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1095 /// The start of the chain of message blocks, even though in the
1096 /// current version the chain always has length 1.
1097 ACE_Message_Block start_
;
1099 /// The CDR stream byte order does not match the one on the machine,
1100 /// swapping is needed while reading.
1103 /// set to @c false when an error occurs.
1106 /// The GIOP versions for this stream
1107 ACE_CDR::Octet major_version_
;
1108 ACE_CDR::Octet minor_version_
;
1110 /// If not nil, invoke for translation of character and string data.
1111 ACE_Char_Codeset_Translator
*char_translator_
;
1112 ACE_WChar_Codeset_Translator
*wchar_translator_
;
1114 #if defined (ACE_HAS_MONITOR_POINTS) && (ACE_HAS_MONITOR_POINTS == 1)
1115 ACE::Monitor_Control::Size_Monitor
*monitor_
;
1116 #endif /* ACE_HAS_MONITOR_POINTS==1 */
1119 ACE_CDR::Boolean
read_1 (ACE_CDR::Octet
*x
);
1120 ACE_CDR::Boolean
read_2 (ACE_CDR::UShort
*x
);
1121 ACE_CDR::Boolean
read_4 (ACE_CDR::ULong
*x
);
1122 ACE_CDR::Boolean
read_8 (ACE_CDR::ULongLong
*x
);
1123 ACE_CDR::Boolean
read_16 (ACE_CDR::LongDouble
*x
);
1125 // Several types can be read using the same routines, since TAO
1126 // tries to use native types with known size for each CORBA type.
1127 // We could use void* or char* to make the interface more
1128 // consistent, but using native types let us exploit the strict
1129 // alignment requirements of CDR streams and implement the
1130 // operations using assignment.
1133 * Read an array of @a length elements, each of @a size bytes and the
1134 * start aligned at a multiple of @a align. The elements are assumed
1135 * to be packed with the right alignment restrictions. It is mostly
1136 * designed for buffers of the basic types.
1138 * This operation uses @c memcpy; as explained above it is expected
1139 * that using assignment is faster that @c memcpy for one element,
1140 * but for several elements @c memcpy should be more efficient, it
1141 * could be interesting to find the break even point and optimize
1142 * for that case, but that would be too platform dependent.
1144 ACE_CDR::Boolean
read_array (void* x
,
1147 ACE_CDR::ULong length
);
1150 * On those occasions when the native codeset for wchar is smaller than
1151 * the size of a wchar_t, such as using UTF-16 with a 4-byte wchar_t, a
1152 * special form of reading the array is needed. Actually, this should be
1153 * a default translator.
1155 ACE_CDR::Boolean
read_wchar_array_i (ACE_CDR::WChar
* x
,
1156 ACE_CDR::ULong length
);
1158 /// Move the rd_ptr ahead by @a offset bytes.
1159 void rd_ptr (size_t offset
);
1161 /// Points to the continuation field of the current message block.
1165 // ****************************************************************
1168 * @class ACE_Char_Codeset_Translator
1170 * @brief Codeset translation routines common to both Output and Input
1173 * This class is a base class for defining codeset translation
1174 * routines to handle the character set translations required by
1175 * both CDR Input streams and CDR Output streams.
1177 * Translators are reference counted. This allows for stateful as well
1178 * as stateless translators. Stateless translators will be allocated
1179 * once whereas CDR Streams own their own copy of a stateful translator.
1181 class ACE_Export ACE_Char_Codeset_Translator
1184 virtual ~ACE_Char_Codeset_Translator () = default;
1186 /// Read a single character from the stream, converting from the
1187 /// stream codeset to the native codeset
1188 virtual ACE_CDR::Boolean
read_char (ACE_InputCDR
&,
1189 ACE_CDR::Char
&) = 0;
1191 /// Read a string from the stream, including the length, converting
1192 /// the characters from the stream codeset to the native codeset
1193 virtual ACE_CDR::Boolean
read_string (ACE_InputCDR
&,
1194 ACE_CDR::Char
*&) = 0;
1196 /// Read a std::string from the stream, including the length, converting
1197 /// the characters from the stream codeset to the native codeset
1198 /// (provide non-optimized default implementation)
1199 virtual ACE_CDR::Boolean
read_string (ACE_InputCDR
&,
1202 /// Read an array of characters from the stream, converting the
1203 /// characters from the stream codeset to the native codeset.
1204 virtual ACE_CDR::Boolean
read_char_array (ACE_InputCDR
&,
1206 ACE_CDR::ULong
) = 0;
1208 /// Write a single character to the stream, converting from the
1209 /// native codeset to the stream codeset
1210 virtual ACE_CDR::Boolean
write_char (ACE_OutputCDR
&,
1213 /// Write a string to the stream, including the length, converting
1214 /// from the native codeset to the stream codeset
1215 virtual ACE_CDR::Boolean
write_string (ACE_OutputCDR
&,
1217 const ACE_CDR::Char
*) = 0;
1219 /// Write an array of characters to the stream, converting from the
1220 /// native codeset to the stream codeset
1221 virtual ACE_CDR::Boolean
write_char_array (ACE_OutputCDR
&,
1222 const ACE_CDR::Char
*,
1223 ACE_CDR::ULong
) = 0;
1225 virtual ACE_CDR::ULong
ncs () = 0;
1226 virtual ACE_CDR::ULong
tcs () = 0;
1228 /// Children have access to low-level routines because they cannot
1229 /// use read_char or something similar (it would recurse).
1230 ACE_CDR::Boolean
read_1 (ACE_InputCDR
& input
,
1232 ACE_CDR::Boolean
write_1 (ACE_OutputCDR
& output
,
1233 const ACE_CDR::Octet
*x
);
1235 /// Efficiently read @a length elements of size @a size each from
1236 /// @a input into @a x; the data must be aligned to @a align.
1237 ACE_CDR::Boolean
read_array (ACE_InputCDR
& input
,
1241 ACE_CDR::ULong length
);
1244 * Efficiently write @a length elements of size @a size from <x> into
1245 * <output>. Before inserting the elements enough padding is added
1246 * to ensure that the elements will be aligned to <align> in the
1249 ACE_CDR::Boolean
write_array (ACE_OutputCDR
& output
,
1253 ACE_CDR::ULong length
);
1256 * Exposes the stream implementation of <adjust>, this is useful in
1257 * many cases to minimize memory allocations during marshaling.
1258 * On success @a buf will contain a contiguous area in the CDR stream
1259 * that can hold @a size bytes aligned to @a align.
1262 int adjust (ACE_OutputCDR
& out
,
1267 /// Used by derived classes to set errors in the CDR stream.
1268 void good_bit (ACE_OutputCDR
& out
, bool bit
);
1270 /// Obtain the CDR Stream's major & minor version values.
1271 ACE_CDR::Octet
major_version (ACE_InputCDR
& input
);
1272 ACE_CDR::Octet
minor_version (ACE_InputCDR
& input
);
1273 ACE_CDR::Octet
major_version (ACE_OutputCDR
& output
);
1274 ACE_CDR::Octet
minor_version (ACE_OutputCDR
& output
);
1277 // ****************************************************************
1280 * @class ACE_WChar_Codeset_Translator
1282 * @brief Codeset translation routines common to both Output and Input
1285 * This class is a base class for defining codeset translation
1286 * routines to handle the character set translations required by
1287 * both CDR Input streams and CDR Output streams.
1289 class ACE_Export ACE_WChar_Codeset_Translator
1292 virtual ~ACE_WChar_Codeset_Translator () = default;
1294 virtual ACE_CDR::Boolean
read_wchar (ACE_InputCDR
&,
1295 ACE_CDR::WChar
&) = 0;
1296 virtual ACE_CDR::Boolean
read_wstring (ACE_InputCDR
&,
1297 ACE_CDR::WChar
*&) = 0;
1298 #if !defined(ACE_LACKS_STD_WSTRING)
1299 /// Read a std::wstring from the stream, including the length, converting
1300 /// the characters from the stream codeset to the native codeset
1301 /// (provide non-optimized default implementation)
1302 virtual ACE_CDR::Boolean
read_wstring (ACE_InputCDR
&,
1305 virtual ACE_CDR::Boolean
read_wchar_array (ACE_InputCDR
&,
1307 ACE_CDR::ULong
) = 0;
1308 virtual ACE_CDR::Boolean
write_wchar (ACE_OutputCDR
&,
1309 ACE_CDR::WChar
) = 0;
1310 virtual ACE_CDR::Boolean
write_wstring (ACE_OutputCDR
&,
1312 const ACE_CDR::WChar
*) = 0;
1313 virtual ACE_CDR::Boolean
write_wchar_array (ACE_OutputCDR
&,
1314 const ACE_CDR::WChar
*,
1315 ACE_CDR::ULong
) = 0;
1317 virtual ACE_CDR::ULong
ncs () = 0;
1318 virtual ACE_CDR::ULong
tcs () = 0;
1320 /// Children have access to low-level routines because they cannot
1321 /// use read_char or something similar (it would recurse).
1322 ACE_CDR::Boolean
read_1 (ACE_InputCDR
& input
,
1324 ACE_CDR::Boolean
read_2 (ACE_InputCDR
& input
,
1325 ACE_CDR::UShort
*x
);
1326 ACE_CDR::Boolean
read_4 (ACE_InputCDR
& input
,
1328 ACE_CDR::Boolean
write_1 (ACE_OutputCDR
& output
,
1329 const ACE_CDR::Octet
*x
);
1330 ACE_CDR::Boolean
write_2 (ACE_OutputCDR
& output
,
1331 const ACE_CDR::UShort
*x
);
1332 ACE_CDR::Boolean
write_4 (ACE_OutputCDR
& output
,
1333 const ACE_CDR::ULong
*x
);
1335 /// Efficiently read @a length elements of size @a size each from
1336 /// @a input into @a x; the data must be aligned to @a align.
1337 ACE_CDR::Boolean
read_array (ACE_InputCDR
& input
,
1341 ACE_CDR::ULong length
);
1344 * Efficiently write @a length elements of size @a size from @a x into
1345 * @a output. Before inserting the elements enough padding is added
1346 * to ensure that the elements will be aligned to @a align in the
1349 ACE_CDR::Boolean
write_array (ACE_OutputCDR
& output
,
1353 ACE_CDR::ULong length
);
1356 * Exposes the stream implementation of @a adjust, this is useful in
1357 * many cases to minimize memory allocations during marshaling.
1358 * On success @a buf will contain a contiguous area in the CDR stream
1359 * that can hold @a size bytes aligned to @a align.
1362 int adjust (ACE_OutputCDR
& out
,
1367 /// Used by derived classes to set errors in the CDR stream.
1368 void good_bit (ACE_OutputCDR
& out
, bool bit
);
1370 /// Obtain the CDR Stream's major & minor version values.
1371 ACE_CDR::Octet
major_version (ACE_InputCDR
& input
);
1372 ACE_CDR::Octet
minor_version (ACE_InputCDR
& input
);
1373 ACE_CDR::Octet
major_version (ACE_OutputCDR
& output
);
1374 ACE_CDR::Octet
minor_version (ACE_OutputCDR
& output
);
1377 // @@ These operators should not be inlined since they force SString.h
1378 // to be included in this header.
1379 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1380 const ACE_CString
&x
);
1382 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1386 ACE_END_VERSIONED_NAMESPACE_DECL
1388 #if defined (__ACE_INLINE__)
1389 # include "ace/CDR_Stream.inl"
1390 #else /* __ACE_INLINE__ */
1392 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1394 // Not used by CORBA or TAO
1395 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1397 // CDR output operators for primitive types
1399 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1401 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1403 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1405 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1407 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1408 ACE_CDR::LongLong x
);
1409 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1410 ACE_CDR::ULongLong x
);
1411 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
& os
,
1412 ACE_CDR::LongDouble x
);
1413 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1415 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1417 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1418 const ACE_CDR::Fixed
&x
);
1420 // CDR output operator from helper classes
1422 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1423 ACE_OutputCDR::from_boolean x
);
1424 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1425 ACE_OutputCDR::from_char x
);
1426 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1427 ACE_OutputCDR::from_wchar x
);
1428 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1429 ACE_OutputCDR::from_octet x
);
1430 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1431 ACE_OutputCDR::from_string x
);
1432 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1433 ACE_OutputCDR::from_wstring x
);
1434 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1435 const ACE_CDR::Char
* x
);
1436 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1437 const ACE_CDR::WChar
* x
);
1438 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1439 ACE_OutputCDR::from_std_string x
);
1440 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1441 const std::string
& x
);
1442 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1443 const std::string_view
& x
);
1444 #if !defined(ACE_LACKS_STD_WSTRING)
1445 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1446 ACE_OutputCDR::from_std_wstring x
);
1447 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
,
1448 const std::wstring
& x
);
1450 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
, ACE_OutputCDR::from_uint8 x
);
1451 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_OutputCDR
&os
, ACE_OutputCDR::from_int8 x
);
1453 // Not used by CORBA or TAO
1454 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1456 // CDR input operators for primitive types
1458 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1460 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1461 ACE_CDR::UShort
&x
);
1462 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1464 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1466 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1467 ACE_CDR::LongLong
&x
);
1468 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1469 ACE_CDR::ULongLong
&x
);
1470 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1471 ACE_CDR::LongDouble
&x
);
1472 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1474 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1475 ACE_CDR::Double
&x
);
1476 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1479 // CDR input operator from helper classes
1481 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1482 ACE_InputCDR::to_boolean x
);
1483 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1484 ACE_InputCDR::to_char x
);
1485 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1486 ACE_InputCDR::to_wchar x
);
1487 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1488 ACE_InputCDR::to_octet x
);
1489 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1490 ACE_InputCDR::to_string x
);
1491 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1492 ACE_InputCDR::to_wstring x
);
1493 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1495 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1496 ACE_CDR::WChar
*& x
);
1497 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_InputCDR
&os
,
1498 ACE_InputCDR::to_std_string x
);
1499 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1501 #if !defined(ACE_LACKS_STD_WSTRING)
1502 extern ACE_Export
ACE_CDR::Boolean
operator<< (ACE_InputCDR
&os
,
1503 ACE_InputCDR::to_std_wstring x
);
1504 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&is
,
1507 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&os
, ACE_InputCDR::to_uint8 x
);
1508 extern ACE_Export
ACE_CDR::Boolean
operator>> (ACE_InputCDR
&os
, ACE_InputCDR::to_int8 x
);
1510 ACE_END_VERSIONED_NAMESPACE_DECL
1512 #endif /* __ACE_INLINE__ */
1514 #if defined (GEN_OSTREAM_OPS)
1516 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
1518 // ostream insertion operators for debugging code generated from IDL. All
1519 // but these below are either in generated code itself or are unambiguous
1522 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1523 ACE_OutputCDR::from_boolean x
);
1525 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1526 ACE_OutputCDR::from_char x
);
1528 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1529 ACE_OutputCDR::from_wchar x
);
1531 ACE_Export
std::ostream
& operator<< (std::ostream
&os
,
1532 ACE_OutputCDR::from_octet x
);
1534 ACE_END_VERSIONED_NAMESPACE_DECL
1536 #endif /* GEN_OSTREAM_OPS */
1538 #include /**/ "ace/post.h"
1540 #endif /* ACE_CDR_STREAM_H */