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

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: Use unexported functions instead of variables 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 %}
7 {% import "mojom_util_macros.tmpl" as util %}
6 8
7 9 {% macro define(union, typepkg, package, exported=True) %}
8 {% macro define(union, exported=True) %}
9 type {{union|name(exported)}} interface { 10 type {{union|name(exported)}} interface {
10 Tag() uint32 11 Tag() uint32
11 Interface() interface{} 12 Interface() interface{}
12 __Reflect(__{{union|name(exported)}}Reflect) 13 __Reflect(__{{union|name(exported)}}Reflect)
13 Encode(encoder *bindings.Encoder) error 14 Encode(encoder *bindings.Encoder) error
14 } 15 }
15 16
16 type __{{union|name(exported)}}Reflect struct { 17 type __{{union|name(exported)}}Reflect struct {
17 {% for field in union.fields %} 18 {% for field in union.fields %}
18 {{field|name(exported)}} {{field.kind|go_type}} 19 {{field|name(exported)}} {{field.kind|go_type}}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 return nil 71 return nil
71 } 72 }
72 73
73 func (u *{{struct_name}}) decodeInternal(decoder *bindings.Decoder) error { 74 func (u *{{struct_name}}) decodeInternal(decoder *bindings.Decoder) error {
74 {{decode_union_field('u.Value', field.kind)|tab_indent()}} 75 {{decode_union_field('u.Value', field.kind)|tab_indent()}}
75 return nil 76 return nil
76 } 77 }
77 78
78 {% endfor %} 79 {% endfor %}
79 80
81 // String names and labels used by the MojomUnion types.
82 var (
83 unionName_{{union|name}} = "{{union|name}}"
84 {% for field in union.fields %}
85 unionFieldName_{{union|name}}_{{field|name}} = "{{field|name}}"
86 {% endfor %}
87 )
88
89 func {{util.typeName(union, typepkg, package)}}() {{typepkg}}MojomUnion {
90 return {{ mojom_type_macros.writeMojomType(typepkg, union, package, expo rted) }}
91 }
92
80 {% endmacro %} 93 {% endmacro %}
81 94
82 {% macro encode_union_field(value, kind) %} 95 {% macro encode_union_field(value, kind) %}
83 {% if kind|is_union %} 96 {% if kind|is_union %}
84 if err := encoder.WritePointer(); err != nil { 97 if err := encoder.WritePointer(); err != nil {
85 return err 98 return err
86 } 99 }
87 100
88 encoder.StartNestedUnion() 101 encoder.StartNestedUnion()
89 {{encoding_macros.encode(value, kind)}} 102 {{encoding_macros.encode(value, kind)}}
(...skipping 21 matching lines...) Expand all
111 return err 124 return err
112 } 125 }
113 126
114 {{encoding_macros.decode(value, kind)}} 127 {{encoding_macros.decode(value, kind)}}
115 128
116 decoder.Finish() 129 decoder.Finish()
117 {% else %} 130 {% else %}
118 {{encoding_macros.decode(value, kind)}} 131 {{encoding_macros.decode(value, kind)}}
119 {% endif %} 132 {% endif %}
120 {% endmacro %} 133 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698