Skip to content

Commit bd1ef52

Browse files
chore: release 3.0.1
1 parent e5bdc6e commit bd1ef52

File tree

5 files changed

+71
-18
lines changed

5 files changed

+71
-18
lines changed

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [3.0.1](https://github.com/darrachequesne/notepack/compare/3.0.0...3.0.1) (2022-05-22)
2+
3+
The browser bundle was not updated in the previous release.
4+
5+
6+
17
# [3.0.0](https://github.com/darrachequesne/notepack/compare/2.3.0...3.0.0) (2022-05-22)
28

39

dist/notepack.js

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
2-
* Notepack.io 2.3.0
3-
* (c) 2014-2020 Damien Arrachequesne
2+
* Notepack.io 3.0.1
3+
* (c) 2014-2022 Damien Arrachequesne
44
* Released under the MIT License.
55
*/
66
(function (root) {
@@ -148,6 +148,14 @@
148148
length = this._view.getUint8(this._offset);
149149
type = this._view.getInt8(this._offset + 1);
150150
this._offset += 2;
151+
if (type === -1) {
152+
// timestamp 96
153+
var ns = this._view.getUint32(this._offset);
154+
hi = this._view.getInt32(this._offset + 4);
155+
lo = this._view.getUint32(this._offset + 8);
156+
this._offset += 12;
157+
return new Date((hi * 0x100000000 + lo) * 1e3 + ns / 1e6);
158+
}
151159
return [type, this._bin(length)];
152160
case 0xc8:
153161
length = this._view.getUint16(this._offset);
@@ -213,6 +221,7 @@
213221
type = this._view.getInt8(this._offset);
214222
this._offset += 1;
215223
if (type === 0x00) {
224+
// custom encoding for 'undefined' (kept for backward-compatibility)
216225
this._offset += 1;
217226
return void 0;
218227
}
@@ -224,16 +233,31 @@
224233
case 0xd6:
225234
type = this._view.getInt8(this._offset);
226235
this._offset += 1;
236+
if (type === -1) {
237+
// timestamp 32
238+
value = this._view.getUint32(this._offset);
239+
this._offset += 4;
240+
return new Date(value * 1e3);
241+
}
227242
return [type, this._bin(4)];
228243
case 0xd7:
229244
type = this._view.getInt8(this._offset);
230245
this._offset += 1;
231246
if (type === 0x00) {
247+
// custom date encoding (kept for backward-compatibility)
232248
hi = this._view.getInt32(this._offset) * Math.pow(2, 32);
233249
lo = this._view.getUint32(this._offset + 4);
234250
this._offset += 8;
235251
return new Date(hi + lo);
236252
}
253+
if (type === -1) {
254+
// timestamp 64
255+
hi = this._view.getUint32(this._offset);
256+
lo = this._view.getUint32(this._offset + 4);
257+
this._offset += 8;
258+
var s = (hi & 0x3) * 0x100000000 + lo;
259+
return new Date(s * 1e3 + (hi >>> 2) / 1e6);
260+
}
237261
return [type, this._bin(8)];
238262
case 0xd8:
239263
type = this._view.getInt8(this._offset);
@@ -287,6 +311,9 @@
287311
return value;
288312
}
289313

314+
var TIMESTAMP32_MAX_SEC = 0x100000000 - 1; // 32-bit unsigned int
315+
var TIMESTAMP64_MAX_SEC = 0x400000000 - 1; // 34-bit unsigned int
316+
290317
function utf8Write(view, offset, str) {
291318
var c = 0;
292319
for (var i = 0, l = str.length; i < l; i++) {
@@ -463,13 +490,30 @@
463490
return size;
464491
}
465492

466-
// fixext 8 / Date
467493
if (value instanceof Date) {
468-
var time = value.getTime();
469-
hi = Math.floor(time / Math.pow(2, 32));
470-
lo = time >>> 0;
471-
bytes.push(0xd7, 0, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo);
472-
return 10;
494+
var ms = value.getTime();
495+
var s = Math.floor(ms / 1e3);
496+
var ns = (ms - s * 1e3) * 1e6;
497+
498+
if (s >= 0 && ns >= 0 && s <= TIMESTAMP64_MAX_SEC) {
499+
if (ns === 0 && s <= TIMESTAMP32_MAX_SEC) {
500+
// timestamp 32
501+
bytes.push(0xd6, 0xff, s >> 24, s >> 16, s >> 8, s);
502+
return 6;
503+
} else {
504+
// timestamp 64
505+
hi = s / 0x100000000;
506+
lo = s & 0xffffffff;
507+
bytes.push(0xd7, 0xff, ns >> 22, ns >> 14, ns >> 6, hi, lo >> 24, lo >> 16, lo >> 8, lo);
508+
return 10;
509+
}
510+
} else {
511+
// timestamp 96
512+
hi = Math.floor(s / 0x100000000);
513+
lo = s >>> 0;
514+
bytes.push(0xc7, 0x0c, 0xff, ns >> 24, ns >> 16, ns >> 8, ns, hi >> 24, hi >> 16, hi >> 8, hi, lo >> 24, lo >> 16, lo >> 8, lo);
515+
return 15;
516+
}
473517
}
474518

475519
if (value instanceof ArrayBuffer) {
@@ -505,7 +549,7 @@
505549
var allKeys = Object.keys(value);
506550
for (i = 0, l = allKeys.length; i < l; i++) {
507551
key = allKeys[i];
508-
if (typeof value[key] !== 'function') {
552+
if (value[key] !== undefined && typeof value[key] !== 'function') {
509553
keys.push(key);
510554
}
511555
}
@@ -541,10 +585,13 @@
541585
bytes.push(value ? 0xc3 : 0xc2);
542586
return 1;
543587
}
544-
// fixext 1 / undefined
545588
if (type === 'undefined') {
546-
bytes.push(0xd4, 0, 0);
547-
return 3;
589+
bytes.push(0xc0);
590+
return 1;
591+
}
592+
// custom types like BigInt (typeof value === 'bigint')
593+
if (typeof value.toJSON === 'function') {
594+
return _encode(bytes, defers, value.toJSON());
548595
}
549596
throw new Error('Could not encode');
550597
}
@@ -590,4 +637,4 @@
590637
}
591638

592639

593-
})(self);
640+
})(self);

dist/notepack.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "notepack.io",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "A fast Node.js implementation of the latest MessagePack spec",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

0 commit comments

Comments
 (0)