Add standard function documentation comments.
The documentation should be available here:
https://pkg.go.dev/libguestfs.org/libnbd#AioBuffer
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
golang/aio_buffer.go | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/golang/aio_buffer.go b/golang/aio_buffer.go
index 2b77d6ee..8f33f500 100644
--- a/golang/aio_buffer.go
+++ b/golang/aio_buffer.go
@@ -32,37 +32,49 @@ package libnbd
import "C"
import "unsafe"
/* Asynchronous I/O buffer. */
type AioBuffer struct {
P unsafe.Pointer
Size uint
}
+// MakeAioBuffer makes a new buffer backed by an unitilialized C allocated
+// array.
func MakeAioBuffer(size uint) AioBuffer {
return AioBuffer{C.malloc(C.ulong(size)), size}
}
+// FromBytes makes a new buffer backed by a C allocated array, initialized by
+// copying the given Go slice.
func FromBytes(buf []byte) AioBuffer {
size := len(buf)
ret := MakeAioBuffer(uint(size))
for i := 0; i < len(buf); i++ {
*ret.Get(uint(i)) = buf[i]
}
return ret
}
+// Free deallocates the underlying C allocated array. Using the buffer after
+// Free() will panic.
func (b *AioBuffer) Free() {
if b.P != nil {
C.free(b.P)
b.P = nil
}
}
+// Bytes copies the underlying C array to Go allocated memory and return a
+// slice. Modifying the returned slice does not modify the unerlying buffer
+// backking array.
func (b *AioBuffer) Bytes() []byte {
return C.GoBytes(b.P, C.int(b.Size))
}
+// Get returns a pointer to a byte in the underlying C array. The pointer can
+// be used to modify the underlying array. The pointer must not be used after
+// caling Free().
func (b *AioBuffer) Get(i uint) *byte {
return (*byte)(unsafe.Pointer(uintptr(b.P) + uintptr(i)))
}
--
2.34.1