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

Side by Side Diff: mojo/public/tools/bindings/generators/go_templates/union.tmpl

Issue 1345263002: Generate Mojom Types in Go (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Update Comments and Enum Template+Tests Created 5 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 {% import "encoding_macros.tmpl" as encoding_macros %} 5 {% import "encoding_macros.tmpl" as encoding_macros %}
6 {% import "mojom_type_macros.tmpl" as mojom_type_macros %}
6 7
7 8 {% macro define(union, typepkg, package, exported=True) %}
8 {% macro define(union, exported=True) %}
9 type {{union|name(exported)}} interface { 9 type {{union|name(exported)}} interface {
10 Tag() uint32 10 Tag() uint32
11 Interface() interface{} 11 Interface() interface{}
12 __Reflect(__{{union|name(exported)}}Reflect) 12 __Reflect(__{{union|name(exported)}}Reflect)
13 Encode(encoder *bindings.Encoder) error 13 Encode(encoder *bindings.Encoder) error
14 } 14 }
15 15
16 type __{{union|name(exported)}}Reflect struct { 16 type __{{union|name(exported)}}Reflect struct {
17 {% for field in union.fields %} 17 {% for field in union.fields %}
18 {{field|name(exported)}} {{field.kind|go_type}} 18 {{field|name(exported)}} {{field.kind|go_type}}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 return nil 70 return nil
71 } 71 }
72 72
73 func (u *{{struct_name}}) decodeInternal(decoder *bindings.Decoder) error { 73 func (u *{{struct_name}}) decodeInternal(decoder *bindings.Decoder) error {
74 {{decode_union_field('u.Value', field.kind)|tab_indent()}} 74 {{decode_union_field('u.Value', field.kind)|tab_indent()}}
75 return nil 75 return nil
76 } 76 }
77 77
78 {% endfor %} 78 {% endfor %}
79 79
80 {{ mojom_type_macros.writeMojomTypeDef(typepkg, union, package, exported) }}
81
80 {% endmacro %} 82 {% endmacro %}
81 83
82 {% macro encode_union_field(value, kind) %} 84 {% macro encode_union_field(value, kind) %}
83 {% if kind|is_union %} 85 {% if kind|is_union %}
84 if err := encoder.WritePointer(); err != nil { 86 if err := encoder.WritePointer(); err != nil {
85 return err 87 return err
86 } 88 }
87 89
88 encoder.StartNestedUnion() 90 encoder.StartNestedUnion()
89 {{encoding_macros.encode(value, kind)}} 91 {{encoding_macros.encode(value, kind)}}
(...skipping 21 matching lines...) Expand all
111 return err 113 return err
112 } 114 }
113 115
114 {{encoding_macros.decode(value, kind)}} 116 {{encoding_macros.decode(value, kind)}}
115 117
116 decoder.Finish() 118 decoder.Finish()
117 {% else %} 119 {% else %}
118 {{encoding_macros.decode(value, kind)}} 120 {{encoding_macros.decode(value, kind)}}
119 {% endif %} 121 {% endif %}
120 {% endmacro %} 122 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698