mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
17 lines
435 B
JavaScript
17 lines
435 B
JavaScript
var varint = require('varint')
|
|
exports.encode = function encode (v, b, o) {
|
|
v = v >= 0 ? v*2 : v*-2 - 1
|
|
var r = varint.encode(v, b, o)
|
|
encode.bytes = varint.encode.bytes
|
|
return r
|
|
}
|
|
exports.decode = function decode (b, o) {
|
|
var v = varint.decode(b, o)
|
|
decode.bytes = varint.decode.bytes
|
|
return v & 1 ? (v+1) / -2 : v / 2
|
|
}
|
|
|
|
exports.encodingLength = function (v) {
|
|
return varint.encodingLength(v >= 0 ? v*2 : v*-2 - 1)
|
|
}
|