OLD | NEW |
| (Empty) |
1 size_t GetSerializedSize_(const {{struct.name}}Ptr& input) { | |
2 if (!input) | |
3 return 0; | |
4 size_t size = sizeof(internal::{{struct.name}}_Data); | |
5 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} | |
6 size += GetSerializedSize_(input->{{pf.field.name}}); | |
7 {%- endfor %} | |
8 return size; | |
9 } | |
10 | |
11 void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buf, | |
12 internal::{{struct.name}}_Data** output) { | |
13 if (input) { | |
14 internal::{{struct.name}}_Data* result = | |
15 internal::{{struct.name}}_Data::New(buf); | |
16 {%- for pf in struct.packed.packed_fields %} | |
17 {%- if pf.field.kind|is_object_kind %} | |
18 {%- if pf.field.kind|is_array_kind %} | |
19 mojo::SerializeArray_<{{pf.field.kind|get_array_validate_params|indent(26)}}
>( | |
20 mojo::internal::Forward(input->{{pf.field.name}}), buf, &result->{{pf.fi
eld.name}}.ptr); | |
21 {%- elif pf.field.kind|is_map_kind %} | |
22 mojo::SerializeMap_<{{pf.field.kind.value_kind|get_map_validate_params|inden
t(26)}}>( | |
23 mojo::internal::Forward(input->{{pf.field.name}}), buf, &result->{{pf.fi
eld.name}}.ptr); | |
24 {%- else %} | |
25 Serialize_(mojo::internal::Forward(input->{{pf.field.name}}), buf, &result->
{{pf.field.name}}.ptr); | |
26 {%- endif %} | |
27 {%- if not pf.field.kind|is_nullable_kind %} | |
28 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | |
29 !result->{{pf.field.name}}.ptr, | |
30 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | |
31 "null {{pf.field.name}} field in {{struct.name}} struct"); | |
32 {%- endif %} | |
33 {%- elif pf.field.kind|is_any_handle_kind %} | |
34 {%- if pf.field.kind|is_interface_kind %} | |
35 result->{{pf.field.name}} = input->{{pf.field.name}}.PassMessagePipe().relea
se(); | |
36 {%- else %} | |
37 result->{{pf.field.name}} = input->{{pf.field.name}}.release(); | |
38 {%- endif %} | |
39 {%- if not pf.field.kind|is_nullable_kind %} | |
40 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | |
41 !result->{{pf.field.name}}.is_valid(), | |
42 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, | |
43 "invalid {{pf.field.name}} field in {{struct.name}} struct"); | |
44 {%- endif %} | |
45 {%- else %} | |
46 result->{{pf.field.name}} = input->{{pf.field.name}}; | |
47 {%- endif %} | |
48 {%- endfor %} | |
49 *output = result; | |
50 } else { | |
51 *output = nullptr; | |
52 } | |
53 } | |
54 | |
55 void Deserialize_(internal::{{struct.name}}_Data* input, | |
56 {{struct.name}}Ptr* output) { | |
57 if (input) { | |
58 {{struct.name}}Ptr result({{struct.name}}::New()); | |
59 {%- for pf in struct.packed.packed_fields %} | |
60 {%- if pf.field.kind|is_object_kind %} | |
61 Deserialize_(input->{{pf.field.name}}.ptr, &result->{{pf.field.name}}); | |
62 {%- elif pf.field.kind|is_interface_kind %} | |
63 if (input->{{pf.field.name}}.is_valid()) | |
64 result->{{pf.field.name}}.Bind(mojo::MakeScopedHandle(mojo::internal::Fetc
hAndReset(&input->{{pf.field.name}}))); | |
65 {%- elif pf.field.kind|is_any_handle_kind %} | |
66 result->{{pf.field.name}}.reset(mojo::internal::FetchAndReset(&input->{{pf.f
ield.name}})); | |
67 {%- elif pf.field.kind|is_enum_kind %} | |
68 result->{{pf.field.name}} = static_cast<{{pf.field.kind|cpp_wrapper_type}}>( | |
69 input->{{pf.field.name}}); | |
70 {%- else %} | |
71 result->{{pf.field.name}} = input->{{pf.field.name}}; | |
72 {%- endif %} | |
73 {%- endfor %} | |
74 *output = result.Pass(); | |
75 } else { | |
76 output->reset(); | |
77 } | |
78 } | |
OLD | NEW |