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

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: Address Naming changes and Comment Updates Created 5 years, 1 month 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 {% macro define(struct, exported=True) %} 8 {% macro define(struct, typepkg, package, exported=True) %}
8 type {{struct|name(exported)}} struct { 9 type {{struct|name(exported)}} struct {
9 {% for field in struct.fields %} 10 {% for field in struct.fields %}
10 {{field|name(exported)}} {{field.kind|go_type}} 11 {{field|name(exported)}} {{field.kind|go_type}}
11 {% endfor %} 12 {% endfor %}
12 } 13 }
13 14
14 func (s *{{struct|name(exported)}}) Encode(encoder *bindings.Encoder) error { 15 func (s *{{struct|name(exported)}}) Encode(encoder *bindings.Encoder) error {
15 {% set HEADER_SIZE = 8 %} 16 {% set HEADER_SIZE = 8 %}
16 encoder.StartStruct({{struct.versions[-1].num_bytes - HEADER_SIZE}}, {{s truct.versions[-1].version}}) 17 encoder.StartStruct({{struct.versions[-1].num_bytes - HEADER_SIZE}}, {{s truct.versions[-1].version}})
17 {% for byte in struct.bytes %} 18 {% 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)}} 57 {{encoding_macros.decode('s.'~packed_field.field|name(exported), packed_field.field.kind)|tab_indent(2)}}
57 } 58 }
58 {% endfor %} 59 {% endfor %}
59 {% endfor %} 60 {% endfor %}
60 if err := decoder.Finish(); err != nil { 61 if err := decoder.Finish(); err != nil {
61 return err 62 return err
62 } 63 }
63 return nil 64 return nil
64 } 65 }
65 66
67 {{ mojom_type_macros.writeMojomTypeDef(typepkg, struct, package, exported) }}
68
66 {% endmacro %} 69 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698