mirror of
https://github.com/tornadocash/provider.git
synced 2024-11-22 17:50:02 +01:00
27 lines
452 B
JavaScript
27 lines
452 B
JavaScript
module.exports = 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
|
|
}
|