| 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();
|
| +}
|
|
|