ie.omk.smpp.message.tlv
Interface Encoder

All Known Implementing Classes:
BitmaskEncoder, NullEncoder, NumberEncoder, OctetEncoder, StringEncoder

public interface Encoder

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 StringEncoderclass 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 BitmaskEncoder java.util.BitSet
Integer NumberEncoder java.lang.Number
(java.lang.Byte, java.lang.Short, java.lang.Integer, java.lang.Long)
Octet string OctetEncoder byte[]
C-Octet string StringEncoder java.lang.String
There is also one more encoder, NullEncoder, which is used in special cases where a particular optional parameter has a tag but no value.

Version:
$Id: Encoder.java 255 2006-03-09 09:34:37Z orank $
Author:
Oran Kelly

Method Summary
 int getValueLength(Tag tag, Object value)
          Calculate the length, in bytes, that the value will encode as.
 Object readFrom(Tag tag, byte[] b, int offset, int length)
          Decode a value from a byte array.
 void writeTo(Tag tag, Object value, byte[] b, int offset)
          Encode a value to a byte array.
 

Method Detail

writeTo

void writeTo(Tag tag,
             Object value,
             byte[] b,
             int offset)
Encode a value to a byte array.

Parameters:
tag - The tag of the value to encode.
value - The value to encode.
b - The byte array to encode the value to.
offset - The offset within b to begin encoding from.
Throws:
ArrayIndexOutOfBoundsException - if the encoding tries to write beyond the end of the byte array.

readFrom

Object readFrom(Tag tag,
                byte[] b,
                int offset,
                int length)
Decode a value from a byte array.

Parameters:
tag - The tag of the value to decode.
b - The byte array to decode the value from.
offset - The offset in b to begin decoding from.
length - The length of the value to decode.
Returns:
The value object.
Throws:
ArrayIndexOutOfBoundsException - if the decoding tries to read beyond the end of the byte array.

getValueLength

int getValueLength(Tag tag,
                   Object value)
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.

Parameters:
tag - The tag of the value to get the length for.
value - The value to get the length for.
Returns:
The length value will encode to in bytes.


Copyright © 2011 smppapi at Sourceforge. All Rights Reserved.