org.mobicents.protocols.smpp.message.param
Interface ParamDescriptor

All Superinterfaces:
Serializable
All Known Implementing Classes:
AbstractDescriptor, BitmaskParamDescriptor, BytesParamDescriptor, CStringParamDescriptor, DateParamDescriptor, IntegerParamDescriptor, NullParamDescriptor, StringParamDescriptor

public interface ParamDescriptor
extends Serializable

Parameter descriptor. The parameter descriptor interface provides a way for SMPP types to be read from byte arrays and written to output streams. Descriptors are used for both mandatory and optional parameters.

Version:
$Id: ParamDescriptor.java 457 2009-01-15 17:37:42Z orank $

Method Summary
 int getLengthSpecifier()
          Get the index of another numerical mandatory parameter which specifies the length of the parameter this descriptor represents.
 Object readObject(PacketDecoder decoder, int length)
          Read an object from a byte array.
 int sizeOf(Object obj)
          Get the encoded byte-size of obj.
 void writeObject(Object obj, PacketEncoder encoder)
          Write the specified object to an output stream.
 

Method Detail

getLengthSpecifier

int getLengthSpecifier()
Get the index of another numerical mandatory parameter which specifies the length of the parameter this descriptor represents. For example, in a submit_sm packet, the length of the short_message parameter is specified by the sm_length parameter, a 1-byte integer immediately preceding short_message in the mandatory parameter section of the packet. Therefore, the parameter descriptor that will be used to decode the short_message would return the index of the sm_length parameter in the body. This specified length can then be used to decode the correct number of bytes for the short message.

As another example, take the submit_multi packet. It has a mandatory parameter called dest_address(es) which specify all the destinations the message should be submitted to. The number of destinations in the destination table is specified by the number_of_dests mandatory parameter. In this case, the descriptor used to read the dest_addresses would return the index of number_of_dests from this method.

Returns:
The index in the mandatory parameters of where to find the length specifier for this descriptor. If this descriptor does not need or support a length specifier, -1 must be returned.

sizeOf

int sizeOf(Object obj)
Get the encoded byte-size of obj.

Parameters:
obj - The object to calculate the encoded size for.
Returns:
The number of bytes the specified object would be encoded to via the #writeObject(Object, OutputStream) method.

writeObject

void writeObject(Object obj,
                 PacketEncoder encoder)
                 throws IOException
Write the specified object to an output stream.

Parameters:
obj - The object to encode.
out - The output stream to write the object to.
Throws:
IOException - If there was an error writing to the stream.

readObject

Object readObject(PacketDecoder decoder,
                  int length)
Read an object from a byte array.

Parameters:
data - The byte data to read (or decode) an object from.
position - The position to begin parsing from. This position will be updated upon return to point to the first byte after the decoded object in the byte array.
length - The number of bytes to use in reading the object. If the length is unknown and intrinsic to the type being decoded (such as a C-String, which is terminated by a nul-byte), then -1 may be supplied.
Returns:
The decoded object.


Copyright © 2011 Mobicents. All Rights Reserved.