MCPcopy Index your code
hub / github.com/CodisLabs/codis / Btoi64

Function Btoi64

pkg/proxy/redis/decoder.go:33–62  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

31)
32
33func Btoi64(b []byte) (int64, error) {
34 if len(b) != 0 && len(b) < 10 {
35 var neg, i = false, 0
36 switch b[0] {
37 case '-':
38 neg = true
39 fallthrough
40 case '+':
41 i++
42 }
43 if len(b) != i {
44 var n int64
45 for ; i < len(b) && b[i] >= '0' && b[i] <= '9'; i++ {
46 n = int64(b[i]-'0') + n*10
47 }
48 if len(b) == i {
49 if neg {
50 n = -n
51 }
52 return n, nil
53 }
54 }
55 }
56
57 if n, err := strconv.ParseInt(string(b), 10, 64); err != nil {
58 return 0, errors.Trace(err)
59 } else {
60 return n, nil
61 }
62}
63
64type Decoder struct {
65 br *bufio2.Reader

Callers 2

decodeIntMethod · 0.85
TestBtoi64Function · 0.85

Calls

no outgoing calls

Tested by 1

TestBtoi64Function · 0.68