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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
package example
// Code generated by go-bare/cmd/gen, DO NOT EDIT.
import (
"errors"
bare "git.sr.ht/~runxiyu/go-bareish"
)
type PublicKey [128]byte
func (t *PublicKey) Decode(data []byte) error {
return bare.Unmarshal(data, t)
}
func (t *PublicKey) Encode() ([]byte, error) {
return bare.Marshal(t)
}
type Customer struct {
Name string `bare:"name"`
Email string `bare:"email"`
Address Address `bare:"address"`
Orders []struct {
OrderId int64 `bare:"orderId"`
Quantity int32 `bare:"quantity"`
} `bare:"orders"`
Metadata map[string][]byte `bare:"metadata"`
}
func (t *Customer) Decode(data []byte) error {
return bare.Unmarshal(data, t)
}
func (t *Customer) Encode() ([]byte, error) {
return bare.Marshal(t)
}
type Employee struct {
Name string `bare:"name"`
Email string `bare:"email"`
Address Address `bare:"address"`
Department Department `bare:"department"`
HireDate Time `bare:"hireDate"`
PublicKey *PublicKey `bare:"publicKey"`
Metadata map[string][]byte `bare:"metadata"`
}
func (t *Employee) Decode(data []byte) error {
return bare.Unmarshal(data, t)
}
func (t *Employee) Encode() ([]byte, error) {
return bare.Marshal(t)
}
type TerminatedEmployee struct{}
func (t *TerminatedEmployee) Decode(data []byte) error {
return bare.Unmarshal(data, t)
}
func (t *TerminatedEmployee) Encode() ([]byte, error) {
return bare.Marshal(t)
}
type Address struct {
Address [4]string `bare:"address"`
City string `bare:"city"`
State string `bare:"state"`
Country string `bare:"country"`
}
func (t *Address) Decode(data []byte) error {
return bare.Unmarshal(data, t)
}
func (t *Address) Encode() ([]byte, error) {
return bare.Marshal(t)
}
type Department uint
const (
ACCOUNTING Department = 0
ADMINISTRATION Department = 1
CUSTOMER_SERVICE Department = 2
DEVELOPMENT Department = 3
JSMITH Department = 99
)
func (t Department) String() string {
switch t {
case ACCOUNTING:
return "ACCOUNTING"
case ADMINISTRATION:
return "ADMINISTRATION"
case CUSTOMER_SERVICE:
return "CUSTOMER_SERVICE"
case DEVELOPMENT:
return "DEVELOPMENT"
case JSMITH:
return "JSMITH"
}
panic(errors.New("Invalid Department value"))
}
type Person interface {
bare.Union
}
func (_ Customer) IsUnion() {}
func (_ Employee) IsUnion() {}
func (_ TerminatedEmployee) IsUnion() {}
func init() {
bare.RegisterUnion((*Person)(nil)).
Member(*new(Customer), 0).
Member(*new(Employee), 1).
Member(*new(TerminatedEmployee), 2)
}
|