mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-26 21:24:14 +00:00
buffer.go: Add a Clone method to the Buffer type.
This commit is contained in:
parent
fbae89d017
commit
562f48b2d1
1 changed files with 11 additions and 0 deletions
|
@ -331,6 +331,17 @@ func (b *Buffer) ReadFullFrom(reader io.Reader, size int32) (int64, error) {
|
||||||
return int64(n), err
|
return int64(n), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clone creates a new Buffer with a copy of the current buffer's contents.
|
||||||
|
func (b *Buffer) Clone() *Buffer {
|
||||||
|
if b == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
newBuf := NewWithSize(b.Len())
|
||||||
|
copy(newBuf.v, b.Bytes())
|
||||||
|
newBuf.end = int32(len(b.Bytes()))
|
||||||
|
return newBuf
|
||||||
|
}
|
||||||
|
|
||||||
// String returns the string form of this Buffer.
|
// String returns the string form of this Buffer.
|
||||||
func (b *Buffer) String() string {
|
func (b *Buffer) String() string {
|
||||||
return string(b.Bytes())
|
return string(b.Bytes())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue