重构输出流转发, TransStream不再持有Sink

This commit is contained in:
yangjiechina
2024-10-28 19:15:53 +08:00
parent 9090e28077
commit ec707c8dc1
27 changed files with 894 additions and 747 deletions

View File

@@ -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}
}