// Don't do any work if this is native
if (_kind == TCKind._tk_native)
throw wrapper.cannotMarshalNative() ;
TypeCodeOutputStream topStream = tcos.getTopLevelStream();
//if (debug) tcos.printBuffer();
if (_kind == tk_indirect) {
//if (debug) System.out.println("Writing indirection " + _name + "to " + _id);
// The encoding used for indirection is the same as that used for recursive ,
// TypeCodes i.e., a 0xffffffff indirection marker followed by a long offset
// (in units of octets) from the beginning of the long offset.
int pos = topStream.getPositionForID(_id);
int topPos = tcos.getTopLevelPosition();
//if (debug) System.out.println("TypeCodeImpl " + tcos +
// " writing indirection " + _id +
//" to position " + pos + " at position " + topPos);
tcos.writeIndirection(tk_indirect, pos);
// All that gets written is _kind and offset.
return;
}
// The original approach changed for 5034649
// topStream.addIDAtPosition(_id, tcos.getTopLevelPosition());
// marshal the kind
tcos.write_long(_kind);
//if (debug) System.out.println("Writing " + _name + " with id " + _id);
// We have to remember the stream and position for EVERY type code
// in case some recursive or indirect type code references it.
//
// Bug fix 5034649:
// Do this AFTER the write of the _kind in case the alignment
// for the long changes the position.
topStream.addIDAtPosition(_id, tcos.getTopLevelPosition()-4);
switch (typeTable[_kind]) {
case EMPTY:
// nothing more to marshal
break;
case SIMPLE:
switch (_kind) {
case TCKind._tk_string:
case TCKind._tk_wstring:
// marshal the bound on string length
tcos.write_long(_length);
break;
case TCKind._tk_fixed:
tcos.write_ushort(_digits);
tcos.write_short(_scale);
break;
default:
// unknown typecode kind
throw wrapper.invalidSimpleTypecode() ;
}
break;
case COMPLEX:
{
// create an encapsulation
TypeCodeOutputStream _encap = tcos.createEncapsulation(tcos.orb());
switch(_kind) {
case TCKind._tk_objref:
case TCKind._tk_abstract_interface:
{
// put the repository id
_encap.write_string(_id);
// put the name
_encap.write_string(_name);
}
break;
case TCKind._tk_union:
{
// put the repository id
_encap.write_string(_id);
// put the name
_encap.write_string(_name);
// discriminant typecode
_discriminator.write_value(_encap);
// default index
_encap.write_long(_defaultIndex);
// put the number of members
_encap.write_long(_memberCount);
// marshal label values, names and types
for (int i=0; i < _memberCount; i++) {
// for the default case, marshal the zero octet
if (i == _defaultIndex)
_encap.write_octet(_unionLabels[i].extract_octet());
else {
switch (realType(_discriminator).kind().value()) {
case TCKind._tk_short:
_encap.write_short(_unionLabels[i].extract_short());
break;
case TCKind._tk_long:
_encap.write_long(_unionLabels[i].extract_long());
break;
case TCKind._tk_ushort:
_encap.write_short(_unionLabels[i].extract_ushort());
break;
case TCKind._tk_ulong:
_encap.write_long(_unionLabels[i].extract_ulong());
break;
case TCKind._tk_float:
_encap.write_float(_unionLabels[i].extract_float());
break;
case TCKind._tk_double:
_encap.write_double(_unionLabels[i].extract_double());
break;
case TCKind._tk_boolean:
_encap.write_boolean(_unionLabels[i].extract_boolean());
break;
case TCKind._tk_char:
_encap.write_char(_unionLabels[i].extract_char());
break;
case TCKind._tk_enum:
_encap.write_long(_unionLabels[i].extract_long());
break;
case TCKind._tk_longlong:
_encap.write_longlong(_unionLabels[i].extract_longlong());
break;
case TCKind._tk_ulonglong:
_encap.write_longlong(_unionLabels[i].extract_ulonglong());
break;
// _REVISIT_ figure out long double mapping
// case TCKind.tk_longdouble:
// _encap.putDouble(_unionLabels[i].extract_longdouble());
// break;
case TCKind._tk_wchar:
_encap.write_wchar(_unionLabels[i].extract_wchar());
break;
default:
throw wrapper.invalidComplexTypecode() ;
}
}
_encap.write_string(_memberNames[i]);
_memberTypes[i].write_value(_encap);
}
}
break;
case TCKind._tk_enum:
{
// put the repository id
_encap.write_string(_id);
// put the name
_encap.write_string(_name);
// put the number of members
_encap.write_long(_memberCount);
// marshal identifier names
for (int i=0; i < _memberCount; i++)
_encap.write_string(_memberNames[i]);
}
break;
case TCKind._tk_sequence:
{
// put the type of the sequence
lazy_content_type().write_value(_encap);
// put the bound on the length of the sequence
_encap.write_long(_length);
}
break;
case TCKind._tk_array:
{
// put the type of the array
_contentType.write_value(_encap);
// put the length of the array
_encap.write_long(_length);
}
break;
case TCKind._tk_alias:
case TCKind._tk_value_box:
{
// put the repository id
_encap.write_string(_id);
// put the name
_encap.write_string(_name);
// put the type aliased
_contentType.write_value(_encap);
}
break;
case TCKind._tk_struct:
case TCKind._tk_except:
{
// put the repository id
_encap.write_string(_id);
// put the name
_encap.write_string(_name);
// put the number of members
_encap.write_long(_memberCount);
// marshal member names and types
for (int i=0; i < _memberCount; i++) {
_encap.write_string(_memberNames[i]);
//if (debug) System.out.println("TypeCode " + _name +
// " writing member " + _memberNames[i]);
_memberTypes[i].write_value(_encap);
}
}
break;
case TCKind._tk_value:
{
// put the repository id
_encap.write_string(_id);
// put the name
_encap.write_string(_name);
// put the type modifier
_encap.write_short(_type_modifier);
// put the type aliased
if (_concrete_base == null) {
_orb.get_primitive_tc(TCKind._tk_null).write_value(_encap);
} else {
_concrete_base.write_value(_encap);
}
// put the number of members
_encap.write_long(_memberCount);
// marshal member names and types
for (int i=0; i < _memberCount; i++) {
_encap.write_string(_memberNames[i]);
//if (debug) System.out.println("TypeCode " + _name +
// " writing member " + _memberNames[i]);
_memberTypes[i].write_value(_encap);
_encap.write_short(_memberAccess[i]);
}
}
break;
default:
throw wrapper.invalidTypecodeKindMarshal() ;
}
// marshal the encapsulation
_encap.writeOctetSequenceTo(tcos);
break;
}
}
}