Browse Source

export encodingLength

master
Dominic Tarr 9 years ago
parent
commit
bb93a5a51b
  1. 3
      index.js
  2. 21
      length.js

3
index.js

@ -1,4 +1,5 @@
module.exports = {
encode: require('./encode.js')
, decode: require('./decode.js')
}
, encodingLength: require('./length.js')
}

21
length.js

@ -0,0 +1,21 @@
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)
module.exports = function (value) {
return (
value < N1 ? 1
: value < N2 ? 2
: value < N3 ? 3
: value < N4 ? 4
: value < N5 ? 5
: value < N6 ? 6
: value < N7 ? 7
: 8
)
}
Loading…
Cancel
Save