Chromium Code Reviews| 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..031dfccb2362ea6f7dc28cd67d9c6788b1e32111 |
| --- /dev/null |
| +++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_definition.tmpl |
| @@ -0,0 +1,44 @@ |
| +size_t GetSerializedSize_(const {{struct.name}}Ptr& input) { |
| + size_t size = mojo::internal::Align(sizeof(internal::{{struct.name}}_Data)); |
|
yzshen1
2014/05/27 22:16:59
nit: I think the size of *_Data is always 8-byte m
|
| +{%- 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::internal::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 (input->{{pf.field.name}}) |
| + 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; |
| +} |
| + |
| +void Deserialize_(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 (input->{{pf.field.name}}.ptr) |
| + 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(); |
| +} |