有没有方便的方法来初始化字节数组?
package main
import "fmt"
type T1 struct {
f1 [5]byte // I use fixed size here for file format or network packet format.
f2 int32
}
func main() {
t := T1{"abcde", 3}
// t:= T1{[5]byte{'a','b','c','d','e'}, 3} // work, but ugly
fmt.Println(t)
}
掠夺.go:8:无法在字段值中将"abcde"(类型字符串)用作类型[5]uint8
如果我换成t := T1{[5]byte("abcde"), 3}
proc.go:8:无法将"abcde"(类型字符串)转换为类型[5]uint8