-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmoa_codec_test.go
48 lines (41 loc) · 1.04 KB
/
moa_codec_test.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 core
import (
_ "bytes"
"encoding/json"
"reflect"
"testing"
)
type ParamsTmp struct {
Method string `json:"m"`
// Args []interface{} `json:"args"`
Args []*json.RawMessage `json:"args"`
}
type User struct {
Name string `json:"name"`
// Args []interface{} `json:"args"`
}
type Request struct {
ServiceUri string `json:"action"`
Params struct {
Method string `json:"m"`
// Args []interface{} `json:"args"`
Args []*json.RawMessage `json:"args"`
} `json:"params"`
}
func BenchmarkUnmarshal(t *testing.B) {
t.StopTimer()
cmd := []byte("{\"action\":\"/service/user-service\",\"params\":{\"m\":\"setName\",\"args\":[\"a\",1,2,{\"name\":\"bbafa\"}]}}")
t.StartTimer()
var reqtmp Request
for i := 0; i < t.N; i++ {
var req Request
json.Unmarshal(cmd, &req)
// args := []interface{}{"", 0, 0, ""}
// json.Unmarshal(req.Params.Args, &args)
reqtmp = req
}
t.StopTimer()
inst := reflect.New(reflect.ValueOf((*User)(nil)).Type())
json.Unmarshal(*reqtmp.Params.Args[3], inst.Interface())
t.Log(inst.Elem().Interface())
}