File size: 475 Bytes
ca7217f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package bufferpool

import (
	"bytes"

	"github.com/metatube-community/metatube-sdk-go/common/pool"
)

type BufferPool struct {
	pool *pool.Pool[*bytes.Buffer]
}

func New(size int) *BufferPool {
	return &BufferPool{
		pool: pool.New(func() *bytes.Buffer {
			return bytes.NewBuffer(make([]byte, 0, size))
		}),
	}
}

func (bp *BufferPool) Get() *bytes.Buffer {
	buf := bp.pool.Get()
	buf.Reset()
	return buf
}

func (bp *BufferPool) Put(b *bytes.Buffer) {
	bp.pool.Put(b)
}