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

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

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: serialization Created 6 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/struct_serialization_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_definition.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..4ff2e4f23f60ed453ff54fe75b24ef298cc43048
--- /dev/null
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_definition.tmpl
@@ -0,0 +1,40 @@
+size_t GetSerializedSize_(const {{struct.name}}Ptr& input) {
+ size_t size = sizeof(internal::{{struct.name}}_Data);
+{%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
+ if (input->{{pf.field.name}})
+ size += GetSerializedSize_(input->{{pf.field.name}});
+{%- endfor %}
+ return size;
+}
+
+void Serialize_({{struct.name}}Ptr input, mojo::Buffer* buf,
+ internal::{{struct.name}}_Data** output) {
+ internal::{{struct.name}}_Data* result =
+ internal::{{struct.name}}_Data::New(buf);
+{%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
+{%- if pf.field.kind|is_object_kind %}
+ if (input->{{pf.field.name}}) {
+ {{pf.field.kind|cpp_type}} tmp;
+ Serialize_(mojo::internal::Forward(input->{{pf.field.name}}), buf, &tmp);
+ result->set_{{pf.field.name}}(tmp);
+ }
+{%- else %}
+ result->set_{{pf.field.name}}(input->{{pf.field.name}});
+{%- endif %}
+{%- endfor %}
+ *output = result;
+}
+
+void Deserialize_(const internal::{{struct.name}}_Data* input,
+ {{struct.name}}Ptr* output) {
+ {{struct.name}}Ptr result({{struct.name}}::New());
+{%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
+{%- if pf.field.kind|is_object_kind %}
+ if (input->{{pf.field.name}}())
+ Deserialize_(input->{{pf.field.name}}(), &result->{{pf.field.name}});
+{%- else %}
+ result->{{pf.field.name}} = input->{{pf.field.name}}();
+{%- endif %}
+{%- endfor %}
+ *output = result.Pass();
+}

Powered by Google App Engine
This is Rietveld 408576698