Class Capsule
- java.lang.Object
-
- com.automation_pros.odva.cip.types.Capsule
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
public abstract class Capsule extends java.lang.Object implements java.io.Externalizable
Streaming protocols need to mark message boundaries and indicate message type and total length. In fully generic form, such a message has a header from which the trailing boundary can be computed or inferred. Instances are expected to serialize themselves to their standard bytestream and deserialize themselves accordingly.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Capsule()
No-args constructor for deserialization.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Capsule
decode(EndianDataInput in)
Construct a complete instance from a suitable stream data source.abstract Capsule
decodeHeader(EndianDataInput in)
Initialize an instance from a suitable stream data source.abstract Capsule
decodeVariant(EndianDataInput in)
Populate an instance's payload from a suitable stream data source.Capsule
encode(EndianDataOutput out)
Export an instance's header and payload to wire format in a suitable stream data sink.abstract Capsule
encodeHeader(EndianDataOutput out)
Export an instance's header to wire format in a suitable stream data sink.abstract Capsule
encodeVariant(EndianDataOutput out)
Export an instance's payload to wire format in a suitable stream data sink.abstract int
headerLength()
Subclasses must report a constant header length, which must include enough information to compute the length of the balance of the encoded message.void
readExternal(java.io.ObjectInput in)
abstract int
variantLength()
After an instance's decodeHeader() method has been called, or an instance is constructed by other means, the payload length must be known.void
writeExternal(java.io.ObjectOutput out)
-
-
-
Method Detail
-
headerLength
public abstract int headerLength()
Subclasses must report a constant header length, which must include enough information to compute the length of the balance of the encoded message.- Returns:
- Number of bytes in the specific type's message header.
-
variantLength
public abstract int variantLength()
After an instance's decodeHeader() method has been called, or an instance is constructed by other means, the payload length must be known.- Returns:
- Number of bytes in the specific instance's variant payload.
-
decodeHeader
public abstract Capsule decodeHeader(EndianDataInput in) throws java.io.IOException
Initialize an instance from a suitable stream data source.- Parameters:
in
- A stream that offers big endian and little endian primitive access.- Returns:
- A chainable reference to the instance.
- Throws:
java.io.IOException
-
decodeVariant
public abstract Capsule decodeVariant(EndianDataInput in) throws java.io.IOException
Populate an instance's payload from a suitable stream data source.- Parameters:
in
- A stream that offers big endian and little endian primitive access.- Returns:
- A chainable reference to the instance.
- Throws:
java.io.IOException
-
decode
public Capsule decode(EndianDataInput in) throws java.io.IOException
Construct a complete instance from a suitable stream data source.- Parameters:
in
- A stream that offers big endian and little endian primitive access.- Returns:
- A chainable reference to the instance.
- Throws:
java.io.IOException
-
encodeHeader
public abstract Capsule encodeHeader(EndianDataOutput out) throws java.io.IOException
Export an instance's header to wire format in a suitable stream data sink. This method must be followed by a call to encodePayload() to have a valid message on the wire.- Parameters:
out
- A stream that offers big endian and little endian primitive access.- Returns:
- A chainable reference to the instance.
- Throws:
java.io.IOException
-
encodeVariant
public abstract Capsule encodeVariant(EndianDataOutput out) throws java.io.IOException
Export an instance's payload to wire format in a suitable stream data sink. Should immediately follow encodeHeader().- Parameters:
out
- A stream that offers big endian and little endian primitive access.- Returns:
- A chainable reference to the instance.
- Throws:
java.io.IOException
-
encode
public Capsule encode(EndianDataOutput out) throws java.io.IOException
Export an instance's header and payload to wire format in a suitable stream data sink.- Parameters:
out
- A stream that offers big endian and little endian primitive access.- Returns:
- A chainable reference to the instance.
- Throws:
java.io.IOException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.lang.ClassNotFoundException, java.io.IOException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.lang.ClassNotFoundException
java.io.IOException
-
-