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

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

Issue 2061243002: Encode and decode fields of union type. (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 | « no previous file | mojom/generators/go/templates/decoding_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/generators/go/templates/decoding.go
diff --git a/mojom/generators/go/templates/decoding.go b/mojom/generators/go/templates/decoding.go
index ff9361a4ca740b5294e89af81e8d1d47c331267a..87d856e8ba4423c419c24d4cb0f5e6a8eddbeb11 100644
--- a/mojom/generators/go/templates/decoding.go
+++ b/mojom/generators/go/templates/decoding.go
@@ -17,9 +17,11 @@ if err != nil {
return err
}
if pointer == 0 {
-{{- if $info.IsNullable }}
+{{- if $info.IsNullable}}
{{$info.Identifier}} = nil
-{{- else }}
+{{- else if $info.IsUnion}}
+ return &bindings.ValidationError{bindings.UnexpectedNullPointer, "unexpected null union pointer"}
+{{- else}}
return &bindings.ValidationError{bindings.UnexpectedNullPointer, "unexpected null pointer"}
{{- end }}
} else {
@@ -63,6 +65,25 @@ if handle.IsValid() {
if err := {{$info.Identifier}}.Decode(decoder); err != nil {
return err
}
+{{- else if $info.IsUnion -}}
+{{- if $info.IsPointer -}}
+if err := decoder.StartNestedUnion(); err != nil {
+ return err
+}
+{{end -}}
+var err error
+{{$info.Identifier}}, err = Decode{{$info.GoType}}(decoder)
+if err != nil {
+ return err
+}
+{{- if not $info.IsNullable}}
+if {{$info.Identifier}} == nil {
+ return &bindings.ValidationError{bindings.UnexpectedNullUnion, "unexpected null union"}
+}
+{{- end -}}
+{{- if $info.IsPointer}}
+decoder.Finish()
+{{- end -}}
{{- else if $info.IsArray -}}
{{ $elInfo := $info.ElementEncodingInfo -}}
len0, err := decoder.StartArray({{$elInfo.BitSize}})
« no previous file with comments | « no previous file | mojom/generators/go/templates/decoding_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698