Skip to content

Commit

Permalink
fix: cache schema globally (hamba#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma authored Aug 21, 2023
1 parent 0781a60 commit 4c8b624
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 68 deletions.
9 changes: 3 additions & 6 deletions cmd/avrogen/testdata/golden_encoders.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,22 @@ import (
)
{{ end }}
{{- range .Typedefs }}
// {{ .Name }} is a generated struct.
type {{ .Name }} struct {
{{- range .Fields }}
{{ .Name }} {{ .Type }} {{ .Tag }}
{{- end }}
{{- if $encoders }}
schema avro.Schema
{{- end }}
}
{{- if $encoders }}
var schema{{ .Name }} = avro.MustParse(` + "`{{ .Schema }}`" + `)
// Schema returns the schema for {{ .Name }}.
func (o *{{ .Name }}) Schema() avro.Schema {
if o.schema == nil {
o.schema = avro.MustParse(` + "`{{ .Schema }}`" + `)
}
return o.schema
return schema{{ .Name }}
}
// Unmarshal decodes b into the receiver.
Expand Down
81 changes: 27 additions & 54 deletions gen/testdata/golden_encoders.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4c8b624

Please sign in to comment.