I want to convert *C.uchar to bytes slice.
I've tried C.GoBytes. But, C.GoBytes is not giving the exact result. Because, it is truncating at zero.
for example.
If I have *C.uchar like this, [1,3,5,0,2,4,5]. I expect my go bytes like this [1,3,5,0,2,4,5]
But, I get [1,3,5,0,0,0] If I use C.Gobytes.
I'm able to get the correct results, If I do a casting like this
func charToBytes(src *C.uchar, sz int) []byte {
dest := make([]byte, sz)
copy(dest, (*(*[1024]byte)(unsafe.Pointer(src)))[:sz:sz])
return dest
}
Is this a safe code? And also how to increase the size of slice dynamically. Right now it is capped at 1024