diff options
author | Yazhong Liu <yorkiefixer@gmail.com> | 2014-10-02 16:24:58 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2014-10-03 01:31:20 -0700 |
commit | 83d7d9e6d81fc35764a9000b6d7b17a0e7d8cc92 (patch) | |
tree | 9bf43e0f7264737867125a91ce4c01ef94c6e5fa /doc | |
parent | e9ca7b9d8de68e13d40698f34145e2a0428aa9d7 (diff) | |
download | node-new-83d7d9e6d81fc35764a9000b6d7b17a0e7d8cc92.tar.gz |
buffer: add generic functions for (u)int ops
Add generic functions for (U)Int read/write operations on Buffers. These
support up to and including 48 bit reads and writes.
Include documentation and tests.
Additional work done by Trevor Norris to include 40 and 48 bit write
support. Because bitwise operations cannot be used on values greater
than 32 bits, the operations have been replaced with mathematical
calculations. Regardless, they are still faster than floating point
operations.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/buffer.markdown | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/doc/api/buffer.markdown b/doc/api/buffer.markdown index fb86accebb..e4ba04ed7f 100644 --- a/doc/api/buffer.markdown +++ b/doc/api/buffer.markdown @@ -180,6 +180,48 @@ The method will not write partial characters. len = buf.write('\u00bd + \u00bc = \u00be', 0); console.log(len + " bytes: " + buf.toString('utf8', 0, len)); +### buf.writeUIntLE(value, offset, byteLength[, noAssert]) +### buf.writeUIntBE(value, offset, byteLength[, noAssert]) +### buf.writeIntLE(value, offset, byteLength[, noAssert]) +### buf.writeIntBE(value, offset, byteLength[, noAssert]) + +* `value` {Number} Bytes to be written to buffer +* `offset` {Number} `0 <= offset <= buf.length` +* `byteLength` {Number} `0 < byteLength <= 6` +* `noAssert` {Boolean} Default: false +* Return: {Number} + +Writes `value` to the buffer at the specified `offset` and `byteLength`. +Supports up to 48 bits of accuracy. For example: + + var b = new Buffer(6); + b.writeUIntBE(0x1234567890ab, 0, 6); + // <Buffer 12 34 56 78 90 ab> + +Set `noAssert` to `true` to skip validation of `value` and `offset`. Defaults +to `false`. + +### buf.readUIntLE(offset, byteLength[, noAssert]) +### buf.readUIntBE(offset, byteLength[, noAssert]) +### buf.readIntLE(offset, byteLength[, noAssert]) +### buf.readIntBE(offset, byteLength[, noAssert]) + +* `offset` {Number} `0 <= offset <= buf.length` +* `byteLength` {Number} `0 < byteLength <= 6` +* `noAssert` {Boolean} Default: false +* Return: {Number} + +A generalized version of all numeric read methods. Supports up to 48 bits of +accuracy. For example: + + var b = new Buffer(6); + b.writeUint16LE(0x90ab, 0); + b.writeUInt32LE(0x12345678, 2); + b.readUIntLE(0, 6).toString(16); // Specify 6 bytes (48 bits) + // output: '1234567890ab' + +Set `noAssert` to true to skip validation of `offset`. This means that `offset` +may be beyond the end of the buffer. Defaults to `false`. ### buf.toString([encoding][, start][, end]) |