msgpackr 1.6.0 → 1.7.0-alpha1
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/index.js +1953 -1918
- package/dist/index.min.js +67 -68
- package/dist/node.cjs +2263 -1983
- package/dist/test.js +2879 -674
- package/index.d.ts +23 -12
- package/node-index.js +24 -23
- package/pack.js +957 -933
- package/package.json +83 -83
- package/struct.js +260 -0
- package/unpack.d.ts +52 -50
- package/unpack.js +1078 -1052
- package/dist/str.cjs +0 -100
package/dist/str.cjs
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
let utfz = require('../../msgpack-benchmark/node_modules/utfz-lib')
|
|
2
|
-
|
|
3
|
-
var safeEnd = 1000000;
|
|
4
|
-
var b = new Uint8Array(32768)
|
|
5
|
-
function writeString(value, target, position) {
|
|
6
|
-
var length, strLength = value.length;
|
|
7
|
-
let headerSize;
|
|
8
|
-
// first we estimate the header size, so we can write to the correct location
|
|
9
|
-
if (strLength < 0x20) {
|
|
10
|
-
headerSize = 1;
|
|
11
|
-
} else if (strLength < 0x100) {
|
|
12
|
-
headerSize = 2;
|
|
13
|
-
} else if (strLength < 0x10000) {
|
|
14
|
-
headerSize = 3;
|
|
15
|
-
} else {
|
|
16
|
-
headerSize = 5;
|
|
17
|
-
}
|
|
18
|
-
let maxBytes = strLength * 3;
|
|
19
|
-
//if (position + maxBytes > safeEnd)
|
|
20
|
-
// target = makeRoom(position + maxBytes);
|
|
21
|
-
for (let i = 0; i < 100; i++) {
|
|
22
|
-
length = pack(value, strLength, target, position + headerSize);
|
|
23
|
-
}
|
|
24
|
-
if (strLength < 0x40 || !encodeUtf8) {
|
|
25
|
-
var strPosition = position + headerSize;
|
|
26
|
-
var c2 = 0;
|
|
27
|
-
for (let i = 0; i < strLength; i++) {
|
|
28
|
-
const c1 = value.charCodeAt(i);
|
|
29
|
-
if (c1 < 0x80) {
|
|
30
|
-
target[strPosition++] = c1;
|
|
31
|
-
} else if (c1 < 0x800) {
|
|
32
|
-
target[strPosition++] = c1 >> 6 | 0xc0;
|
|
33
|
-
target[strPosition++] = c1 & 0x3f | 0x80;
|
|
34
|
-
} else if (
|
|
35
|
-
(c1 & 0xfc00) === 0xd800 &&
|
|
36
|
-
((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
|
|
37
|
-
) {
|
|
38
|
-
c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
|
|
39
|
-
i++;
|
|
40
|
-
target[strPosition++] = c1 >> 18 | 0xf0;
|
|
41
|
-
target[strPosition++] = c1 >> 12 & 0x3f | 0x80;
|
|
42
|
-
target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
|
|
43
|
-
target[strPosition++] = c1 & 0x3f | 0x80;
|
|
44
|
-
} else {
|
|
45
|
-
target[strPosition++] = c1 >> 12 | 0xe0;
|
|
46
|
-
target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
|
|
47
|
-
target[strPosition++] = c1 & 0x3f | 0x80;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
length = strPosition - position - headerSize;
|
|
51
|
-
} else {
|
|
52
|
-
length = encodeUtf8(value, position + headerSize, maxBytes);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (length < 0x20) {
|
|
57
|
-
target[position++] = 0xa0 | length;
|
|
58
|
-
} else if (length < 0x100) {
|
|
59
|
-
if (headerSize < 2) {
|
|
60
|
-
target.copyWithin(position + 2, position + 1, position + 1 + length);
|
|
61
|
-
}
|
|
62
|
-
target[position++] = 0xd9;
|
|
63
|
-
target[position++] = length;
|
|
64
|
-
} else if (length < 0x10000) {
|
|
65
|
-
if (headerSize < 3) {
|
|
66
|
-
target.copyWithin(position + 3, position + 2, position + 2 + length);
|
|
67
|
-
}
|
|
68
|
-
target[position++] = 0xda;
|
|
69
|
-
target[position++] = length >> 8;
|
|
70
|
-
target[position++] = length & 0xff;
|
|
71
|
-
} else {
|
|
72
|
-
if (headerSize < 5) {
|
|
73
|
-
target.copyWithin(position + 5, position + 3, position + 3 + length);
|
|
74
|
-
}
|
|
75
|
-
target[position++] = 0xdb;
|
|
76
|
-
targetView.setUint32(position, length);
|
|
77
|
-
position += 4;
|
|
78
|
-
}
|
|
79
|
-
return position + length
|
|
80
|
-
};
|
|
81
|
-
const pack = (str, length, buf, offset) => {
|
|
82
|
-
const start = offset;
|
|
83
|
-
let currHigh = 0;
|
|
84
|
-
for (let i = 0; i < length; i++) {
|
|
85
|
-
const code = str.charCodeAt(i);
|
|
86
|
-
const high = code >> 8;
|
|
87
|
-
if (high !== currHigh) {
|
|
88
|
-
buf[i + offset++] = 0;
|
|
89
|
-
buf[i + offset++] = high;
|
|
90
|
-
currHigh = high;
|
|
91
|
-
}
|
|
92
|
-
const low = code & 0xff;
|
|
93
|
-
buf[i + offset] = low;
|
|
94
|
-
if (!low) {
|
|
95
|
-
buf[i + ++offset] = currHigh;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return length + offset - start;
|
|
99
|
-
};
|
|
100
|
-
module.exports = writeString;
|