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.
@@ -2126,6 +2126,8 @@ class MinKey extends BSONValue {
2126
2126
 
2127
2127
  const FLOAT = new Float64Array(1);
2128
2128
  const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
2129
+ FLOAT[0] = -1;
2130
+ const isBigEndian = FLOAT_BYTES[7] === 0;
2129
2131
  const NumberUtils = {
2130
2132
  getInt32LE(source, offset) {
2131
2133
  return (source[offset] |
@@ -2146,21 +2148,39 @@ const NumberUtils = {
2146
2148
  source[offset] * 16777216);
2147
2149
  },
2148
2150
  getBigInt64LE(source, offset) {
2149
- const lo = NumberUtils.getUint32LE(source, offset);
2150
- const hi = NumberUtils.getUint32LE(source, offset + 4);
2151
- return (BigInt(hi) << BigInt(32)) + BigInt(lo);
2152
- },
2153
- getFloat64LE(source, offset) {
2154
- FLOAT_BYTES[0] = source[offset];
2155
- FLOAT_BYTES[1] = source[offset + 1];
2156
- FLOAT_BYTES[2] = source[offset + 2];
2157
- FLOAT_BYTES[3] = source[offset + 3];
2158
- FLOAT_BYTES[4] = source[offset + 4];
2159
- FLOAT_BYTES[5] = source[offset + 5];
2160
- FLOAT_BYTES[6] = source[offset + 6];
2161
- FLOAT_BYTES[7] = source[offset + 7];
2162
- return FLOAT[0];
2151
+ const hi = BigInt(source[offset + 4] +
2152
+ source[offset + 5] * 256 +
2153
+ source[offset + 6] * 65536 +
2154
+ (source[offset + 7] << 24));
2155
+ const lo = BigInt(source[offset] +
2156
+ source[offset + 1] * 256 +
2157
+ source[offset + 2] * 65536 +
2158
+ source[offset + 3] * 16777216);
2159
+ return (hi << BigInt(32)) + lo;
2163
2160
  },
2161
+ getFloat64LE: isBigEndian
2162
+ ? (source, offset) => {
2163
+ FLOAT_BYTES[7] = source[offset];
2164
+ FLOAT_BYTES[6] = source[offset + 1];
2165
+ FLOAT_BYTES[5] = source[offset + 2];
2166
+ FLOAT_BYTES[4] = source[offset + 3];
2167
+ FLOAT_BYTES[3] = source[offset + 4];
2168
+ FLOAT_BYTES[2] = source[offset + 5];
2169
+ FLOAT_BYTES[1] = source[offset + 6];
2170
+ FLOAT_BYTES[0] = source[offset + 7];
2171
+ return FLOAT[0];
2172
+ }
2173
+ : (source, offset) => {
2174
+ FLOAT_BYTES[0] = source[offset];
2175
+ FLOAT_BYTES[1] = source[offset + 1];
2176
+ FLOAT_BYTES[2] = source[offset + 2];
2177
+ FLOAT_BYTES[3] = source[offset + 3];
2178
+ FLOAT_BYTES[4] = source[offset + 4];
2179
+ FLOAT_BYTES[5] = source[offset + 5];
2180
+ FLOAT_BYTES[6] = source[offset + 6];
2181
+ FLOAT_BYTES[7] = source[offset + 7];
2182
+ return FLOAT[0];
2183
+ },
2164
2184
  setInt32BE(destination, offset, value) {
2165
2185
  destination[offset + 3] = value;
2166
2186
  value >>>= 8;
@@ -2201,18 +2221,31 @@ const NumberUtils = {
2201
2221
  destination[offset + 7] = hi;
2202
2222
  return 8;
2203
2223
  },
2204
- setFloat64LE(destination, offset, value) {
2205
- FLOAT[0] = value;
2206
- destination[offset] = FLOAT_BYTES[0];
2207
- destination[offset + 1] = FLOAT_BYTES[1];
2208
- destination[offset + 2] = FLOAT_BYTES[2];
2209
- destination[offset + 3] = FLOAT_BYTES[3];
2210
- destination[offset + 4] = FLOAT_BYTES[4];
2211
- destination[offset + 5] = FLOAT_BYTES[5];
2212
- destination[offset + 6] = FLOAT_BYTES[6];
2213
- destination[offset + 7] = FLOAT_BYTES[7];
2214
- return 8;
2215
- }
2224
+ setFloat64LE: isBigEndian
2225
+ ? (destination, offset, value) => {
2226
+ FLOAT[0] = value;
2227
+ destination[offset] = FLOAT_BYTES[7];
2228
+ destination[offset + 1] = FLOAT_BYTES[6];
2229
+ destination[offset + 2] = FLOAT_BYTES[5];
2230
+ destination[offset + 3] = FLOAT_BYTES[4];
2231
+ destination[offset + 4] = FLOAT_BYTES[3];
2232
+ destination[offset + 5] = FLOAT_BYTES[2];
2233
+ destination[offset + 6] = FLOAT_BYTES[1];
2234
+ destination[offset + 7] = FLOAT_BYTES[0];
2235
+ return 8;
2236
+ }
2237
+ : (destination, offset, value) => {
2238
+ FLOAT[0] = value;
2239
+ destination[offset] = FLOAT_BYTES[0];
2240
+ destination[offset + 1] = FLOAT_BYTES[1];
2241
+ destination[offset + 2] = FLOAT_BYTES[2];
2242
+ destination[offset + 3] = FLOAT_BYTES[3];
2243
+ destination[offset + 4] = FLOAT_BYTES[4];
2244
+ destination[offset + 5] = FLOAT_BYTES[5];
2245
+ destination[offset + 6] = FLOAT_BYTES[6];
2246
+ destination[offset + 7] = FLOAT_BYTES[7];
2247
+ return 8;
2248
+ }
2216
2249
  };
2217
2250
 
2218
2251
  const checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');