msgpackr 1.9.6 → 1.9.7
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/node.cjs +20 -17
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +20 -17
- package/dist/test.js.map +1 -1
- package/package.json +1 -1
- package/struct.js +20 -17
package/package.json
CHANGED
package/struct.js
CHANGED
|
@@ -132,25 +132,28 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
|
|
|
132
132
|
switch (typeof value) {
|
|
133
133
|
case 'number':
|
|
134
134
|
let number = value;
|
|
135
|
-
if
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
position += 4;
|
|
143
|
-
}
|
|
144
|
-
break;
|
|
145
|
-
} else if (number < 0x100000000 && number >= -0x80000000) {
|
|
146
|
-
targetView.setFloat32(position, number, true);
|
|
147
|
-
if (float32Headers[target[position + 3] >>> 5]) {
|
|
148
|
-
let xShifted
|
|
149
|
-
// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
150
|
-
if (((xShifted = number * mult10[((target[position + 3] & 0x7f) << 1) | (target[position + 2] >> 7)]) >> 0) === xShifted) {
|
|
135
|
+
// first check to see if we are using a lot of ids and should default to wide/common format
|
|
136
|
+
if (nextId < 200 || !nextTransition.num64) {
|
|
137
|
+
if (number >> 0 === number && number < 0x20000000 && number > -0x1f000000) {
|
|
138
|
+
if (number < 0xf6 && number >= 0 && (nextTransition.num8 && !(nextId > 200 && nextTransition.num32) || number < 0x20 && !nextTransition.num32)) {
|
|
139
|
+
transition = nextTransition.num8 || createTypeTransition(nextTransition, NUMBER, 1);
|
|
140
|
+
target[position++] = number;
|
|
141
|
+
} else {
|
|
151
142
|
transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
|
|
143
|
+
targetView.setUint32(position, number, true);
|
|
152
144
|
position += 4;
|
|
153
|
-
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
} else if (number < 0x100000000 && number >= -0x80000000) {
|
|
148
|
+
targetView.setFloat32(position, number, true);
|
|
149
|
+
if (float32Headers[target[position + 3] >>> 5]) {
|
|
150
|
+
let xShifted
|
|
151
|
+
// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
152
|
+
if (((xShifted = number * mult10[((target[position + 3] & 0x7f) << 1) | (target[position + 2] >> 7)]) >> 0) === xShifted) {
|
|
153
|
+
transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
|
|
154
|
+
position += 4;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
154
157
|
}
|
|
155
158
|
}
|
|
156
159
|
}
|