github.com/hamba/avro/v2@v2.22.1-0.20240518180522-aff3955acf7d/gen/output_template.tmpl (about)

     1  package {{ .PackageName }}
     2  
     3  // Code generated by avro/gen. DO NOT EDIT.
     4  
     5  {{- $encoders := .WithEncoders }}
     6  {{ if len .Imports }}
     7  	import (
     8  	{{- range .Imports }}
     9  		"{{ . }}"
    10  	{{- end }}
    11  	)
    12  {{ end }}
    13  
    14  {{- range .Typedefs }}
    15  	// {{ .Name }} is a generated struct.
    16  	type {{ .Name }} struct {
    17  	{{- range .Fields }}
    18  		{{- $f := . }}
    19  		{{ .Name }} {{ .Type }} `avro:"{{ $f.AvroFieldName }}"
    20  		{{- range $tag, $style := .Tags }}
    21  			{{- " "}}{{ $tag }}:"
    22  			{{- if eq $style "kebab" }}{{ kebab $f.AvroFieldName }}
    23  			{{- else if eq $style "upper-camel"}}{{ upperCamel $f.AvroFieldName }}
    24  			{{- else if eq $style "camel"}}{{ camel $f.AvroFieldName }}
    25  			{{- else if eq $style "snake"}}{{ snake $f.AvroFieldName }}
    26  			{{- else}}{{ $f.AvroFieldName }}
    27  			{{- end}}"
    28  		{{- end }}`
    29  	{{- end }}
    30  	}
    31  
    32  	{{- if $encoders }}
    33  		var schema{{ .Name }} = avro.MustParse(`{{ .Schema }}`)
    34  
    35  		// Schema returns the schema for {{ .Name }}.
    36  		func (o *{{ .Name }}) Schema() avro.Schema {
    37  		return schema{{ .Name }}
    38  		}
    39  
    40  		// Unmarshal decodes b into the receiver.
    41  		func (o *{{ .Name }}) Unmarshal(b []byte) error {
    42  		return avro.Unmarshal(o.Schema(), b, o)
    43  		}
    44  
    45  		// Marshal encodes the receiver.
    46  		func (o *{{ .Name }}) Marshal() ([]byte, error) {
    47  		return avro.Marshal(o.Schema(), o)
    48  		}
    49  	{{- end }}
    50  {{ end }}