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

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl

Issue 923033003: Implement unions as members of structs. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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/cpp_templates/struct_macros.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
index 03911b9b39b47e10ae9386c56624cb41e2c08d09..e8a625bc8e9fb94167dde3923aa25289eeb91905 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
@@ -14,7 +14,11 @@
{%- macro get_serialized_size(struct, input_field_pattern) -%}
size_t size = sizeof(internal::{{struct.name}}_Data);
{%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is_object_kind %}
+{%- if pf.field.kind|is_union_kind %}
+ size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true);
+{%- else %}
size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}});
+{%- endif %}
{%- endfor %}
{%- endmacro -%}
@@ -46,12 +50,19 @@
{%- elif kind|is_map_kind %}
mojo::SerializeMap_<{{kind.value_kind|get_map_validate_params|indent(24)}}>(
mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr);
+{%- elif kind|is_union_kind %}
+ internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}};
+ SerializeUnion_(mojo::internal::Forward({{input_field}}), {{buffer}}, &{{name}}_ptr, true);
{%- else %}
Serialize_(mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr);
{%- endif %}
{%- if not kind|is_nullable_kind %}
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
+{%- if kind|is_union_kind %}
+ {{output}}->{{name}}.is_null(),
+{%- else %}
!{{output}}->{{name}}.ptr,
+{%- endif %}
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null {{name}} in {{struct_display_name}}");
{%- endif %}
@@ -103,7 +114,11 @@
break;
{%- endif %}
{%- if kind|is_object_kind %}
+{%- if kind|is_union_kind %}
+ Deserialize_(&{{input}}->{{name}}, &{{output_field}});
+{%- else %}
Deserialize_({{input}}->{{name}}.ptr, &{{output_field}});
+{%- endif %}
{%- elif kind|is_interface_kind or kind|is_interface_request_kind %}
{{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(&{{input}}->{{name}})));
{%- elif kind|is_any_handle_kind %}

Powered by Google App Engine
This is Rietveld 408576698