## NAME

ACE_OutputCDR - A CDR stream for writing, i.e. for marshalling.

## SYNOPSIS

    #include <ace/CDR_Stream.h>

    class ACE_OutputCDR
    {
      public:
        friend class ACE_Char_Codeset_Translator;
        friend class ACE_WChar_Codeset_Translator;
        friend class ACE_InputCDR;
        ACE_OutputCDR (
            size_t size = 0,
            int byte_order = ACE_CDR_BYTE_ORDER,
            ACE_Allocator* buffer_allocator = 0,
            ACE_Allocator* data_block_allocator = 0,
            size_t memcpy_tradeoff = ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
            );
        ACE_OutputCDR (
            char *data,
            size_t size,
            int byte_order = ACE_CDR_BYTE_ORDER,
            ACE_Allocator* buffer_allocator = 0,
            ACE_Allocator* data_block_allocator = 0,
            size_t memcpy_tradeoff= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
            );
        ACE_OutputCDR (
            ACE_Message_Block *data,
            int byte_order = ACE_CDR_BYTE_ORDER,
            size_t memcpy_tradeoff= ACE_DEFAULT_CDR_MEMCPY_TRADEOFF
            );
        ~ACE_OutputCDR (void);

        struct ACE_Export from_boolean
        {
          public:
            from_boolean (ACE_CDR::Boolean b);
            ACE_CDR::Boolean val_;
        };

`ACE_CDR::Boolean write_boolean (ACE_CDR::Boolean x);` `ACE_CDR::Boolean write_char (ACE_CDR::Char x);` `ACE_CDR::Boolean write_wchar (ACE_CDR::WChar x);` `ACE_CDR::Boolean write_octet (ACE_CDR::Octet x);` `ACE_CDR::Boolean write_short (ACE_CDR::Short x);` `ACE_CDR::Boolean write_ushort (ACE_CDR::UShort x);` `ACE_CDR::Boolean write_long (ACE_CDR::Long x);` `ACE_CDR::Boolean write_ulong (ACE_CDR::ULong x);` `ACE_CDR::Boolean write_longlong (const ACE_CDR::LongLong &x);` `ACE_CDR::Boolean write_ulonglong (const ACE_CDR::ULongLong &x);` `ACE_CDR::Boolean write_float (ACE_CDR::Float x);` `ACE_CDR::Boolean write_double (const ACE_CDR::Double &x);` `ACE_CDR::Boolean write_longdouble (const ACE_CDR::LongDouble &x);` `ACE_CDR::Boolean write_string (const ACE_CDR::Char *x);` `ACE_CDR::Boolean write_string ( ACE_CDR::ULong len, const ACE_CDR::Char *x );` `ACE_CDR::Boolean write_string (const ACE_CString &x);` `ACE_CDR::Boolean write_wstring (const ACE_CDR::WChar *x);` `ACE_CDR::Boolean write_wstring ( ACE_CDR::ULong length, const ACE_CDR::WChar *x );` `ACE_CDR::Boolean write_boolean_array ( const ACE_CDR::Boolean *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_char_array ( const ACE_CDR::Char *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_wchar_array ( const ACE_CDR::WChar* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_octet_array ( const ACE_CDR::Octet* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_short_array ( const ACE_CDR::Short *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_ushort_array ( const ACE_CDR::UShort *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_long_array ( const ACE_CDR::Long *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_ulong_array ( const ACE_CDR::ULong *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_longlong_array ( const ACE_CDR::LongLong* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_ulonglong_array ( const ACE_CDR::ULongLong *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_float_array ( const ACE_CDR::Float *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_double_array ( const ACE_CDR::Double *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_longdouble_array ( const ACE_CDR::LongDouble* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean write_octet_array_mb ( const ACE_Message_Block* mb );` `ACE_CDR::Boolean append_boolean (ACE_InputCDR &);` `ACE_CDR::Boolean append_char (ACE_InputCDR &);` `ACE_CDR::Boolean append_wchar (ACE_InputCDR &);` `ACE_CDR::Boolean append_octet (ACE_InputCDR &);` `ACE_CDR::Boolean append_short (ACE_InputCDR &);` `ACE_CDR::Boolean append_ushort (ACE_InputCDR &);` `ACE_CDR::Boolean append_long (ACE_InputCDR &);` `ACE_CDR::Boolean append_ulong (ACE_InputCDR &);` `ACE_CDR::Boolean append_longlong (ACE_InputCDR &);` `ACE_CDR::Boolean append_ulonglong (ACE_InputCDR &);` `ACE_CDR::Boolean append_float (ACE_InputCDR &);` `ACE_CDR::Boolean append_double (ACE_InputCDR &);` `ACE_CDR::Boolean append_longdouble (ACE_InputCDR &);` `ACE_CDR::Boolean append_wstring (ACE_InputCDR &);` `ACE_CDR::Boolean append_string (ACE_InputCDR &);` `int good_bit (void) const;` `void reset (void);` `size_t total_length (void) const;` `const ACE_Message_Block *begin (void) const;` `const ACE_Message_Block *end (void) const;` `const ACE_Message_Block *current (void) const;` `const char *buffer (void) const;` `size_t length (void) const;` `int align_write_ptr (size_t alignment);` `ACE_Char_Codeset_Translator *char_translator (void) const;` `ACE_WChar_Codeset_Translator *wchar_translator (void) const;` `protected:` `ACE_Char_Codeset_Translator *char_translator_;` `ACE_WChar_Codeset_Translator *wchar_translator_;` `private:` `ACE_OutputCDR (const ACE_OutputCDR& rhs);` `ACE_OutputCDR& operator= (const ACE_OutputCDR& rhs);` `ACE_CDR::Boolean write_1 (const ACE_CDR::Octet *x);` `ACE_CDR::Boolean write_2 (const ACE_CDR::UShort *x);` `ACE_CDR::Boolean write_4 (const ACE_CDR::ULong *x);` `ACE_CDR::Boolean write_8 (const ACE_CDR::ULongLong *x);` `ACE_CDR::Boolean write_16 (const ACE_CDR::LongDouble *x);` `ACE_CDR::Boolean write_array ( const void *x, size_t size, size_t align, ACE_CDR::ULong length );` `int adjust (size_t size, char *&buf);` `int adjust (size_t size, size_t align, char *&buf);` `int grow_and_adjust (size_t size, size_t align, char *&buf);` `int do_byte_swap (void) const;` `ACE_Message_Block start_;` `ACE_Message_Block *current_;` `int do_byte_swap_;` `int good_bit_;` `size_t memcpy_tradeoff_;` `};`

## DESCRIPTION

ACE Common Data Representation (CDR) marshaling and demarshaling classes.

This implementation was inspired in the CDR class in SunSoft's IIOP engine, but has a completely different implementation and a different interface too.

The current implementation assumes that the host has 1-byte, 2-byte and 4-byte integral types, and that it has single precision and double precision IEEE floats. Those assumptions are pretty good these days, with Crays beign the only known exception.

## Special types.

These are needed for insertion and extraction of booleans, octets, chars, and bounded strings.

## We have one method per basic IDL type....

They return 0 on failure and 1 on success.

    ACE_CDR::Boolean write_boolean (ACE_CDR::Boolean x);

    ACE_CDR::Boolean write_char (ACE_CDR::Char x);

    ACE_CDR::Boolean write_wchar (ACE_CDR::WChar x);

    ACE_CDR::Boolean write_octet (ACE_CDR::Octet x);

    ACE_CDR::Boolean write_short (ACE_CDR::Short x);

    ACE_CDR::Boolean write_ushort (ACE_CDR::UShort x);

    ACE_CDR::Boolean write_long (ACE_CDR::Long x);

    ACE_CDR::Boolean write_ulong (ACE_CDR::ULong x);

    ACE_CDR::Boolean write_longlong (const ACE_CDR::LongLong &x);

    ACE_CDR::Boolean write_ulonglong (const ACE_CDR::ULongLong &x);

    ACE_CDR::Boolean write_float (ACE_CDR::Float x);

    ACE_CDR::Boolean write_double (const ACE_CDR::Double &x);

    ACE_CDR::Boolean write_longdouble (const ACE_CDR::LongDouble &x);

## For string we offer methods that accept a precomputed length.

    ACE_CDR::Boolean write_string (const ACE_CDR::Char *x);

    ACE_CDR::Boolean write_string (
        ACE_CDR::ULong len,
        const ACE_CDR::Char *x
        );

    ACE_CDR::Boolean write_string (const ACE_CString &x);

    ACE_CDR::Boolean write_wstring (const ACE_CDR::WChar *x);

    ACE_CDR::Boolean write_wstring (
        ACE_CDR::ULong length,
        const ACE_CDR::WChar *x
        );

## We add one method to write arrays of basic IDL types.

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

    ACE_CDR::Boolean write_boolean_array (
        const ACE_CDR::Boolean *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_char_array (
        const ACE_CDR::Char *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_wchar_array (
        const ACE_CDR::WChar* x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_octet_array (
        const ACE_CDR::Octet* x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_short_array (
        const ACE_CDR::Short *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_ushort_array (
        const ACE_CDR::UShort *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_long_array (
        const ACE_CDR::Long *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_ulong_array (
        const ACE_CDR::ULong *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_longlong_array (
        const ACE_CDR::LongLong* x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_ulonglong_array (
        const ACE_CDR::ULongLong *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_float_array (
        const ACE_CDR::Float *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_double_array (
        const ACE_CDR::Double *x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_longdouble_array (
        const ACE_CDR::LongDouble* x,
        ACE_CDR::ULong length
        );

    ACE_CDR::Boolean write_octet_array_mb (const ACE_Message_Block* mb);

Write an octet array contained inside a MB, this can be optimized to minimize copies.

## AUTHORS

Aniruddha Gokhale `gokhale@cs.wustl.edu` and Carlos O'Ryan `coryan@cs.wustl.edu` for the original implementation in TAO. ACE version by Jeff Parsons `parsons@cs.wustl.edu` and Istvan Buki `istvan.buki@euronet.be`. Codeset translation by Jim Rogers (jrogers@viasoft.com) and Carlos O'Ryan `coryan@cs.wustl.edu`

## LIBRARY

ace