forked from actgardner/gogen-avro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
union_ip_address_event.go
148 lines (122 loc) · 4.58 KB
/
union_ip_address_event.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Code generated by Skaidus. DO NOT EDIT.
/*
* SOURCE:
* schema.avsc
*/
package avro
import (
"encoding/json"
"fmt"
"io"
"github.com/Skaidus/gogen-avro/v10/compiler"
"github.com/Skaidus/gogen-avro/v10/vm"
"github.com/Skaidus/gogen-avro/v10/vm/types"
)
type UnionIp_addressEventTypeEnum int
const (
UnionIp_addressEventTypeEnumIp_address UnionIp_addressEventTypeEnum = 0
UnionIp_addressEventTypeEnumEvent UnionIp_addressEventTypeEnum = 1
)
type UnionIp_addressEvent struct {
Ip_address Ip_address
Event Event
UnionType UnionIp_addressEventTypeEnum
}
func writeUnionIp_addressEvent(r UnionIp_addressEvent, w io.Writer) error {
err := vm.WriteLong(int64(r.UnionType), w)
if err != nil {
return err
}
switch r.UnionType {
case UnionIp_addressEventTypeEnumIp_address:
return writeIp_address(r.Ip_address, w)
case UnionIp_addressEventTypeEnumEvent:
return writeEvent(r.Event, w)
}
return fmt.Errorf("invalid value for UnionIp_addressEvent")
}
func NewUnionIp_addressEvent() UnionIp_addressEvent {
return UnionIp_addressEvent{}
}
func (r UnionIp_addressEvent) Serialize(w io.Writer) error {
return writeUnionIp_addressEvent(r, w)
}
func DeserializeUnionIp_addressEvent(r io.Reader) (UnionIp_addressEvent, error) {
t := NewUnionIp_addressEvent()
deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema()))
if err != nil {
return t, err
}
err = vm.Eval(r, deser, &t)
if err != nil {
return t, err
}
return t, err
}
func DeserializeUnionIp_addressEventFromSchema(r io.Reader, schema string) (UnionIp_addressEvent, error) {
t := NewUnionIp_addressEvent()
deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema()))
if err != nil {
return t, err
}
err = vm.Eval(r, deser, &t)
if err != nil {
return t, err
}
return t, err
}
func (r UnionIp_addressEvent) Schema() string {
return "[{\"name\":\"ip_address\",\"size\":16,\"type\":\"fixed\"},{\"doc\":\"The test record\",\"fields\":[{\"doc\":\"Unique ID for this event.\",\"name\":\"id\",\"type\":\"string\"},{\"doc\":\"Start IP of this observation's IP range.\",\"name\":\"start_ip\",\"type\":\"ip_address\"},{\"doc\":\"End IP of this observation's IP range.\",\"name\":\"end_ip\",\"type\":\"ip_address\"}],\"name\":\"event\",\"subject\":\"event\",\"type\":\"record\"}]"
}
func (_ UnionIp_addressEvent) SetBoolean(v bool) { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) SetInt(v int32) { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) SetFloat(v float32) { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) SetDouble(v float64) { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) SetBytes(v []byte) { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) SetString(v string) { panic("Unsupported operation") }
func (r *UnionIp_addressEvent) SetLong(v int64) {
r.UnionType = (UnionIp_addressEventTypeEnum)(v)
}
func (r *UnionIp_addressEvent) Get(i int) types.Field {
switch i {
case 0:
return &Ip_addressWrapper{Target: (&r.Ip_address)}
case 1:
r.Event = NewEvent()
return &types.Record{Target: (&r.Event)}
}
panic("Unknown field index")
}
func (_ UnionIp_addressEvent) NullField(i int) { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) HintSize(i int) { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) SetDefault(i int) { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) AppendMap(key string) types.Field { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) AppendArray() types.Field { panic("Unsupported operation") }
func (_ UnionIp_addressEvent) Finalize() {}
func (r UnionIp_addressEvent) MarshalJSON() ([]byte, error) {
switch r.UnionType {
case UnionIp_addressEventTypeEnumIp_address:
return json.Marshal(map[string]interface{}{"ip_address": r.Ip_address})
case UnionIp_addressEventTypeEnumEvent:
return json.Marshal(map[string]interface{}{"event": r.Event})
}
return nil, fmt.Errorf("invalid value for UnionIp_addressEvent")
}
func (r *UnionIp_addressEvent) UnmarshalJSON(data []byte) error {
var fields map[string]json.RawMessage
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
if len(fields) > 1 {
return fmt.Errorf("more than one type supplied for union")
}
if value, ok := fields["ip_address"]; ok {
r.UnionType = 0
return json.Unmarshal([]byte(value), &r.Ip_address)
}
if value, ok := fields["event"]; ok {
r.UnionType = 1
return json.Unmarshal([]byte(value), &r.Event)
}
return fmt.Errorf("invalid value for UnionIp_addressEvent")
}