github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/buf/multi.go (about)

     1  package buf
     2  
     3  import "github.com/sagernet/sing/common"
     4  
     5  func LenMulti(buffers []*Buffer) int {
     6  	var n int
     7  	for _, buffer := range buffers {
     8  		n += buffer.Len()
     9  	}
    10  	return n
    11  }
    12  
    13  func ToSliceMulti(buffers []*Buffer) [][]byte {
    14  	return common.Map(buffers, func(it *Buffer) []byte {
    15  		return it.Bytes()
    16  	})
    17  }
    18  
    19  func CopyMulti(toBuffer []byte, buffers []*Buffer) int {
    20  	var n int
    21  	for _, buffer := range buffers {
    22  		n += copy(toBuffer[n:], buffer.Bytes())
    23  	}
    24  	return n
    25  }
    26  
    27  func ReleaseMulti(buffers []*Buffer) {
    28  	for _, buffer := range buffers {
    29  		buffer.Release()
    30  	}
    31  }