| Index: third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/union.tmpl
|
| diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/union.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/union.tmpl
|
| deleted file mode 100644
|
| index a7c47eee2d7c7889fbba31c56953f3bd53b4ef8d..0000000000000000000000000000000000000000
|
| --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/go_templates/union.tmpl
|
| +++ /dev/null
|
| @@ -1,109 +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 %}
|
| -
|
| -
|
| -{% macro define(union, exported=True) %}
|
| -type {{union|name(exported)}} interface {
|
| - Tag() uint32
|
| - Interface() interface{}
|
| - __Reflect(__{{union|name(exported)}}Reflect)
|
| - Encode(encoder *bindings.Encoder) error
|
| -}
|
| -
|
| -type __{{union|name(exported)}}Reflect struct {
|
| -{% for field in union.fields %}
|
| - {{field|name(exported)}} {{field.kind|go_type}}
|
| -{% endfor %}
|
| -}
|
| -
|
| -func Decode{{union|name(exported)}}(decoder *bindings.Decoder) ({{union|name(exported)}}, error) {
|
| - size, tag, err := decoder.ReadUnionHeader()
|
| - if err != nil {
|
| - return nil, err
|
| - }
|
| -
|
| - if size == 0 {
|
| - decoder.SkipNullUnionValue()
|
| - return nil, nil
|
| - }
|
| -
|
| - switch tag {
|
| -{% for field in union.fields %}
|
| - case {{field.ordinal}}:
|
| - var value {{union|name(exported)}}{{field|name(exported)}}
|
| - if err := value.decodeInternal(decoder); err != nil {
|
| - return nil, err
|
| - }
|
| - decoder.FinishReadingUnionValue()
|
| - return &value, nil
|
| -{% endfor %}
|
| - }
|
| -
|
| - return nil, fmt.Errorf("Unknown tag %d in {{union|name(exported)}}", tag);
|
| -}
|
| -
|
| -{% for field in union.fields %}
|
| -{%- set struct_name = union|name(exported) + field|name(exported) %}
|
| -type {{struct_name}} struct { Value {{field.kind|go_type}} }
|
| -func (u *{{struct_name}}) Tag() uint32 { return {{field.ordinal}} }
|
| -func (u *{{struct_name}}) Interface() interface{} { return u.Value }
|
| -func (u *{{struct_name}}) __Reflect(__{{union|name(exported)}}Reflect) {}
|
| -
|
| -func (u *{{struct_name}}) Encode(encoder *bindings.Encoder) error {
|
| - encoder.WriteUnionHeader(u.Tag())
|
| - {{encode_union_field('u.Value', field.kind)|tab_indent()}}
|
| - encoder.FinishWritingUnionValue()
|
| - return nil
|
| -}
|
| -
|
| -func (u *{{struct_name}}) decodeInternal(decoder *bindings.Decoder) error {
|
| - {{decode_union_field('u.Value', field.kind)|tab_indent()}}
|
| - return nil
|
| -}
|
| -
|
| -{% endfor %}
|
| -
|
| -{% endmacro %}
|
| -
|
| -{% macro encode_union_field(value, kind) %}
|
| -{% if kind|is_union %}
|
| -if err := encoder.WritePointer(); err != nil {
|
| - return err
|
| -}
|
| -
|
| -encoder.StartNestedUnion()
|
| -{{encoding_macros.encode(value, kind)}}
|
| -encoder.Finish()
|
| -{% else %}
|
| -{{encoding_macros.encode(value, kind)}}
|
| -{% endif %}
|
| -{% endmacro %}
|
| -
|
| -{% macro decode_union_field(value, kind) %}
|
| -{% if kind|is_union %}
|
| -if pointer, err := decoder.ReadPointer(); err != nil || pointer == 0 {
|
| - if err != nil {
|
| - return err
|
| - }
|
| -{% if kind|is_nullable %}
|
| - {{value}} = nil
|
| - return nil
|
| -{% else %}
|
| - return &bindings.ValidationError{bindings.UnexpectedNullUnion, "unexpected null union"}
|
| -{% endif %}
|
| -}
|
| -
|
| -if err := decoder.StartNestedUnion(); err != nil {
|
| - return err
|
| -}
|
| -
|
| -{{encoding_macros.decode(value, kind)}}
|
| -
|
| -decoder.Finish()
|
| -{% else %}
|
| -{{encoding_macros.decode(value, kind)}}
|
| -{% endif %}
|
| -{% endmacro %}
|
|
|