This commit is contained in:
Lei Xue
2017-08-02 19:01:41 +08:00
parent 4ae643e9f8
commit fcb96b323d
6 changed files with 91 additions and 101 deletions

View File

@@ -19,12 +19,16 @@ package pool
import "sync"
var bytePool sync.Pool = sync.Pool{}
func NewBuffer(size int) []byte {
var bytePool = sync.Pool{
New: func() interface{} {
return make([]byte, size)
},
bytePool.New = func() interface{} {
return make([]byte, size)
}
return bytePool.Get().([]byte)
}
func ReleaseBuffer(b []byte) {
bytePool.Put(b)
}

View File

@@ -91,13 +91,14 @@ func MarshalUint32(i uint32) []byte {
return data
}
func MarshalUint64(i uint64) []byte {
var data []byte
func MarshalUint64(v uint64) []byte {
var data = [8]byte{}
var i = 0
for j := 56; j >= 0; j -= 8 {
b := byte(i >> uint32(j))
data = append(data, b)
data[i] = byte(v >> uint32(j))
i++
}
return data
return data[0:8]
}
func StringToByte(str string, align int, maxlength int) []byte {