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

Unified Diff: mojo/public/tools/bindings/generators/dart_templates/struct_definition.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/dart_templates/struct_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/dart_templates/struct_definition.tmpl b/mojo/public/tools/bindings/generators/dart_templates/struct_definition.tmpl
deleted file mode 100644
index 88c68aa8b71a76beff488d6b01801db9d06bb7e9..0000000000000000000000000000000000000000
--- a/mojo/public/tools/bindings/generators/dart_templates/struct_definition.tmpl
+++ /dev/null
@@ -1,101 +0,0 @@
-{#--- Begin #}
-{%- import "encoding_macros.tmpl" as encoding_macros %}
-{%- macro struct_def(struct, typepkg, package) %}
-{#--- Enums #}
-{%- from "enum_definition.tmpl" import enum_def %}
-{%- for enum in struct.enums %}
-{{enum_def(enum, typepkg, package)}}
-{%- endfor %}
-
-class {{struct|name}} extends bindings.Struct {
- static const List<bindings.StructDataHeader> kVersions = const [
-{%- for version in struct.versions %}
- const bindings.StructDataHeader({{version.num_bytes}}, {{version.version}}){% if not loop.last %},{% endif %}
-{%- endfor %}
- ];
-
-{#--- Constants #}
-{%- for constant in struct.constants %}
- static const {{constant.kind|dart_type}} {{constant|name}} = {{constant.resolved_value}};
-{%- endfor %}
-
-{#--- initDefaults() #}
-{%- for packed_field in struct.packed.packed_fields %}
- {{packed_field.field.kind|dart_type}} {{packed_field.field|name}} = {{packed_field.field|default_value}};
-{%- endfor %}
-
- {{struct|name}}() : super(kVersions.last.size);
-
- {{struct|name}}.init(
-{%- for packed_field in struct.packed.packed_fields %}
- {{packed_field.field.kind|dart_type}} this.{{packed_field.field|name}}{% if not loop.last %}, {% endif %}
-{%- endfor %}
- ) : super(kVersions.last.size);
-
- static {{struct|name}} deserialize(bindings.Message message) =>
- bindings.Struct.deserialize(decode, message);
-
- static {{struct|name}} decode(bindings.Decoder decoder0) {
- if (decoder0 == null) {
- return null;
- }
- {{struct|name}} result = new {{struct|name}}();
-
-{%- if struct.bytes %}
- var mainDataHeader = bindings.Struct.checkVersion(decoder0, kVersions);
-{%- else %}
- bindings.Struct.checkVersion(decoder0, kVersions);
-{%- endif %}
-{%- for byte in struct.bytes %}
-{%- for packed_field in byte.packed_fields %}
- if (mainDataHeader.version >= {{packed_field.min_version}}) {
- {{encoding_macros.decode('result.' ~ packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(6)}}
- }
-{%- endfor %}
-{%- endfor %}
- return result;
- }
-
- void encode(bindings.Encoder encoder) {
-{%- if not struct.bytes %}
- encoder.getStructEncoderAtOffset(kVersions.last);
-{%- else %}
- var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last);
-{%- endif %}
- const String structName = "{{struct|name}}";
- String fieldName;
- try {
-{%- for byte in struct.bytes %}
-{%- for packed_field in byte.packed_fields %}
- fieldName = "{{packed_field.field|name}}";
- {{encoding_macros.encode(packed_field.field|name, packed_field.field.kind, 8+packed_field.offset, packed_field.bit)|indent(6)}}
-{%- endfor %}
-{%- endfor %}
- } on bindings.MojoCodecError catch(e) {
- bindings.Struct.fixErrorMessage(e, fieldName, structName);
- rethrow;
- }
- }
-
- String toString() {
- return "{{struct|name}}("
-{%- for packed_field in struct.packed.packed_fields %}
- "{{packed_field.field|name}}: ${{packed_field.field|name}}" {% if not loop.last %}", "{% endif %}
-{%- endfor %}")";
- }
-
- Map toJson() {
- {%- if struct|is_cloneable_kind %}
- Map map = new Map();
- {%- for packed_field in struct.packed.packed_fields %}
- map["{{packed_field.field|name}}"] = {{packed_field.field|name}};
- {%- endfor %}
- return map;
- {%- else %}
- throw new bindings.MojoCodecError(
- 'Object containing handles cannot be encoded to JSON.');
- {%- endif %}
- }
-}
-
-{%- endmacro %}

Powered by Google App Engine
This is Rietveld 408576698