CDREncapsCodecpublic final class CDREncapsCodec extends org.omg.CORBA.LocalObject implements org.omg.IOP.CodecCDREncapsCodec is an implementation of Codec, as described
in orbos/99-12-02, that supports CDR encapsulation version 1.0, 1.1, and
1.2. |
Fields Summary |
---|
private org.omg.CORBA.ORB | orb | com.sun.corba.se.impl.logging.ORBUtilSystemException | wrapper | private com.sun.corba.se.spi.ior.iiop.GIOPVersion | giopVersion |
Constructors Summary |
---|
public CDREncapsCodec(org.omg.CORBA.ORB orb, int major, int minor)Creates a new codec implementation. Uses the given ORB to create
CDRInputStreams when necessary.
this.orb = orb;
wrapper = ORBUtilSystemException.get(
(com.sun.corba.se.spi.orb.ORB)orb, CORBALogDomains.RPC_PROTOCOL ) ;
giopVersion = GIOPVersion.getInstance( (byte)major, (byte)minor );
|
Methods Summary |
---|
public org.omg.CORBA.Any | decode(byte[] data)Decode the given octet sequence into an any based on a CDR
encapsulated octet sequence.
if( data == null )
throw wrapper.nullParam() ;
return decodeImpl( data, null );
| private org.omg.CORBA.Any | decodeImpl(byte[] data, org.omg.CORBA.TypeCode tc)Decode the given octet sequence into an any based on a CDR
encapsulated octet sequence. If the type code is null, it is
expected to appear in the octet sequence. Otherwise, the given
type code is used.
if( data == null )
throw wrapper.nullParam() ;
AnyImpl any = null; // return value
// _REVISIT_ Currently there is no way for us to distinguish between
// a FormatMismatch and a TypeMismatch because we cannot get this
// information from the CDRInputStream. If a RuntimeException occurs,
// it is turned into a FormatMismatch exception.
try {
EncapsInputStream cdrIn = new EncapsInputStream( orb, data,
data.length, giopVersion );
cdrIn.consumeEndian();
// If type code not specified, read it from octet stream:
if( tc == null ) {
tc = cdrIn.read_TypeCode();
}
// Create a new Any object:
any = new AnyImpl( (com.sun.corba.se.spi.orb.ORB)orb );
any.read_value( cdrIn, tc );
}
catch( RuntimeException e ) {
// See above note.
throw new FormatMismatch();
}
return any;
| public org.omg.CORBA.Any | decode_value(byte[] data, org.omg.CORBA.TypeCode tc)Decode the given octet sequence into an any based on a CDR
encapsulated octet sequence. The type code is expected not to appear
in the octet sequence, and the given type code is used instead.
if( data == null )
throw wrapper.nullParam() ;
if( tc == null )
throw wrapper.nullParam() ;
return decodeImpl( data, tc );
| public byte[] | encode(org.omg.CORBA.Any data)Convert the given any into a CDR encapsulated octet sequence
if ( data == null )
throw wrapper.nullParam() ;
return encodeImpl( data, true );
| private byte[] | encodeImpl(org.omg.CORBA.Any data, boolean sendTypeCode)Convert the given any into a CDR encapsulated octet sequence.
If sendTypeCode is true, the type code is sent with the message, as in
a standard encapsulation. If it is false, only the data is sent.
Either way, the endian type is sent as the first part of the message.
if( data == null )
throw wrapper.nullParam() ;
// _REVISIT_ Note that InvalidTypeForEncoding is never thrown in
// the body of this method. This is due to the fact that CDR*Stream
// will never throw an exception if the encoding is invalid. To
// fix this, the CDROutputStream must know the version of GIOP it
// is encoding for and it must check to ensure that, for example,
// wstring cannot be encoded in GIOP 1.0.
//
// As part of the GIOP 1.2 work, the CDRInput and OutputStream will
// be versioned. This can be handled once this work is complete.
// Create output stream with default endianness.
EncapsOutputStream cdrOut = new EncapsOutputStream(
(com.sun.corba.se.spi.orb.ORB)orb, giopVersion );
// This is an encapsulation, so put out the endian:
cdrOut.putEndian();
// Sometimes encode type code:
if( sendTypeCode ) {
cdrOut.write_TypeCode( data.type() );
}
// Encode value and return.
data.write_value( cdrOut );
return cdrOut.toByteArray();
| public byte[] | encode_value(org.omg.CORBA.Any data)Convert the given any into a CDR encapsulated octet sequence. Only
the data is stored. The type code is not.
if( data == null )
throw wrapper.nullParam() ;
return encodeImpl( data, false );
|
|