Can you post some code that reproduces the C.GoBytes() behavior you see? According to the documentation it should work as you expect. This "simulation" works (but can not be run in the playground because of cgo usage): https://play.golang.org/p/gec7VNy4-UW
On Saturday, June 6, 2020 at 2:57:41 AM UTC-4, Balaji Rajendran wrote: > > 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/2844cd5f-ac4c-46d0-ac64-bc15d5c12e73o%40googlegroups.com.