Skip to content

Commit f362cad

Browse files
committed
feat(pbuf): add api B()
1 parent 8c0982b commit f362cad

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pbuf/bytes.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ type UserBytes[USRDAT any] struct {
1515

1616
// BufferItemToBytes convert between *Buffer
1717
// and Bytes.
18-
//
19-
// Please notice that Bytes cannnot convert back to
20-
// *Buffer again.
2118
func BufferItemToBytes[USRDAT any](
2219
buf *orbyte.Item[UserBuffer[USRDAT]],
2320
) (b UserBytes[USRDAT]) {
@@ -28,6 +25,13 @@ func BufferItemToBytes[USRDAT any](
2825
return
2926
}
3027

28+
// B directly use inner buf data and USRDAT safely.
29+
func (b UserBytes[USRDAT]) B(f func([]byte, *USRDAT)) {
30+
b.buf.P(func(ub *UserBuffer[USRDAT]) {
31+
f(ub.Buffer.Bytes(), &ub.DAT)
32+
})
33+
}
34+
3135
// NewBytes alloc sz bytes.
3236
func (bufferPool BufferPool[USRDAT]) NewBytes(sz int) (b UserBytes[USRDAT]) {
3337
buf := bufferPool.p.New(sz)

0 commit comments

Comments
 (0)