package relayproto

import 

var (
	smallPool = sync.Pool{New: func() any {  := make([]byte, 2048); return & }}
	largePool = sync.Pool{New: func() any {  := make([]byte, MaxPacketSize); return & }}
)

// GetBuf returns a buffer of length n. A frame may encode to more than
// MaxPacketSize, which no pool here holds, so n above that is allocated.
func ( int) *[]byte {
	var  *[]byte
	switch {
	case  <= 2048:
		 = smallPool.Get().(*[]byte)
	case  <= MaxPacketSize:
		 = largePool.Get().(*[]byte)
	default:
		 := make([]byte, )
		return &
	}
	* = (*)[:]
	return 
}

// PutBuf returns a buffer obtained from GetBuf. A buffer larger than either
// pool holds is dropped rather than kept.
func ( *[]byte) {
	switch  := cap(*); {
	case  <= 2048:
		smallPool.Put()
	case  <= MaxPacketSize:
		largePool.Put()
	}
}