forked from confluentinc/confluent-kafka-go
/
recursive_union_test_record.go
150 lines (124 loc) · 4.25 KB
/
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
150
// 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"
)
var _ = fmt.Printf
type RecursiveUnionTestRecord struct {
RecursiveField *UnionNullRecursiveUnionTestRecord `json:"RecursiveField"`
}
const RecursiveUnionTestRecordAvroCRC64Fingerprint = "\xc6U)C\v\x8a\xa6\x89"
func NewRecursiveUnionTestRecord() RecursiveUnionTestRecord {
r := RecursiveUnionTestRecord{}
return r
}
func DeserializeRecursiveUnionTestRecord(r io.Reader) (RecursiveUnionTestRecord, error) {
t := NewRecursiveUnionTestRecord()
deser, err := compiler.CompileSchemaBytes([]byte(t.Schema()), []byte(t.Schema()))
if err != nil {
return t, err
}
err = vm.Eval(r, deser, &t)
return t, err
}
func DeserializeRecursiveUnionTestRecordFromSchema(r io.Reader, schema string) (RecursiveUnionTestRecord, error) {
t := NewRecursiveUnionTestRecord()
deser, err := compiler.CompileSchemaBytes([]byte(schema), []byte(t.Schema()))
if err != nil {
return t, err
}
err = vm.Eval(r, deser, &t)
return t, err
}
func writeRecursiveUnionTestRecord(r RecursiveUnionTestRecord, w io.Writer) error {
var err error
err = writeUnionNullRecursiveUnionTestRecord(r.RecursiveField, w)
if err != nil {
return err
}
return err
}
func (r RecursiveUnionTestRecord) Serialize(w io.Writer) error {
return writeRecursiveUnionTestRecord(r, w)
}
func (r RecursiveUnionTestRecord) Schema() string {
return "{\"fields\":[{\"name\":\"RecursiveField\",\"type\":[\"null\",\"RecursiveUnionTestRecord\"]}],\"name\":\"RecursiveUnionTestRecord\",\"type\":\"record\"}"
}
func (r RecursiveUnionTestRecord) SchemaName() string {
return "RecursiveUnionTestRecord"
}
func (_ RecursiveUnionTestRecord) SetBoolean(v bool) { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) SetInt(v int32) { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) SetLong(v int64) { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) SetFloat(v float32) { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) SetDouble(v float64) { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) SetBytes(v []byte) { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) SetString(v string) { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) SetUnionElem(v int64) { panic("Unsupported operation") }
func (r *RecursiveUnionTestRecord) Get(i int) types.Field {
switch i {
case 0:
r.RecursiveField = NewUnionNullRecursiveUnionTestRecord()
return r.RecursiveField
}
panic("Unknown field index")
}
func (r *RecursiveUnionTestRecord) SetDefault(i int) {
switch i {
}
panic("Unknown field index")
}
func (r *RecursiveUnionTestRecord) NullField(i int) {
switch i {
case 0:
r.RecursiveField = nil
return
}
panic("Not a nullable field index")
}
func (_ RecursiveUnionTestRecord) AppendMap(key string) types.Field { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) AppendArray() types.Field { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) HintSize(int) { panic("Unsupported operation") }
func (_ RecursiveUnionTestRecord) Finalize() {}
func (_ RecursiveUnionTestRecord) AvroCRC64Fingerprint() []byte {
return []byte(RecursiveUnionTestRecordAvroCRC64Fingerprint)
}
func (r RecursiveUnionTestRecord) MarshalJSON() ([]byte, error) {
var err error
output := make(map[string]json.RawMessage)
output["RecursiveField"], err = json.Marshal(r.RecursiveField)
if err != nil {
return nil, err
}
return json.Marshal(output)
}
func (r *RecursiveUnionTestRecord) UnmarshalJSON(data []byte) error {
var fields map[string]json.RawMessage
if err := json.Unmarshal(data, &fields); err != nil {
return err
}
var val json.RawMessage
val = func() json.RawMessage {
if v, ok := fields["RecursiveField"]; ok {
return v
}
return nil
}()
if val != nil {
if err := json.Unmarshal([]byte(val), &r.RecursiveField); err != nil {
return err
}
} else {
return fmt.Errorf("no value specified for RecursiveField")
}
return nil
}