rearrage_stuff
This commit is contained in:
29
node_modules/varint/decode.js
generated
vendored
Normal file
29
node_modules/varint/decode.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
module.exports = read
|
||||
|
||||
var MSB = 0x80
|
||||
, REST = 0x7F
|
||||
|
||||
function read(buf, offset) {
|
||||
var res = 0
|
||||
, offset = offset || 0
|
||||
, shift = 0
|
||||
, counter = offset
|
||||
, b
|
||||
, l = buf.length
|
||||
|
||||
do {
|
||||
if (counter >= l || shift > 49) {
|
||||
read.bytes = 0
|
||||
throw new RangeError('Could not decode varint')
|
||||
}
|
||||
b = buf[counter++]
|
||||
res += shift < 28
|
||||
? (b & REST) << shift
|
||||
: (b & REST) * Math.pow(2, shift)
|
||||
shift += 7
|
||||
} while (b >= MSB)
|
||||
|
||||
read.bytes = counter - offset
|
||||
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user