| 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 %} |
| 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 Loading... |
| 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 Loading... |
| 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 %} |
| OLD | NEW |