From 562f48b2d13064494c95cab1cdbfb5a46e853acc Mon Sep 17 00:00:00 2001 From: Tanvir Ahamed <tanvirahamed.official@outlook.com> Date: Tue, 17 Jun 2025 20:42:16 +0600 Subject: [PATCH] buffer.go: Add a Clone method to the Buffer type. --- common/buf/buffer.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/buf/buffer.go b/common/buf/buffer.go index 2aa60e6a..dc34bcdd 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -331,6 +331,17 @@ func (b *Buffer) ReadFullFrom(reader io.Reader, size int32) (int64, error) { 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. func (b *Buffer) String() string { return string(b.Bytes())