Re: [go-nuts] Convert *C.char to array of strings in Go

2019-05-01 Thread Justin Israel
On Wed, May 1, 2019, 11:44 PM Nitish Saboo wrote: > Hi Jusitn, > > I realised I have value_len field in my arguments.I did this : > > func Nitish(key *C.char, value *C.char, value_len C.size_t){ > > f.WriteString(C.GoString(key)+ ":") > s := C.GoStringN(value, C.int(value_len)) > //fmt.Println(s)

Re: [go-nuts] Convert *C.char to array of strings in Go

2019-05-01 Thread Nitish Saboo
Hi Jusitn, I realised I have value_len field in my arguments.I did this : func Nitish(key *C.char, value *C.char, value_len C.size_t){ f.WriteString(C.GoString(key)+ ":") s := C.GoStringN(value, C.int(value_len)) //fmt.Println(s) f.WriteString(s) f.WriteString("\n") } Am I doing it correctly?

Re: [go-nuts] Convert *C.char to array of strings in Go

2019-05-01 Thread Nitish Saboo
Hi Justin, As you had suggested: You could use something like this: https://play.golang.org/p/fcE2UJEUFPy That example has the option of only converting a fixed number of bytes from the C string to the Go string, if you know how big the prefix is.

Re: [go-nuts] Convert *C.char to array of strings in Go

2019-05-01 Thread Justin Israel
On Wed, May 1, 2019 at 9:40 PM Nitish Saboo wrote: > Actually, this is what is happening: > > func Nitish(key *C.char, value *C.char, value_len C.size_t){ > >f.WriteString(C.GoString(key)+ ":") >f.WriteString(C.GoString(value)) >f.WriteString("\n") > > } > > This callback method is ge

Re: [go-nuts] Convert *C.char to array of strings in Go

2019-05-01 Thread Nitish Saboo
Actually, this is what is happening: func Nitish(key *C.char, value *C.char, value_len C.size_t){ f.WriteString(C.GoString(key)+ ":") f.WriteString(C.GoString(value)) f.WriteString("\n") } This callback method is getting called from C code multiple times. I am planning to write the k

Re: [go-nuts] Convert *C.char to array of strings in Go

2019-04-30 Thread Nitish Saboo
Hi, I have this method: func CallBack(key *C.char, value *C.char, value_len C.size_t){ } and the *value* parameter in the arguments is containing the given string 'Fp5PpR2roT6uPnte47 image/gif'. I want to extract only first word from the string.Let me know how can I do this. I don't wa

Re: [go-nuts] Convert *C.char to array of strings in Go

2019-04-30 Thread Justin Israel
On Wednesday, May 1, 2019 at 7:06:47 AM UTC+12, Nitish Saboo wrote: > > Apologies.I did this 'strings.Split(C.GoString(*C.char),""). > I am getting 'Incompatible types' compilation error. > Are you literally doing this? strings.Split(C.GoString(*C.char),"") Something like this should be wor

Re: [go-nuts] Convert *C.char to array of strings in Go

2019-04-30 Thread Nitish Saboo
Apologies.I did this 'strings.Split(C.GoString(*C.char),""). I am getting 'Incompatible types' compilation error. Thanks On Wed, May 1, 2019 at 12:30 AM Nitish Saboo wrote: > Hi, > > I want to convert *C.char to array of strings in Go. > I want to do this because I want the first word from the