示例#1
0
文件: thread.go 项目: gaxxx/funx
func getMemFunc(f *reflect.PtrValue, name string) (fv *reflect.FuncValue) {
	typ := f.Type().(*reflect.PtrType)
	for i := 0; i < typ.NumMethod(); i++ {
		tt := typ.Method(i)
		if tt.Name == name {
			fv = tt.Func
		}
	}
	return
}
示例#2
0
func (jm *jsonDemarshaler) Demarshal() (id Id, ctrlMsg interface{}, appMsg reflect.Value, err os.Error) {
	seedId := jm.proxy.router.seedId
	id, _ = seedId.Clone()
	if err = jm.Decode(id); err != nil {
		return
	}
	if id.Scope() == NumScope && id.Member() == NumMembership {
		return
	}
	switch id.SysIdIndex() {
	case ConnId, DisconnId, ErrorId:
		idc, _ := seedId.Clone()
		ctrlMsg = &ConnInfoMsg{Id: idc}
		err = jm.demarshalCtrlMsg(ctrlMsg)
	case ReadyId:
		idc, _ := seedId.Clone()
		ctrlMsg = &ConnReadyMsg{[]*ChanReadyInfo{&ChanReadyInfo{Id: idc}}}
		err = jm.demarshalCtrlMsg(ctrlMsg)
	case PubId, UnPubId, SubId, UnSubId:
		idc, _ := seedId.Clone()
		ctrlMsg = &IdChanInfoMsg{[]*IdChanInfo{&IdChanInfo{idc, nil, nil}}}
		err = jm.demarshalCtrlMsg(ctrlMsg)
	default: //appMsg
		chanType := jm.proxy.getExportRecvChanType(id)
		if chanType == nil {
			err = os.ErrorString(fmt.Sprintf("failed to find chanType for id %v", id))
			return
		}
		et := chanType.Elem()
		appMsg = reflect.MakeZero(et)
		var ptrT *reflect.PtrValue
		switch et := et.(type) {
		case *reflect.BoolType:
			ptrT = jm.ptrBool
			ptrT.PointTo(appMsg)
		case *reflect.IntType:
			ptrT = jm.ptrInt
			ptrT.PointTo(appMsg)
		case *reflect.FloatType:
			ptrT = jm.ptrFloat
			ptrT.PointTo(appMsg)
		case *reflect.StringType:
			ptrT = jm.ptrString
			ptrT.PointTo(appMsg)
		case *reflect.PtrType:
			sto := reflect.MakeZero(et.Elem())
			ptrT = appMsg.(*reflect.PtrValue)
			ptrT.PointTo(sto)
		default:
			err = os.ErrorString(fmt.Sprintf("invalid chanType for id %v", id))
			return
		}
		err = jm.Decode(ptrT.Interface())
	}
	return
}