代码拉取完成,页面将自动刷新
package server
import (
"reflect"
"sync/atomic"
)
/*net rpc need suffice the following conditions
the method’s type is exported. – 方法所属类型是导出的。
the method is exported. – 方式是导出的。
the method has two arguments, both exported (or builtin) types. – 两个入参,均为导出或内置类型。
the method’s second argument is a pointer. – 第二个入参必须是一个指针。
the method has return type error. – 返回值为 error 类型。
*/
//methodType represents a method
//include method itself, first argtype,second arg type(must be a pointer) and callCnt
type methodType struct {
method reflect.Method
ArgType reflect.Type // first arg type
ReplyType reflect.Type // second arg type
numCalls uint64 //has call this method numCalls cnts
}
func (m *methodType) NumCalls() uint64 {
//automic get numCalls
return atomic.LoadUint64(&m.numCalls)
}
func (m *methodType) newArgv() reflect.Value {
var argv reflect.Value
if m.ArgType.Kind() == reflect.Ptr {
//is pointer type return argv is also pointer
argv = reflect.New(m.ArgType.Elem())
} else {
//a value type return argv is a value type
argv = reflect.New(m.ArgType).Elem()
}
return argv
}
func (m *methodType) newReply() reflect.Value {
//reply must be a pointer type
replyv := reflect.New(m.ReplyType.Elem())
switch m.ReplyType.Elem().Kind() {
//if ReplyType is map or slice, it must make address
case reflect.Map:
replyv.Elem().Set(reflect.MakeMap(m.ReplyType.Elem()))
case reflect.Slice:
replyv.Elem().Set(reflect.MakeSlice(m.ReplyType.Elem(), 0, 0))
}
return replyv
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。