forked from go-avro/avro
-
Notifications
You must be signed in to change notification settings - Fork 5
/
vars.go
156 lines (144 loc) · 3.8 KB
/
vars.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
151
152
153
154
155
156
package fuzzes
import avro "gopkg.in/avro.v0"
const ComplexSchemaRaw = `{
"type": "record",
"namespace": "example.avro",
"name": "Complex",
"fields": [
{
"name": "stringArray",
"type": {
"type": "array",
"items": "string"
}
},
{
"name": "longArray",
"type": {
"type": "array",
"items": "long"
}
},
{
"name": "enumField",
"type": {
"type": "enum",
"name": "foo",
"symbols": [
"A",
"B",
"C",
"D"
]
}
},
{
"name": "mapOfInts",
"type": {
"type": "map",
"values": "int"
}
},
{
"name": "unionField",
"type": [
"null",
"string",
"boolean"
]
},
{
"name": "fixedField",
"type": {
"type": "fixed",
"size": 16,
"name": "md5"
}
},
{
"name": "recordField",
"type": ["null", {
"type": "record",
"name": "TestRecord",
"fields": [
{
"name": "longRecordField",
"type": "long"
},
{
"name": "stringRecordField",
"type": "string"
},
{
"name": "intRecordField",
"type": "int"
},
{
"name": "floatRecordField",
"type": "float"
}
]
}]
},
{
"name":"mapOfRecord",
"type":{
"type": "map",
"values": "TestRecord"
}
}
]
}`
var ComplexSchema = avro.MustParseSchema(ComplexSchemaRaw)
var ComplexEnumSymbols = []string{"A", "B", "C", "D"}
func NewComplexEnumField() *avro.GenericEnum {
return avro.NewGenericEnum(ComplexEnumSymbols)
}
//complex
type Complex struct {
StringArray []string
LongArray []int64
EnumField *avro.GenericEnum
MapOfInts map[string]int32
UnionField interface{}
FixedField []byte
RecordField *TestRecord
MapOfRecord map[string]*TestRecord
}
type TestRecord struct {
LongRecordField int64
StringRecordField string
IntRecordField int32
FloatRecordField float32
}
const PrimitiveSchemaRaw = `{"type":"record","name":"Primitive","namespace":"example.avro","fields":[{"name":"booleanField","type":"boolean"},{"name":"intField","type":"int"},{"name":"longField","type":"long"},{"name":"floatField","type":"float"},{"name":"doubleField","type":"double"},{"name":"bytesField","type":"bytes"},{"name":"stringField","type":"string"},{"name":"nullField","type":"null"}]}`
type Primitive struct {
BooleanField bool
IntField int32
LongField int64
FloatField float32
DoubleField float64
BytesField []byte
StringField string
NullField interface{}
}
var CombinedSchemaRaw = `{
"type": "record",
"namespace": "example.avro",
"name": "CombinedEverything",
"fields": [
{
"name": "complex",
"type": ["null", ` + ComplexSchemaRaw + `]
},
{
"name": "primitive",
"type": ["null", ` + PrimitiveSchemaRaw + `]
}
]
}`
var CombinedSchema = avro.MustParseSchema(CombinedSchemaRaw)
type Combined struct {
Complex *Complex
Primitive *Primitive
}