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.rn.cjs CHANGED
@@ -2140,6 +2140,8 @@ class MinKey extends BSONValue {
2140
2140
 
2141
2141
  const FLOAT = new Float64Array(1);
2142
2142
  const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
2143
+ FLOAT[0] = -1;
2144
+ const isBigEndian = FLOAT_BYTES[7] === 0;
2143
2145
  const NumberUtils = {
2144
2146
  getInt32LE(source, offset) {
2145
2147
  return (source[offset] |
@@ -2160,21 +2162,39 @@ const NumberUtils = {
2160
2162
  source[offset] * 16777216);
2161
2163
  },
2162
2164
  getBigInt64LE(source, offset) {
2163
- const lo = NumberUtils.getUint32LE(source, offset);
2164
- const hi = NumberUtils.getUint32LE(source, offset + 4);
2165
- return (BigInt(hi) << BigInt(32)) + BigInt(lo);
2166
- },
2167
- getFloat64LE(source, offset) {
2168
- FLOAT_BYTES[0] = source[offset];
2169
- FLOAT_BYTES[1] = source[offset + 1];
2170
- FLOAT_BYTES[2] = source[offset + 2];
2171
- FLOAT_BYTES[3] = source[offset + 3];
2172
- FLOAT_BYTES[4] = source[offset + 4];
2173
- FLOAT_BYTES[5] = source[offset + 5];
2174
- FLOAT_BYTES[6] = source[offset + 6];
2175
- FLOAT_BYTES[7] = source[offset + 7];
2176
- return FLOAT[0];
2165
+ const hi = BigInt(source[offset + 4] +
2166
+ source[offset + 5] * 256 +
2167
+ source[offset + 6] * 65536 +
2168
+ (source[offset + 7] << 24));
2169
+ const lo = BigInt(source[offset] +
2170
+ source[offset + 1] * 256 +
2171
+ source[offset + 2] * 65536 +
2172
+ source[offset + 3] * 16777216);
2173
+ return (hi << BigInt(32)) + lo;
2177
2174
  },
2175
+ getFloat64LE: isBigEndian
2176
+ ? (source, offset) => {
2177
+ FLOAT_BYTES[7] = source[offset];
2178
+ FLOAT_BYTES[6] = source[offset + 1];
2179
+ FLOAT_BYTES[5] = source[offset + 2];
2180
+ FLOAT_BYTES[4] = source[offset + 3];
2181
+ FLOAT_BYTES[3] = source[offset + 4];
2182
+ FLOAT_BYTES[2] = source[offset + 5];
2183
+ FLOAT_BYTES[1] = source[offset + 6];
2184
+ FLOAT_BYTES[0] = source[offset + 7];
2185
+ return FLOAT[0];
2186
+ }
2187
+ : (source, offset) => {
2188
+ FLOAT_BYTES[0] = source[offset];
2189
+ FLOAT_BYTES[1] = source[offset + 1];
2190
+ FLOAT_BYTES[2] = source[offset + 2];
2191
+ FLOAT_BYTES[3] = source[offset + 3];
2192
+ FLOAT_BYTES[4] = source[offset + 4];
2193
+ FLOAT_BYTES[5] = source[offset + 5];
2194
+ FLOAT_BYTES[6] = source[offset + 6];
2195
+ FLOAT_BYTES[7] = source[offset + 7];
2196
+ return FLOAT[0];
2197
+ },
2178
2198
  setInt32BE(destination, offset, value) {
2179
2199
  destination[offset + 3] = value;
2180
2200
  value >>>= 8;
@@ -2215,18 +2235,31 @@ const NumberUtils = {
2215
2235
  destination[offset + 7] = hi;
2216
2236
  return 8;
2217
2237
  },
2218
- setFloat64LE(destination, offset, value) {
2219
- FLOAT[0] = value;
2220
- destination[offset] = FLOAT_BYTES[0];
2221
- destination[offset + 1] = FLOAT_BYTES[1];
2222
- destination[offset + 2] = FLOAT_BYTES[2];
2223
- destination[offset + 3] = FLOAT_BYTES[3];
2224
- destination[offset + 4] = FLOAT_BYTES[4];
2225
- destination[offset + 5] = FLOAT_BYTES[5];
2226
- destination[offset + 6] = FLOAT_BYTES[6];
2227
- destination[offset + 7] = FLOAT_BYTES[7];
2228
- return 8;
2229
- }
2238
+ setFloat64LE: isBigEndian
2239
+ ? (destination, offset, value) => {
2240
+ FLOAT[0] = value;
2241
+ destination[offset] = FLOAT_BYTES[7];
2242
+ destination[offset + 1] = FLOAT_BYTES[6];
2243
+ destination[offset + 2] = FLOAT_BYTES[5];
2244
+ destination[offset + 3] = FLOAT_BYTES[4];
2245
+ destination[offset + 4] = FLOAT_BYTES[3];
2246
+ destination[offset + 5] = FLOAT_BYTES[2];
2247
+ destination[offset + 6] = FLOAT_BYTES[1];
2248
+ destination[offset + 7] = FLOAT_BYTES[0];
2249
+ return 8;
2250
+ }
2251
+ : (destination, offset, value) => {
2252
+ FLOAT[0] = value;
2253
+ destination[offset] = FLOAT_BYTES[0];
2254
+ destination[offset + 1] = FLOAT_BYTES[1];
2255
+ destination[offset + 2] = FLOAT_BYTES[2];
2256
+ destination[offset + 3] = FLOAT_BYTES[3];
2257
+ destination[offset + 4] = FLOAT_BYTES[4];
2258
+ destination[offset + 5] = FLOAT_BYTES[5];
2259
+ destination[offset + 6] = FLOAT_BYTES[6];
2260
+ destination[offset + 7] = FLOAT_BYTES[7];
2261
+ return 8;
2262
+ }
2230
2263
  };
2231
2264
 
2232
2265
  const checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');