-
Notifications
You must be signed in to change notification settings - Fork 12
/
rw3.go.txt
104 lines (85 loc) · 1.62 KB
/
rw3.go.txt
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
package main
import (
"fmt"
"os"
"reflect"
"bytes"
"github.com/glycerine/go-goon"
)
// used in rw3_test.go for round-trip testing write/read
// demonstrate anonymous (embedded) structs,
// as well as pointers to structs and
// also just nested structs.
type Anon struct {
SerialNum int
}
type Dude struct {
Anon
Name string
Age int
Addr *Address
Fro Hair
Allprim AllPrim
}
type Address struct {
Street string
Zip string
}
type Hair struct {
Desc string
}
type AllPrim struct {
S string
I int
B bool
I8 int8
I16 int16
I32 int32
I64 int64
Ui8 uint8
Ui16 uint16
Ui32 uint32
Ui64 uint64
F32 float32
F64 float64
By byte
}
func main() {
rw := Dude{
Name: "Hank",
Age: 33,
Addr: &Address{Street: "123 Main Street", Zip: "11111"},
Anon: Anon{SerialNum: 52},
Fro: Hair{ Desc: "awesome"},
Allprim: AllPrim{
S: "mystring",
I: 43,
B: true,
I8: -7,
I16: -16,
I32: -32,
I64: -64,
Ui8: 9,
Ui16: 17,
Ui32: 33,
Ui64: 65,
F32: 2.7,
F64: 3.14,
By: 'a',
},
}
var o bytes.Buffer
rw.Save(&o)
rw2 := &Dude{}
rw2.Load(&o)
if !reflect.DeepEqual(&rw, rw2) {
fmt.Printf("rw and rw2 were not equal!\n")
fmt.Printf("\n\n ============= rw: ====\n")
goon.Dump(rw)
fmt.Printf("\n\n ============= rw2: ====\n")
goon.Dump(rw2)
fmt.Printf("\n\n ================\n")
os.Exit(1)
}
fmt.Printf("Load() data matched Saved() data.\n")
}