Give the esm_class bits one owner beside the constants

This commit is contained in:
2026-08-27 16:18:05 +02:00
parent b9f77ec969
commit c9c3121d40
7 changed files with 21 additions and 21 deletions
+9
View File
@@ -103,6 +103,15 @@ export const consts = {
},
} as const;
/** esm_class bits 5-2 name the message type; bit 6 is the UDH indicator. */
export function hasUdh(esmClass: number): boolean {
return (esmClass & consts.ESM_CLASS.UDH_INDICATOR) === consts.ESM_CLASS.UDH_INDICATOR;
}
export function messageTypeOf(esmClass: number): number {
return esmClass & 0x3c;
}
export type ConstGroup = keyof typeof consts;
export type MessageState = keyof typeof consts.MESSAGE_STATE;
+2 -5
View File
@@ -1,7 +1,7 @@
import type { MessageState } from './defs/constants.ts';
import type { ParamValue } from './defs/types.ts';
import type { PduObject } from './pdu.ts';
import { consts, constsById } from './defs/constants.ts';
import { consts, constsById, messageTypeOf } from './defs/constants.ts';
import { decodeMessage } from './message.ts';
import { paramNumber, paramText } from './defs/types.ts';
@@ -123,13 +123,10 @@ export function parseReceipt(message: string): Receipt {
};
}
/** esm_class bits 5-2 name the message type; the rest are the messaging mode and the GSM features. */
const messageTypeBits = 0x3c;
type MessageType = 'other' | 'receipt' | 'unmarked';
function messageType(pduObj: PduObject): MessageType {
const type = paramNumber(pduObj.params.esm_class, 0) & messageTypeBits;
const type = messageTypeOf(paramNumber(pduObj.params.esm_class, 0));
if (type === consts.ESM_CLASS.MC_DELIVERY_RECEIPT) return 'receipt';
if (type !== 0) return 'other';
+4 -6
View File
@@ -6,10 +6,10 @@ import type { SmppLog } from './log.ts';
import { Reassembler, decodeSegments } from './reassembly.ts';
import { bindCommands, defaults } from './session-options.ts';
import { concatInfo } from './udh.ts';
import { consts } from './defs/constants.ts';
import { hasUdh } from './defs/constants.ts';
import { createSms } from './sms.ts';
import { dlrFromPdu } from './dlr.ts';
import { paramText } from './defs/types.ts';
import { paramNumber, paramText } from './defs/types.ts';
export type IncomingRequestsOptions = {
dlrMerger: DlrMerger;
@@ -115,10 +115,8 @@ export class IncomingRequests {
private onMessage(pduObj: PduObject): void {
const message = pduObj.params.short_message;
const esmClass = pduObj.params.esm_class;
const hasUdh = typeof esmClass === 'number'
&& (esmClass & consts.ESM_CLASS.UDH_INDICATOR) === consts.ESM_CLASS.UDH_INDICATOR;
const concat = hasUdh && Buffer.isBuffer(message) ? concatInfo(message) : undefined;
const carriesUdh = hasUdh(paramNumber(pduObj.params.esm_class, 0));
const concat = carriesUdh && Buffer.isBuffer(message) ? concatInfo(message) : undefined;
if (!concat) {
this.emitSms([pduObj]);
+2 -2
View File
@@ -1,6 +1,6 @@
import type { Result } from './result.ts';
import type { EncodingName } from './defs/encodings.ts';
import { consts } from './defs/constants.ts';
import { hasUdh } from './defs/constants.ts';
import { detect, encodingByDataCoding, encodings } from './defs/encodings.ts';
/** A single SMS carries 1120 bits, whatever the alphabet. */
@@ -33,7 +33,7 @@ export function decodeMessage(
): { message: string; udh: Buffer | undefined } {
const encoding = encodingByDataCoding(dataCoding);
if ((esmClass & consts.ESM_CLASS.UDH_INDICATOR) !== consts.ESM_CLASS.UDH_INDICATOR) {
if (!hasUdh(esmClass)) {
return { message: encodings[encoding].decode(buffer), udh: undefined };
}
+2 -2
View File
@@ -4,7 +4,7 @@ import type { ParamValue } from './defs/types.ts';
import type { Result, VoidResult } from './result.ts';
import type { Tlv } from './defs/tlvs.ts';
import { cmds, commandNameById, isCommandName } from './defs/commands.ts';
import { consts } from './defs/constants.ts';
import { consts, hasUdh } from './defs/constants.ts';
import { decodeMessage, encodeMessage } from './message.ts';
import { detect, encodingByDataCoding } from './defs/encodings.ts';
import { errorNameById, errors, isErrorName } from './defs/errors.ts';
@@ -327,7 +327,7 @@ function parseOnce(pdu: Buffer, trailingNull: boolean): Result<{ aligned: boolea
const esmClass = paramNumber(params.esm_class, 0);
// A message carrying a UDH stays a buffer; the session needs the header intact to reassemble.
if (Buffer.isBuffer(message) && (esmClass & consts.ESM_CLASS.UDH_INDICATOR) !== consts.ESM_CLASS.UDH_INDICATOR) {
if (Buffer.isBuffer(message) && !hasUdh(esmClass)) {
params.short_message = decodeMessage(message, paramNumber(params.data_coding, 0)).message;
}