public interface Encodable
This interface provides an alternative to the DatatypeCodec
interface where the codec behaviour can be inlined directly into the datatype code.
This interface can be used as a substitute for FastSerializable
when the additional utility functions provided to codecs are necessary.
Classes implementing Encodable
must provide a public constructor that takes, in this order:
a DataInput
argument;
a ClassLoader
argument; and
a DecoderUtils
argument.
Object state is read from the DataInput
stream.
The ClassLoader
argument can be used to resolve any application-specific classes stored in the stream, and the DecoderUtils
can be used to restore certain SLEE-specific types.
The constructor may throw IOException
.
In order for Rhino to utilise the function of the Encodable
interface, a CMP field must be declared with a type of at least Encodable
- a CMP field declared with a type of Object
will fall back to Rhino’s default serialisation behaviour.
Serialisation efficiency will be gained by storing into a CMP field an object of exactly the declared CMP field type.
Rhino will correctly handle the case if at runtime a subclass of the declared CMP field type is stored into the CMP field, however in this case reflection must be used during deserialisation to instantiate an object of the stored class, as it cannot be known at deploy time.
As for FastSerializable
, there is no handling of shared references to objects.
If an Encodable
object is encountered twice during serialisation, then two copies of the object will exist upon deserialisation.
DatatypeCodec
Modifier and Type | Method and Description |
---|---|
void |
encode(DataOutput out,
EncoderUtils utils)
Encode the state of this object to the given data output stream.
|
void encode(DataOutput out, EncoderUtils utils) throws IOException
Encode the state of this object to the given data output stream.
out
- the data output stream to encode the value to.utils
- additional utility encoding functions that may be useful to the encoder.IOException
- if an I/O error occurs.