diff --git a/lib/utils.js b/lib/utils.js index 12c5571..535288c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -607,9 +607,10 @@ function splitMsg(msg) { msgs = [], encoding = defs.encodings.detect(msg), totBitCount = bitCount(msg, encoding), - partBitCount, udh, - i; + i, + i2, + partCharLimit; // A single message could contain up to 1120 bits // Return directly if the message fits into that @@ -626,16 +627,24 @@ function splitMsg(msg) { log.silly('larvitsmpp: lib/utils.js: splitMsg() - bundleMsgId set to ' + bundleMsgId); - i = 0; + if (encoding === 'ASCII') { + partCharLimit = 153; + } else { + partCharLimit = 67; + } + + i = 0; + i2 = 0; while (msg[i] !== undefined) { msgPart += msg[i]; - partBitCount = bitCount(msgPart, encoding); + i2 ++; - if (partBitCount > 1072) { + if (i2 === partCharLimit) { // We've reached the message limit - log.debug('larvitsmpp: lib/utils.js: splitMsg() - Msg part defined. partBitCount: ' + partBitCount + ' msgPart: "' + msgPart + '"'); + // Reset the local counter + i2 = 0; // Add this msgPart minus the last character to the msgs array as an encoded buffer msgs.push(defs.encodings[encoding].encode(msgPart.slice(0, - 1))); @@ -683,4 +692,4 @@ exports.objToPdu = objToPdu; exports.pduReturn = pduReturn; exports.smppDate = smppDate; exports.bitCount = bitCount; -exports.splitMsg = splitMsg; +exports.splitMsg = splitMsg; \ No newline at end of file