有没有方便的方法来初始化一个字节数组?
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)
}
prog.go:8:不能将字符串"abcde"(类型为string)用作字段值中的[5]uint8类型
如果我将该行更改为t := T1{[5]byte("abcde"), 3}
prog.go:8:无法将字符串"abcde"(类型为string)转换为[5]uint8类型