Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1700)

Unified Diff: mojom/generators/go/templates/encoding.go

Issue 2045063002: [New go generator] Implement declaring unions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/generators/go/templates/decoding_test.go ('k') | mojom/generators/go/templates/encoding_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/generators/go/templates/encoding.go
diff --git a/mojom/generators/go/templates/encoding.go b/mojom/generators/go/templates/encoding.go
index d3cb2a611e6a8d2b526bdb8fe1ad46bce186b50c..56c6235cd8573c8705f623c4aa2c134132d4a945 100644
--- a/mojom/generators/go/templates/encoding.go
+++ b/mojom/generators/go/templates/encoding.go
@@ -4,22 +4,9 @@
package templates
-const structEncodingTmplText = `
-{{- define "StructEncodingTmpl" -}}
-{{ $struct := . }}
-func (s *{{$struct.Name}}) Encode(encoder *bindings.Encoder) error {
- encoder.StartStruct({{$struct.CurVersionSize}}, {{$struct.CurVersionNumber}})
- {{- range $field := $struct.Fields}}
- {{ template "FieldEncodingTmpl" $field.EncodingInfo }}
- {{- end}}
-
- if err := encoder.Finish(); err != nil {
- return err
- }
- return nil
-}
-{{- end -}}
-`
+import (
+ "text/template"
+)
const fieldEncodingTmplText = `
{{- define "FieldEncodingTmpl" -}}
@@ -100,3 +87,8 @@ if err := encoder.Finish(); err != nil {
{{- end -}}
{{- end -}}
`
+
+func initEncodingTemplates() {
+ template.Must(goFileTmpl.Parse(nonNullableFieldEncodingTmplText))
+ template.Must(goFileTmpl.Parse(fieldEncodingTmplText))
+}
« no previous file with comments | « mojom/generators/go/templates/decoding_test.go ('k') | mojom/generators/go/templates/encoding_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698