## NAME

ACE_InputCDR - A CDR stream for reading, i.e. for demarshalling.

## SYNOPSIS

    #include <ace/CDR_Stream.h>

    class ACE_InputCDR
    {
      public:
        friend class ACE_Char_Codeset_Translator;
        friend class ACE_WChar_Codeset_Translator;
        ACE_InputCDR (
            const char *buf,
            size_t bufsiz,
            int byte_order = ACE_CDR_BYTE_ORDER
            );
        ACE_InputCDR (size_t bufsiz, int byte_order = ACE_CDR_BYTE_ORDER);
        ACE_InputCDR (
            const ACE_Message_Block *data,
            int byte_order = ACE_CDR_BYTE_ORDER
            );
        ACE_InputCDR (
            ACE_Data_Block *data,
            int byte_order = ACE_CDR_BYTE_ORDER
            );
        ACE_InputCDR (const ACE_InputCDR& rhs);
        ACE_InputCDR& operator= (const ACE_InputCDR& rhs);
        ACE_InputCDR (
            const ACE_InputCDR& rhs,
            size_t size,
            ACE_CDR::Long offset
            );
        ACE_InputCDR (const ACE_InputCDR& rhs, size_t size);
        ACE_InputCDR (
            const ACE_OutputCDR& rhs,
            ACE_Allocator* buffer_allocator = 0,
            ACE_Allocator* data_block_allocator = 0
            );
        ~ACE_InputCDR (void);

        struct ACE_Export to_boolean
        {
          public:
            to_boolean (ACE_CDR::Boolean &b);
            ACE_CDR::Boolean &ref_;
        };

`ACE_CDR::Boolean read_boolean (ACE_CDR::Boolean& x);` `ACE_CDR::Boolean read_char (ACE_CDR::Char &x);` `ACE_CDR::Boolean read_wchar (ACE_CDR::WChar& x);` `ACE_CDR::Boolean read_octet (ACE_CDR::Octet& x);` `ACE_CDR::Boolean read_short (ACE_CDR::Short &x);` `ACE_CDR::Boolean read_ushort (ACE_CDR::UShort &x);` `ACE_CDR::Boolean read_long (ACE_CDR::Long &x);` `ACE_CDR::Boolean read_ulong (ACE_CDR::ULong &x);` `ACE_CDR::Boolean read_longlong (ACE_CDR::LongLong& x);` `ACE_CDR::Boolean read_ulonglong (ACE_CDR::ULongLong& x);` `ACE_CDR::Boolean read_float (ACE_CDR::Float &x);` `ACE_CDR::Boolean read_double (ACE_CDR::Double &x);` `ACE_CDR::Boolean read_longdouble (ACE_CDR::LongDouble &x);` `ACE_CDR::Boolean read_string (ACE_CDR::Char *&x);` `ACE_CDR::Boolean read_string (ACE_CString &x);` `ACE_CDR::Boolean read_wstring (ACE_CDR::WChar*& x);` `ACE_CDR::Boolean read_boolean_array ( ACE_CDR::Boolean* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_char_array ( ACE_CDR::Char *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_wchar_array ( ACE_CDR::WChar* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_octet_array ( ACE_CDR::Octet* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_short_array ( ACE_CDR::Short *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_ushort_array ( ACE_CDR::UShort *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_long_array ( ACE_CDR::Long *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_ulong_array ( ACE_CDR::ULong *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_longlong_array ( ACE_CDR::LongLong* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_ulonglong_array ( ACE_CDR::ULongLong* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_float_array ( ACE_CDR::Float *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_double_array ( ACE_CDR::Double *x, ACE_CDR::ULong length );` `ACE_CDR::Boolean read_longdouble_array ( ACE_CDR::LongDouble* x, ACE_CDR::ULong length );` `ACE_CDR::Boolean skip_boolean (void);` `ACE_CDR::Boolean skip_char (void);` `ACE_CDR::Boolean skip_wchar (void);` `ACE_CDR::Boolean skip_octet (void);` `ACE_CDR::Boolean skip_short (void);` `ACE_CDR::Boolean skip_ushort (void);` `ACE_CDR::Boolean skip_long (void);` `ACE_CDR::Boolean skip_ulong (void);` `ACE_CDR::Boolean skip_longlong (void);` `ACE_CDR::Boolean skip_ulonglong (void);` `ACE_CDR::Boolean skip_float (void);` `ACE_CDR::Boolean skip_double (void);` `ACE_CDR::Boolean skip_longdouble (void);` `ACE_CDR::Boolean skip_wstring (void);` `ACE_CDR::Boolean skip_string (void);` `ACE_CDR::Boolean skip_bytes (size_t n);` `int good_bit (void) const;` `const ACE_Message_Block* start (void) const;` `int grow (size_t newsize);` `void reset_byte_order (int byte_order);` `void reset (const ACE_Message_Block *data, int byte_order);` `ACE_Message_Block *steal_contents (void);` `void steal_from (ACE_InputCDR &cdr);` `void reset_contents (void);` `char* rd_ptr (void);` `size_t length (void) const;` `int align_read_ptr (size_t alignment);` `int do_byte_swap (void) const;` `int byte_order (void) const;` `ACE_Char_Codeset_Translator *char_translator (void) const;` `ACE_WChar_Codeset_Translator *wchar_translator (void) const;` `protected:` `ACE_Message_Block start_;` `int do_byte_swap_;` `int good_bit_;` `ACE_Char_Codeset_Translator *char_translator_;` `ACE_WChar_Codeset_Translator *wchar_translator_;` `private:` `ACE_CDR::Boolean read_1 (ACE_CDR::Octet *x);` `ACE_CDR::Boolean read_2 (ACE_CDR::UShort *x);` `ACE_CDR::Boolean read_4 (ACE_CDR::ULong *x);` `ACE_CDR::Boolean read_8 (ACE_CDR::ULongLong *x);` `ACE_CDR::Boolean read_16 (ACE_CDR::LongDouble *x);` `ACE_CDR::Boolean read_array ( void* x, size_t size, size_t align, ACE_CDR::ULong length );` `void rd_ptr (size_t offset);` `char* end (void);` `int adjust (size_t size, char *&buf);` `int adjust (size_t size, size_t align, char *&buf);` `};`

## 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 extract octets, chars, booleans, and bounded strings

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

They return 0 on failure and 1 on success.

    ACE_CDR::Boolean read_boolean (ACE_CDR::Boolean& x);

    ACE_CDR::Boolean read_char (ACE_CDR::Char &x);

    ACE_CDR::Boolean read_wchar (ACE_CDR::WChar& x);

    ACE_CDR::Boolean read_octet (ACE_CDR::Octet& x);

    ACE_CDR::Boolean read_short (ACE_CDR::Short &x);

    ACE_CDR::Boolean read_ushort (ACE_CDR::UShort &x);

    ACE_CDR::Boolean read_long (ACE_CDR::Long &x);

    ACE_CDR::Boolean read_ulong (ACE_CDR::ULong &x);

    ACE_CDR::Boolean read_longlong (ACE_CDR::LongLong& x);

    ACE_CDR::Boolean read_ulonglong (ACE_CDR::ULongLong& x);

    ACE_CDR::Boolean read_float (ACE_CDR::Float &x);

    ACE_CDR::Boolean read_double (ACE_CDR::Double &x);

    ACE_CDR::Boolean read_longdouble (ACE_CDR::LongDouble &x);

    ACE_CDR::Boolean read_string (ACE_CDR::Char *&x);

    ACE_CDR::Boolean read_string (ACE_CString &x);

    ACE_CDR::Boolean read_wstring (ACE_CDR::WChar*& x);

## One method for each basic type...

The buffer `x` must be large enough to contain `length` elements. They return -1 on failure and 0 on success.

    ACE_CDR::Boolean read_boolean_array (
        ACE_CDR::Boolean* x,
        ACE_CDR::ULong length
        );

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

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

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

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

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

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

    ACE_CDR::Boolean read_ulong_array (
        ACE_CDR::ULong *x,
        ACE_CDR::ULong length
        );

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

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

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

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

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

## The following functions are useful to read the contents of the

CDR stream from a socket or file.

    int grow (size_t newsize);

Grow the internal buffer, reset rd_ptr() to the first byte in the new buffer that is properly aligned, and set wr_ptr() to rd_ptr() + newsize

    void reset_byte_order (int byte_order);

After reading and partially parsing the contents the user can detect a change in the byte order, this method will let him change it.

    void reset (const ACE_Message_Block *data, int byte_order);

Re-initialize the CDR stream, copying the contents of the chain of message_blocks starting from `data`.

    ACE_Message_Block *steal_contents (void);

Steal the contents from the currect CDR.

    void steal_from (ACE_InputCDR &cdr);

Steal the contents of `cdr` and make a shallow copy into this stream.

    void reset_contents (void);

Re-initialize the CDR stream, forgetting about the old contents of the stream and allocating a new buffer (from the allocators).

    char* rd_ptr (void);

Returns the current position for the rd_ptr....

    size_t length (void) const;

Return how many bytes are left in the stream.

    int align_read_ptr (size_t alignment);

Utility function to allow the user more flexibility. Skips up to the nearest `alignment`-byte boundary. Argument MUST be a power of 2. Returns 0 on success and -1 on failure.

    int do_byte_swap (void) const;

If non-zero then this stream is writing in non-native byte order, this is only meaningful if ACE_ENABLE_SWAP_ON_WRITE is defined.

    int byte_order (void) const;

If `do_byte_swap` returns 1, this returns ACE_CDR_BYTE_ORDER else it returns ~ACE_CDR_BYTE_ORDER.

    ACE_Char_Codeset_Translator *char_translator (void) const;

    ACE_WChar_Codeset_Translator *wchar_translator (void) const;

Access the codeset translators. They can be nil!

## 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