-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove big-varint lib * Move big-varint to utils
- Loading branch information
Showing
6 changed files
with
61 additions
and
10 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
/* eslint-disable @typescript-eslint/no-magic-numbers */ | ||
// This code was taken from the lib big-varint. https://github.com/joeltg/big-varint/blob/65346e5688245b20f05e5ce2dd8c784eb3ae3e15/src/unsigned.ts#L1C1-L58C2 | ||
const LIMIT = 0x7fn | ||
|
||
export function encodingLength(value: bigint): number { | ||
let i = 0 | ||
|
||
for (; value >= 0x80n; i++) { | ||
value >>= 7n | ||
} | ||
|
||
return i + 1 | ||
} | ||
|
||
export function encode( | ||
i: bigint, | ||
buffer?: ArrayBuffer, | ||
byteOffset?: number | ||
): Uint8Array { | ||
if (i < 0n) { | ||
throw new RangeError('value must be unsigned') | ||
} | ||
|
||
const byteLength = encodingLength(i) | ||
buffer = buffer || new ArrayBuffer(byteLength) | ||
byteOffset = byteOffset || 0 | ||
if (buffer.byteLength < byteOffset + byteLength) { | ||
throw new RangeError( | ||
'the buffer is too small to encode the number at the offset' | ||
) | ||
} | ||
|
||
const array = new Uint8Array(buffer, byteOffset) | ||
|
||
let offset = 0 | ||
while (LIMIT < i) { | ||
array[offset++] = Number(i & LIMIT) | 0x80 | ||
i >>= 7n | ||
} | ||
|
||
array[offset] = Number(i) | ||
|
||
return array | ||
} | ||
|
||
export function decode(data: Uint8Array, offset = 0): bigint { | ||
let i = 0n | ||
let n = 0 | ||
let b: number | ||
do { | ||
b = data[offset + n] | ||
if (b === undefined) { | ||
throw new RangeError('offset out of range') | ||
} | ||
|
||
i += BigInt(b & 0x7f) << BigInt(n * 7) | ||
n++ | ||
} while (0x80 <= b) | ||
return i | ||
} |
6cbade5
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.
Coverage report for experimental massa-web3
Test suite run success
129 tests passing in 13 suites.
Report generated by 🧪jest coverage report action from 6cbade5