OLD | NEW |
| (Empty) |
1 {%- import "struct_macros.tmpl" as struct_macros %} | |
2 {%- set class_name = "%s::internal::%s_Data"|format(namespace, struct.name) -%} | |
3 {%- set param_name = struct.name|camel_to_underscores %} | |
4 | |
5 // static | |
6 size_t ObjectTraits<{{class_name}}>::ComputeSizeOf( | |
7 const {{class_name}}* {{param_name}}) { | |
8 return sizeof(*{{param_name}}) | |
9 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} + | |
10 mojo::internal::ComputeSizeOf({{param_name}}->{{pf.field.name}}()) | |
11 {%- endfor %}; | |
12 } | |
13 | |
14 // static | |
15 {{class_name}}* ObjectTraits<{{class_name}}>::Clone( | |
16 const {{class_name}}* {{param_name}}, Buffer* buf) { | |
17 {{class_name}}* clone = {{class_name}}::New(buf); | |
18 memcpy(clone, {{param_name}}, sizeof(*{{param_name}})); | |
19 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} | |
20 clone->set_{{pf.field.name}}(mojo::internal::Clone({# | |
21 #}{{param_name}}->{{pf.field.name}}(), buf)); | |
22 {%- endfor %} | |
23 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_handle_kind %} | |
24 mojo::internal::ResetIfNonNull({{param_name}}->{{pf.field.name}}()); | |
25 {%- endfor %} | |
26 return clone; | |
27 } | |
28 | |
29 // static | |
30 void ObjectTraits<{{class_name}}>::CloseHandles( | |
31 {{class_name}}* {{param_name}}) { | |
32 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} | |
33 mojo::internal::CloseHandles({{param_name}}->{{pf.field.name}}_.ptr); | |
34 {%- endfor %} | |
35 {%- if struct|is_struct_with_handles %} | |
36 {{struct.name}}_Data_Destructor({{param_name}}); | |
37 {%- endif %} | |
38 } | |
39 | |
40 // static | |
41 void ObjectTraits<{{class_name}}>::EncodePointersAndHandles( | |
42 {{class_name}}* {{param_name}}, std::vector<mojo::Handle>* handles) { | |
43 {{ struct_macros.encodes(struct, param_name)|indent(2) }} | |
44 } | |
45 | |
46 // static | |
47 bool ObjectTraits<{{class_name}}>::DecodePointersAndHandles( | |
48 {{class_name}}* {{param_name}}, mojo::Message* message) { | |
49 {{ struct_macros.decodes(struct, param_name)|indent(2) }} | |
50 return true; | |
51 } | |
OLD | NEW |