From 17ba555622c7b1530e6a66f62757f5dc39ef812a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Mon, 24 Feb 2025 23:59:12 +0900 Subject: [PATCH] feat(pbuf): add api BufferItemToBytes --- pbuf/bytes.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pbuf/bytes.go b/pbuf/bytes.go index 9fabc22..a743176 100644 --- a/pbuf/bytes.go +++ b/pbuf/bytes.go @@ -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)