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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/go_templates/struct.tmpl
diff --git a/mojo/public/tools/bindings/generators/go_templates/struct.tmpl b/mojo/public/tools/bindings/generators/go_templates/struct.tmpl
deleted file mode 100644
index 3b0ddf57d9f96c6ff37209966437a8264b01a54f..0000000000000000000000000000000000000000
--- a/mojo/public/tools/bindings/generators/go_templates/struct.tmpl
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-{% import "encoding_macros.tmpl" as encoding_macros %}
-{% import "runtime_type_macros.tmpl" as runtime_type_macros %}
-
-{% macro define(struct, typepkg, package, exported=True) %}
-type {{struct|name(exported)}} struct {
-{% for field in struct.fields %}
- {{field|name(exported)}} {{field.kind|go_type}}
-{% endfor %}
-}
-
-{%- set type_name = struct|name(exported) %}
-{{runtime_type_macros.maybeWriteStaticMojomTypeAccessor(typepkg, struct)}}
-{{runtime_type_macros.maybeWriteMojomTypeAccessor(typepkg, struct, type_name)}}
-
-func (s *{{struct|name(exported)}}) Encode(encoder *bindings.Encoder) error {
-{% set HEADER_SIZE = 8 %}
- encoder.StartStruct({{struct.versions[-1].num_bytes - HEADER_SIZE}}, {{struct.versions[-1].version}})
-{% for byte in struct.bytes %}
-{% for packed_field in byte.packed_fields %}
- {{encoding_macros.encode('s.'~packed_field.field|name(exported), packed_field.field.kind)|tab_indent()}}
-{% endfor %}
-{% endfor %}
- if err := encoder.Finish(); err != nil {
- return err
- }
- return nil
-}
-
-var {{struct|name(False)}}_Versions []bindings.DataHeader = []bindings.DataHeader{
-{% for versionInfo in struct.versions %}
- bindings.DataHeader{{'{'}}{{versionInfo.num_bytes}}, {{versionInfo.version}}{{'}'}},
-{% endfor %}
-}
-
-func (s *{{struct|name(exported)}}) Decode(decoder *bindings.Decoder) error {
- header, err := decoder.StartStruct()
- if err != nil {
- return err
- }
- index := sort.Search(len({{struct|name(False)}}_Versions), func(i int) bool {
- return {{struct|name(False)}}_Versions[i].ElementsOrVersion >= header.ElementsOrVersion
- })
- if index < len({{struct|name(False)}}_Versions) {
- if {{struct|name(False)}}_Versions[index].ElementsOrVersion > header.ElementsOrVersion {
- index--
- }
- expectedSize := {{struct|name(False)}}_Versions[index].Size
- if expectedSize != header.Size {
- return &bindings.ValidationError{bindings.UnexpectedStructHeader,
- fmt.Sprintf("invalid struct header size: should be %d, but was %d", expectedSize, header.Size),
- }
- }
- }
-{% for byte in struct.bytes %}
-{% for packed_field in byte.packed_fields %}
- if header.ElementsOrVersion >= {{packed_field.min_version}} {
- {{encoding_macros.decode('s.'~packed_field.field|name(exported), packed_field.field.kind)|tab_indent(2)}}
- }
-{% endfor %}
-{% endfor %}
- if err := decoder.Finish(); err != nil {
- return err
- }
- return nil
-}
-
-{% endmacro %}

Powered by Google App Engine
This is Rietveld 408576698