Class CipReply
- java.lang.Object
-
- com.automation_pros.odva.cip.requests.CipReply
-
- All Implemented Interfaces:
CipMessage
,java.io.Externalizable
,java.io.Serializable
- Direct Known Subclasses:
FwdCloseRsp
,FwdOpenRsp
public class CipReply extends java.lang.Object implements java.io.Externalizable, CipMessage
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected CipException
exc
protected CipRequest
request
protected int
svccode
-
Constructor Summary
Constructors Constructor Description CipReply()
Externalizable support requires a public no-arg constructor.CipReply(int service, int status, short... extraCodes)
Construct an empty reply from scratch.CipReply(int service, int status, java.nio.ByteBuffer source, short... extraCodes)
Construct a reply with payload from scratchCipReply(int service, CipException e)
Construct an empty reply from an exception.CipReply(int service, CipException e, java.nio.ByteBuffer source)
Construct a reply from an exception plus payloadCipReply(int service, java.nio.ByteBuffer source)
Construct a success reply with a payload.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
bytes()
static CipReply
decode(java.nio.ByteBuffer source, CipReplyConsumer callback)
CipException
getException()
short[]
getExtras()
java.nio.ByteBuffer
getPayload()
Clients typically want to decode the payload into their own field(s).CipRequest
getRequest()
int
getServiceCode()
CIP messages always have a service code, either requesting or replying.int
getStatusCode()
byte[]
payloadBytes()
Encode the message payload for transmission and return it as an array of bytes.int
payloadLength()
Subclasses must override this unless they populate the payload field.java.lang.String
payloadString()
void
put(java.nio.ByteBuffer dest)
Encode the entire message for transmission.void
putPayload(java.nio.ByteBuffer dest)
Subclasses that encode fields into their payloads must override this.void
readExternal(java.io.ObjectInput in)
CIP replies are read by decoding their CIP Message Router Response Format byte array.CipReply
readResolve()
CipReply
set(java.nio.ByteBuffer source)
void
setException(CipException exc)
Allow a response's exception to be modified, especially to support adjusting the extra words.void
setPayload(java.nio.ByteBuffer source)
Subclasses should override this method to permit reparsing of protocol packets into the desired request type.void
setRequest(CipRequest request)
byte[]
toBytes()
Encode the entire message for transmission and return it as an array of bytes.java.lang.String
toString()
void
writeExternal(java.io.ObjectOutput out)
CIP replies may be placed "on the wire" in serialized form, but ancillary data like connection objects or exception tracebacks are discarded.
-
-
-
Field Detail
-
svccode
protected int svccode
-
exc
protected CipException exc
-
request
protected CipRequest request
-
-
Constructor Detail
-
CipReply
public CipReply()
Externalizable support requires a public no-arg constructor.
-
CipReply
public CipReply(int service, int status, short... extraCodes)
Construct an empty reply from scratch.- Parameters:
service
-status
-extraCodes
-
-
CipReply
public CipReply(int service, CipException e)
Construct an empty reply from an exception.- Parameters:
service
-e
-
-
CipReply
public CipReply(int service, CipException e, java.nio.ByteBuffer source)
Construct a reply from an exception plus payload- Parameters:
service
-e
-source
-
-
CipReply
public CipReply(int service, java.nio.ByteBuffer source)
Construct a success reply with a payload.- Parameters:
service
-source
-
-
CipReply
public CipReply(int service, int status, java.nio.ByteBuffer source, short... extraCodes)
Construct a reply with payload from scratch- Parameters:
service
-status
-source
-extraCodes
-
-
-
Method Detail
-
set
public CipReply set(java.nio.ByteBuffer source)
-
decode
public static CipReply decode(java.nio.ByteBuffer source, CipReplyConsumer callback)
-
setRequest
public void setRequest(CipRequest request)
-
getRequest
public CipRequest getRequest()
-
getServiceCode
public int getServiceCode()
Description copied from interface:CipMessage
CIP messages always have a service code, either requesting or replying. In the protocol, replies have bit seven turned on. In reply classes implementing this interface, the bit is stripped.- Specified by:
getServiceCode
in interfaceCipMessage
- Returns:
- The unsigned byte service code as an integer.
-
getStatusCode
public int getStatusCode()
-
getExtras
public short[] getExtras()
-
getException
public CipException getException()
-
put
public void put(java.nio.ByteBuffer dest)
Description copied from interface:CipMessage
Encode the entire message for transmission.- Specified by:
put
in interfaceCipMessage
- Parameters:
dest
- Destination buffer for the encoded message.
-
bytes
public int bytes()
- Specified by:
bytes
in interfaceCipMessage
- Returns:
- The total byte length of the encoded message.
-
setPayload
public void setPayload(java.nio.ByteBuffer source)
Subclasses should override this method to permit reparsing of protocol packets into the desired request type.- Specified by:
setPayload
in interfaceCipMessage
- Parameters:
source
- Source buffer containing the encoded new payload.
-
getPayload
public java.nio.ByteBuffer getPayload()
Clients typically want to decode the payload into their own field(s).- Returns:
- A buffer containing the payload ready to read. Callers should deliver it to ByteBuffersSoftCache.release() if known to not be used further.
-
putPayload
public void putPayload(java.nio.ByteBuffer dest)
Subclasses that encode fields into their payloads must override this.- Specified by:
putPayload
in interfaceCipMessage
- Parameters:
dest
- Destination buffer for the encoded payload.
-
payloadLength
public int payloadLength()
Subclasses must override this unless they populate the payload field.- Specified by:
payloadLength
in interfaceCipMessage
- Returns:
- The byte length of the encoded payload only.
-
payloadString
public java.lang.String payloadString()
-
payloadBytes
public byte[] payloadBytes()
Description copied from interface:CipMessage
Encode the message payload for transmission and return it as an array of bytes.- Specified by:
payloadBytes
in interfaceCipMessage
- Returns:
- The encoded payload as a byte array.
-
toBytes
public byte[] toBytes()
Description copied from interface:CipMessage
Encode the entire message for transmission and return it as an array of bytes.- Specified by:
toBytes
in interfaceCipMessage
- Returns:
- The entire encoded message as a byte array.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
CIP replies are read by decoding their CIP Message Router Response Format byte array.- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
CIP replies may be placed "on the wire" in serialized form, but ancillary data like connection objects or exception tracebacks are discarded.- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
readResolve
public CipReply readResolve()
-
setException
public void setException(CipException exc)
Allow a response's exception to be modified, especially to support adjusting the extra words.- Parameters:
exc
-
-
-