org.mobicents.protocols.smpp.util
Interface PacketDecoder

All Known Implementing Classes:
PacketDecoderImpl

public interface PacketDecoder

Utility interface for decoding packet fields.

Version:
$Id: PacketDecoder.java 452 2009-01-15 16:56:36Z orank $

Method Summary
 int getAvailableBytes()
          Get the number of available bytes to be read by this decoder.
 int getParsePosition()
          Get the current parse position of this packet decoder.
 Address readAddress()
          Read an SMPP address from the byte array.
 byte readByte()
          Read a byte from the byte array.
 byte[] readBytes(int length)
          Get a byte array sub-set from the specified byte array.
 String readCString()
          Read a C-String (a string terminated by a nul-byte) from the byte array.
 SMPPDate readDate()
          Read an SMPP date from the byte array.
 ErrorAddress readErrorAddress()
          Read an SMPP address and error code pairing.
 long readInt8()
           
 String readString(int length)
          Read a fixed-length String from the bytes.
 int readUInt1()
          Read a 1-byte unsigned integer from the array.
 int readUInt2()
          Read a 2-byte unsigned integer from the array.
 long readUInt4()
          Read a 4-byte unsigned integer from the array.
 void setParsePosition(int parsePosition)
          Set the current parse position of this decoder.
 

Method Detail

getParsePosition

int getParsePosition()
Get the current parse position of this packet decoder.

Returns:
The current parse position.

setParsePosition

void setParsePosition(int parsePosition)
Set the current parse position of this decoder.

Parameters:
parsePosition - The new parse position.

getAvailableBytes

int getAvailableBytes()
Get the number of available bytes to be read by this decoder.

Returns:
The number of bytes that can be decoded.

readCString

String readCString()
Read a C-String (a string terminated by a nul-byte) from the byte array. The bytes will be interpreted as US-ASCII characters.

Parameters:
bytes - The bytes to decode the string from.
pos - The position to start parsing the string from. The parse position must be updated to point to the first byte after the terminating nul byte.
Returns:
The decoded String.
Throws:
ArrayIndexOutOfBoundsException - if there are insufficient bytes to parse the string.

readString

String readString(int length)
Read a fixed-length String from the bytes. The bytes will be interpreted as US-ASCII characters.

Parameters:
bytes - The bytes to decode the string from.
pos - The position to start parsing the string from. The parse position will be updated to point to the first byte after the end of the string.
length - The number of bytes to parse for the string.
Returns:
The decoded String.
Throws:
ArrayIndexOutOfBoundsException - if there are insufficient bytes to parse the string.

readByte

byte readByte()
Read a byte from the byte array.

Parameters:
bytes - The byte array to read from.
pos - The position to return the byte from. The parse position will be incremented by 1 upon return from this method.
Returns:
The byte at the specified parse position in the array.
Throws:
ArrayIndexOutOfBoundsException - if there are insufficient bytes available.

readUInt1

int readUInt1()
Read a 1-byte unsigned integer from the array.

Parameters:
bytes - The byte array to read from.
pos - The position to obtain the integer from. The parse position will be incremented by 1 upon return from this method.
Returns:
The decoded integer.
Throws:
ArrayIndexOutOfBoundsException - if there are insufficient bytes to parse the integer.

readUInt2

int readUInt2()
Read a 2-byte unsigned integer from the array. SMPP integers are big-endian, also known as network byte order.

Parameters:
bytes - The byte array to read from.
pos - The position to obtain the integer from. The parse position will be incremented by 2 upon return from this method.
Returns:
The decoded integer.
Throws:
ArrayIndexOutOfBoundsException - if there are insufficient bytes to parse the integer.

readUInt4

long readUInt4()
Read a 4-byte unsigned integer from the array. SMPP integers are big-endian, also known as network byte order. Since the integers are unsigned, a Java long primitive is required to hold all the possible values.

Parameters:
bytes - The byte array to read from.
pos - The position to obtain the integer from. The parse position will be incremented by 4 upon return from this method.
Returns:
The decoded (long) integer.
Throws:
ArrayIndexOutOfBoundsException - if there are insufficient bytes to parse the integer.

readInt8

long readInt8()

readAddress

Address readAddress()
Read an SMPP address from the byte array.

Parameters:
bytes - The byte array to read the address from.
pos - The position to begin parsing the address from. The parse position will be updated to point to the first byte after the address in the byte array.
Returns:
The parsed address.
Throws:
ArrayIndexOutOfBoundsException - if there are insufficient bytes to parse an address.

readErrorAddress

ErrorAddress readErrorAddress()
Read an SMPP address and error code pairing. This is used in the submit multi response packet to create its table of unsuccessful submissions.

Returns:
An error address object.

readDate

SMPPDate readDate()
Read an SMPP date from the byte array.

Parameters:
bytes - The byte array to read the date from.
pos - The position to begin parsing the date from. The parse position will be updated to point to the first byte after the date in the array.
Returns:
The parsed SMPP date, or null if the date is null.

readBytes

byte[] readBytes(int length)
Get a byte array sub-set from the specified byte array.

Parameters:
bytes - The array to extract bytes from.
pos - The position to begin extracting bytes at. The parse position will be updated to point to the next byte after the extracted byte array.
length - The number of bytes to copy out of the array.
Returns:
A byte array with length bytes in it copied from bytes.


Copyright © 2011 Mobicents. All Rights Reserved.