This repository was archived by the owner on Jan 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathtypes_test.go
More file actions
91 lines (69 loc) · 1.37 KB
/
types_test.go
File metadata and controls
91 lines (69 loc) · 1.37 KB
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
package avro_test
import "errors"
type TestInterface interface {
SomeFunc() int
}
type TestRecord struct {
A int64 `avro:"a"`
B string `avro:"b"`
}
func (*TestRecord) SomeFunc() int {
return 0
}
type UnionRecordParent struct {
UnionRecord *UnionRecord `avro:"union"`
}
type UnionRecord struct {
Int *int
Test *TestRecord
}
func (u *UnionRecord) ToAny() (any, error) {
if u.Int != nil {
return u.Int, nil
} else if u.Test != nil {
return u.Test, nil
}
return nil, errors.New("no value to encode")
}
func (u *UnionRecord) FromAny(payload any) error {
switch t := payload.(type) {
case int:
u.Int = &t
case TestRecord:
u.Test = &t
default:
return errors.New("unknown type during decode of union")
}
return nil
}
type TestPartialRecord struct {
B string `avro:"b"`
}
type TestNestedRecord struct {
A TestRecord `avro:"a"`
B TestRecord `avro:"b"`
}
type TestUnion struct {
A any `avro:"a"`
}
type TestEmbeddedRecord struct {
C string `avro:"c"`
TestEmbed // tests not-first position
}
type TestEmbeddedPtrRecord struct {
C string `avro:"c"`
*TestEmbed // tests not-first position
}
type TestEmbed struct {
A int64 `avro:"a"`
B string `avro:"b"`
}
type TestEmbedInt int
type TestEmbeddedIntRecord struct {
B string `avro:"b"`
TestEmbedInt // tests not-first position
}
type TestUnexportedRecord struct {
A int64 `avro:"a"`
b string `avro:"b"`
}