Perhaps someone can spot the error just by looking at your code. But a couple of tips that will help others help you.
1. Specify what exactly the "failure" is. What output do you get? 2. Include the log output for a sample run. 3. Print, and include a sample value of "data" (the binary data from ReadErrorMsg) so other can run and reproduce the problem. 4. You should not be discarding the error from binary.Read. Always check your errors. If there is one, then handle it, or at least log it to help diagnose the problem. Good luck. On Wednesday, August 15, 2018 at 11:29:44 PM UTC-4, naveen.b....@gmail.com wrote: > > Hi All, > > I am learning golang and in the process i am trying to decode the buffer > sent from a C client to a structure in golang. > however that fails , please guide me through the process. The > communication uses UNIX domain socket, between a c program and a > golang process. > > C structure. > struct error_notify_msg_t { > int type; > > char str[384]; > > char name[64]; > > char id[256]; > > char ip[60]; > } > > Golang Structure. > > type ErrorNotifyMsg struct { > //Type ... > Type uint32 > //Str ... > Str [384]string > //Name ... > Name [64]string > //ID ... > ID [256]string > //Ip ... > IP [60]string > } > > func ReadErrorMsg() { > //var n int > buf := make([]byte, 1024) > for { > > n, err := ConnErr.Read(buf[:]) > if err != nil { > return > } > data := buf[0:n] > Log.InfoS("DecodeErrorMsg", log.KV{"Bytes read :": n}) > msg, err := DecodeErrorMsg(data) > if msg != nil { > ErrNotify <- *msg > } > } > } > > var ourEnd = binary.LittleEndian > > func DecodeErrorMsg(val []byte) ErrorNotifyMsg { > ntfy := ErrorNotifyMsg{} > buf := bytes.NewBuffer(val) > buf.Next(1) > _ = binary.Read(buf, ourEnd, &ntfy.Type) > Log.InfoS("DecodeErrorMsg", log.KV{"ntfy.Type": ntfy.Type}) > buf.Next(384) > _ = binary.Read(buf, ourEnd, &ntfy.Str) > Log.InfoS("DecodeErrorMsg", log.KV{"ntfy.Str": ntfy.Str}) > buf.Next(64) > _ = binary.Read(buf, ourEnd, &ntfy.Name) > Log.InfoS("DecodeErrorMsg", log.KV{"ntfy.Name": ntfy.Name}) > buf.Next(256) > _ = binary.Read(buf, ourEnd, &ntfy.ID) > Log.InfoS("DecodeErrorMsg", log.KV{"ntfy.ID": ntfy.ID}) > buf.Next(60) > _ = binary.Read(buf, ourEnd, &ntfy.IP) > Log.InfoS("DecodeErrorMsg", log.KV{"ntfy.IP": ntfy.IP}) > return ntfy > } > > Thanks, > Naveen > > -- 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. For more options, visit https://groups.google.com/d/optout.