1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-25 11:35:34 -05:00

refine buffer usage

This commit is contained in:
Darien Raymond
2016-12-05 15:19:14 +01:00
parent 9ecf89657c
commit cf3eb0e77d
16 changed files with 73 additions and 45 deletions

View File

@@ -117,11 +117,39 @@ func (b *Buffer) PrependHash(h hash.Hash) *Buffer {
return b
}
func (b *Buffer) Byte(index int) byte {
return b.Value[index]
}
// Bytes returns the content bytes of this Buffer.
func (b *Buffer) Bytes() []byte {
return b.Value
}
func (b *Buffer) BytesRange(from, to int) []byte {
if from < 0 {
from += len(b.Value)
}
if to < 0 {
to += len(b.Value)
}
return b.Value[from:to]
}
func (b *Buffer) BytesFrom(from int) []byte {
if from < 0 {
from += len(b.Value)
}
return b.Value[from:]
}
func (b *Buffer) BytesTo(to int) []byte {
if to < 0 {
to += len(b.Value)
}
return b.Value[:to]
}
// Slice cuts the buffer at the given position.
func (b *Buffer) Slice(from, to int) *Buffer {
b.offset += from