mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-05 15:16:49 +08:00
重构输出流转发, TransStream不再持有Sink
This commit is contained in:
@@ -17,12 +17,24 @@ type ReceiveBuffer struct {
|
||||
index int
|
||||
}
|
||||
|
||||
func (r *ReceiveBuffer) Index() int {
|
||||
return r.index
|
||||
}
|
||||
|
||||
func (r *ReceiveBuffer) Get(index int) []byte {
|
||||
return r.data[index*r.blockSize : (index+1)*r.blockSize]
|
||||
}
|
||||
|
||||
func (r *ReceiveBuffer) GetBlock() []byte {
|
||||
bytes := r.data[r.index*r.blockSize:]
|
||||
r.index = (r.index + 1) % r.blockCount
|
||||
return bytes[:r.blockSize]
|
||||
}
|
||||
|
||||
func (r *ReceiveBuffer) BlockCount() int {
|
||||
return r.blockCount
|
||||
}
|
||||
|
||||
func NewReceiveBuffer(blockSize, blockCount int) *ReceiveBuffer {
|
||||
return &ReceiveBuffer{blockSize: blockSize, blockCount: blockCount, data: make([]byte, blockSize*blockCount), index: 0}
|
||||
}
|
||||
|
Reference in New Issue
Block a user