Cómo calcular el campo SM Length en SMPP
En el protocolo SMPP, el campo sm_length
especifica la longitud en bytes del contenido del mensaje corto contenido en el campo short_message
de PDUs como submit_sm
, deliver_sm
y data_sm
.
Detalles del campo
- Nombre del campo: sm_length
- Tamaño: 1 byte (entero sin signo)
- Rango: 0–254 (máximo permitido por SMPP 3.4)
- Ubicación: Justo antes del campo
short_message
- Propósito: Indica el número de bytes en la carga útil de
short_message
Comportamiento clave
El valor de sm_length
depende de la codificación utilizada:
Codificación | Caracteres por SMS | Tamaño en bytes | Notas |
---|---|---|---|
GSM 7-bit | Hasta 160 | Hasta 140 | Bits empaquetados; el tamaño real en bytes depende del contenido |
UCS2 | Hasta 70 | 2 × número de caracteres | Cada carácter ocupa 2 bytes |
8-bit binario | N/A | Hasta 140 | Longitud en bytes crudos |
Ejemplo: Mensaje ASCII
Un mensaje simple usando codificación 7-bit por defecto:
Texto: "Hello" Codificación: GSM 7-bit Bytes empaquetados (Hex): C8 32 9B FD 06 Longitud en bytes: 5 sm_length: 5
Ejemplo: Mensaje codificado en UCS2
Un mensaje Unicode usando codificación UCS2 (data_coding = 0x08):
Texto: "Hi" Hex UCS2: 0048 0069 Array de bytes: 00 48 00 69 Longitud en bytes: 4 sm_length: 4
Ejemplo de PDU SMPP (submit_sm)
0000003B // Longitud del comando (59 bytes) 00000004 // ID del comando: submit_sm 00000000 // Estado del comando 00000001 // Número de secuencia 00 // service_type 01 // source_addr_ton 01 // source_addr_npi 31323334 // source_addr ("1234") 00 01 // dest_addr_ton 01 // dest_addr_npi 35363738 // destination_addr ("5678") 00 00 // esm_class 00 // protocol_id 00 // priority_flag 00 // schedule_delivery_time 00 // validity_period 00 // registered_delivery 00 // replace_if_present_flag 08 // data_coding: UCS2 00 // sm_default_msg_id 04 // sm_length: 4 00480069 // short_message: "Hi" en UCS2
Notas importantes
sm_length
se refiere a la longitud en bytes, no al conteo de caracteres.- Si el contenido del mensaje se divide en múltiples mensajes (concatenación), cada parte tiene su propio
sm_length
. - No confundas
sm_length
con la longitud total del mensaje (longitud PDU).
División y concatenación de mensajes
Cuando un mensaje excede el tamaño máximo de carga útil, se divide en partes usando un UDH (User Data Header). El sm_length
en estos casos incluye también el UDH:
Ejemplo: UDH (6 bytes) + 67 bytes UCS2 = 73 sm_length = 73
Conclusión
El campo sm_length
es crítico en la mensajería SMPP ya que define cuántos bytes debe leer el SMSC para el cuerpo real del mensaje. Entender cómo afecta la codificación a este campo garantiza una entrega precisa y exitosa de los mensajes.
Referencias
- Especificación SMPP 3.4
- Juego de caracteres GSM 03.38
- Codificación Unicode UCS2
More information
- How to configure the SMPP Service Type field
- How to configure the SMPP Phone Number fields
- How to configure the SMPP ESM Class field
- How to configure the SMPP PID field
- How to configure the SMPP Prioirity field
- How to configure the SMPP Scheduled Time field
- How to configure the SMPP Validity Period field
- How to configure the SMPP Registered Delivery field
- How to configure the SMPP Replace if Present field
- How to configure the sm_default_msg_id field
- How to configure the SMPP DCS field
- How to calculate the SMPP SM Length field
- How to put data into the SMPP SM field