From e69f1b7475209c8b4843f3b8e90c4099d9ee8171 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 21 May 2013 14:11:40 +0200 Subject: [PATCH 1/2] Add support for signed data - Use Buffer write functions --- lib/unpackbuffer.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/unpackbuffer.js b/lib/unpackbuffer.js index 706fcd8..2fdbfea 100644 --- a/lib/unpackbuffer.js +++ b/lib/unpackbuffer.js @@ -22,27 +22,31 @@ module.exports.addUnpack = function(Buffer) { var arg = format[current_arg]; switch (arg) { - case 'C': - data.push(this[offset++]); + case 'C': + data.push(this.readUInt8(offset++)); + break; + case 'c': + data.push(this.readInt8(offset++)); break; case 'S': - case 's': //TODO: 16bit signed unpack - var b1 = this[offset++]; - var b2 = this[offset++]; - data.push(b2*256+b1); + data.push(this.readUInt16LE(offset)); + offset += 2; + break; + case 's': + data.push(this.readInt16LE(offset)); + offset += 2; break; case 'n': - var b1 = this[offset++]; - var b2 = this[offset++]; - data.push(b1*256+b2); + data.push(this.readUInt16BE(offset)); + offset += 2; break; case 'L': - case 'l': //TODO: 32bit signed unpack - var b1 = this[offset++]; - var b2 = this[offset++]; - var b3 = this[offset++]; - var b4 = this[offset++]; - data.push(((b4*256+b3)*256 + b2)*256 + b1); + data.push(this.readUInt32LE(offset)); + offset += 4; + break; + case 'l': + data.push(this.readInt32LE(offset)); + offset += 4; break; case 'x': offset++; From e361424792e8508574d2ecd596103be148242f96 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 21 May 2013 14:31:59 +0200 Subject: [PATCH 2/2] Fix format of some requests --- lib/corereqs.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index 5019882..a386d64 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -488,7 +488,7 @@ module.exports = { }, function(buf) { - var res = buf.unpack('LSS'); + var res = buf.unpack('Lss'); ext = {}; ext.child = res[0]; ext.destX = res[1]; @@ -682,7 +682,7 @@ module.exports = { PolyText8: [ function(drawable, gc, x, y, items) { - var format = 'CxSLLSS'; + var format = 'CxSLLss'; var numItems = items.length; var reqLen = 16; var args = [74, 0, drawable, gc, x, y]; @@ -801,7 +801,7 @@ module.exports = { }, function(buff) { - var res = buff.unpack('LSSSSSx'); + var res = buff.unpack('LssSSSx'); var ext = {}; ext.windowid = res[0] ext.xPos = res[1]; @@ -821,7 +821,7 @@ module.exports = { SetScreenSaver: [ function(timeout, interval, preferBlanking, allowExposures) { - return [ 'CxSSSCCxx', [107, 3, timeout, interval, preferBlanking, allowExposures]]; + return [ 'CxSssCCxx', [107, 3, timeout, interval, preferBlanking, allowExposures]]; } ],