Open nowind opened 5 years ago
+1
type message struct {
crc uint16
}
msg := &message{}
unpack(b, msg)
func unpack(b []byte, msg interface{}) error {
buf := bytes.NewBuffer(b)
typ := reflect2.TypeOf(msg)
structType := typ.(*reflect2.UnsafeStructType) // panic
...
I fingure it out, it should be reflect2.TypeOfPtr(msg).Elem()
code as following failed: var m interface{}=[]int{1,2} slType:=reflect2.TypeOf(m).(reflect2.SliceType) slType.LengthOf(m) //<--here i can't use &m