/
prototest.go
86 lines (83 loc) · 2.38 KB
/
prototest.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"code.google.com/p/goprotobuf/proto"
"git.code4.in/mobilegameserver/platcommon"
"github.com/dedis/protobuf"
//"github.com/golang/protobuf/ptypes"
"fmt"
"reflect"
)
func main() {
uj := &Pmd.UserJsMessageForwardUserPmd_CS{}
uj.Msgbytes = []byte(`{"whj":111}`)
fmt.Println("XXXXX", uj.String(), proto.MarshalTextString(uj))
rc := &Pmd.ReconnectErrorLoginUserPmd_S{}
rc.Desc = proto.String(`{"whj":111}`)
fmt.Println("xxxxx", rc.String(), proto.MarshalTextString(rc), *rc.Desc)
m := make(map[int]string)
m[1] = "wabghaijun"
a := 1
fmt.Println(protobuf.Encode(&a))
mset := make(map[int32]proto.Extension)
//mset[1] = proto.Extension{enc: []byte("sss")}
//umset, err := proto.MarshalMessageSet(mset)
var b []byte
fmt.Println(len(b))
nmd := &Pmd.ForwardNullUserPmd_CS{}
nmd1 := &Pmd.ForwardNullUserPmd_CS{}
nmd2 := &Pmd.ForwardNullUserPmd_CS{}
cmd3 := &Pmd.RequestCloseNullUserPmd_CS{}
cmd4 := &Pmd.RequestCloseNullUserPmd_CS{}
cmd3.Reason = proto.String("2222")
fmt.Println(proto.GetProperties(reflect.TypeOf(cmd3).Elem()))
cmd3byte, err1 := proto.Marshal(cmd3)
if err1 != nil {
fmt.Println("xxxxxxxxxxx", err1)
}
fmt.Println(proto.Unmarshal(cmd3byte, cmd3))
fmt.Println(mset)
cmd3test := proto.MarshalTextString(cmd3)
fmt.Println(cmd3test)
fmt.Println(proto.UnmarshalText(cmd3test, nmd))
//nmd.Prototype = proto.Uint64(2)
nmd.ByCmd = proto.Uint32(0)
//nmd.ByParam = proto.Uint32(0)
//nmd.ByCmd = append(nmd.ByCmd, 0)
//nmd.ByParam = append(nmd.ByParam, 0)
sendbuf := proto.NewBuffer(nil)
err := sendbuf.Marshal(nmd)
if err != nil {
fmt.Println("1", err)
}
nmd.Data = sendbuf.Bytes()
fmt.Println(nmd, proto.Size(nmd), len(sendbuf.Bytes()))
fmt.Println(len(sendbuf.Bytes()), sendbuf.Bytes())
//data := sendbuf.Bytes()
err = sendbuf.Marshal(cmd3)
if err != nil {
fmt.Println("2", err)
}
fmt.Println(len(sendbuf.Bytes()), sendbuf.Bytes())
data := sendbuf.Bytes()
fmt.Println(len(data), data)
//data = append(data, byte(1))
databuf := proto.NewBuffer(data)
err = databuf.Unmarshal(nmd1)
if err != nil {
fmt.Println("3", err)
}
//err = databuf.Unmarshal(nmd2)
err = proto.Unmarshal(data[:2], nmd2)
if err != nil {
fmt.Println("4", err)
}
err = proto.Unmarshal(data[2:], cmd4)
//err = databuf.Unmarshal(cmd4)
if err != nil {
fmt.Println("5", err)
}
fmt.Println(nmd, proto.Size(nmd))
fmt.Println(nmd1)
fmt.Println(nmd2)
fmt.Println(cmd4)
}