-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use bigint for 64 bit ints if needed and available. (#383)
Read values as BigInt when appropriate. Potentially, cases where this happens already results in broken playback, but out of abundance of caution we're marking this as a breaking change. BREAKING CHANGE: In some cases, mux.js will now be returning a BigInt rather than a regular Number value. This means that consumers of this library will need to add checks for BigInt for optimal operation.
- Loading branch information
1 parent
87f777f
commit 83779b9
Showing
12 changed files
with
1,144 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var MAX_UINT32 = Math.pow(2, 32); | ||
|
||
var getUint64 = (uint8) => { | ||
var dv = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength); | ||
var value; | ||
|
||
if (dv.getBigUint64) { | ||
value = dv.getBigUint64(0); | ||
|
||
if (value < Number.MAX_SAFE_INTEGER) { | ||
return Number(value); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
return (dv.getUint32(0) * MAX_UINT32) + dv.getUint32(4); | ||
}; | ||
|
||
module.exports = { | ||
getUint64: getUint64, | ||
MAX_UINT32: MAX_UINT32 | ||
}; |
Oops, something went wrong.