| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package templates | 5 package templates |
| 6 | 6 |
| 7 const structEncodingTmplText = ` | 7 import ( |
| 8 {{- define "StructEncodingTmpl" -}} | 8 » "text/template" |
| 9 {{ $struct := . }} | 9 ) |
| 10 func (s *{{$struct.Name}}) Encode(encoder *bindings.Encoder) error { | |
| 11 » encoder.StartStruct({{$struct.CurVersionSize}}, {{$struct.CurVersionNumb
er}}) | |
| 12 » {{- range $field := $struct.Fields}} | |
| 13 » » {{ template "FieldEncodingTmpl" $field.EncodingInfo }} | |
| 14 » {{- end}} | |
| 15 | |
| 16 » if err := encoder.Finish(); err != nil { | |
| 17 » » return err | |
| 18 » } | |
| 19 » return nil | |
| 20 } | |
| 21 {{- end -}} | |
| 22 ` | |
| 23 | 10 |
| 24 const fieldEncodingTmplText = ` | 11 const fieldEncodingTmplText = ` |
| 25 {{- define "FieldEncodingTmpl" -}} | 12 {{- define "FieldEncodingTmpl" -}} |
| 26 {{- $info := . -}} | 13 {{- $info := . -}} |
| 27 {{- if $info.IsNullable -}} | 14 {{- if $info.IsNullable -}} |
| 28 if {{$info.Identifier}} == nil { | 15 if {{$info.Identifier}} == nil { |
| 29 {{- if $info.IsPointer -}} | 16 {{- if $info.IsPointer -}} |
| 30 encoder.WriteNullPointer() | 17 encoder.WriteNullPointer() |
| 31 {{- else if $info.IsHandle -}} | 18 {{- else if $info.IsHandle -}} |
| 32 encoder.WriteInvalidHandle() | 19 encoder.WriteInvalidHandle() |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 80 } |
| 94 {{ template "FieldEncodingTmpl" $keyInfo }} | 81 {{ template "FieldEncodingTmpl" $keyInfo }} |
| 95 {{ template "FieldEncodingTmpl" $valueInfo }} | 82 {{ template "FieldEncodingTmpl" $valueInfo }} |
| 96 } | 83 } |
| 97 if err := encoder.Finish(); err != nil { | 84 if err := encoder.Finish(); err != nil { |
| 98 return err | 85 return err |
| 99 } | 86 } |
| 100 {{- end -}} | 87 {{- end -}} |
| 101 {{- end -}} | 88 {{- end -}} |
| 102 ` | 89 ` |
| 90 |
| 91 func initEncodingTemplates() { |
| 92 template.Must(goFileTmpl.Parse(nonNullableFieldEncodingTmplText)) |
| 93 template.Must(goFileTmpl.Parse(fieldEncodingTmplText)) |
| 94 } |
| OLD | NEW |