bson 6.4.0 → 6.4.1
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/lib/bson.bundle.js +59 -26
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +59 -26
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +59 -26
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.rn.cjs +59 -26
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +1 -1
- package/src/utils/number_utils.ts +69 -30
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
const FLOAT = new Float64Array(1);
|
|
2
2
|
const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
|
|
3
3
|
|
|
4
|
+
FLOAT[0] = -1;
|
|
5
|
+
// Little endian [0, 0, 0, 0, 0, 0, 240, 191]
|
|
6
|
+
// Big endian [191, 240, 0, 0, 0, 0, 0, 0]
|
|
7
|
+
const isBigEndian = FLOAT_BYTES[7] === 0;
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* Number parsing and serializing utilities.
|
|
6
11
|
*
|
|
@@ -39,28 +44,49 @@ export const NumberUtils = {
|
|
|
39
44
|
|
|
40
45
|
/** Reads a little-endian 64-bit integer from source */
|
|
41
46
|
getBigInt64LE(source: Uint8Array, offset: number): bigint {
|
|
42
|
-
|
|
43
|
-
const hi =
|
|
47
|
+
// eslint-disable-next-line no-restricted-globals
|
|
48
|
+
const hi = BigInt(
|
|
49
|
+
source[offset + 4] +
|
|
50
|
+
source[offset + 5] * 256 +
|
|
51
|
+
source[offset + 6] * 65536 +
|
|
52
|
+
(source[offset + 7] << 24)
|
|
53
|
+
); // Overflow
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
// eslint-disable-next-line no-restricted-globals
|
|
56
|
+
const lo = BigInt(
|
|
57
|
+
source[offset] +
|
|
58
|
+
source[offset + 1] * 256 +
|
|
59
|
+
source[offset + 2] * 65536 +
|
|
60
|
+
source[offset + 3] * 16777216
|
|
61
|
+
);
|
|
62
|
+
// eslint-disable-next-line no-restricted-globals
|
|
63
|
+
return (hi << BigInt(32)) + lo;
|
|
50
64
|
},
|
|
51
65
|
|
|
52
66
|
/** Reads a little-endian 64-bit float from source */
|
|
53
|
-
getFloat64LE
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
getFloat64LE: isBigEndian
|
|
68
|
+
? (source: Uint8Array, offset: number) => {
|
|
69
|
+
FLOAT_BYTES[7] = source[offset];
|
|
70
|
+
FLOAT_BYTES[6] = source[offset + 1];
|
|
71
|
+
FLOAT_BYTES[5] = source[offset + 2];
|
|
72
|
+
FLOAT_BYTES[4] = source[offset + 3];
|
|
73
|
+
FLOAT_BYTES[3] = source[offset + 4];
|
|
74
|
+
FLOAT_BYTES[2] = source[offset + 5];
|
|
75
|
+
FLOAT_BYTES[1] = source[offset + 6];
|
|
76
|
+
FLOAT_BYTES[0] = source[offset + 7];
|
|
77
|
+
return FLOAT[0];
|
|
78
|
+
}
|
|
79
|
+
: (source: Uint8Array, offset: number) => {
|
|
80
|
+
FLOAT_BYTES[0] = source[offset];
|
|
81
|
+
FLOAT_BYTES[1] = source[offset + 1];
|
|
82
|
+
FLOAT_BYTES[2] = source[offset + 2];
|
|
83
|
+
FLOAT_BYTES[3] = source[offset + 3];
|
|
84
|
+
FLOAT_BYTES[4] = source[offset + 4];
|
|
85
|
+
FLOAT_BYTES[5] = source[offset + 5];
|
|
86
|
+
FLOAT_BYTES[6] = source[offset + 6];
|
|
87
|
+
FLOAT_BYTES[7] = source[offset + 7];
|
|
88
|
+
return FLOAT[0];
|
|
89
|
+
},
|
|
64
90
|
|
|
65
91
|
/** Writes a big-endian 32-bit integer to destination, can be signed or unsigned */
|
|
66
92
|
setInt32BE(destination: Uint8Array, offset: number, value: number): 4 {
|
|
@@ -120,16 +146,29 @@ export const NumberUtils = {
|
|
|
120
146
|
},
|
|
121
147
|
|
|
122
148
|
/** Writes a little-endian 64-bit float to destination */
|
|
123
|
-
setFloat64LE
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
149
|
+
setFloat64LE: isBigEndian
|
|
150
|
+
? (destination: Uint8Array, offset: number, value: number) => {
|
|
151
|
+
FLOAT[0] = value;
|
|
152
|
+
destination[offset] = FLOAT_BYTES[7];
|
|
153
|
+
destination[offset + 1] = FLOAT_BYTES[6];
|
|
154
|
+
destination[offset + 2] = FLOAT_BYTES[5];
|
|
155
|
+
destination[offset + 3] = FLOAT_BYTES[4];
|
|
156
|
+
destination[offset + 4] = FLOAT_BYTES[3];
|
|
157
|
+
destination[offset + 5] = FLOAT_BYTES[2];
|
|
158
|
+
destination[offset + 6] = FLOAT_BYTES[1];
|
|
159
|
+
destination[offset + 7] = FLOAT_BYTES[0];
|
|
160
|
+
return 8;
|
|
161
|
+
}
|
|
162
|
+
: (destination: Uint8Array, offset: number, value: number) => {
|
|
163
|
+
FLOAT[0] = value;
|
|
164
|
+
destination[offset] = FLOAT_BYTES[0];
|
|
165
|
+
destination[offset + 1] = FLOAT_BYTES[1];
|
|
166
|
+
destination[offset + 2] = FLOAT_BYTES[2];
|
|
167
|
+
destination[offset + 3] = FLOAT_BYTES[3];
|
|
168
|
+
destination[offset + 4] = FLOAT_BYTES[4];
|
|
169
|
+
destination[offset + 5] = FLOAT_BYTES[5];
|
|
170
|
+
destination[offset + 6] = FLOAT_BYTES[6];
|
|
171
|
+
destination[offset + 7] = FLOAT_BYTES[7];
|
|
172
|
+
return 8;
|
|
173
|
+
}
|
|
135
174
|
};
|