@@ -22,6 +22,7 @@ import (
2222 "github.com/apache/arrow/go/arrow/internal/debug"
2323)
2424
25+ // Buffer is a wrapper type for a buffer of bytes.
2526type Buffer struct {
2627 refCount int64
2728 buf []byte
@@ -35,7 +36,7 @@ func NewBufferBytes(data []byte) *Buffer {
3536 return & Buffer {refCount : 0 , buf : data , length : len (data )}
3637}
3738
38- // NewBuffer creates a mutable, resizable buffer with an Allocator for managing memory.
39+ // NewResizableBuffer creates a mutable, resizable buffer with an Allocator for managing memory.
3940func NewResizableBuffer (mem Allocator ) * Buffer {
4041 return & Buffer {refCount : 1 , mutable : true , mem : mem }
4142}
@@ -60,15 +61,28 @@ func (b *Buffer) Release() {
6061 }
6162}
6263
64+ // Reset resets the buffer for reuse.
65+ func (b * Buffer ) Reset (buf []byte ) {
66+ b .buf = buf
67+ b .length = len (buf )
68+ }
69+
6370// Buf returns the slice of memory allocated by the Buffer, which is adjusted by calling Reserve.
6471func (b * Buffer ) Buf () []byte { return b .buf }
6572
6673// Bytes returns a slice of size Len, which is adjusted by calling Resize.
6774func (b * Buffer ) Bytes () []byte { return b .buf [:b .length ] }
75+
76+ // Mutable returns a bool indicating whether the buffer is mutable or not.
6877func (b * Buffer ) Mutable () bool { return b .mutable }
69- func (b * Buffer ) Len () int { return b .length }
70- func (b * Buffer ) Cap () int { return len (b .buf ) }
7178
79+ // Len returns the length of the buffer.
80+ func (b * Buffer ) Len () int { return b .length }
81+
82+ // Cap returns the capacity of the buffer.
83+ func (b * Buffer ) Cap () int { return len (b .buf ) }
84+
85+ // Reserve reserves the provided amount of capacity for the buffer.
7286func (b * Buffer ) Reserve (capacity int ) {
7387 if capacity > len (b .buf ) {
7488 newCap := roundUpToMultipleOf64 (capacity )
@@ -80,10 +94,13 @@ func (b *Buffer) Reserve(capacity int) {
8094 }
8195}
8296
97+ // Resize resizes the buffer to the target size.
8398func (b * Buffer ) Resize (newSize int ) {
8499 b .resize (newSize , true )
85100}
86101
102+ // ResizeNoShrink resizes the buffer to the target size, but will not
103+ // shrink it.
87104func (b * Buffer ) ResizeNoShrink (newSize int ) {
88105 b .resize (newSize , false )
89106}
0 commit comments