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

Side by Side Diff: mojom/generators/go/templates/encoding.go

Issue 2082173002: New go generator shakedown. (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 unified diff | Download patch
OLDNEW
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 import ( 7 import (
8 "text/template" 8 "text/template"
9 ) 9 )
10 10
11 const fieldEncodingTmplText = ` 11 const fieldEncodingTmplText = `
12 {{- define "FieldEncodingTmpl" -}} 12 {{- define "FieldEncodingTmpl" -}}
13 {{- $info := . -}} 13 {{- $info := . -}}
14 {{- if and (not $info.IsUnion) $info.IsNullable -}} 14 {{- if and (not $info.IsUnion) $info.IsNullable -}}
15 if {{$info.Identifier}} == nil { 15 if {{$info.Identifier}} == nil {
16 {{- if $info.IsPointer -}} 16 {{- if $info.IsPointer -}}
17 encoder.WriteNullPointer() 17 encoder.WriteNullPointer()
18 {{- else if $info.IsHandle -}} 18 {{- else if or $info.IsInterfaceRequest $info.IsHandle -}}
19 encoder.WriteInvalidHandle() 19 encoder.WriteInvalidHandle()
20 {{- else if $info.IsInterface -}}
21 encoder.WriteInvalidInterface()
20 {{- end -}} 22 {{- end -}}
21 } else { 23 } else {
22 {{ template "NonNullableFieldEncodingTmpl" $info }} 24 {{ template "NonNullableFieldEncodingTmpl" $info }}
23 } 25 }
24 {{- else -}} 26 {{- else -}}
25 {{ template "NonNullableFieldEncodingTmpl" $info }} 27 {{ template "NonNullableFieldEncodingTmpl" $info }}
26 {{- end -}} 28 {{- end -}}
27 {{- end -}} 29 {{- end -}}
28 ` 30 `
29 31
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 {{- if $info.IsNullable -}} 65 {{- if $info.IsNullable -}}
64 encoder.WriteNullUnion() 66 encoder.WriteNullUnion()
65 {{- else -}} 67 {{- else -}}
66 return &bindings.ValidationError{bindings.UnexpectedNullUnion, "unexpect ed null union"} 68 return &bindings.ValidationError{bindings.UnexpectedNullUnion, "unexpect ed null union"}
67 {{- end -}} 69 {{- end -}}
68 } else { 70 } else {
69 if err := {{$info.Identifier}}.Encode(encoder); err != nil { 71 if err := {{$info.Identifier}}.Encode(encoder); err != nil {
70 return err 72 return err
71 } 73 }
72 } 74 }
75 {{- else if $info.IsInterface -}}
76 if err := encoder.{{$info.WriteFunction}}({{$info.Identifier}}.PassMessagePipe() ); err != nil {
77 return err
78 }
73 {{- else if $info.IsArray -}} 79 {{- else if $info.IsArray -}}
74 {{ $elInfo := $info.ElementEncodingInfo -}} 80 {{ $elInfo := $info.ElementEncodingInfo -}}
75 encoder.StartArray(uint32(len({{$info.Identifier}})), {{$elInfo.BitSize}}) 81 encoder.StartArray(uint32(len({{$info.Identifier}})), {{$elInfo.BitSize}})
76 for _, {{$elInfo.Identifier}} := range {{$info.Identifier}} { 82 for _, {{$elInfo.Identifier}} := range {{$info.Identifier}} {
77 {{ template "FieldEncodingTmpl" $elInfo }} 83 {{ template "FieldEncodingTmpl" $elInfo }}
78 } 84 }
79 if err := encoder.Finish(); err != nil { 85 if err := encoder.Finish(); err != nil {
80 return err 86 return err
81 } 87 }
82 {{- else if $info.IsMap -}} 88 {{- else if $info.IsMap -}}
(...skipping 21 matching lines...) Expand all
104 return err 110 return err
105 } 111 }
106 {{- end -}} 112 {{- end -}}
107 {{- end -}} 113 {{- end -}}
108 ` 114 `
109 115
110 func initEncodingTemplates() { 116 func initEncodingTemplates() {
111 template.Must(goFileTmpl.Parse(nonNullableFieldEncodingTmplText)) 117 template.Must(goFileTmpl.Parse(nonNullableFieldEncodingTmplText))
112 template.Must(goFileTmpl.Parse(fieldEncodingTmplText)) 118 template.Must(goFileTmpl.Parse(fieldEncodingTmplText))
113 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698