Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't work with interface var #7

Open
nowind opened this issue Jun 24, 2019 · 2 comments
Open

can't work with interface var #7

nowind opened this issue Jun 24, 2019 · 2 comments

Comments

@nowind
Copy link

nowind commented Jun 24, 2019

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

@whisper-bye
Copy link

whisper-bye commented Jul 23, 2019

+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
...

@whisper-bye
Copy link

I fingure it out, it should be reflect2.TypeOfPtr(msg).Elem()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants