ie.omk.smpp.message.tlv.Encoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smppapi Show documentation
Show all versions of smppapi Show documentation
Java Implementation of the Short Message Peer to Peer API.
The newest version!
package ie.omk.smpp.message.tlv;
/**
* Interface for a value type encoder. Implementations of this interface are
* responsible for encoding Java types to byte arrays for optional parameter
* values.
*
* Optional parameter support in this API is based on using standard Java types
* for parameter values. Therefore, where the SMPP specification defines a
* parameter as being a C octet string, applications should be able to us the
* standard java.lang.String. An appropriate {@link StringEncoder}class will
* then handle encoding the Java String to appropriate byte values. The
* following table details the default encoders supplied with the API and the
* types of values they encode.
*
*
*
* SMPP type
* Encoder
* Java type
*
*
* Bit mask
* {@link BitmaskEncoder}
* java.util.BitSet
*
*
* Integer
* {@link NumberEncoder}
* java.lang.Number
* (java.lang.Byte, java.lang.Short, java.lang.Integer, java.lang.Long)
*
*
* Octet string
* {@link OctetEncoder}
* byte[]
*
*
* C-Octet string
* {@link StringEncoder}
* java.lang.String
*
*
There is also one more encoder, {@link NullEncoder},
* which is used in special cases where a particular optional parameter has a
* tag but no value.
*
* @author Oran Kelly
* @version $Id: Encoder.java 255 2006-03-09 09:34:37Z orank $
*/
public interface Encoder {
/**
* Encode a value to a byte array.
*
* @param tag
* The tag of the value to encode.
* @param value
* The value to encode.
* @param b
* The byte array to encode the value to.
* @param offset
* The offset within b
to begin encoding from.
* @throws java.lang.ArrayIndexOutOfBoundsException
* if the encoding tries to write beyond the end of the byte
* array.
*/
void writeTo(Tag tag, Object value, byte[] b, int offset);
/**
* Decode a value from a byte array.
*
* @param tag
* The tag of the value to decode.
* @param b
* The byte array to decode the value from.
* @param offset
* The offset in b
to begin decoding from.
* @param length
* The length of the value to decode.
* @return The value object.
* @throws java.lang.ArrayIndexOutOfBoundsException
* if the decoding tries to read beyond the end of the byte
* array.
*/
Object readFrom(Tag tag, byte[] b, int offset, int length);
/**
* Calculate the length, in bytes, that the value will encode as. The value
* returned from this method must exactly match the number of bytes that
* writeTo
will attempt to encode to a byte array.
*
* @param tag
* The tag of the value to get the length for.
* @param value
* The value to get the length for.
* @return The length value
will encode to in bytes.
*/
int getValueLength(Tag tag, Object value);
}