| Index: mojom/generators/go/templates/decoding.go
|
| diff --git a/mojom/generators/go/templates/decoding.go b/mojom/generators/go/templates/decoding.go
|
| index 7033bbf7a7e94ba9abd8f493ce26c39c00f77bfb..ff9361a4ca740b5294e89af81e8d1d47c331267a 100644
|
| --- a/mojom/generators/go/templates/decoding.go
|
| +++ b/mojom/generators/go/templates/decoding.go
|
| @@ -4,49 +4,9 @@
|
|
|
| package templates
|
|
|
| -const structVersions = `
|
| -{{- define "StructVersions" -}}
|
| -{{- $struct := . -}}
|
| -var {{$struct.PrivateName}}_Versions []bindings.DataHeader = []bindings.DataHeader{
|
| - {{- range $version := $struct.Versions}}
|
| - bindings.DataHeader{ {{$version.NumBytes}}, {{$version.Version}} },
|
| - {{- end}}
|
| -}
|
| -{{- end -}}
|
| -`
|
| -
|
| -const structDecodingTmplText = `
|
| -{{- define "StructDecodingTmpl" -}}
|
| -{{- $struct := . -}}
|
| -func (s *{{$struct.Name}}) Decode(decoder *bindings.Decoder) error {
|
| - header, err := decoder.StartStruct()
|
| - if err != nil {
|
| - return err
|
| - }
|
| -
|
| - index := sort.Search(len({{$struct.PrivateName}}_Versions), func(i int) bool {
|
| - return {{$struct.PrivateName}}_Versions[i].ElementsOrVersion >= header.ElementsOrVersion
|
| - })
|
| - if index < len({{$struct.PrivateName}}_Versions) {
|
| - if {{$struct.PrivateName}}_Versions[index].ElementsOrVersion > header.ElementsOrVersion {
|
| - index--
|
| - }
|
| - expectedSize := {{$struct.PrivateName}}_Versions[index].Size
|
| - if expectedSize != header.Size {
|
| - return &bindings.ValidationError{bindings.UnexpectedStructHeader,
|
| - fmt.Sprintf("invalid struct header size: should be %d, but was %d", expectedSize, header.Size),
|
| - }
|
| - }
|
| - }
|
| -
|
| - {{- range $field := $struct.Fields}}
|
| - if header.ElementsOrVersion >= {{$field.MinVersion}} {
|
| - {{ template "FieldDecodingTmpl" $field.EncodingInfo }}
|
| - }
|
| - {{- end}}
|
| -}
|
| -{{- end -}}
|
| -`
|
| +import (
|
| + "text/template"
|
| +)
|
|
|
| const fieldDecodingTmplText = `
|
| {{- define "FieldDecodingTmpl" -}}
|
| @@ -148,3 +108,8 @@ for i := 0; i < len({{$keyInfo.Identifier}}); i++ {
|
| {{- end -}}
|
| {{- end -}}
|
| `
|
| +
|
| +func initDecodingTemplates() {
|
| + template.Must(goFileTmpl.Parse(nonNullableFieldDecodingTmplText))
|
| + template.Must(goFileTmpl.Parse(fieldDecodingTmplText))
|
| +}
|
|
|