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

Unified Diff: mojom/generators/go/templates/decoding.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 side-by-side diff with in-line comments
Download patch
Index: mojom/generators/go/templates/decoding.go
diff --git a/mojom/generators/go/templates/decoding.go b/mojom/generators/go/templates/decoding.go
index 3f54c2ee20de52d0f3502709855465b2813289b5..b2d5ebfe3245f2241c5c775f514fffb9c5ba4eb9 100644
--- a/mojom/generators/go/templates/decoding.go
+++ b/mojom/generators/go/templates/decoding.go
@@ -8,6 +8,15 @@ import (
"text/template"
)
+const ampersandIfNullable = `
+{{- define "AmpersandIfNullable" -}}
vardhan 2016/06/22 15:17:15 haha
+{{- $info := . -}}
+{{- if $info.IsNullable -}}
+&
+{{- end -}}
+{{- end -}}
+`
+
const fieldDecodingTmplText = `
{{- define "FieldDecodingTmpl" -}}
{{- $info := . -}}
@@ -88,6 +97,25 @@ if {{$info.Identifier}} == nil {
{{- if $info.IsPointer}}
decoder.Finish()
{{- end -}}
+{{- else if $info.IsInterface -}}
+handle, err := decoder.{{$info.ReadFunction}}()
+if err != nil {
+ return err
+}
+if handle.IsValid() {
+ handleOwner := bindings.NewMessagePipeHandleOwner(handle)
+{{- if $info.IsInterfaceRequest}}
+ {{$info.Identifier}} = {{template "AmpersandIfNullable" $info}}{{$info.GoType}}_Request{handleOwner}
+{{- else}}
+ {{$info.Identifier}} = {{template "AmpersandIfNullable" $info}}{{$info.GoType}}_Pointer{handleOwner}
+{{- end -}}
+} else {
+{{- if $info.IsNullable}}
+ {{$info.Identifier}} = nil
+{{- else}}
+ return &bindings.ValidationError{bindings.UnexpectedInvalidHandle, "unexpected invalid handle"}
+{{- end -}}
+}
{{- else if $info.IsArray -}}
{{ $elInfo := $info.ElementEncodingInfo -}}
len0, err := decoder.StartArray({{$elInfo.BitSize}})
@@ -137,4 +165,5 @@ for i := 0; i < len({{$keyInfo.Identifier}}); i++ {
func initDecodingTemplates() {
template.Must(goFileTmpl.Parse(nonNullableFieldDecodingTmplText))
template.Must(goFileTmpl.Parse(fieldDecodingTmplText))
+ template.Must(goFileTmpl.Parse(ampersandIfNullable))
}
« no previous file with comments | « mojo/public/tools/bindings/mojom_tool/bin/mac64/generators/go.sha1 ('k') | mojom/generators/go/templates/decoding_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698