2023-11-28 03:23:28 +00:00
|
|
|
package protocol
|
2023-03-11 01:56:05 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2023-03-11 09:28:11 +00:00
|
|
|
var allocator = &sync.Pool{
|
2023-03-11 01:56:05 +00:00
|
|
|
New: func() any { return new(bytes.Buffer) },
|
|
|
|
}
|
|
|
|
|
2023-11-28 03:23:28 +00:00
|
|
|
// grabs a *bytes.Buffer from the pool
|
|
|
|
func GetBuffer() *bytes.Buffer {
|
2023-03-11 01:56:05 +00:00
|
|
|
return allocator.Get().(*bytes.Buffer)
|
|
|
|
}
|
|
|
|
|
2023-11-28 03:23:28 +00:00
|
|
|
// returns a *bytes.Buffer to the pool
|
|
|
|
func PutBuffer(buf *bytes.Buffer) {
|
2023-03-11 01:56:05 +00:00
|
|
|
buf.Reset()
|
|
|
|
allocator.Put(buf)
|
|
|
|
}
|