I have a type myByte byte
that I use because I want to logically differentiate different kinds of bytes.
I can convert easily with byte(myByte(1))
,
but I can't find away to cast or convert an slice: []byte([]myByte{1})
fails.
Is such a thing possible? The bits are the same in memory (right?) so there should be some way, short of copying byte by byte into a new object..
For example, none of this works: http://play.golang.org/p/WPhD3KufR8
package main
type myByte byte
func main() {
a := []myByte{1}
fmt.Print(byte(myByte(1))) // Works OK
fmt.Print([]byte([]myByte{1})) // Fails: cannot convert []myByte literal (type []myByte) to type []byte
// cannot use a (type []myByte) as type []byte in function argument
// fmt.Print(bytes.Equal(a, b))
// cannot convert a (type []myByte) to type []byte
// []byte(a)
// panic: interface conversion: interface is []main.myByte, not []uint8
// abyte := (interface{}(a)).([]byte)
}