-
Notifications
You must be signed in to change notification settings - Fork 87
/
demo_schema_container.go
49 lines (41 loc) · 1.08 KB
/
demo_schema_container.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
// Code generated by github.com/actgardner/gogen-avro/v10. DO NOT EDIT.
/*
* SOURCE:
* example.avsc
*/
package avro
import (
"io"
"github.com/actgardner/gogen-avro/v10/compiler"
"github.com/actgardner/gogen-avro/v10/container"
"github.com/actgardner/gogen-avro/v10/vm"
)
func NewDemoSchemaWriter(writer io.Writer, codec container.Codec, recordsPerBlock int64) (*container.Writer, error) {
str := NewDemoSchema()
return container.NewWriter(writer, codec, recordsPerBlock, str.Schema())
}
// container reader
type DemoSchemaReader struct {
r io.Reader
p *vm.Program
}
func NewDemoSchemaReader(r io.Reader) (*DemoSchemaReader, error) {
containerReader, err := container.NewReader(r)
if err != nil {
return nil, err
}
t := NewDemoSchema()
deser, err := compiler.CompileSchemaBytes([]byte(containerReader.AvroContainerSchema()), []byte(t.Schema()))
if err != nil {
return nil, err
}
return &DemoSchemaReader{
r: containerReader,
p: deser,
}, nil
}
func (r DemoSchemaReader) Read() (DemoSchema, error) {
t := NewDemoSchema()
err := vm.Eval(r.r, r.p, &t)
return t, err
}