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.
Golang Structure.
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
}
}
}
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
}