public abstract class PDU extends ByteData implements java.io.Externalizable, com.opencloud.util.FastSerializable
Common base class for all SMPP PDU types
Modifier and Type | Field and Description |
---|---|
protected int |
commandID |
protected int |
commandStatus |
static int |
MIN_SIZE |
protected int |
sequenceNumber |
Modifier | Constructor and Description |
---|---|
protected |
PDU(java.io.DataInput in) |
|
PDU(int commandID) |
Modifier and Type | Method and Description |
---|---|
void |
addTLV(TLV tlv)
Adds a TLV (optional field) to the end of this PDU.
|
protected boolean |
bodyEquals(PDU pdu)
Compares the body of given PDU with the body (not including header or TLVs) of this PDU for equality.
|
protected void |
bodyFromBuffer(java.nio.ByteBuffer buf)
Read PDU body (not including header or TLVs) from a ByteBuffer.
|
protected int |
bodyHashCode()
Get the hash code value of PDU body (not including header or TLVs).
|
protected int |
bodySize()
Return size (in bytes) of PDU body (not including header or TLVs).
|
protected void |
bodyToBuffer(java.nio.ByteBuffer buf)
Write PDU body (not including header or TLVs) to a ByteBuffer.
|
protected java.lang.String |
bodyToString() |
boolean |
equals(java.lang.Object o)
Compares given object with this PDU for equality, including header, body and optional TLVs.
|
void |
fromBuffer(java.nio.ByteBuffer buf)
NOTE fromBuffer() assumes buffer contains ONLY one PDU
|
void |
fromStream(java.io.DataInput in) |
java.util.List<TLV> |
getAllTLVs()
Get the list of TLVs that this PDU contains.
|
int |
getCommandID() |
int |
getCommandLength() |
int |
getCommandStatus() |
int |
getSequenceNumber() |
TLV |
getTLV(short tag)
Get the TLV object that has this tag.
|
int |
hashCode()
Get the hash code value of this PDU, including header, body and optional TLVs.
|
boolean |
hasTLV(short tag) |
protected boolean |
headerEquals(PDU pdu) |
protected void |
headerFromBuffer(java.nio.ByteBuffer buf) |
protected int |
headerHashCode() |
protected int |
headerSize() |
protected void |
headerToBuffer(java.nio.ByteBuffer buf) |
protected java.lang.String |
headerToString() |
void |
readExternal(java.io.ObjectInput in) |
void |
setCommandID(int commandID) |
void |
setCommandStatus(int commandStatus) |
void |
setSequenceNumber(int sequenceNumber) |
int |
size()
Get the number of bytes that this object contains
|
protected boolean |
tlvEquals(PDU pdu)
Compares the optional TLVs of given PDU with the optional TLVs of this PDU for equality.
|
protected void |
tlvFromBuffer(java.nio.ByteBuffer buf) |
protected int |
tlvHashCode()
Get the hash code value of all optional TLVs that have been added to this PDU.
|
protected int |
tlvSize()
Get size (in bytes) of all optional TLVs that have been added to this PDU.
|
protected void |
tlvToBuffer(java.nio.ByteBuffer buf) |
protected java.lang.String |
tlvToString() |
void |
toBuffer(java.nio.ByteBuffer buf)
Write PDU, including header, body and TLV, to a buffer.
|
void |
toStream(java.io.DataOutput out) |
java.lang.String |
toString() |
void |
writeExternal(java.io.ObjectOutput out) |
checkCString, checkCString, checkDate, decodeUnsigned, encodeUnsigned, equalCStrings, getCString, getCString, getCStringByteArray, getCStringHashCode, isNullOrEmptyCString, printAsHex, putCString
protected int commandID
protected int commandStatus
protected int sequenceNumber
public static final int MIN_SIZE
public PDU(int commandID)
protected PDU(java.io.DataInput in) throws java.io.IOException
java.io.IOException
public int getCommandLength()
public int getCommandID()
public int getCommandStatus()
public int getSequenceNumber()
public void setCommandID(int commandID)
public void setCommandStatus(int commandStatus)
public void setSequenceNumber(int sequenceNumber)
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException
public void toStream(java.io.DataOutput out) throws java.io.IOException
toStream
in interface com.opencloud.util.FastSerializable
java.io.IOException
public void fromStream(java.io.DataInput in) throws java.io.IOException
java.io.IOException
public final void toBuffer(java.nio.ByteBuffer buf) throws java.nio.BufferOverflowException
Write PDU, including header, body and TLV, to a buffer.
protected final void headerToBuffer(java.nio.ByteBuffer buf) throws java.nio.BufferOverflowException
java.nio.BufferOverflowException
protected void bodyToBuffer(java.nio.ByteBuffer buf) throws java.nio.BufferOverflowException
Write PDU body (not including header or TLVs) to a ByteBuffer. Subclasses MUST override this if they have any additional fields in their body. Fields must be written in big-endian byte order (the default with ByteBuffer anyway).
java.nio.BufferOverflowException
protected final void tlvToBuffer(java.nio.ByteBuffer buf) throws java.nio.BufferOverflowException
java.nio.BufferOverflowException
public final void fromBuffer(java.nio.ByteBuffer buf) throws java.nio.BufferUnderflowException, InvalidPDUFieldException
NOTE fromBuffer() assumes buffer contains ONLY one PDU
fromBuffer
in class ByteData
java.nio.BufferUnderflowException
InvalidPDUFieldException
protected final void headerFromBuffer(java.nio.ByteBuffer buf) throws java.nio.BufferUnderflowException
java.nio.BufferUnderflowException
protected void bodyFromBuffer(java.nio.ByteBuffer buf) throws java.nio.BufferUnderflowException, InvalidPDUFieldException
Read PDU body (not including header or TLVs) from a ByteBuffer. Subclasses MUST override this if they have any additional fields in their body. Fields are read in big-endian byte order (the default with ByteBuffer anyway).
java.nio.BufferUnderflowException
InvalidPDUFieldException
protected final void tlvFromBuffer(java.nio.ByteBuffer buf) throws java.nio.BufferUnderflowException, InvalidPDUFieldException
java.nio.BufferUnderflowException
InvalidPDUFieldException
public final int size()
ByteData
Get the number of bytes that this object contains
protected final int headerSize()
protected int bodySize()
Return size (in bytes) of PDU body (not including header or TLVs). Subclasses MUST override this if they have any additional fields in their body, so that PDU lengths will be calculated correctly.
protected final int tlvSize()
Get size (in bytes) of all optional TLVs that have been added to this PDU.
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String headerToString()
protected java.lang.String bodyToString()
protected java.lang.String tlvToString()
public void addTLV(TLV tlv) throws TLVAlreadyExistsException
Adds a TLV (optional field) to the end of this PDU. Note that for some types of TLV, the insertion order is significant, namely CALLBACK_NUM, CALLBACK_NUM_ATAG, CALLBACK_NUM_PRES_IND, and BROADCAST_AREA_IDENTIFIER, BROADCAST_ERROR_STATUS. For instance, there may be any number of callback TLVs and the order determines which CALLBACK_NUM_ATAG is associated with which CALLBACK_NUM etc. For all other TLV types, repetition is not permitted and attempting to add the same TLV twice will cause a TLVAlreadyExistsException
.
tlv
- the TLV to be added to this PDU.TLVAlreadyExistsException
- if a TLV of the same type has already been added to the PDU.public TLV getTLV(short tag)
Get the TLV object that has this tag.
tag
- the TLV tag to search for.tag
, or null
if it is not present in this PDU.public boolean hasTLV(short tag)
public java.util.List<TLV> getAllTLVs()
Get the list of TLVs that this PDU contains. This should only be used by applications that need to support multiple occurrences of the same TLV (e.g. CALLBACK_NUM_xxx etc). For singular TLVs, use getTLV(short)
.
public boolean equals(java.lang.Object o)
Compares given object with this PDU for equality, including header, body and optional TLVs.
NOTE that the order/duplicates of TLVs are ONLY significant in terms of TLV pairs for TLV types, for which multiple occurrences are supported (e.g. CALLBACK_NUM_xxx etc). For all other TLV types the order/duplicates are insignificant in terms of the comparison result.
equals
in class java.lang.Object
protected final boolean headerEquals(PDU pdu)
protected boolean bodyEquals(PDU pdu)
Compares the body of given PDU with the body (not including header or TLVs) of this PDU for equality. Subclasses MUST override this if they have any additional fields in their body, so that PDUs comparison will be performed correctly.
protected final boolean tlvEquals(PDU pdu)
Compares the optional TLVs of given PDU with the optional TLVs of this PDU for equality.
NOTE that the order/duplicates are ONLY significant in terms of TLV pairs for TLV types, for which multiple occurrences are supported (e.g. CALLBACK_NUM_xxx). For all other TLV types the order/duplicates are insignificant in terms of the comparison result.
public int hashCode()
Get the hash code value of this PDU, including header, body and optional TLVs.
NOTE that the hash code will be computed using the mutable PDU fields. Meaning that the resulting hash code value following a PDU field value change, may differ from the hash code computed before the change.
hashCode
in class java.lang.Object
protected final int headerHashCode()
protected int bodyHashCode()
Get the hash code value of PDU body (not including header or TLVs). Subclasses MUST override this if they have any additional fields in their body, so that PDU hash code will be calculated correctly.
protected final int tlvHashCode()
Get the hash code value of all optional TLVs that have been added to this PDU.