mirror of
https://github.com/fumiama/orbyte.git
synced 2026-06-05 18:20:31 +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
|
||||
// and Bytes.
|
||||
//
|
||||
// Please notice that Bytes cannnot convert back to
|
||||
// *Buffer again.
|
||||
func BufferItemToBytes[USRDAT any](
|
||||
buf *orbyte.Item[UserBuffer[USRDAT]],
|
||||
) (b UserBytes[USRDAT]) {
|
||||
@@ -28,6 +25,13 @@ func BufferItemToBytes[USRDAT any](
|
||||
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.
|
||||
func (bufferPool BufferPool[USRDAT]) NewBytes(sz int) (b UserBytes[USRDAT]) {
|
||||
buf := bufferPool.p.New(sz)
|
||||
|
||||
Reference in New Issue
Block a user