OLD | NEW |
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 Loading... |
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 var {{util.unionName(union, typepkg, package)}} = {{ |
| 82 mojom_type_macros.writeMojomType(typepkg, union, package, exported) }} |
| 83 |
80 {% endmacro %} | 84 {% endmacro %} |
81 | 85 |
82 {% macro encode_union_field(value, kind) %} | 86 {% macro encode_union_field(value, kind) %} |
83 {% if kind|is_union %} | 87 {% if kind|is_union %} |
84 if err := encoder.WritePointer(); err != nil { | 88 if err := encoder.WritePointer(); err != nil { |
85 return err | 89 return err |
86 } | 90 } |
87 | 91 |
88 encoder.StartNestedUnion() | 92 encoder.StartNestedUnion() |
89 {{encoding_macros.encode(value, kind)}} | 93 {{encoding_macros.encode(value, kind)}} |
(...skipping 21 matching lines...) Expand all Loading... |
111 return err | 115 return err |
112 } | 116 } |
113 | 117 |
114 {{encoding_macros.decode(value, kind)}} | 118 {{encoding_macros.decode(value, kind)}} |
115 | 119 |
116 decoder.Finish() | 120 decoder.Finish() |
117 {% else %} | 121 {% else %} |
118 {{encoding_macros.decode(value, kind)}} | 122 {{encoding_macros.decode(value, kind)}} |
119 {% endif %} | 123 {% endif %} |
120 {% endmacro %} | 124 {% endmacro %} |
OLD | NEW |