-
Notifications
You must be signed in to change notification settings - Fork 644
/
union_null_recursive_union_test_record.go
149 lines (122 loc) · 4.8 KB
/
union_null_recursive_union_test_record.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
149
// Code generated by github.com/actgardner/gogen-avro/v10. DO NOT EDIT.
/*
* SOURCE:
* recursive.avsc
*/
package test
import (
"encoding/json"
"fmt"
"io"
"github.com/actgardner/gogen-avro/v10/compiler"
"github.com/actgardner/gogen-avro/v10/vm"
"github.com/actgardner/gogen-avro/v10/vm/types"
)
type UnionNullRecursiveUnionTestRecordTypeEnum int
const (
UnionNullRecursiveUnionTestRecordTypeEnumRecursiveUnionTestRecord UnionNullRecursiveUnionTestRecordTypeEnum = 1
)
type UnionNullRecursiveUnionTestRecord struct {
Null *types.NullVal
RecursiveUnionTestRecord RecursiveUnionTestRecord
UnionType UnionNullRecursiveUnionTestRecordTypeEnum
}
func writeUnionNullRecursiveUnionTestRecord(r *UnionNullRecursiveUnionTestRecord, w io.Writer) error {
if r == nil {
err := vm.WriteLong(0, w)
return err
}
err := vm.WriteLong(int64(r.UnionType), w)
if err != nil {
return err
}
switch r.UnionType {
case UnionNullRecursiveUnionTestRecordTypeEnumRecursiveUnionTestRecord:
return writeRecursiveUnionTestRecord(r.RecursiveUnionTestRecord, w)
}
return fmt.Errorf("invalid value for *UnionNullRecursiveUnionTestRecord")
}
func NewUnionNullRecursiveUnionTestRecord() *UnionNullRecursiveUnionTestRecord {
return &UnionNullRecursiveUnionTestRecord{}
}
func (r *UnionNullRecursiveUnionTestRecord) Serialize(w io.Writer) error {
return writeUnionNullRecursiveUnionTestRecord(r, w)
}
func DeserializeUnionNullRecursiveUnionTestRecord(r io.Reader) (*UnionNullRecursiveUnionTestRecord, error) {
t := NewUnionNullRecursiveUnionTestRecord()
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 DeserializeUnionNullRecursiveUnionTestRecordFromSchema(r io.Reader, schema string) (*UnionNullRecursiveUnionTestRecord, error) {
t := NewUnionNullRecursiveUnionTestRecord()
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 *UnionNullRecursiveUnionTestRecord) Schema() string {
return "[\"null\",{\"fields\":[{\"name\":\"RecursiveField\",\"type\":[\"null\",\"RecursiveUnionTestRecord\"]}],\"name\":\"RecursiveUnionTestRecord\",\"type\":\"record\"}]"
}
func (_ *UnionNullRecursiveUnionTestRecord) SetBoolean(v bool) { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) SetInt(v int32) { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) SetFloat(v float32) { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) SetDouble(v float64) { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) SetBytes(v []byte) { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) SetString(v string) { panic("Unsupported operation") }
func (r *UnionNullRecursiveUnionTestRecord) SetLong(v int64) {
r.UnionType = (UnionNullRecursiveUnionTestRecordTypeEnum)(v)
}
func (r *UnionNullRecursiveUnionTestRecord) Get(i int) types.Field {
switch i {
case 0:
return r.Null
case 1:
r.RecursiveUnionTestRecord = NewRecursiveUnionTestRecord()
return &types.Record{Target: (&r.RecursiveUnionTestRecord)}
}
panic("Unknown field index")
}
func (_ *UnionNullRecursiveUnionTestRecord) NullField(i int) { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) HintSize(i int) { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) SetDefault(i int) { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) AppendMap(key string) types.Field {
panic("Unsupported operation")
}
func (_ *UnionNullRecursiveUnionTestRecord) AppendArray() types.Field { panic("Unsupported operation") }
func (_ *UnionNullRecursiveUnionTestRecord) Finalize() {}
func (r *UnionNullRecursiveUnionTestRecord) MarshalJSON() ([]byte, error) {
if r == nil {
return []byte("null"), nil
}
switch r.UnionType {
case UnionNullRecursiveUnionTestRecordTypeEnumRecursiveUnionTestRecord:
return json.Marshal(map[string]interface{}{"RecursiveUnionTestRecord": r.RecursiveUnionTestRecord})
}
return nil, fmt.Errorf("invalid value for *UnionNullRecursiveUnionTestRecord")
}
func (r *UnionNullRecursiveUnionTestRecord) 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["RecursiveUnionTestRecord"]; ok {
r.UnionType = 1
return json.Unmarshal([]byte(value), &r.RecursiveUnionTestRecord)
}
return fmt.Errorf("invalid value for *UnionNullRecursiveUnionTestRecord")
}