blob: 923f490f7571f4ab111ffff367a5d7568b68cef4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package binproto
import "math"
var (
n1 = uint64(math.Pow(2, 7))
n2 = uint64(math.Pow(2, 14))
n3 = uint64(math.Pow(2, 21))
n4 = uint64(math.Pow(2, 28))
n5 = uint64(math.Pow(2, 35))
n6 = uint64(math.Pow(2, 42))
n7 = uint64(math.Pow(2, 49))
n8 = uint64(math.Pow(2, 56))
n9 = uint64(math.Pow(2, 63))
)
func encodingLength(i uint64) int {
if i < n1 {
return 1
} else if i < n2 {
return 2
} else if i < n3 {
return 3
} else if i < n4 {
return 4
} else if i < n5 {
return 5
} else if i < n6 {
return 6
} else if i < n7 {
return 7
} else if i < n8 {
return 8
} else if i < n9 {
return 9
}
return 10
}
|