I've defined the two types
type zFrame []byte
type zMsg []zFrame
and I have the variable
var message [][]byte
. Go compiler is telling me
cannot use msg (type [][]byte) as type zMsg in function argument
when I try to compile
myZMsg := zMsg(message)
. Changing to
type zMsg [][]byte
makes things compile, but I like the first solution better. Is there an easy way for me to convert from [][]byte
to zMsg
for that case?
You'll have to do the conversion yourself. For example,
package main
type zFrame []byte
type zMsg []zFrame
func main() {
var message [][]byte
myZMsg := make(zMsg, len(message))
for i := range message {
myZMsg[i] = zFrame(message[i])
}
}