Core
Encodings
GSM 03.38, Latin-1, UCS2 — detection, data_coding, and 7-bit packing.
Three text codecs cover real-world SMS traffic:
| Encoding | dataCoding | Capacity (single / segment) | Notes |
|---|---|---|---|
"ASCII" (GSM 03.38) | 0x01 | 160 / 153 septets | the GSM default alphabet — not US-ASCII |
"LATIN1" (ISO-8859-1) | 0x03 | 140 / 134 octets | |
"UCS2" (UTF-16BE) | 0x08 | 70 / 67 characters | catch-all for any text |
Detection
import { detectEncoding, encodeMessage, decodeMessage } from "@better-smpp/core";
detectEncoding("hello"); // "ASCII"
detectEncoding("héllo©"); // "LATIN1"
detectEncoding("привет"); // "UCS2"
encodeMessage("привет");
// { bytes: <Buffer …>, encoding: "UCS2", dataCoding: 8 }
decodeMessage(bytes, 0x08); // "привет"
decodeMessage(bytes, 0x04); // undefined — binary scheme, keep the BufferThe message filter inside the codec uses the same detection when a PDU's dataCoding
is unset, so most code never calls these directly.
GSM 03.38 details
The GSM coder produces unpacked septets (one septet per octet) — the format SMPP
peers exchange in shortMessage. Extension characters (€ [ ] { } | ^ ~ \) cost two
septets via the escape mechanism. All four national-language variants are supported:
import { GsmCharset, encodeGsm, decodeGsm, isGsmEncodable, detectGsmCharset } from "@better-smpp/core";
encodeGsm("@€"); // <Buffer 00 1b 65>
decodeGsm(bytes, GsmCharset.TURKISH); // Turkish shift table (UDH IE 0x24/0x25)
isGsmEncodable("Ğğİş", GsmCharset.TURKISH); // true
detectGsmCharset("ÁÍÓÚá"); // GsmCharset.SPANISHInbound messages carrying a national-language UDH IE (0x24/0x25) are decoded with the correct shift table automatically.
Packed 7-bit
For GSM air-interface TPDUs (160 characters in 140 octets), pack and unpack septets:
import { packSeptets, unpackSeptets, encodeGsm } from "@better-smpp/core";
packSeptets(encodeGsm("hello")); // <Buffer e8 32 9b fd 06>
unpackSeptets(packed, septetCount); // back to one septet per octetdata_coding constants
import { DATA_CODING } from "@better-smpp/core";
DATA_CODING.SMSC_DEFAULT; // 0x00 — decoded using the configurable defaultEncoding
DATA_CODING.ASCII; // 0x01
DATA_CODING.LATIN1; // 0x03
DATA_CODING.BINARY; // 0x04 — payload stays a Buffer
DATA_CODING.UCS2; // 0x08
// …plus CYRILLIC, HEBREW, JIS, PICTOGRAM, and the other spec values