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

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

Issue 1953493002: Mojo C++ bindings: custom type mapping for array - part 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@21_simplify
Patch Set: Created 4 years, 7 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/union_serialization_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl
index b4c65621e1c6ddcccc84d6f45c6f6fea24cd6695..0ae22ee3de0e8e2169407aaed02cc12162270749 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl
@@ -1,4 +1,4 @@
-size_t GetSerializedSize_(const {{union.name}}Ptr& input,
+size_t GetSerializedSize_({{union.name}}Ptr& input,
bool inlined,
mojo::internal::SerializationContext* context) {
size_t size = 0U;
@@ -13,9 +13,13 @@ size_t GetSerializedSize_(const {{union.name}}Ptr& input,
switch (input->which()) {
{% for field in union.fields %}
{% if field.kind|is_object_kind %}
+{%- set serializer_type = field.kind|unmapped_type_for_serializer %}
case {{union.name}}::Tag::{{field.name|upper}}:
{% if field.kind|is_union_kind %}
size += GetSerializedSize_(*(input_acc.data()->{{field.name}}), false, context);
+{% elif field.kind|is_array_kind or field.kind|is_map_kind %}
+ size += mojo::internal::PrepareToSerialize<{{serializer_type}}>(
+ *(input_acc.data()->{{field.name}}), context);
{% else %}
size += GetSerializedSize_(*(input_acc.data()->{{field.name}}), context);
{% endif %}
@@ -47,6 +51,7 @@ void SerializeUnion_({{union.name}}Ptr input,
{% for field in union.fields %}
case {{union.name}}::Tag::{{field.name|upper}}: {
{% if field.kind|is_object_kind %}
+{%- set serializer_type = field.kind|unmapped_type_for_serializer %}
{% if field.kind|is_string_kind %}
Serialize_(
*(input_acc.data()->{{field.name}}),
@@ -59,20 +64,13 @@ void SerializeUnion_({{union.name}}Ptr input,
SerializeUnion_(
std::move(*(input_acc.data()->{{field.name}})),
buf, &result->data.f_{{field.name}}.ptr, false, context);
-{% elif field.kind|is_array_kind %}
+{% elif field.kind|is_array_kind or field.kind|is_map_kind %}
const mojo::internal::ArrayValidateParams {{field.name}}_validate_params(
{{field.kind|get_array_validate_params_ctor_args|indent(16)}});
- SerializeArray_(
- std::move(*(input_acc.data()->{{field.name}})),
- buf, &result->data.f_{{field.name}}.ptr,
- &{{field.name}}_validate_params, context);
-{% elif field.kind|is_map_kind %}
- const mojo::internal::ArrayValidateParams {{field.name}}_validate_params(
- {{field.kind.value_kind|get_map_validate_params_ctor_args|indent(16)}});
- SerializeMap_(
- std::move(*(input_acc.data()->{{field.name}})),
- buf, &result->data.f_{{field.name}}.ptr,
- &{{field.name}}_validate_params, context);
+ mojo::internal::Serialize<{{serializer_type}}>(
+ *(input_acc.data()->{{field.name}}), buf,
+ &result->data.f_{{field.name}}.ptr, &{{field.name}}_validate_params,
+ context);
{%- endif %}
{% elif field.kind|is_any_handle_kind %}
result->data.f_{{field.name}} = context->handles.AddHandle(
@@ -114,9 +112,17 @@ bool Deserialize_(internal::{{union.name}}_Data* input,
{% for field in union.fields %}
case {{union.name}}::Tag::{{field.name|upper}}: {
{% if field.kind|is_object_kind %}
+{%- set serializer_type = field.kind|unmapped_type_for_serializer %}
result_acc.SwitchActive({{union.name}}::Tag::{{field.name|upper}});
+{%- if field.kind|is_array_kind or field.kind|is_map_kind %}
+ if (!mojo::internal::Deserialize<{{serializer_type}}>(
+ input->data.f_{{field.name}}.ptr,
+ result_acc.data()->{{field.name}}, context))
+ success = false;
+{%- else %}
if (!Deserialize_(input->data.f_{{field.name}}.ptr, result_acc.data()->{{field.name}}, context))
success = false;
+{%- endif %}
{% elif field.kind|is_any_handle_kind %}
{{field.kind|cpp_wrapper_type}} {{field.name}};
{{field.name}} = context->handles.TakeHandleAs<

Powered by Google App Engine
This is Rietveld 408576698