|
|
@ -20,14 +20,16 @@ type Buffer struct {
|
|
|
|
pool Pool
|
|
|
|
pool Pool
|
|
|
|
Value []byte
|
|
|
|
Value []byte
|
|
|
|
offset int
|
|
|
|
offset int
|
|
|
|
|
|
|
|
startingOffset int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func CreateBuffer(container []byte, parent Pool) *Buffer {
|
|
|
|
func CreateBuffer(container []byte, offset int, parent Pool) *Buffer {
|
|
|
|
b := new(Buffer)
|
|
|
|
b := new(Buffer)
|
|
|
|
b.head = container
|
|
|
|
b.head = container
|
|
|
|
b.pool = parent
|
|
|
|
b.pool = parent
|
|
|
|
b.Value = b.head[defaultOffset:]
|
|
|
|
b.Value = b.head[offset:]
|
|
|
|
b.offset = defaultOffset
|
|
|
|
b.offset = offset
|
|
|
|
|
|
|
|
b.startingOffset = offset
|
|
|
|
return b
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -47,15 +49,15 @@ func (b *Buffer) Release() {
|
|
|
|
// Clear clears the content of the buffer, results an empty buffer with
|
|
|
|
// Clear clears the content of the buffer, results an empty buffer with
|
|
|
|
// Len() = 0.
|
|
|
|
// Len() = 0.
|
|
|
|
func (b *Buffer) Clear() *Buffer {
|
|
|
|
func (b *Buffer) Clear() *Buffer {
|
|
|
|
b.offset = defaultOffset
|
|
|
|
b.offset = b.startingOffset
|
|
|
|
b.Value = b.head[b.offset:b.offset]
|
|
|
|
b.Value = b.head[b.offset:b.offset]
|
|
|
|
return b
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Reset resets this Buffer into its original state.
|
|
|
|
// Reset resets this Buffer into its original state.
|
|
|
|
func (b *Buffer) Reset() *Buffer {
|
|
|
|
func (b *Buffer) Reset() *Buffer {
|
|
|
|
b.offset = defaultOffset
|
|
|
|
b.offset = b.startingOffset
|
|
|
|
b.Value = b.head
|
|
|
|
b.Value = b.head[b.offset:]
|
|
|
|
return b
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -219,5 +221,5 @@ func NewBuffer() *Buffer {
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
func NewLocalBuffer(size int) *Buffer {
|
|
|
|
func NewLocalBuffer(size int) *Buffer {
|
|
|
|
return CreateBuffer(make([]byte, size), nil)
|
|
|
|
return CreateBuffer(make([]byte, size), defaultOffset, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|