-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update deps, remove cycle from tests
- Loading branch information
Showing
6 changed files
with
155 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Type definitions for varint 5.0 | ||
// Project: https://github.com/chrisdickinson/varint#readme | ||
// Definitions by: David Brockman Smoliansky <https://github.com/dbrockman> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
interface Varint { | ||
encode: { | ||
/** | ||
* Encodes `num` into `buffer` starting at `offset`. returns `buffer`, with the encoded varint written into it. | ||
* `varint.encode.bytes` will now be set to the number of bytes modified. | ||
*/ | ||
(num: number, buffer: Uint8Array, offset?: number): Buffer | ||
|
||
/** | ||
* Encodes `num` into `array` starting at `offset`. returns `array`, with the encoded varint written into it. | ||
* If `array` is not provided, it will default to a new array. | ||
* `varint.encode.bytes` will now be set to the number of bytes modified. | ||
*/ | ||
(num: number, array?: number[], offset?: number): number[] | ||
|
||
/** | ||
* Similar to `decode.bytes` when encoding a number it can be useful to know how many bytes where written (especially if you pass an output array). | ||
* You can access this via `varint.encode.bytes` which holds the number of bytes written in the last encode. | ||
*/ | ||
bytes: number | ||
} | ||
|
||
decode: { | ||
/** | ||
* Decodes `data`, which can be either a buffer or array of integers, from position `offset` or default 0 and returns the decoded original integer. | ||
* Throws a `RangeError` when `data` does not represent a valid encoding. | ||
*/ | ||
(buf: Uint8Array | number[], offset?: number): number | ||
|
||
/** | ||
* If you also require the length (number of bytes) that were required to decode the integer you can access it via `varint.decode.bytes`. | ||
* This is an integer property that will tell you the number of bytes that the last .decode() call had to use to decode. | ||
*/ | ||
bytes: number | ||
} | ||
|
||
/** | ||
* returns the number of bytes this number will be encoded as, up to a maximum of 8. | ||
*/ | ||
encodingLength(num: number): number | ||
} | ||
|
||
declare const varint: Varint | ||
export default varint |
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,96 @@ | ||
var encode_1 = encode | ||
|
||
var MSB = 0x80, | ||
REST = 0x7f, | ||
MSBALL = ~REST, | ||
INT = Math.pow(2, 31) | ||
|
||
function encode(num, out, offset) { | ||
out = out || [] | ||
offset = offset || 0 | ||
var oldOffset = offset | ||
|
||
while (num >= INT) { | ||
out[offset++] = (num & 0xff) | MSB | ||
num /= 128 | ||
} | ||
while (num & MSBALL) { | ||
out[offset++] = (num & 0xff) | MSB | ||
num >>>= 7 | ||
} | ||
out[offset] = num | 0 | ||
|
||
encode.bytes = offset - oldOffset + 1 | ||
|
||
return out | ||
} | ||
|
||
var decode = read | ||
|
||
var MSB$1 = 0x80, | ||
REST$1 = 0x7f | ||
|
||
function read(buf, offset) { | ||
var res = 0, | ||
offset = offset || 0, | ||
shift = 0, | ||
counter = offset, | ||
b, | ||
l = buf.length | ||
|
||
do { | ||
if (counter >= l) { | ||
read.bytes = 0 | ||
throw new RangeError('Could not decode varint') | ||
} | ||
b = buf[counter++] | ||
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift) | ||
shift += 7 | ||
} while (b >= MSB$1) | ||
|
||
read.bytes = counter - offset | ||
|
||
return res | ||
} | ||
|
||
var N1 = Math.pow(2, 7) | ||
var N2 = Math.pow(2, 14) | ||
var N3 = Math.pow(2, 21) | ||
var N4 = Math.pow(2, 28) | ||
var N5 = Math.pow(2, 35) | ||
var N6 = Math.pow(2, 42) | ||
var N7 = Math.pow(2, 49) | ||
var N8 = Math.pow(2, 56) | ||
var N9 = Math.pow(2, 63) | ||
|
||
var length = function (value) { | ||
return value < N1 | ||
? 1 | ||
: value < N2 | ||
? 2 | ||
: value < N3 | ||
? 3 | ||
: value < N4 | ||
? 4 | ||
: value < N5 | ||
? 5 | ||
: value < N6 | ||
? 6 | ||
: value < N7 | ||
? 7 | ||
: value < N8 | ||
? 8 | ||
: value < N9 | ||
? 9 | ||
: 10 | ||
} | ||
|
||
var varint = { | ||
encode: encode_1, | ||
decode: decode, | ||
encodingLength: length, | ||
} | ||
|
||
var _brrp_varint = varint | ||
|
||
export default _brrp_varint |
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.