protocol/util.go

21 lines
326 B
Go

package protocol
import (
"bytes"
"encoding/binary"
"sync"
)
var uint32BytesPool = sync.Pool{
New: func() interface{} {
return make([]byte, 4)
},
}
func writeUint32Bytes(b *bytes.Buffer, i uint32) {
buf := uint32BytesPool.Get().([]byte)
binary.BigEndian.PutUint32(buf, i)
b.Write(buf)
uint32BytesPool.Put(buf)
}