优化序列化方法
This commit is contained in:
parent
ba7065a6b9
commit
735504cf6b
@ -234,8 +234,10 @@ func GobMarshal(data interface{}) ([]byte, error) {
|
|||||||
bufferPool.Put(buf) // 即使出错也要归还
|
bufferPool.Put(buf) // 即使出错也要归还
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
result := make([]byte, buf.Len())
|
||||||
|
copy(result, buf.Bytes())
|
||||||
bufferPool.Put(buf) // 归还到对象池
|
bufferPool.Put(buf) // 归还到对象池
|
||||||
return buf.Bytes(), nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GobUnmarshal(data []byte, obj interface{}) error {
|
func GobUnmarshal(data []byte, obj interface{}) error {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user