org.mobicents.protocols.smpp.encoding
Class DefaultAlphabetEncoding

java.lang.Object
  extended by org.mobicents.protocols.smpp.encoding.AbstractMessageEncoding<String>
      extended by org.mobicents.protocols.smpp.encoding.AlphabetEncoding
          extended by org.mobicents.protocols.smpp.encoding.DefaultAlphabetEncoding
All Implemented Interfaces:
MessageEncoding<String>

public class DefaultAlphabetEncoding
extends AlphabetEncoding

This class encodes and decodes Java Strings to and from the SMS default alphabet. It also supports the default extension table. The default alphabet and it's extension table is defined in GSM 03.38.

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

Field Summary
protected  char[] CHAR_TABLE
           
protected  char[] EXT_CHAR_TABLE
          Extended character table.
static int EXTENDED_ESCAPE
           
static int PAGE_BREAK
          Page break (extended table).
 
Constructor Summary
DefaultAlphabetEncoding()
           
 
Method Summary
 String decode(byte[] data, int offset, int length)
          Decode an SMS default alphabet-encoded octet string into a Java String.
 byte[] encode(String s)
          Encode a Java String into a byte array using the SMS Default alphabet.
 int getCharSize()
           
 int getUnknownCharReplacement()
          Get the current code point in use for unknown characters.
 byte[] pack(byte[] unpacked)
          Pack a byte array according to the GSM bit-packing algorithm.
 void setUnknownCharReplacement(int unknownCharReplacement)
          Set the byte to use when there is no code point for a Unicode character.
 byte[] unpack(byte[] packed)
          Unpack a byte array according to the GSM bit-packing algorithm.
 
Methods inherited from class org.mobicents.protocols.smpp.encoding.AlphabetEncoding
decode, getCharset, getEncodedSize, setCharset
 
Methods inherited from class org.mobicents.protocols.smpp.encoding.AbstractMessageEncoding
getDataCoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTENDED_ESCAPE

public static final int EXTENDED_ESCAPE
See Also:
Constant Field Values

PAGE_BREAK

public static final int PAGE_BREAK
Page break (extended table).

See Also:
Constant Field Values

CHAR_TABLE

protected final char[] CHAR_TABLE

EXT_CHAR_TABLE

protected final char[] EXT_CHAR_TABLE
Extended character table. Characters in this table are accessed by the 'escape' character in the base table. It is important that none of the 'inactive' characters ever be matchable with a valid base-table character as this breaks the encoding loop.

See Also:
EXTENDED_ESCAPE
Constructor Detail

DefaultAlphabetEncoding

public DefaultAlphabetEncoding()
Method Detail

setUnknownCharReplacement

public void setUnknownCharReplacement(int unknownCharReplacement)
Set the byte to use when there is no code point for a Unicode character. This byte will be inserted into an encoded byte array if the String being encoded contains a character that the GSM default alphabet has no code point for. The default is to insert the code point for the '?' character - that is, byte 0x3f.

Parameters:
unknownCharReplacement - A code point for one of the characters in the basic character table.
Throws:
IllegalArgumentException - If 0 < unknownCharReplacement < 127 or unknownCharReplacement is 0x1b (the extended escape character).

getUnknownCharReplacement

public int getUnknownCharReplacement()
Get the current code point in use for unknown characters.

Returns:
The current code point in use for unknown characters.
See Also:
setUnknownCharReplacement(int)

decode

public String decode(byte[] data,
                     int offset,
                     int length)
Decode an SMS default alphabet-encoded octet string into a Java String.

Overrides:
decode in class AlphabetEncoding
Parameters:
data - The bytes to decode.
offset - The offset within the data to begin decoding characters.
length - The number of bytes to decode to characters.

encode

public byte[] encode(String s)
Encode a Java String into a byte array using the SMS Default alphabet.

Specified by:
encode in interface MessageEncoding<String>
Overrides:
encode in class AlphabetEncoding

getCharSize

public int getCharSize()

pack

public byte[] pack(byte[] unpacked)
Pack a byte array according to the GSM bit-packing algorithm. The GSM specification defines a simple compression mechanism for its default alphabet to pack more message characters into a smaller space. Since the alphabet only contains 128 symbols, each one can be represented in 7 bits. The packing algorithm squeezes the bits for each symbol "down" into the preceeding byte (so bit 7 of the first byte actually contains bit 0 of the second symbol in a default alphabet string, bits 6 and 7 in the second byte contain bits 0 and 1 of the third symbol etc.) Since the maximum short message length is 140 bytes, you save one bit per byte using the default alphabet giving you a total of 140 + (140 / 8) = 160 characters to use. This is where the 160 character limit comes from in SMPP packets.

Having said all that, most SMSCs do NOT use the packing algorithm when communicating over TCP/IP. They either use a full 8-bit alphabet such as ASCII or Latin-1, or they accept the default alphabet in its unpacked form. As such, you will be unlikely to need this method.

Parameters:
unpacked - The unpacked byte array.
Returns:
A new byte array containing the bytes in their packed form.

unpack

public byte[] unpack(byte[] packed)
Unpack a byte array according to the GSM bit-packing algorithm. Read the full description in the documentation of the pack method.

Parameters:
packed - The packed byte array.
Returns:
A new byte array containing the unpacked bytes.
See Also:
pack(byte[])


Copyright © 2011 Mobicents. All Rights Reserved.