forked from tinylib/msgp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
any_test.go
107 lines (96 loc) · 1.94 KB
/
any_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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package _generated
// Code generated by github.com/henrylee2cn/msgp DO NOT EDIT.
import (
"bytes"
"encoding/json"
"testing"
"github.com/henrylee2cn/msgp/msgp"
)
func TestMarshalUnmarshalTable2(t *testing.T) {
v1 := Table{
A: &GridView{"0000"},
B: [5]msgp.Any{
&GridView{"1111"},
&GridView{"2222"},
&GridView{"3333"},
&GridView{"4444"},
},
C: []msgp.Any{
&GridView{"5555"},
&GridView{"6666"},
},
D: map[string]msgp.Any{
"aaaa": &GridView{"7777"},
"bbbb": &GridView{"8888"},
},
E: map[string][]msgp.Any{
"cccc": {&GridView{"9999"}},
},
}
b1, _ := json.Marshal(v1)
t.Logf("send table: %s", b1)
bts, err := v1.MarshalMsg(nil)
if err != nil {
t.Fatal(err)
}
v2 := Table{}
left, err := v2.UnmarshalMsg(bts)
if err != nil {
t.Fatal(err)
}
if len(left) > 0 {
t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left)
}
b2, _ := json.Marshal(v2)
t.Logf("recv table: %s", b2)
left, err = msgp.Skip(bts)
if err != nil {
t.Fatal(err)
}
if len(left) > 0 {
t.Errorf("%d bytes left over after Skip(): %q", len(left), left)
}
}
func TestEncodeDecodeTable2(t *testing.T) {
v1 := Table{
A: &GridView{"0000"},
B: [5]msgp.Any{
&GridView{"1111"},
&GridView{"2222"},
&GridView{"3333"},
&GridView{"4444"},
},
C: []msgp.Any{
&GridView{"5555"},
&GridView{"6666"},
},
D: map[string]msgp.Any{
"aaaa": &GridView{"7777"},
"bbbb": &GridView{"8888"},
},
E: map[string][]msgp.Any{
"cccc": {&GridView{"9999"}},
},
}
b1, _ := json.Marshal(v1)
t.Logf("send table: %s", b1)
var buf bytes.Buffer
msgp.Encode(&buf, &v1)
m := v1.Msgsize()
if buf.Len() > m {
t.Logf("WARNING: Msgsize() for %v is inaccurate", v1)
}
vn := Table{}
err := msgp.Decode(&buf, &vn)
if err != nil {
t.Error(err)
}
bn, _ := json.Marshal(vn)
t.Logf("recv table: %s", bn)
buf.Reset()
msgp.Encode(&buf, &v1)
err = msgp.NewReader(&buf).Skip()
if err != nil {
t.Error(err)
}
}