protocol: packets operate on io.ReadWritter; now use a buffer pool to encode/decode packets

This commit is contained in:
2023-03-10 19:56:05 -06:00
parent 5cc3f275c1
commit 985890d351
3 changed files with 63 additions and 81 deletions

19
protocol/pool/pool.go Normal file
View File

@@ -0,0 +1,19 @@
package pool
import (
"bytes"
"sync"
)
var allocator = sync.Pool{
New: func() any { return new(bytes.Buffer) },
}
func Get() *bytes.Buffer {
return allocator.Get().(*bytes.Buffer)
}
func Put(buf *bytes.Buffer) {
buf.Reset()
allocator.Put(buf)
}