Added option to force encoding on message splitter
This commit is contained in:
+3
-2
@@ -603,12 +603,13 @@ function bitCount(msg, encoding) {
|
|||||||
* Split a message into multiple messages
|
* Split a message into multiple messages
|
||||||
*
|
*
|
||||||
* @param str msg
|
* @param str msg
|
||||||
|
* @param str encoding - Force encoding ASCII or UCS2 (OPTIONAL)
|
||||||
* @return array of buffers
|
* @return array of buffers
|
||||||
*/
|
*/
|
||||||
function splitMsg(msg) {
|
function splitMsg(msg, encoding) {
|
||||||
var msgPart = '',
|
var msgPart = '',
|
||||||
msgs = [],
|
msgs = [],
|
||||||
encoding = defs.encodings.detect(msg),
|
encoding = encoding || defs.encodings.detect(msg),
|
||||||
totBitCount = bitCount(msg, encoding),
|
totBitCount = bitCount(msg, encoding),
|
||||||
udh,
|
udh,
|
||||||
i,
|
i,
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@
|
|||||||
"url": "https://github.com/larvit/larvitsmpp",
|
"url": "https://github.com/larvit/larvitsmpp",
|
||||||
"type": "git"
|
"type": "git"
|
||||||
},
|
},
|
||||||
"version": "0.1.8",
|
"version": "0.1.9",
|
||||||
"readmeFilename": "README.md",
|
"readmeFilename": "README.md",
|
||||||
"readme": "larvitsmpp",
|
"readme": "larvitsmpp",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|||||||
@@ -398,6 +398,7 @@ describe('PDU convertion', function() {
|
|||||||
|
|
||||||
assert(larvitsmpp.utils.bitCount(a) === 28, 'ASCII');
|
assert(larvitsmpp.utils.bitCount(a) === 28, 'ASCII');
|
||||||
assert(larvitsmpp.utils.bitCount(b) === 1120, 'ASCII');
|
assert(larvitsmpp.utils.bitCount(b) === 1120, 'ASCII');
|
||||||
|
assert(larvitsmpp.utils.bitCount(b, 'UCS2') === 2560, 'ASCII, expected 2560 but got ' + larvitsmpp.utils.bitCount(b, 'UCS2'));
|
||||||
assert(larvitsmpp.utils.bitCount(c) === 1120, 'UCS2');
|
assert(larvitsmpp.utils.bitCount(c) === 1120, 'UCS2');
|
||||||
assert(larvitsmpp.utils.bitCount(d) === 1225, 'ASCII');
|
assert(larvitsmpp.utils.bitCount(d) === 1225, 'ASCII');
|
||||||
assert(larvitsmpp.utils.bitCount(e) === 4528, 'UCS2');
|
assert(larvitsmpp.utils.bitCount(e) === 4528, 'UCS2');
|
||||||
@@ -406,6 +407,7 @@ describe('PDU convertion', function() {
|
|||||||
|
|
||||||
assert(larvitsmpp.utils.splitMsg(a).length === 1);
|
assert(larvitsmpp.utils.splitMsg(a).length === 1);
|
||||||
assert(larvitsmpp.utils.splitMsg(b).length === 1);
|
assert(larvitsmpp.utils.splitMsg(b).length === 1);
|
||||||
|
assert(larvitsmpp.utils.splitMsg(b, 'UCS2').length === 3, 'Expected length 2, but got ' + larvitsmpp.utils.splitMsg(b, 'UCS2').length);
|
||||||
assert(larvitsmpp.utils.splitMsg(c).length === 1);
|
assert(larvitsmpp.utils.splitMsg(c).length === 1);
|
||||||
assert(larvitsmpp.utils.splitMsg(d).length === 2);
|
assert(larvitsmpp.utils.splitMsg(d).length === 2);
|
||||||
assert(larvitsmpp.utils.splitMsg(e).length === 5);
|
assert(larvitsmpp.utils.splitMsg(e).length === 5);
|
||||||
|
|||||||
Reference in New Issue
Block a user