mirror of
https://github.com/fumiama/orbyte.git
synced 2026-06-12 14:10:53 +08:00
feat(pbuf): add api B()
This commit is contained in:
@@ -15,9 +15,6 @@ type UserBytes[USRDAT any] struct {
|
|||||||
|
|
||||||
// BufferItemToBytes convert between *Buffer
|
// BufferItemToBytes convert between *Buffer
|
||||||
// and Bytes.
|
// and Bytes.
|
||||||
//
|
|
||||||
// Please notice that Bytes cannnot convert back to
|
|
||||||
// *Buffer again.
|
|
||||||
func BufferItemToBytes[USRDAT any](
|
func BufferItemToBytes[USRDAT any](
|
||||||
buf *orbyte.Item[UserBuffer[USRDAT]],
|
buf *orbyte.Item[UserBuffer[USRDAT]],
|
||||||
) (b UserBytes[USRDAT]) {
|
) (b UserBytes[USRDAT]) {
|
||||||
@@ -28,6 +25,13 @@ func BufferItemToBytes[USRDAT any](
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// B directly use inner buf data and USRDAT safely.
|
||||||
|
func (b UserBytes[USRDAT]) B(f func([]byte, *USRDAT)) {
|
||||||
|
b.buf.P(func(ub *UserBuffer[USRDAT]) {
|
||||||
|
f(ub.Buffer.Bytes(), &ub.DAT)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// NewBytes alloc sz bytes.
|
// NewBytes alloc sz bytes.
|
||||||
func (bufferPool BufferPool[USRDAT]) NewBytes(sz int) (b UserBytes[USRDAT]) {
|
func (bufferPool BufferPool[USRDAT]) NewBytes(sz int) (b UserBytes[USRDAT]) {
|
||||||
buf := bufferPool.p.New(sz)
|
buf := bufferPool.p.New(sz)
|
||||||
|
|||||||
Reference in New Issue
Block a user