| 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..aec2afa93e5eb81446e335f5ae7c7751cd5ee976
|
| --- /dev/null
|
| +++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_definition.tmpl
|
| @@ -0,0 +1,51 @@
|
| +size_t GetSerializedSize_(const {{struct.name}}Ptr& input) {
|
| + if (!input)
|
| + return 0;
|
| + size_t size = sizeof(internal::{{struct.name}}_Data);
|
| +{%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
|
| + size += GetSerializedSize_(input->{{pf.field.name}});
|
| +{%- endfor %}
|
| + return size;
|
| +}
|
| +
|
| +void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buf,
|
| + internal::{{struct.name}}_Data** output) {
|
| + if (input) {
|
| + 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 %}
|
| + Serialize_(mojo::internal::Forward(input->{{pf.field.name}}), buf, &result->{{pf.field.name}}.ptr);
|
| +{%- elif pf.field.kind|is_handle_kind %}
|
| + result->{{pf.field.name}} = input->{{pf.field.name}}.release();
|
| +{%- else %}
|
| + result->{{pf.field.name}} = input->{{pf.field.name}};
|
| +{%- endif %}
|
| +{%- endfor %}
|
| + *output = result;
|
| + } else {
|
| + *output = NULL;
|
| + }
|
| +}
|
| +
|
| +void Deserialize_(internal::{{struct.name}}_Data* input,
|
| + {{struct.name}}Ptr* output) {
|
| + if (input) {
|
| + {{struct.name}}Ptr result({{struct.name}}::New());
|
| +{%- for pf in struct.packed.packed_fields %}
|
| +{%- if pf.field.kind|is_object_kind %}
|
| + Deserialize_(input->{{pf.field.name}}.ptr, &result->{{pf.field.name}});
|
| +{%- elif pf.field.kind|is_handle_kind %}
|
| + result->{{pf.field.name}}.reset(mojo::internal::FetchAndReset(&input->{{pf.field.name}}));
|
| +{%- elif pf.field.kind|is_enum_kind %}
|
| + result->{{pf.field.name}} = static_cast<{{pf.field.kind|cpp_wrapper_type}}>(
|
| + input->{{pf.field.name}});
|
| +{%- else %}
|
| + result->{{pf.field.name}} = input->{{pf.field.name}};
|
| +{%- endif %}
|
| +{%- endfor %}
|
| + *output = result.Pass();
|
| + } else {
|
| + output->reset();
|
| + }
|
| +}
|
|
|