1
0
mirror of https://github.com/fumiama/orbyte.git synced 2026-06-05 02:00:30 +08:00

feat(pbuf): add api BufferItemToBytes

This commit is contained in:
源文雨
2025-02-24 23:59:12 +09:00
parent eec7c4821d
commit 17ba555622

View File

@@ -13,6 +13,16 @@ type Bytes struct {
dat []byte
}
// BufferItemToBytes convert between *orbyte.Item[bytes.Buffer]
// and Bytes.
//
// Please notice that Bytes cannnot convert back to
// *orbyte.Item[bytes.Buffer] again.
func BufferItemToBytes(buf *orbyte.Item[bytes.Buffer]) Bytes {
x := buf.Unwrap()
return Bytes{buf: buf, dat: x.Bytes()}
}
// NewBytes alloc sz bytes.
func (bufferPool BufferPool) NewBytes(sz int) Bytes {
buf := bufferPool.p.New(sz)