Fit every concatenated segment in an SMS, and close the encoding helpers' throw (#96)
* Regression tests for the concatenated segment budget and the encoding-name door * Budget unpacked segments at 134 octets, and export isEncodingName * Name the length a Latin-1 message starts costing more segments at * Fold the totality clause into hard rule 1, and log the unrepresentable-alphabet finding * Make the maxSegments regression discriminate, and drop the narrating comments * State the per-alphabet capacities accurately, and log the invalid-date path
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ export { Session } from './session.ts';
|
||||
|
||||
export { cmds, cmdsById, commandNameById, isCommandName } from './defs/commands.ts';
|
||||
export { consts, constsById } from './defs/constants.ts';
|
||||
export { detect, encodingByDataCoding, encodings, messageClassOf } from './defs/encodings.ts';
|
||||
export { detect, encodingByDataCoding, encodings, isEncodingName, messageClassOf } from './defs/encodings.ts';
|
||||
export { errorNameById, errors, errorsById, isErrorName } from './defs/errors.ts';
|
||||
export { tlvs, tlvsById } from './defs/tlvs.ts';
|
||||
export { types } from './defs/types.ts';
|
||||
|
||||
+3
-3
@@ -10,8 +10,8 @@ const singleMessageBits = 1120;
|
||||
/** The concatenation UDH numbers the segments of a message in a single octet. */
|
||||
export const maxSegments = 255;
|
||||
|
||||
/** Budget per concatenated segment: septets for GSM, octets for UCS2. */
|
||||
const segmentUnits = { ASCII: 153, UCS2: 67 * 2 } as const;
|
||||
/** Budget per segment: the 134 octets left of 140 after the UDH, or the 153 septets GSM packs into them. */
|
||||
const segmentUnits: Record<EncodingName, number> = { ASCII: 153, LATIN1: 134, UCS2: 134 };
|
||||
|
||||
export type SplitOptions = {
|
||||
encoding?: EncodingName;
|
||||
@@ -69,7 +69,7 @@ export function splitMessage(message: string, options: SplitOptions): Buffer[] {
|
||||
return [encodings[encoding].encode(message)];
|
||||
}
|
||||
|
||||
const budget = encoding === 'UCS2' ? segmentUnits.UCS2 : segmentUnits.ASCII;
|
||||
const budget = segmentUnits[encoding];
|
||||
const parts: string[] = [];
|
||||
let current = '';
|
||||
let used = 0;
|
||||
|
||||
Reference in New Issue
Block a user