extendscript-rpc-server
Advanced tools
Comparing version 1.0.2 to 1.0.3
// taken from http://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript | ||
function byteLength(str) { | ||
// returns the byte length of an utf8 string | ||
var s = str.length; | ||
for (var i=str.length-1; i>=0; i--) { | ||
var code = str.charCodeAt(i); | ||
if (code > 0x7f && code <= 0x7ff) s++; | ||
else if (code > 0x7ff && code <= 0xffff) s+=2; | ||
if (code >= 0xDC00 && code <= 0xDFFF) i--; //trail surrogate | ||
// thanks to http://stackoverflow.com/questions/14592364/utf-16-to-utf-8-conversion-in-javascript | ||
function decodeUTF16LE( binaryStr ) { | ||
var cp = []; | ||
for( var i = 0; i < binaryStr.length; i+=2) { | ||
cp.push( | ||
binaryStr.charCodeAt(i) | | ||
( binaryStr.charCodeAt(i+1) << 8 ) | ||
); | ||
} | ||
return s; | ||
return String.fromCharCode.apply( String, cp ); | ||
} | ||
function encodeUTF16LE( binaryStr ) { | ||
var cp = []; | ||
for( var i = 0; i < binaryStr.length; ++i) { | ||
cp.push( | ||
binaryStr.charCodeAt(i) & 0xFF | ||
); | ||
cp.push( | ||
( (binaryStr.charCodeAt(i) >> 8) & 0xFF ) | ||
); | ||
} | ||
return String.fromCharCode.apply( String, cp ); | ||
} | ||
function xmlconnection(host) { | ||
@@ -48,6 +63,2 @@ this.sock = new Socket(); | ||
if(type == 1) { | ||
this.sock.encoding = 'utf8'; | ||
} | ||
data = this.sock.read(length); | ||
@@ -58,8 +69,6 @@ if(!data || !data.length) { | ||
this.sock.encoding = 'binary'; | ||
offset += length; | ||
if(type == 1) { | ||
datas.push(new XML(data)); | ||
datas.push(new XML(decodeUTF16LE(data))); | ||
} else { | ||
@@ -84,6 +93,6 @@ datas.push({cid: cid, data: data}); | ||
if(data.toXMLString) { | ||
var str = data.toXMLString(); | ||
data = datas[i] = { cid: 0, type: 1, data: str, length: byteLength(str), charset: 'utf8' }; | ||
var str = encodeUTF16LE(data.toXMLString()); | ||
data = datas[i] = { cid: 0, type: 1, data: str, length: str.length }; | ||
} else { | ||
data = datas[i] = { cid: data.cid || i, type: 2, data: data, length: data.length, charset: 'binary' }; | ||
data = datas[i] = { cid: data.cid || i, type: 2, data: data, length: data.length }; | ||
} | ||
@@ -115,6 +124,3 @@ | ||
this.sock.write(payload); | ||
this.sock.encoding = data.charset || 'binary'; | ||
this.sock.write(data.data); | ||
this.sock.encoding = 'binary'; | ||
} | ||
@@ -121,0 +127,0 @@ |
12
index.js
@@ -60,3 +60,3 @@ | ||
case 1: | ||
var xmlDATA = et.parse(new Buffer(data.slice(offset3, nextSize + offset3), 'binary').toString('utf8')); | ||
var xmlDATA = et.parse(new Buffer(data.slice(offset3, nextSize + offset3), 'binary').toString('ucs2')); | ||
@@ -90,4 +90,4 @@ var fnc = functionTable[xmlDATA._root.tag]; | ||
var xml = etree.write({'xml_declaration': false}); | ||
//var len = Buffer.byteLength(xml, 'utf8'); | ||
return { cid: cids[index], type: 1, data: xml, length: xml.length }; | ||
var edata = new Buffer(xml, 'ucs2'); | ||
return { cid: cids[index], type: 1, data: edata, length: edata.length }; | ||
} | ||
@@ -122,7 +122,3 @@ }); | ||
socket.write(payload2, 'binary'); | ||
if(value.type == 1) { | ||
socket.write(value.data, 'utf-8'); | ||
} else { | ||
socket.write(value.data, 'binary'); | ||
} | ||
socket.write(value.data, 'binary'); | ||
}); | ||
@@ -129,0 +125,0 @@ }); |
{ | ||
"name": "extendscript-rpc-server", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "ExtendScript XML / Binary RPC server & client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
203
13077