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

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

Issue 1345263002: Generate Mojom Types in Go (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 3 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 {% macro define(struct, exported=True) %} 9 {% macro define(struct, typepkg, package, exported=True) %}
8 type {{struct|name(exported)}} struct { 10 type {{struct|name(exported)}} struct {
9 {% for field in struct.fields %} 11 {% for field in struct.fields %}
10 {{field|name(exported)}} {{field.kind|go_type}} 12 {{field|name(exported)}} {{field.kind|go_type}}
11 {% endfor %} 13 {% endfor %}
12 } 14 }
13 15
14 func (s *{{struct|name(exported)}}) Encode(encoder *bindings.Encoder) error { 16 func (s *{{struct|name(exported)}}) Encode(encoder *bindings.Encoder) error {
15 {% set HEADER_SIZE = 8 %} 17 {% set HEADER_SIZE = 8 %}
16 encoder.StartStruct({{struct.versions[-1].num_bytes - HEADER_SIZE}}, {{s truct.versions[-1].version}}) 18 encoder.StartStruct({{struct.versions[-1].num_bytes - HEADER_SIZE}}, {{s truct.versions[-1].version}})
17 {% for byte in struct.bytes %} 19 {% for byte in struct.bytes %}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 {{encoding_macros.decode('s.'~packed_field.field|name(exported), packed_field.field.kind)|tab_indent(2)}} 58 {{encoding_macros.decode('s.'~packed_field.field|name(exported), packed_field.field.kind)|tab_indent(2)}}
57 } 59 }
58 {% endfor %} 60 {% endfor %}
59 {% endfor %} 61 {% endfor %}
60 if err := decoder.Finish(); err != nil { 62 if err := decoder.Finish(); err != nil {
61 return err 63 return err
62 } 64 }
63 return nil 65 return nil
64 } 66 }
65 67
68 var {{util.structName(struct, typepkg, package)}} = {{
mattr 2015/09/17 00:37:35 What if instead of declaring global exported varia
alexfandrianto 2015/10/09 17:43:55 I need some level of globalness and will only expo
69 mojom_type_macros.writeMojomType(typepkg, struct, package, exported) }}
70
66 {% endmacro %} 71 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698