Previous Table of Contents Next


5.5.2 Marshaling Streams


   The streams used for marshaling are defined below. They are responsible for marshaling and demarshaling the data that makes up a custom value in CDR format.

   module CORBA {

   typedef sequence<any> AnySeq; typedef sequence<boolean> BooleanSeq; typedef sequence<char> CharSeq; typedef sequence<wchar> WCharSeq; typedef sequence<octet> OctetSeq; typedef sequence<short> ShortSeq; typedef sequence<unsigned short> UShortSeq; typedef sequence<long> LongSeq; typedef sequence<unsigned long> ULongSeq; typedef sequence<long long> LongLongSeq; typedef sequence<unsigned long long> ULongLongSeq; typedef sequence<float> FloatSeq; typedef sequence<double> DoubleSeq; typedef sequence<long double> LongDoubleSeq;

   typedef sequence<string> StringSeq;typedef sequence<wstring> WStringSeq;

   exception BadFixedValue {unsigned long offset; };

   abstract valuetype DataOutputStream { void write_any(in any value); void write_boolean(in boolean value); void write_char(in char value); void write_wchar(in wchar value); void write_octet(in octet value); void write_short(in short value); void write_ushort(in unsigned short value); void write_long(in long value); void write_ulong(in unsigned long value); void write_longlong(in long long value); void write_ulonglong(in unsigned long long value); void write_float(in float value);

   void write_double(in double value);

   void write_longdouble(in long double value);

   void write_string(in string value);

   void write_wstring(in wstring value);

   void write_Object(in Object value);

   void write_Abstract(in AbstractBase value);

   void write_Value(in ValueBase value);

   void write_TypeCode(in TypeCode value);

   void write_any_array(in AnySeq seq,in unsigned long offset,in unsigned long length

   );

   void write_boolean_array( in BooleanSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_char_array( in CharSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_wchar_array( in WCharSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_octet_array( in OctetSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_short_array( in ShortSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_ushort_array( in UShortSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_long_array( in LongSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_ulong_array( in ULongSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_ulonglong_array( in ULongLongSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_longlong_array( in LongLongSeq seq, in unsigned long offset, in unsigned long length

   );

   void write_float_array(in FloatSeq seq,in unsigned long offset,in unsigned long length

   );

   void write_double_array(in DoubleSeq seq,in unsigned long offset,in unsigned long length

   );

   void write_long_double_array( in LongDoubleSeq seq, in unsigned long offset, in unsigned long length

   );void write_fixed(

   in any fixed_value) raises (BadFixedValue);void write_fixed_array(

   in AnySeq seq, in unsigned long offset, in unsigned long length

   ) raises (BadFixedValue); };

   abstract valuetype DataInputStream { any read_any(); boolean read_boolean(); char read_char(); wchar read_wchar(); octet read_octet(); short read_short(); unsigned short read_ushort(); long read_long(); unsigned long read_ulong(); long long read_longlong(); unsigned long long read_ulonglong(); float read_float(); double read_double(); long double read_longdouble(); string read_string(); wstring read_wstring(); Object read_Object(); AbstractBase read_Abstract(); ValueBase read_Value(); TypeCode read_TypeCode();

   void read_any_array(inout AnySeq seq,in unsigned long offset,in unsigned long length

   );

   void read_boolean_array( inout BooleanSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_char_array( inout CharSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_wchar_array( inout WCharSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_octet_array( inout OctetSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_short_array( inout ShortSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_ushort_array( inout UShortSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_long_array( inout LongSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_ulong_array( inout ULongSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_ulonglong_array( inout ULongLongSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_longlong_array( inout LongLongSeq seq, in unsigned long offset, in unsigned long length

   );

   void read_float_array(inout FloatSeq seq,in unsigned long offset,in unsigned long length

   );

   void read_double_array(inout DoubleSeq seq,in unsigned long offset,in unsigned long length

   );

   void read_long_double_array(inout DoubleSeq seq, in unsigned long offset, in unsigned long length

   );

   any read_fixed(in unsigned short digits, in short scale

   ) raises (BadFixedValue);

   void read_fixed_array(inout AnySeq seq, in unsigned long offset, in unsigned long length, in unsigned short digits, in short scale

   ) raises (BadFixedValue); }; };

   Note that the Data streams are abstract value types. This ensures that their implementation will be local, which is required in order for them to properly flatten and encode nested value types.

   The read_* operations that have an inout parameter named seq are expected to extend the sequence to fit the read value.

   The ORB (i.e., the CDR encoding engine) is responsible for actually constructing the value’s encoding. The application marshaling code merely calls the above operations. The details of writing the value tag, header information, end tag(s) are specifically not exposed to the application code. In particular the size of the custom data is not written by the application. This guarantees that the custom marshaling (and unmarshaling code) cannot corrupt the other parameters of the call.

   If an inconsistency is detected, then the standard system exception MARSHAL is raised.

   A possible implementation might have the engine determine that a custom marshal parameter is “next.? It would then write the value tag and other header information and then return control back to the application defined marshaling policy, which would do the marshaling by calling the DataOutputStream operations to write the data as appropriate. (Note the stream takes care of breaking the data into chunks, if necessary.)

   When control was returned back to the engine, it performs any other cleanup activities to complete the value type, and then proceeds onto the next parameter. How this is actually accomplished is an implementation detail of the ORB.

   The Data Streams shall test for possible shared or null values and place appropriate indirections or null encodings (even when used from the custom streaming policy).

   There are no explicit operations for creating the streams. It is assumed that the ORB implicitly acts as a factory. In a sense they are always available.

   For write_fixed, the fixed_value parameter must be an "any" containing a fixed value. If the "any" passed in does not contain a fixed value, then a BadFixedValue exception is raised with the offset field set to 0.

   For write_fixed_array, the elements of the seq parameter that are specified by the offset and length parameters must be a sequence of "any"s each of which contains a fixed value. If any of these "any"s does not contain a fixed value, or if any of them contains a fixed value whose digits and scale (as specified by the TypeCode in the "any") differ from those of the first of these "any"s (as specified by its TypeCode), then a BadFixedValue exception is raised with the offset field set to a zero-origin ordinal number indicating the position of the first incorrect “any? within the subsequence of fixed values written to the stream.

   For both write_fixed and write_fixed_array, the TypeCode within each “any? being written specifies the digits and scale to be used to write the fixed value contained in the “any.? The TypeCode itself is not written to the DataOutputStream.

   The read_fixed operation returns an “any? containing the fixed value that was read from the DataInputStream. The digits and scale in the TypeCode of the returned “any? are set to the digits and scale parameters passed to read_fixed. If the fixed value read from the DataInputStream is incompatible with the digits and scale parameters passed to read_fixed, then a BadFixedValue exception is raised with the offset field set to 0.

   The read_fixed_array operation sets the elements of the seq parameter that are specified by the offset and length parameters. These elements are set to "any"s with TypeCodes specifying a fixed value whose digits and scale are the same as the digits and scale parameters, and fixed values that were read from the DataInputStream. The previous contents of these “any?s, including their TypeCodes, are destroyed by the read_fixed_array operation. Other "any"s in the seq parameter (if any) are left unchanged. No TypeCode information is read from the DataInputStream. If any of the fixed values read from the DataInputStream is incompatible with the digits and scale parameters, then a BadFixedValue exception is raised with the offset field set to a zero-origin ordinal number indicating the position of the first incorrect “any? within the subsequence of fixed values read from the stream.

   The stream representation of a fixed value is considered incompatible if its digit and scale values do not match the digits and scale values being used to read it from the stream.