typespeed 2.0.13 → 2.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.decorator.js +0 -1
- package/dist/database.decorator.js +0 -1
- package/dist/default/express-server.class.js +0 -1
- package/dist/default/log-default.class.js +0 -1
- package/dist/default/node-cache.class.js +0 -1
- package/dist/default/rabbitmq.class.js +0 -1
- package/dist/default/read-write-db.class.js +0 -1
- package/dist/default/redis.class.js +0 -1
- package/dist/factory/cache-factory.class.js +0 -1
- package/dist/factory/data-source-factory.class.js +0 -1
- package/dist/factory/log-factory.class.js +0 -1
- package/dist/factory/server-factory.class.js +0 -1
- package/dist/route.decorator.js +0 -1
- package/dist/scaffold/command.js +0 -1
- package/dist/typespeed.d.ts +133 -12
- package/dist/typespeed.js +1 -1
- package/package.json +2 -2
- package/src/typespeed.d.ts +133 -0
- package/src/typespeed.ts +2 -1
- package/test/node_modules/.package-lock.json +112 -4
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +17 -0
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +30 -0
- package/test/node_modules/@acuminous/bitsyntax/LICENSE +6 -0
- package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +21 -0
- package/test/node_modules/@acuminous/bitsyntax/Makefile +15 -0
- package/test/node_modules/@acuminous/bitsyntax/README.md +308 -0
- package/test/node_modules/@acuminous/bitsyntax/index.js +10 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +303 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +142 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +67 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +232 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +32 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +1173 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +119 -0
- package/test/node_modules/@acuminous/bitsyntax/package.json +36 -0
- package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +50 -0
- package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +193 -0
- package/test/node_modules/@types/node/README.md +1 -1
- package/test/node_modules/@types/node/buffer.d.ts +5 -2
- package/test/node_modules/@types/node/child_process.d.ts +27 -0
- package/test/node_modules/@types/node/globals.d.ts +1 -0
- package/test/node_modules/@types/node/package.json +2 -2
- package/test/node_modules/@types/node/test.d.ts +43 -20
- package/test/node_modules/@types/node/ts4.8/buffer.d.ts +5 -2
- package/test/node_modules/@types/node/ts4.8/child_process.d.ts +27 -0
- package/test/node_modules/@types/node/ts4.8/globals.d.ts +1 -0
- package/test/node_modules/@types/node/ts4.8/test.d.ts +43 -19
- package/test/node_modules/@types/node/ts4.8/url.d.ts +3 -3
- package/test/node_modules/@types/node/ts4.8/util.d.ts +1 -1
- package/test/node_modules/@types/node/url.d.ts +3 -3
- package/test/node_modules/@types/node/util.d.ts +1 -1
- package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/test/node_modules/amqplib/.github/workflows/test.yml +38 -0
- package/test/node_modules/amqplib/CHANGELOG.md +430 -0
- package/test/node_modules/amqplib/LICENSE +6 -0
- package/test/node_modules/amqplib/LICENSE-MIT +21 -0
- package/test/node_modules/amqplib/Makefile +47 -0
- package/test/node_modules/amqplib/README.md +157 -0
- package/test/node_modules/amqplib/bin/generate-defs.js +722 -0
- package/test/node_modules/amqplib/callback_api.js +22 -0
- package/test/node_modules/amqplib/channel_api.js +16 -0
- package/test/node_modules/amqplib/examples/headers.js +42 -0
- package/test/node_modules/amqplib/examples/receive_generator.js +39 -0
- package/test/node_modules/amqplib/examples/send_generators.js +42 -0
- package/test/node_modules/amqplib/examples/ssl.js +64 -0
- package/test/node_modules/amqplib/examples/tutorials/README.md +93 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +28 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +30 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +27 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +27 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +30 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +36 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +56 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +55 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +49 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +45 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +29 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +35 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log.js +19 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +20 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +19 -0
- package/test/node_modules/amqplib/examples/tutorials/new_task.js +18 -0
- package/test/node_modules/amqplib/examples/tutorials/package.json +16 -0
- package/test/node_modules/amqplib/examples/tutorials/receive.js +21 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +28 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +44 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +43 -0
- package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +52 -0
- package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +39 -0
- package/test/node_modules/amqplib/examples/tutorials/send.js +23 -0
- package/test/node_modules/amqplib/examples/tutorials/worker.js +28 -0
- package/test/node_modules/amqplib/examples/waitForConfirms.js +22 -0
- package/test/node_modules/amqplib/lib/api_args.js +314 -0
- package/test/node_modules/amqplib/lib/bitset.js +130 -0
- package/test/node_modules/amqplib/lib/callback_model.js +327 -0
- package/test/node_modules/amqplib/lib/channel.js +499 -0
- package/test/node_modules/amqplib/lib/channel_model.js +302 -0
- package/test/node_modules/amqplib/lib/codec.js +321 -0
- package/test/node_modules/amqplib/lib/connect.js +189 -0
- package/test/node_modules/amqplib/lib/connection.js +663 -0
- package/test/node_modules/amqplib/lib/credentials.js +42 -0
- package/test/node_modules/amqplib/lib/defs.js +4966 -0
- package/test/node_modules/amqplib/lib/error.js +24 -0
- package/test/node_modules/amqplib/lib/format.js +40 -0
- package/test/node_modules/amqplib/lib/frame.js +113 -0
- package/test/node_modules/amqplib/lib/heartbeat.js +89 -0
- package/test/node_modules/amqplib/lib/mux.js +129 -0
- package/test/node_modules/amqplib/package.json +37 -0
- package/test/node_modules/amqplib/test/bitset.js +69 -0
- package/test/node_modules/amqplib/test/callback_api.js +312 -0
- package/test/node_modules/amqplib/test/channel.js +621 -0
- package/test/node_modules/amqplib/test/channel_api.js +596 -0
- package/test/node_modules/amqplib/test/codec.js +237 -0
- package/test/node_modules/amqplib/test/connect.js +197 -0
- package/test/node_modules/amqplib/test/connection.js +390 -0
- package/test/node_modules/amqplib/test/data.js +254 -0
- package/test/node_modules/amqplib/test/frame.js +198 -0
- package/test/node_modules/amqplib/test/mux.js +204 -0
- package/test/node_modules/amqplib/test/util.js +219 -0
- package/test/node_modules/buffer-more-ints/.travis.yml +6 -0
- package/test/node_modules/buffer-more-ints/LICENSE +19 -0
- package/test/node_modules/buffer-more-ints/README.md +69 -0
- package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +183 -0
- package/test/node_modules/buffer-more-ints/buffer-more-ints.js +432 -0
- package/test/node_modules/buffer-more-ints/package.json +19 -0
- package/test/node_modules/buffer-more-ints/polyfill.js +71 -0
- package/test/node_modules/core-util-is/LICENSE +19 -0
- package/test/node_modules/core-util-is/README.md +3 -0
- package/test/node_modules/core-util-is/lib/util.js +107 -0
- package/test/node_modules/core-util-is/package.json +38 -0
- package/test/node_modules/debug/LICENSE +20 -0
- package/test/node_modules/debug/README.md +481 -0
- package/test/node_modules/debug/package.json +59 -0
- package/test/node_modules/debug/src/browser.js +269 -0
- package/test/node_modules/debug/src/common.js +274 -0
- package/test/node_modules/debug/src/index.js +10 -0
- package/test/node_modules/debug/src/node.js +263 -0
- package/test/node_modules/inherits/LICENSE +16 -0
- package/test/node_modules/inherits/README.md +42 -0
- package/test/node_modules/inherits/inherits.js +9 -0
- package/test/node_modules/inherits/inherits_browser.js +27 -0
- package/test/node_modules/inherits/package.json +29 -0
- package/test/node_modules/isarray/README.md +54 -0
- package/test/node_modules/isarray/build/build.js +209 -0
- package/test/node_modules/isarray/component.json +19 -0
- package/test/node_modules/isarray/index.js +3 -0
- package/test/node_modules/isarray/package.json +25 -0
- package/test/node_modules/ms/index.js +162 -0
- package/test/node_modules/ms/license.md +21 -0
- package/test/node_modules/ms/package.json +37 -0
- package/test/node_modules/ms/readme.md +60 -0
- package/test/node_modules/querystringify/LICENSE +22 -0
- package/test/node_modules/querystringify/README.md +61 -0
- package/test/node_modules/querystringify/index.js +118 -0
- package/test/node_modules/querystringify/package.json +38 -0
- package/test/node_modules/readable-stream/LICENSE +18 -0
- package/test/node_modules/readable-stream/README.md +15 -0
- package/test/node_modules/readable-stream/duplex.js +1 -0
- package/test/node_modules/readable-stream/float.patch +923 -0
- package/test/node_modules/readable-stream/lib/_stream_duplex.js +89 -0
- package/test/node_modules/readable-stream/lib/_stream_passthrough.js +46 -0
- package/test/node_modules/readable-stream/lib/_stream_readable.js +951 -0
- package/test/node_modules/readable-stream/lib/_stream_transform.js +209 -0
- package/test/node_modules/readable-stream/lib/_stream_writable.js +477 -0
- package/test/node_modules/readable-stream/package.json +32 -0
- package/test/node_modules/readable-stream/passthrough.js +1 -0
- package/test/node_modules/readable-stream/readable.js +10 -0
- package/test/node_modules/readable-stream/transform.js +1 -0
- package/test/node_modules/readable-stream/writable.js +1 -0
- package/test/node_modules/requires-port/.travis.yml +19 -0
- package/test/node_modules/requires-port/LICENSE +22 -0
- package/test/node_modules/requires-port/README.md +47 -0
- package/test/node_modules/requires-port/index.js +38 -0
- package/test/node_modules/requires-port/package.json +47 -0
- package/test/node_modules/requires-port/test.js +98 -0
- package/test/node_modules/safe-buffer/LICENSE +21 -0
- package/test/node_modules/safe-buffer/README.md +584 -0
- package/test/node_modules/safe-buffer/index.d.ts +187 -0
- package/test/node_modules/safe-buffer/index.js +62 -0
- package/test/node_modules/safe-buffer/package.json +37 -0
- package/test/node_modules/string_decoder/LICENSE +20 -0
- package/test/node_modules/string_decoder/README.md +7 -0
- package/test/node_modules/string_decoder/index.js +221 -0
- package/test/node_modules/string_decoder/package.json +25 -0
- package/test/node_modules/url-parse/LICENSE +22 -0
- package/test/node_modules/url-parse/README.md +153 -0
- package/test/node_modules/url-parse/dist/url-parse.js +755 -0
- package/test/node_modules/url-parse/dist/url-parse.min.js +1 -0
- package/test/node_modules/url-parse/dist/url-parse.min.js.map +1 -0
- package/test/node_modules/url-parse/index.js +589 -0
- package/test/node_modules/url-parse/package.json +49 -0
- package/test/src/test-mq.class.ts +1 -2
- package/tsconfig.json +4 -3
- package/dist/core.decorator.d.ts +0 -18
- package/dist/core.decorator.js.map +0 -1
- package/dist/database.decorator.d.ts +0 -24
- package/dist/database.decorator.js.map +0 -1
- package/dist/default/express-server.class.d.ts +0 -15
- package/dist/default/express-server.class.js.map +0 -1
- package/dist/default/log-default.class.d.ts +0 -6
- package/dist/default/log-default.class.js.map +0 -1
- package/dist/default/node-cache.class.d.ts +0 -13
- package/dist/default/node-cache.class.js.map +0 -1
- package/dist/default/rabbitmq.class.d.ts +0 -9
- package/dist/default/rabbitmq.class.js.map +0 -1
- package/dist/default/read-write-db.class.d.ts +0 -10
- package/dist/default/read-write-db.class.js.map +0 -1
- package/dist/default/redis.class.d.ts +0 -5
- package/dist/default/redis.class.js.map +0 -1
- package/dist/factory/cache-factory.class.d.ts +0 -7
- package/dist/factory/cache-factory.class.js.map +0 -1
- package/dist/factory/data-source-factory.class.d.ts +0 -4
- package/dist/factory/data-source-factory.class.js.map +0 -1
- package/dist/factory/log-factory.class.d.ts +0 -4
- package/dist/factory/log-factory.class.js.map +0 -1
- package/dist/factory/server-factory.class.d.ts +0 -6
- package/dist/factory/server-factory.class.js.map +0 -1
- package/dist/route.decorator.d.ts +0 -8
- package/dist/route.decorator.js.map +0 -1
- package/dist/scaffold/command.d.ts +0 -2
- package/dist/scaffold/command.js.map +0 -1
- package/dist/typespeed.js.map +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# buffer-more-ints: Add support for more integer widths to Buffer
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/dpw/node-buffer-more-ints)
|
|
4
|
+
|
|
5
|
+
Node's Buffer only supports reading and writing integers of a limited
|
|
6
|
+
range of widths. This module provides support for more widths, so
|
|
7
|
+
that integers from 1 to 8 bytes (64 bits) can be accessed. The
|
|
8
|
+
support takes two forms. Firstly, as stand-alone functions similar to
|
|
9
|
+
the integer reading/writing methods of Buffer:
|
|
10
|
+
|
|
11
|
+
$ node
|
|
12
|
+
> var moreints = require('buffer-more-ints')
|
|
13
|
+
undefined
|
|
14
|
+
> moreints.readInt64BE(new Buffer("0000deadbeef0000", "hex"), 0).toString(16)
|
|
15
|
+
'deadbeef0000'
|
|
16
|
+
|
|
17
|
+
Read and write functions for the regular widths (8, 16, 32) are also
|
|
18
|
+
present in this module, for consistency.
|
|
19
|
+
|
|
20
|
+
The second form is methods patched into `Buffer.prototype`, installed
|
|
21
|
+
by requiring `'buffer-more-ints/polyfill'`:
|
|
22
|
+
|
|
23
|
+
$ node
|
|
24
|
+
> require('buffer-more-ints/polyfill')
|
|
25
|
+
{}
|
|
26
|
+
> new Buffer("0000deadbeef0000", "hex").readInt64BE(0).toString(16)
|
|
27
|
+
'deadbeef0000'
|
|
28
|
+
|
|
29
|
+
buffer-more-ints/polyfill also adds methods `readIntBE`, `writeIntBE`,
|
|
30
|
+
and their LE and UInt counterparts, which take an initial argument
|
|
31
|
+
giving the width of the integer in bytes:
|
|
32
|
+
|
|
33
|
+
> var b = new Buffer(3);
|
|
34
|
+
> b.writeIntLE(3, -123456, 0);
|
|
35
|
+
> b.toString('hex')
|
|
36
|
+
'c01dfe'
|
|
37
|
+
> b.readIntLE(3, 0);
|
|
38
|
+
-123456
|
|
39
|
+
|
|
40
|
+
The functions added by buffer-more-ints are all implemented in terms
|
|
41
|
+
of the core Buffer functions. Part way through writing the code, I
|
|
42
|
+
discovered that node.js currently implements those in JavaScript, so
|
|
43
|
+
this doesn't lead to performance benefits. But should node ever
|
|
44
|
+
switch to implementing its Buffer operations natively, this
|
|
45
|
+
module should get a speed boost.
|
|
46
|
+
|
|
47
|
+
## Limitations
|
|
48
|
+
|
|
49
|
+
As JavaScript uses IEEE754 doubles for numbers, the contiguous range
|
|
50
|
+
of integers it can represent is [-2^53 - 1, 2^53 - 1]. So only
|
|
51
|
+
integer widths up to 6 bytes or 48 bits can be read exactly. Reads of
|
|
52
|
+
7 or 8 bytes (56 or 64 bits) will return the closest value that can be
|
|
53
|
+
represented as a JavaScript number.
|
|
54
|
+
|
|
55
|
+
In certain situations it might be important to check that a JavaScript
|
|
56
|
+
number was read exactly. The `isContiguousInt` or
|
|
57
|
+
`Buffer.isContiguousInt` (polyfill) function will determine this:
|
|
58
|
+
|
|
59
|
+
> Buffer.isContiguousInt(0x1fffffffffffff);
|
|
60
|
+
true
|
|
61
|
+
> Buffer.isContiguousInt(0x20000000000000);
|
|
62
|
+
false
|
|
63
|
+
|
|
64
|
+
And `assertContiguousInt` asserts that a number is so:
|
|
65
|
+
|
|
66
|
+
> Buffer.assertContiguousInt(0x1fffffffffffff);
|
|
67
|
+
undefined
|
|
68
|
+
> Buffer.assertContiguousInt(0x20000000000000);
|
|
69
|
+
AssertionError: number cannot be represented as a contiguous integer
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('./polyfill');
|
|
4
|
+
|
|
5
|
+
// A simple abbreviation to obtain a buffer from a hex string
|
|
6
|
+
function h2b(str) {
|
|
7
|
+
return new Buffer(str, "hex");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Reverse a buffer
|
|
11
|
+
function reverse(buf) {
|
|
12
|
+
var res = new Buffer(buf.length);
|
|
13
|
+
for (var i = 0, j = buf.length - 1; j >= 0; i++, j--) {
|
|
14
|
+
res[i] = buf[j];
|
|
15
|
+
}
|
|
16
|
+
return res;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Fill a buffer with distinctive data
|
|
20
|
+
function scrub(buf) {
|
|
21
|
+
var pos = 0;
|
|
22
|
+
var written;
|
|
23
|
+
while ((written = buf.write("deadbeef", pos, 4, "hex")) == 4) {
|
|
24
|
+
pos += written;
|
|
25
|
+
}
|
|
26
|
+
return buf;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function xint_case(xint) {
|
|
30
|
+
return function (assert, hex, val, inexact) {
|
|
31
|
+
var readBE = "read" + xint + "BE";
|
|
32
|
+
var writeBE = "write" + xint + "BE";
|
|
33
|
+
var readLE = "read" + xint + "LE";
|
|
34
|
+
var writeLE = "write" + xint + "LE";
|
|
35
|
+
|
|
36
|
+
var len = hex.length / 2;
|
|
37
|
+
|
|
38
|
+
// Straightforward read cases
|
|
39
|
+
assert.equal(h2b(hex)[readBE](len, 0), val);
|
|
40
|
+
assert.equal(reverse(h2b(hex))[readLE](len, 0), val);
|
|
41
|
+
|
|
42
|
+
// Test straightforward writes and noAssert writes off the ends of
|
|
43
|
+
// the buffer
|
|
44
|
+
var buf = scrub(new Buffer(len));
|
|
45
|
+
buf[writeBE](len, val, 0);
|
|
46
|
+
if (!inexact) {
|
|
47
|
+
assert.equal(buf.toString("hex"), hex);
|
|
48
|
+
} else {
|
|
49
|
+
assert.equal(buf[readBE](len, 0), val);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
scrub(buf);
|
|
53
|
+
buf[writeLE](len, val, 0);
|
|
54
|
+
if (!inexact) {
|
|
55
|
+
assert.equal(reverse(buf).toString("hex"), hex);
|
|
56
|
+
} else {
|
|
57
|
+
assert.equal(buf[readLE](len, 0), val);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Accesses off the ends of the buffer should throw.
|
|
61
|
+
assert.throws(function () { h2b(hex)[readBE](len, -1); });
|
|
62
|
+
assert.throws(function () { h2b(hex)[readBE](len, 1); });
|
|
63
|
+
assert.throws(function () { reverse(h2b(hex))[readLE](len, 1); });
|
|
64
|
+
assert.throws(function () { reverse(h2b(hex))[readLE](len, -1); });
|
|
65
|
+
assert.throws(function () { buf[writeBE](len, val, 1); });
|
|
66
|
+
assert.throws(function () { buf[writeBE](len, val, -1); });
|
|
67
|
+
assert.throws(function () { buf[writeLE](len, val, 1); });
|
|
68
|
+
assert.throws(function () { buf[writeLE](len, val, -1); });
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var uint_case = xint_case("UInt");
|
|
73
|
+
var int_case = xint_case("Int");
|
|
74
|
+
|
|
75
|
+
module.exports.uint = function (assert) {
|
|
76
|
+
uint_case(assert, "00", 0x00);
|
|
77
|
+
uint_case(assert, "01", 0x01);
|
|
78
|
+
uint_case(assert, "ff", 0xff);
|
|
79
|
+
|
|
80
|
+
uint_case(assert, "0000", 0x0000);
|
|
81
|
+
uint_case(assert, "0102", 0x0102);
|
|
82
|
+
uint_case(assert, "ffff", 0xffff);
|
|
83
|
+
|
|
84
|
+
uint_case(assert, "000000", 0x000000);
|
|
85
|
+
uint_case(assert, "010203", 0x010203);
|
|
86
|
+
uint_case(assert, "ffffff", 0xffffff);
|
|
87
|
+
|
|
88
|
+
uint_case(assert, "00000000", 0x00000000);
|
|
89
|
+
uint_case(assert, "01020304", 0x01020304);
|
|
90
|
+
uint_case(assert, "ffffffff", 0xffffffff);
|
|
91
|
+
|
|
92
|
+
uint_case(assert, "0000000000", 0x0000000000);
|
|
93
|
+
uint_case(assert, "0102030405", 0x0102030405);
|
|
94
|
+
uint_case(assert, "ffffffffff", 0xffffffffff);
|
|
95
|
+
|
|
96
|
+
uint_case(assert, "000000000000", 0x000000000000);
|
|
97
|
+
uint_case(assert, "010203040506", 0x010203040506);
|
|
98
|
+
uint_case(assert, "ffffffffffff", 0xffffffffffff);
|
|
99
|
+
|
|
100
|
+
uint_case(assert, "00000000000000", 0x00000000000000);
|
|
101
|
+
uint_case(assert, "01020304050607", 0x01020304050607);
|
|
102
|
+
uint_case(assert, "ffffffffffffff", 0xffffffffffffff);
|
|
103
|
+
|
|
104
|
+
uint_case(assert, "0000000000000000", 0x0000000000000000);
|
|
105
|
+
uint_case(assert, "0102030405060708", 0x0102030405060708, true);
|
|
106
|
+
uint_case(assert, "ffffffffffffffff", 0xffffffffffffffff);
|
|
107
|
+
|
|
108
|
+
assert.done();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
module.exports.int = function (assert) {
|
|
112
|
+
int_case(assert, "00", 0x00);
|
|
113
|
+
int_case(assert, "01", 0x01);
|
|
114
|
+
int_case(assert, "7f", 0x7f);
|
|
115
|
+
int_case(assert, "80", -0x80);
|
|
116
|
+
int_case(assert, "ff", -0x01);
|
|
117
|
+
|
|
118
|
+
int_case(assert, "0000", 0x0000);
|
|
119
|
+
int_case(assert, "0102", 0x0102);
|
|
120
|
+
int_case(assert, "7fff", 0x7fff);
|
|
121
|
+
int_case(assert, "8000", -0x8000);
|
|
122
|
+
int_case(assert, "ffff", -0x0001);
|
|
123
|
+
|
|
124
|
+
int_case(assert, "000000", 0x000000);
|
|
125
|
+
int_case(assert, "010203", 0x010203);
|
|
126
|
+
int_case(assert, "7fffff", 0x7fffff);
|
|
127
|
+
int_case(assert, "800000", -0x800000);
|
|
128
|
+
int_case(assert, "ffffff", -0x000001);
|
|
129
|
+
|
|
130
|
+
int_case(assert, "00000000", 0x00000000);
|
|
131
|
+
int_case(assert, "01020304", 0x01020304);
|
|
132
|
+
int_case(assert, "7fffffff", 0x7fffffff);
|
|
133
|
+
int_case(assert, "80000000", -0x80000000);
|
|
134
|
+
int_case(assert, "ffffffff", -0x00000001);
|
|
135
|
+
|
|
136
|
+
int_case(assert, "0000000000", 0x0000000000);
|
|
137
|
+
int_case(assert, "0102030405", 0x0102030405);
|
|
138
|
+
int_case(assert, "7fffffffff", 0x7fffffffff);
|
|
139
|
+
int_case(assert, "8000000000", -0x8000000000);
|
|
140
|
+
int_case(assert, "ffffffffff", -0x0000000001);
|
|
141
|
+
|
|
142
|
+
int_case(assert, "000000000000", 0x000000000000);
|
|
143
|
+
int_case(assert, "010203040506", 0x010203040506);
|
|
144
|
+
int_case(assert, "7fffffffffff", 0x7fffffffffff);
|
|
145
|
+
int_case(assert, "800000000000", -0x800000000000);
|
|
146
|
+
int_case(assert, "ffffffffffff", -0x000000000001);
|
|
147
|
+
|
|
148
|
+
int_case(assert, "00000000000000", 0x00000000000000);
|
|
149
|
+
int_case(assert, "01020304050607", 0x01020304050607);
|
|
150
|
+
int_case(assert, "7fffffffffffff", 0x7fffffffffffff);
|
|
151
|
+
int_case(assert, "80000000000000", -0x80000000000000);
|
|
152
|
+
int_case(assert, "ffffffffffffff", -0x00000000000001);
|
|
153
|
+
|
|
154
|
+
int_case(assert, "0000000000000000", 0x0000000000000000);
|
|
155
|
+
int_case(assert, "0102030405060708", 0x0102030405060708, true);
|
|
156
|
+
int_case(assert, "7fffffffffffffff", 0x7fffffffffffffff);
|
|
157
|
+
int_case(assert, "8000000000000000", -0x8000000000000000);
|
|
158
|
+
int_case(assert, "ffffffffffffffff", -0x0000000000000001);
|
|
159
|
+
|
|
160
|
+
assert.done();
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
module.exports.isContiguousInt = function (assert) {
|
|
164
|
+
assert.equal(Buffer.isContiguousInt(0x1fffffffffffff), true);
|
|
165
|
+
assert.equal(Buffer.isContiguousInt(0x20000000000000), false);
|
|
166
|
+
assert.equal(Buffer.isContiguousInt(-0x1fffffffffffff), true);
|
|
167
|
+
assert.equal(Buffer.isContiguousInt(-0x20000000000000), false);
|
|
168
|
+
|
|
169
|
+
assert.doesNotThrow(function () {
|
|
170
|
+
Buffer.assertContiguousInt(0x1fffffffffffff);
|
|
171
|
+
});
|
|
172
|
+
assert.throws(function () {
|
|
173
|
+
Buffer.assertContiguousInt(0x20000000000000);
|
|
174
|
+
});
|
|
175
|
+
assert.doesNotThrow(function () {
|
|
176
|
+
Buffer.assertContiguousInt(-0x1fffffffffffff);
|
|
177
|
+
});
|
|
178
|
+
assert.throws(function () {
|
|
179
|
+
Buffer.assertContiguousInt(-0x20000000000000);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
assert.done();
|
|
183
|
+
};
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// JavaScript is numerically challenged
|
|
4
|
+
var SHIFT_LEFT_32 = (1 << 16) * (1 << 16);
|
|
5
|
+
var SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
|
|
6
|
+
|
|
7
|
+
// The maximum contiguous integer that can be held in a IEEE754 double
|
|
8
|
+
var MAX_INT = 0x1fffffffffffff;
|
|
9
|
+
|
|
10
|
+
function isContiguousInt(val) {
|
|
11
|
+
return val <= MAX_INT && val >= -MAX_INT;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function assertContiguousInt(val) {
|
|
15
|
+
if (!isContiguousInt(val)) {
|
|
16
|
+
throw new TypeError("number cannot be represented as a contiguous integer");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports.isContiguousInt = isContiguousInt;
|
|
21
|
+
module.exports.assertContiguousInt = assertContiguousInt;
|
|
22
|
+
|
|
23
|
+
// Fill in the regular procedures
|
|
24
|
+
['UInt', 'Int'].forEach(function (sign) {
|
|
25
|
+
var suffix = sign + '8';
|
|
26
|
+
module.exports['read' + suffix] =
|
|
27
|
+
Buffer.prototype['read' + suffix].call;
|
|
28
|
+
module.exports['write' + suffix] =
|
|
29
|
+
Buffer.prototype['write' + suffix].call;
|
|
30
|
+
|
|
31
|
+
['16', '32'].forEach(function (size) {
|
|
32
|
+
['LE', 'BE'].forEach(function (endian) {
|
|
33
|
+
var suffix = sign + size + endian;
|
|
34
|
+
var read = Buffer.prototype['read' + suffix];
|
|
35
|
+
module.exports['read' + suffix] =
|
|
36
|
+
function (buf, offset) {
|
|
37
|
+
return read.call(buf, offset);
|
|
38
|
+
};
|
|
39
|
+
var write = Buffer.prototype['write' + suffix];
|
|
40
|
+
module.exports['write' + suffix] =
|
|
41
|
+
function (buf, val, offset) {
|
|
42
|
+
return write.call(buf, val, offset);
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Check that a value is an integer within the given range
|
|
49
|
+
function check_value(val, min, max) {
|
|
50
|
+
val = +val;
|
|
51
|
+
if (typeof(val) != 'number' || val < min || val > max || Math.floor(val) !== val) {
|
|
52
|
+
throw new TypeError("\"value\" argument is out of bounds");
|
|
53
|
+
}
|
|
54
|
+
return val;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check that something is within the Buffer bounds
|
|
58
|
+
function check_bounds(buf, offset, len) {
|
|
59
|
+
if (offset < 0 || offset + len > buf.length) {
|
|
60
|
+
throw new RangeError("Index out of range");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function readUInt24BE(buf, offset) {
|
|
65
|
+
return buf.readUInt8(offset) << 16 | buf.readUInt16BE(offset + 1);
|
|
66
|
+
}
|
|
67
|
+
module.exports.readUInt24BE = readUInt24BE;
|
|
68
|
+
|
|
69
|
+
function writeUInt24BE(buf, val, offset) {
|
|
70
|
+
val = check_value(val, 0, 0xffffff);
|
|
71
|
+
check_bounds(buf, offset, 3);
|
|
72
|
+
buf.writeUInt8(val >>> 16, offset);
|
|
73
|
+
buf.writeUInt16BE(val & 0xffff, offset + 1);
|
|
74
|
+
}
|
|
75
|
+
module.exports.writeUInt24BE = writeUInt24BE;
|
|
76
|
+
|
|
77
|
+
function readUInt40BE(buf, offset) {
|
|
78
|
+
return (buf.readUInt8(offset) || 0) * SHIFT_LEFT_32 + buf.readUInt32BE(offset + 1);
|
|
79
|
+
}
|
|
80
|
+
module.exports.readUInt40BE = readUInt40BE;
|
|
81
|
+
|
|
82
|
+
function writeUInt40BE(buf, val, offset) {
|
|
83
|
+
val = check_value(val, 0, 0xffffffffff);
|
|
84
|
+
check_bounds(buf, offset, 5);
|
|
85
|
+
buf.writeUInt8(Math.floor(val * SHIFT_RIGHT_32), offset);
|
|
86
|
+
buf.writeInt32BE(val & -1, offset + 1);
|
|
87
|
+
}
|
|
88
|
+
module.exports.writeUInt40BE = writeUInt40BE;
|
|
89
|
+
|
|
90
|
+
function readUInt48BE(buf, offset) {
|
|
91
|
+
return buf.readUInt16BE(offset) * SHIFT_LEFT_32 + buf.readUInt32BE(offset + 2);
|
|
92
|
+
}
|
|
93
|
+
module.exports.readUInt48BE = readUInt48BE;
|
|
94
|
+
|
|
95
|
+
function writeUInt48BE(buf, val, offset) {
|
|
96
|
+
val = check_value(val, 0, 0xffffffffffff);
|
|
97
|
+
check_bounds(buf, offset, 6);
|
|
98
|
+
buf.writeUInt16BE(Math.floor(val * SHIFT_RIGHT_32), offset);
|
|
99
|
+
buf.writeInt32BE(val & -1, offset + 2);
|
|
100
|
+
}
|
|
101
|
+
module.exports.writeUInt48BE = writeUInt48BE;
|
|
102
|
+
|
|
103
|
+
function readUInt56BE(buf, offset) {
|
|
104
|
+
return ((buf.readUInt8(offset) || 0) << 16 | buf.readUInt16BE(offset + 1)) * SHIFT_LEFT_32 + buf.readUInt32BE(offset + 3);
|
|
105
|
+
}
|
|
106
|
+
module.exports.readUInt56BE = readUInt56BE;
|
|
107
|
+
|
|
108
|
+
function writeUInt56BE(buf, val, offset) {
|
|
109
|
+
val = check_value(val, 0, 0xffffffffffffff);
|
|
110
|
+
check_bounds(buf, offset, 7);
|
|
111
|
+
|
|
112
|
+
if (val < 0x100000000000000) {
|
|
113
|
+
var hi = Math.floor(val * SHIFT_RIGHT_32);
|
|
114
|
+
buf.writeUInt8(hi >>> 16, offset);
|
|
115
|
+
buf.writeUInt16BE(hi & 0xffff, offset + 1);
|
|
116
|
+
buf.writeInt32BE(val & -1, offset + 3);
|
|
117
|
+
} else {
|
|
118
|
+
// Special case because 2^56-1 gets rounded up to 2^56
|
|
119
|
+
buf[offset] = 0xff;
|
|
120
|
+
buf[offset+1] = 0xff;
|
|
121
|
+
buf[offset+2] = 0xff;
|
|
122
|
+
buf[offset+3] = 0xff;
|
|
123
|
+
buf[offset+4] = 0xff;
|
|
124
|
+
buf[offset+5] = 0xff;
|
|
125
|
+
buf[offset+6] = 0xff;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
module.exports.writeUInt56BE = writeUInt56BE;
|
|
129
|
+
|
|
130
|
+
function readUInt64BE(buf, offset) {
|
|
131
|
+
return buf.readUInt32BE(offset) * SHIFT_LEFT_32 + buf.readUInt32BE(offset + 4);
|
|
132
|
+
}
|
|
133
|
+
module.exports.readUInt64BE = readUInt64BE;
|
|
134
|
+
|
|
135
|
+
function writeUInt64BE(buf, val, offset) {
|
|
136
|
+
val = check_value(val, 0, 0xffffffffffffffff);
|
|
137
|
+
check_bounds(buf, offset, 8);
|
|
138
|
+
|
|
139
|
+
if (val < 0x10000000000000000) {
|
|
140
|
+
buf.writeUInt32BE(Math.floor(val * SHIFT_RIGHT_32), offset);
|
|
141
|
+
buf.writeInt32BE(val & -1, offset + 4);
|
|
142
|
+
} else {
|
|
143
|
+
// Special case because 2^64-1 gets rounded up to 2^64
|
|
144
|
+
buf[offset] = 0xff;
|
|
145
|
+
buf[offset+1] = 0xff;
|
|
146
|
+
buf[offset+2] = 0xff;
|
|
147
|
+
buf[offset+3] = 0xff;
|
|
148
|
+
buf[offset+4] = 0xff;
|
|
149
|
+
buf[offset+5] = 0xff;
|
|
150
|
+
buf[offset+6] = 0xff;
|
|
151
|
+
buf[offset+7] = 0xff;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
module.exports.writeUInt64BE = writeUInt64BE;
|
|
155
|
+
|
|
156
|
+
function readUInt24LE(buf, offset) {
|
|
157
|
+
return buf.readUInt8(offset + 2) << 16 | buf.readUInt16LE(offset);
|
|
158
|
+
}
|
|
159
|
+
module.exports.readUInt24LE = readUInt24LE;
|
|
160
|
+
|
|
161
|
+
function writeUInt24LE(buf, val, offset) {
|
|
162
|
+
val = check_value(val, 0, 0xffffff);
|
|
163
|
+
check_bounds(buf, offset, 3);
|
|
164
|
+
|
|
165
|
+
buf.writeUInt16LE(val & 0xffff, offset);
|
|
166
|
+
buf.writeUInt8(val >>> 16, offset + 2);
|
|
167
|
+
}
|
|
168
|
+
module.exports.writeUInt24LE = writeUInt24LE;
|
|
169
|
+
|
|
170
|
+
function readUInt40LE(buf, offset) {
|
|
171
|
+
return (buf.readUInt8(offset + 4) || 0) * SHIFT_LEFT_32 + buf.readUInt32LE(offset);
|
|
172
|
+
}
|
|
173
|
+
module.exports.readUInt40LE = readUInt40LE;
|
|
174
|
+
|
|
175
|
+
function writeUInt40LE(buf, val, offset) {
|
|
176
|
+
val = check_value(val, 0, 0xffffffffff);
|
|
177
|
+
check_bounds(buf, offset, 5);
|
|
178
|
+
buf.writeInt32LE(val & -1, offset);
|
|
179
|
+
buf.writeUInt8(Math.floor(val * SHIFT_RIGHT_32), offset + 4);
|
|
180
|
+
}
|
|
181
|
+
module.exports.writeUInt40LE = writeUInt40LE;
|
|
182
|
+
|
|
183
|
+
function readUInt48LE(buf, offset) {
|
|
184
|
+
return buf.readUInt16LE(offset + 4) * SHIFT_LEFT_32 + buf.readUInt32LE(offset);
|
|
185
|
+
}
|
|
186
|
+
module.exports.readUInt48LE = readUInt48LE;
|
|
187
|
+
|
|
188
|
+
function writeUInt48LE(buf, val, offset) {
|
|
189
|
+
val = check_value(val, 0, 0xffffffffffff);
|
|
190
|
+
check_bounds(buf, offset, 6);
|
|
191
|
+
buf.writeInt32LE(val & -1, offset);
|
|
192
|
+
buf.writeUInt16LE(Math.floor(val * SHIFT_RIGHT_32), offset + 4);
|
|
193
|
+
}
|
|
194
|
+
module.exports.writeUInt48LE = writeUInt48LE;
|
|
195
|
+
|
|
196
|
+
function readUInt56LE(buf, offset) {
|
|
197
|
+
return ((buf.readUInt8(offset + 6) || 0) << 16 | buf.readUInt16LE(offset + 4)) * SHIFT_LEFT_32 + buf.readUInt32LE(offset);
|
|
198
|
+
}
|
|
199
|
+
module.exports.readUInt56LE = readUInt56LE;
|
|
200
|
+
|
|
201
|
+
function writeUInt56LE(buf, val, offset) {
|
|
202
|
+
val = check_value(val, 0, 0xffffffffffffff);
|
|
203
|
+
check_bounds(buf, offset, 7);
|
|
204
|
+
|
|
205
|
+
if (val < 0x100000000000000) {
|
|
206
|
+
buf.writeInt32LE(val & -1, offset);
|
|
207
|
+
var hi = Math.floor(val * SHIFT_RIGHT_32);
|
|
208
|
+
buf.writeUInt16LE(hi & 0xffff, offset + 4);
|
|
209
|
+
buf.writeUInt8(hi >>> 16, offset + 6);
|
|
210
|
+
} else {
|
|
211
|
+
// Special case because 2^56-1 gets rounded up to 2^56
|
|
212
|
+
buf[offset] = 0xff;
|
|
213
|
+
buf[offset+1] = 0xff;
|
|
214
|
+
buf[offset+2] = 0xff;
|
|
215
|
+
buf[offset+3] = 0xff;
|
|
216
|
+
buf[offset+4] = 0xff;
|
|
217
|
+
buf[offset+5] = 0xff;
|
|
218
|
+
buf[offset+6] = 0xff;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
module.exports.writeUInt56LE = writeUInt56LE;
|
|
222
|
+
|
|
223
|
+
function readUInt64LE(buf, offset) {
|
|
224
|
+
return buf.readUInt32LE(offset + 4) * SHIFT_LEFT_32 + buf.readUInt32LE(offset);
|
|
225
|
+
}
|
|
226
|
+
module.exports.readUInt64LE = readUInt64LE;
|
|
227
|
+
|
|
228
|
+
function writeUInt64LE(buf, val, offset) {
|
|
229
|
+
val = check_value(val, 0, 0xffffffffffffffff);
|
|
230
|
+
check_bounds(buf, offset, 8);
|
|
231
|
+
|
|
232
|
+
if (val < 0x10000000000000000) {
|
|
233
|
+
buf.writeInt32LE(val & -1, offset);
|
|
234
|
+
buf.writeUInt32LE(Math.floor(val * SHIFT_RIGHT_32), offset + 4);
|
|
235
|
+
} else {
|
|
236
|
+
// Special case because 2^64-1 gets rounded up to 2^64
|
|
237
|
+
buf[offset] = 0xff;
|
|
238
|
+
buf[offset+1] = 0xff;
|
|
239
|
+
buf[offset+2] = 0xff;
|
|
240
|
+
buf[offset+3] = 0xff;
|
|
241
|
+
buf[offset+4] = 0xff;
|
|
242
|
+
buf[offset+5] = 0xff;
|
|
243
|
+
buf[offset+6] = 0xff;
|
|
244
|
+
buf[offset+7] = 0xff;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
module.exports.writeUInt64LE = writeUInt64LE;
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
function readInt24BE(buf, offset) {
|
|
251
|
+
return (buf.readInt8(offset) << 16) + buf.readUInt16BE(offset + 1);
|
|
252
|
+
}
|
|
253
|
+
module.exports.readInt24BE = readInt24BE;
|
|
254
|
+
|
|
255
|
+
function writeInt24BE(buf, val, offset) {
|
|
256
|
+
val = check_value(val, -0x800000, 0x7fffff);
|
|
257
|
+
check_bounds(buf, offset, 3);
|
|
258
|
+
buf.writeInt8(val >> 16, offset);
|
|
259
|
+
buf.writeUInt16BE(val & 0xffff, offset + 1);
|
|
260
|
+
}
|
|
261
|
+
module.exports.writeInt24BE = writeInt24BE;
|
|
262
|
+
|
|
263
|
+
function readInt40BE(buf, offset) {
|
|
264
|
+
return (buf.readInt8(offset) || 0) * SHIFT_LEFT_32 + buf.readUInt32BE(offset + 1);
|
|
265
|
+
}
|
|
266
|
+
module.exports.readInt40BE = readInt40BE;
|
|
267
|
+
|
|
268
|
+
function writeInt40BE(buf, val, offset) {
|
|
269
|
+
val = check_value(val, -0x8000000000, 0x7fffffffff);
|
|
270
|
+
check_bounds(buf, offset, 5);
|
|
271
|
+
buf.writeInt8(Math.floor(val * SHIFT_RIGHT_32), offset);
|
|
272
|
+
buf.writeInt32BE(val & -1, offset + 1);
|
|
273
|
+
}
|
|
274
|
+
module.exports.writeInt40BE = writeInt40BE;
|
|
275
|
+
|
|
276
|
+
function readInt48BE(buf, offset) {
|
|
277
|
+
return buf.readInt16BE(offset) * SHIFT_LEFT_32 + buf.readUInt32BE(offset + 2);
|
|
278
|
+
}
|
|
279
|
+
module.exports.readInt48BE = readInt48BE;
|
|
280
|
+
|
|
281
|
+
function writeInt48BE(buf, val, offset) {
|
|
282
|
+
val = check_value(val, -0x800000000000, 0x7fffffffffff);
|
|
283
|
+
check_bounds(buf, offset, 6);
|
|
284
|
+
buf.writeInt16BE(Math.floor(val * SHIFT_RIGHT_32), offset);
|
|
285
|
+
buf.writeInt32BE(val & -1, offset + 2);
|
|
286
|
+
}
|
|
287
|
+
module.exports.writeInt48BE = writeInt48BE;
|
|
288
|
+
|
|
289
|
+
function readInt56BE(buf, offset) {
|
|
290
|
+
return (((buf.readInt8(offset) || 0) << 16) + buf.readUInt16BE(offset + 1)) * SHIFT_LEFT_32 + buf.readUInt32BE(offset + 3);
|
|
291
|
+
}
|
|
292
|
+
module.exports.readInt56BE = readInt56BE;
|
|
293
|
+
|
|
294
|
+
function writeInt56BE(buf, val, offset) {
|
|
295
|
+
val = check_value(val, -0x800000000000000, 0x7fffffffffffff);
|
|
296
|
+
check_bounds(buf, offset, 7);
|
|
297
|
+
|
|
298
|
+
if (val < 0x80000000000000) {
|
|
299
|
+
var hi = Math.floor(val * SHIFT_RIGHT_32);
|
|
300
|
+
buf.writeInt8(hi >> 16, offset);
|
|
301
|
+
buf.writeUInt16BE(hi & 0xffff, offset + 1);
|
|
302
|
+
buf.writeInt32BE(val & -1, offset + 3);
|
|
303
|
+
} else {
|
|
304
|
+
// Special case because 2^55-1 gets rounded up to 2^55
|
|
305
|
+
buf[offset] = 0x7f;
|
|
306
|
+
buf[offset+1] = 0xff;
|
|
307
|
+
buf[offset+2] = 0xff;
|
|
308
|
+
buf[offset+3] = 0xff;
|
|
309
|
+
buf[offset+4] = 0xff;
|
|
310
|
+
buf[offset+5] = 0xff;
|
|
311
|
+
buf[offset+6] = 0xff;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
module.exports.writeInt56BE = writeInt56BE;
|
|
315
|
+
|
|
316
|
+
function readInt64BE(buf, offset) {
|
|
317
|
+
return buf.readInt32BE(offset) * SHIFT_LEFT_32 + buf.readUInt32BE(offset + 4);
|
|
318
|
+
}
|
|
319
|
+
module.exports.readInt64BE = readInt64BE;
|
|
320
|
+
|
|
321
|
+
function writeInt64BE(buf, val, offset) {
|
|
322
|
+
val = check_value(val, -0x800000000000000000, 0x7fffffffffffffff);
|
|
323
|
+
check_bounds(buf, offset, 8);
|
|
324
|
+
|
|
325
|
+
if (val < 0x8000000000000000) {
|
|
326
|
+
buf.writeInt32BE(Math.floor(val * SHIFT_RIGHT_32), offset);
|
|
327
|
+
buf.writeInt32BE(val & -1, offset + 4);
|
|
328
|
+
} else {
|
|
329
|
+
// Special case because 2^63-1 gets rounded up to 2^63
|
|
330
|
+
buf[offset] = 0x7f;
|
|
331
|
+
buf[offset+1] = 0xff;
|
|
332
|
+
buf[offset+2] = 0xff;
|
|
333
|
+
buf[offset+3] = 0xff;
|
|
334
|
+
buf[offset+4] = 0xff;
|
|
335
|
+
buf[offset+5] = 0xff;
|
|
336
|
+
buf[offset+6] = 0xff;
|
|
337
|
+
buf[offset+7] = 0xff;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
module.exports.writeInt64BE = writeInt64BE;
|
|
341
|
+
|
|
342
|
+
function readInt24LE(buf, offset) {
|
|
343
|
+
return (buf.readInt8(offset + 2) << 16) + buf.readUInt16LE(offset);
|
|
344
|
+
}
|
|
345
|
+
module.exports.readInt24LE = readInt24LE;
|
|
346
|
+
|
|
347
|
+
function writeInt24LE(buf, val, offset) {
|
|
348
|
+
val = check_value(val, -0x800000, 0x7fffff);
|
|
349
|
+
check_bounds(buf, offset, 3);
|
|
350
|
+
buf.writeUInt16LE(val & 0xffff, offset);
|
|
351
|
+
buf.writeInt8(val >> 16, offset + 2);
|
|
352
|
+
}
|
|
353
|
+
module.exports.writeInt24LE = writeInt24LE;
|
|
354
|
+
|
|
355
|
+
function readInt40LE(buf, offset) {
|
|
356
|
+
return (buf.readInt8(offset + 4) || 0) * SHIFT_LEFT_32 + buf.readUInt32LE(offset);
|
|
357
|
+
}
|
|
358
|
+
module.exports.readInt40LE = readInt40LE;
|
|
359
|
+
|
|
360
|
+
function writeInt40LE(buf, val, offset) {
|
|
361
|
+
val = check_value(val, -0x8000000000, 0x7fffffffff);
|
|
362
|
+
check_bounds(buf, offset, 5);
|
|
363
|
+
buf.writeInt32LE(val & -1, offset);
|
|
364
|
+
buf.writeInt8(Math.floor(val * SHIFT_RIGHT_32), offset + 4);
|
|
365
|
+
}
|
|
366
|
+
module.exports.writeInt40LE = writeInt40LE;
|
|
367
|
+
|
|
368
|
+
function readInt48LE(buf, offset) {
|
|
369
|
+
return buf.readInt16LE(offset + 4) * SHIFT_LEFT_32 + buf.readUInt32LE(offset);
|
|
370
|
+
}
|
|
371
|
+
module.exports.readInt48LE = readInt48LE;
|
|
372
|
+
|
|
373
|
+
function writeInt48LE(buf, val, offset) {
|
|
374
|
+
val = check_value(val, -0x800000000000, 0x7fffffffffff);
|
|
375
|
+
check_bounds(buf, offset, 6);
|
|
376
|
+
buf.writeInt32LE(val & -1, offset);
|
|
377
|
+
buf.writeInt16LE(Math.floor(val * SHIFT_RIGHT_32), offset + 4);
|
|
378
|
+
}
|
|
379
|
+
module.exports.writeInt48LE = writeInt48LE;
|
|
380
|
+
|
|
381
|
+
function readInt56LE(buf, offset) {
|
|
382
|
+
return (((buf.readInt8(offset + 6) || 0) << 16) + buf.readUInt16LE(offset + 4)) * SHIFT_LEFT_32 + buf.readUInt32LE(offset);
|
|
383
|
+
}
|
|
384
|
+
module.exports.readInt56LE = readInt56LE;
|
|
385
|
+
|
|
386
|
+
function writeInt56LE(buf, val, offset) {
|
|
387
|
+
val = check_value(val, -0x80000000000000, 0x7fffffffffffff);
|
|
388
|
+
check_bounds(buf, offset, 7);
|
|
389
|
+
|
|
390
|
+
if (val < 0x80000000000000) {
|
|
391
|
+
buf.writeInt32LE(val & -1, offset);
|
|
392
|
+
var hi = Math.floor(val * SHIFT_RIGHT_32);
|
|
393
|
+
buf.writeUInt16LE(hi & 0xffff, offset + 4);
|
|
394
|
+
buf.writeInt8(hi >> 16, offset + 6);
|
|
395
|
+
} else {
|
|
396
|
+
// Special case because 2^55-1 gets rounded up to 2^55
|
|
397
|
+
buf[offset] = 0xff;
|
|
398
|
+
buf[offset+1] = 0xff;
|
|
399
|
+
buf[offset+2] = 0xff;
|
|
400
|
+
buf[offset+3] = 0xff;
|
|
401
|
+
buf[offset+4] = 0xff;
|
|
402
|
+
buf[offset+5] = 0xff;
|
|
403
|
+
buf[offset+6] = 0x7f;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
module.exports.writeInt56LE = writeInt56LE;
|
|
407
|
+
|
|
408
|
+
function readInt64LE(buf, offset) {
|
|
409
|
+
return buf.readInt32LE(offset + 4) * SHIFT_LEFT_32 + buf.readUInt32LE(offset);
|
|
410
|
+
}
|
|
411
|
+
module.exports.readInt64LE = readInt64LE;
|
|
412
|
+
|
|
413
|
+
function writeInt64LE(buf, val, offset) {
|
|
414
|
+
val = check_value(val, -0x8000000000000000, 0x7fffffffffffffff);
|
|
415
|
+
check_bounds(buf, offset, 8);
|
|
416
|
+
|
|
417
|
+
if (val < 0x8000000000000000) {
|
|
418
|
+
buf.writeInt32LE(val & -1, offset);
|
|
419
|
+
buf.writeInt32LE(Math.floor(val * SHIFT_RIGHT_32), offset + 4);
|
|
420
|
+
} else {
|
|
421
|
+
// Special case because 2^55-1 gets rounded up to 2^55
|
|
422
|
+
buf[offset] = 0xff;
|
|
423
|
+
buf[offset+1] = 0xff;
|
|
424
|
+
buf[offset+2] = 0xff;
|
|
425
|
+
buf[offset+3] = 0xff;
|
|
426
|
+
buf[offset+4] = 0xff;
|
|
427
|
+
buf[offset+5] = 0xff;
|
|
428
|
+
buf[offset+6] = 0xff;
|
|
429
|
+
buf[offset+7] = 0x7f;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
module.exports.writeInt64LE = writeInt64LE;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "buffer-more-ints",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "David Wragg <david@wragg.org>",
|
|
5
|
+
"description": "Add support for more integer widths to Buffer",
|
|
6
|
+
"homepage": "https://github.com/dpw/node-buffer-more-ints",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/dpw/node-buffer-more-ints.git"
|
|
11
|
+
},
|
|
12
|
+
"main": "buffer-more-ints.js",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"nodeunit": ""
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node ./node_modules/nodeunit/bin/nodeunit buffer-more-ints-tests.js"
|
|
18
|
+
}
|
|
19
|
+
}
|