This commit is contained in:
JackDoan
2025-11-04 15:40:33 -06:00
parent 2ea8a72d5c
commit 2ab75709ad
6 changed files with 73 additions and 61 deletions

View File

@@ -1,6 +1,11 @@
package packet
import "net/netip"
import (
"net/netip"
"sync"
)
const Size = 9001
type Packet struct {
Payload []byte
@@ -8,5 +13,24 @@ type Packet struct {
}
func New() *Packet {
return &Packet{Payload: make([]byte, 9001)}
return &Packet{Payload: make([]byte, Size)}
}
type Pool struct {
pool sync.Pool
}
func NewPool() *Pool {
return &Pool{
pool: sync.Pool{New: func() any { return New() }},
}
}
func (p *Pool) Get() *Packet {
return p.pool.Get().(*Packet)
}
func (p *Pool) Put(x *Packet) {
x.Payload = x.Payload[:Size]
p.pool.Put(x)
}