mirror of
https://github.com/danbulant/node-x11
synced 2026-06-16 21:21:20 +00:00
fix: signed 13 and 32 bit ints (l and s formats)
This commit is contained in:
parent
a930aa4d13
commit
33005e8f76
1 changed files with 21 additions and 11 deletions
|
|
@ -55,7 +55,7 @@ ReadFormatRequest.prototype.execute = function(bufferlist, tag1, tag2)
|
|||
// maybe best approach is to wait all data required for format and then process fixed buffer
|
||||
// TODO: byte order!!!
|
||||
switch (arg) {
|
||||
case 'C':
|
||||
case 'C':
|
||||
this.data.push(bufferlist.getbyte());
|
||||
break;
|
||||
case 'S':
|
||||
|
|
@ -121,7 +121,7 @@ UnpackStream.prototype.unpackTo = function(destination, names_formats, callback)
|
|||
{
|
||||
var names = [];
|
||||
var format = '';
|
||||
|
||||
|
||||
for (var i=0; i < names_formats.length; ++i)
|
||||
{
|
||||
var off = 0;
|
||||
|
|
@ -172,7 +172,7 @@ UnpackStream.prototype.resume = function()
|
|||
}
|
||||
|
||||
UnpackStream.prototype.getbyte = function()
|
||||
{
|
||||
{
|
||||
var res = 0;
|
||||
var b = this.readlist[0];
|
||||
if (this.offset + 1 < b.length)
|
||||
|
|
@ -180,7 +180,7 @@ UnpackStream.prototype.getbyte = function()
|
|||
res = b[this.offset];
|
||||
this.offset++;
|
||||
this.length--;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// last byte in current buffer, shift read list
|
||||
|
|
@ -202,7 +202,7 @@ UnpackStream.prototype.pstr = function(str)
|
|||
if (len == 0)
|
||||
return; // nothing to write
|
||||
var buf = new Buffer(len);
|
||||
buf.write(str, 'binary');
|
||||
buf.write(str, 'binary');
|
||||
this.write_queue.push(buf);
|
||||
}
|
||||
*/
|
||||
|
|
@ -211,7 +211,7 @@ UnpackStream.prototype.pstr = function(str)
|
|||
UnpackStream.prototype.pack = function(format, args)
|
||||
{
|
||||
var packetlength = 0;
|
||||
|
||||
|
||||
var arg = 0;
|
||||
for (var i = 0; i < format.length; ++i)
|
||||
{
|
||||
|
|
@ -238,20 +238,30 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
{
|
||||
switch(format[i])
|
||||
{
|
||||
case 'x':
|
||||
case 'x':
|
||||
buf[offset++] = 0;
|
||||
break;
|
||||
case 'C':
|
||||
var n = args[arg++];
|
||||
buf[offset++] = n;
|
||||
break;
|
||||
case 's': // TODO: implement signed INT16!!!
|
||||
case 's':
|
||||
var n = args[arg++];
|
||||
buf.writeInt16LE(n, offset);
|
||||
offset += 2;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
var n = args[arg++];
|
||||
buf[offset++] = n & 0xff;
|
||||
buf[offset++] = (n >> 8) & 0xff;
|
||||
break;
|
||||
case 'l': // TODO: implement signed INT32!!!
|
||||
case 'l':
|
||||
var n = args[arg++];
|
||||
buf.writeInt32LE(n, offset);
|
||||
offset += 4;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
var n = args[arg++];
|
||||
buf[offset++] = n & 0xff;
|
||||
|
|
@ -281,7 +291,7 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
for (; c < len; ++c)
|
||||
buf[offset++] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.write_queue.push(buf);
|
||||
this.write_length += buf.length;
|
||||
|
|
@ -290,7 +300,7 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
|
||||
UnpackStream.prototype.flush = function(stream)
|
||||
{
|
||||
// TODO: measure performance benefit of
|
||||
// TODO: measure performance benefit of
|
||||
// creating and writing one big concatenated buffer
|
||||
|
||||
// TODO: check write result
|
||||
|
|
|
|||
Loading…
Reference in a new issue