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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 size_t GetSerializedSize_(const {{struct.name}}Ptr& input) {
2 size_t size = sizeof(internal::{{struct.name}}_Data);
3 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
4 if (input->{{pf.field.name}})
5 size += GetSerializedSize_(input->{{pf.field.name}});
6 {%- endfor %}
7 return size;
8 }
9
10 void Serialize_({{struct.name}}Ptr input, mojo::Buffer* buf,
11 internal::{{struct.name}}_Data** output) {
12 internal::{{struct.name}}_Data* result =
13 internal::{{struct.name}}_Data::New(buf);
14 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
15 {%- if pf.field.kind|is_object_kind %}
16 if (input->{{pf.field.name}}) {
17 {{pf.field.kind|cpp_type}} tmp;
18 Serialize_(mojo::internal::Forward(input->{{pf.field.name}}), buf, &tmp);
19 result->set_{{pf.field.name}}(tmp);
20 }
21 {%- else %}
22 result->set_{{pf.field.name}}(input->{{pf.field.name}});
23 {%- endif %}
24 {%- endfor %}
25 *output = result;
26 }
27
28 void Deserialize_(const internal::{{struct.name}}_Data* input,
29 {{struct.name}}Ptr* output) {
30 {{struct.name}}Ptr result({{struct.name}}::New());
31 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
32 {%- if pf.field.kind|is_object_kind %}
33 if (input->{{pf.field.name}}())
34 Deserialize_(input->{{pf.field.name}}(), &result->{{pf.field.name}});
35 {%- else %}
36 result->{{pf.field.name}} = input->{{pf.field.name}}();
37 {%- endif %}
38 {%- endfor %}
39 *output = result.Pass();
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698