mirror of
https://github.com/danbulant/node-x11
synced 2026-05-24 12:35:39 +00:00
allow Buffer to be used as 'a' format pack parameter
This commit is contained in:
parent
7a2761b061
commit
aa5c4bac1c
1 changed files with 11 additions and 4 deletions
|
|
@ -244,6 +244,7 @@ UnpackStream.prototype.pack = function(format, arguments)
|
||||||
var n = arguments[arg++];
|
var n = arguments[arg++];
|
||||||
buf[offset++] = n;
|
buf[offset++] = n;
|
||||||
break;
|
break;
|
||||||
|
case 's': // TODO: implement signed INT16!!!
|
||||||
case 'S':
|
case 'S':
|
||||||
var n = arguments[arg++];
|
var n = arguments[arg++];
|
||||||
buf[offset++] = n & 0xff;
|
buf[offset++] = n & 0xff;
|
||||||
|
|
@ -256,11 +257,17 @@ UnpackStream.prototype.pack = function(format, arguments)
|
||||||
buf[offset++] = (n >> 16) & 0xff;
|
buf[offset++] = (n >> 16) & 0xff;
|
||||||
buf[offset++] = (n >> 24) & 0xff;
|
buf[offset++] = (n >> 24) & 0xff;
|
||||||
break;
|
break;
|
||||||
case 'a': // string
|
case 'a': // string or buffer
|
||||||
var str = arguments[arg++];
|
var str = arguments[arg++];
|
||||||
|
if (Buffer.isBuffer(str))
|
||||||
|
{
|
||||||
|
str.copy(buf, offset);
|
||||||
|
offset += str.length;
|
||||||
|
} else {
|
||||||
// TODO: buffer.write could be faster
|
// TODO: buffer.write could be faster
|
||||||
for (var c = 0; c < str.length; ++c)
|
for (var c = 0; c < str.length; ++c)
|
||||||
buf[offset++] = str.charCodeAt(c);
|
buf[offset++] = str.charCodeAt(c);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'p': // padded string
|
case 'p': // padded string
|
||||||
var str = arguments[arg++];
|
var str = arguments[arg++];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue