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 CipExceptionexcprotected CipRequestrequestprotected intsvccode
-
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 intbytes()static CipReplydecode(java.nio.ByteBuffer source, CipReplyConsumer callback)CipExceptiongetException()short[]getExtras()java.nio.ByteBuffergetPayload()Clients typically want to decode the payload into their own field(s).CipRequestgetRequest()intgetServiceCode()CIP messages always have a service code, either requesting or replying.intgetStatusCode()byte[]payloadBytes()Encode the message payload for transmission and return it as an array of bytes.intpayloadLength()Subclasses must override this unless they populate the payload field.java.lang.StringpayloadString()voidput(java.nio.ByteBuffer dest)Encode the entire message for transmission.voidputPayload(java.nio.ByteBuffer dest)Subclasses that encode fields into their payloads must override this.voidreadExternal(java.io.ObjectInput in)CIP replies are read by decoding their CIP Message Router Response Format byte array.CipReplyreadResolve()CipReplyset(java.nio.ByteBuffer source)voidsetException(CipException exc)Allow a response's exception to be modified, especially to support adjusting the extra words.voidsetPayload(java.nio.ByteBuffer source)Subclasses should override this method to permit reparsing of protocol packets into the desired request type.voidsetRequest(CipRequest request)byte[]toBytes()Encode the entire message for transmission and return it as an array of bytes.java.lang.StringtoString()voidwriteExternal(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:CipMessageCIP 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:
getServiceCodein 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:CipMessageEncode the entire message for transmission.- Specified by:
putin interfaceCipMessage- Parameters:
dest- Destination buffer for the encoded message.
-
bytes
public int bytes()
- Specified by:
bytesin 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:
setPayloadin 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:
putPayloadin 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:
payloadLengthin interfaceCipMessage- Returns:
- The byte length of the encoded payload only.
-
payloadString
public java.lang.String payloadString()
-
payloadBytes
public byte[] payloadBytes()
Description copied from interface:CipMessageEncode the message payload for transmission and return it as an array of bytes.- Specified by:
payloadBytesin interfaceCipMessage- Returns:
- The encoded payload as a byte array.
-
toBytes
public byte[] toBytes()
Description copied from interface:CipMessageEncode the entire message for transmission and return it as an array of bytes.- Specified by:
toBytesin interfaceCipMessage- Returns:
- The entire encoded message as a byte array.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionCIP replies are read by decoding their CIP Message Router Response Format byte array.- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionCIP replies may be placed "on the wire" in serialized form, but ancillary data like connection objects or exception tracebacks are discarded.- Specified by:
writeExternalin 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-
-
-