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

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7b34d8c5-8c75-4aec-b1e8-49b83de55977o%40googlegroups.com.

Reply via email to