-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add util functions for encoding and decoding bytes #34
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfinished review, left some comments
assert(bytes > 0); | ||
|
||
/* eslint-disable no-bitwise */ | ||
const mask = value >> BigInt(31); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
31n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
for (let i = 0; i < bytes.length; i++) { | ||
bytes[i] = Number(BigInt.asUintN(8, numberValue)); | ||
// eslint-disable-next-line no-bitwise | ||
numberValue >>= BigInt(8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
4755293
to
2716e71
Compare
This adds some util functions for working with bytes (
Uint8Array
). These implementations don't rely on the Node.jsBuffer
class, meaning that it does not require a polyfill to be used in browsers.These functions are implemented with performance in mind, so a faster implementation was chosen over a "pretty" implementation.