-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflect_rpc.go
48 lines (35 loc) · 1.01 KB
/
reflect_rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gogonet
import (
"log"
"reflect"
"github.com/TheMrViper/gogonet/marshal"
)
func canCallReflectProcedure(object interface{}, procedureName string) bool {
return reflect.ValueOf(object).MethodByName(procedureName) != reflect.Value{}
}
func reflectProcedureCall(object interface{}, procedureName string, params []reflect.Value) {
reflect.ValueOf(object).MethodByName(procedureName).Call(params)
}
func reflectDecodePacketVariables(data []byte) []reflect.Value {
var paramsCount uint8
paramsCount, data = marshal.DecodeUint8(data)
var p interface{}
result := make([]reflect.Value, paramsCount)
for i := uint8(0); i < paramsCount; i++ {
log.Printf("remain: %x\n", data)
var paramType int32
paramType, data = marshal.DecodeInt32(data)
switch paramType {
case INT:
p, data = marshal.DecodeInt32(data)
case BOOL:
var v int32
v, data = marshal.DecodeInt32(data)
p = v > 0
case STRING:
p, data = marshal.DecodeString(data)
}
result[i] = reflect.ValueOf(p)
}
return result
}