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