OLD | NEW |
1 {# TODO(yzshen): Make these templates more readable. #} | 1 {# TODO(yzshen): Make these templates more readable. #} |
2 | 2 |
3 {# Computes the serialized size for the specified struct. | 3 {# Computes the serialized size for the specified struct. |
4 |struct| is the struct definition. | 4 |struct| is the struct definition. |
5 |input_field_pattern| should be a pattern that contains one string | 5 |input_field_pattern| should be a pattern that contains one string |
6 placeholder, for example, "input->%s", "p_%s". The placeholder will be | 6 placeholder, for example, "input->%s", "p_%s". The placeholder will be |
7 substituted with struct field names to refer to the input fields. | 7 substituted with struct field names to refer to the input fields. |
8 |context| is the name of the serialization context. | 8 |context| is the name of the serialization context. |
9 |input_may_be_temp| indicates whether any input may be temporary obejcts. | 9 |input_may_be_temp| indicates whether any input may be temporary obejcts. |
10 We need to assign temporary objects to local variables before passing it to | 10 We need to assign temporary objects to local variables before passing it to |
(...skipping 11 matching lines...) Expand all Loading... |
22 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is
_object_kind %} | 22 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is
_object_kind %} |
23 {%- set name = pf.field.name -%} | 23 {%- set name = pf.field.name -%} |
24 {%- set kind = pf.field.kind -%} | 24 {%- set kind = pf.field.kind -%} |
25 {%- set original_input_field = input_field_pattern|format(name) %} | 25 {%- set original_input_field = input_field_pattern|format(name) %} |
26 {%- set input_field = "in_%s"|format(name) if input_may_be_temp | 26 {%- set input_field = "in_%s"|format(name) if input_may_be_temp |
27 else original_input_field %} | 27 else original_input_field %} |
28 {%- if input_may_be_temp %} | 28 {%- if input_may_be_temp %} |
29 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}}; | 29 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}}; |
30 {%- endif %} | 30 {%- endif %} |
31 | 31 |
32 {%- if kind|is_struct_kind or kind|is_string_kind or kind|is_array_kind or | 32 {%- set serializer_type = kind|unmapped_type_for_serializer %} |
33 kind|is_map_kind %} | 33 {%- if kind|is_union_kind %} |
34 {%- set serializer_type = kind|unmapped_type_for_serializer %} | 34 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>( |
| 35 {{input_field}}, true, {{context}}); |
| 36 {%- else %} |
35 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>( | 37 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>( |
36 {{input_field}}, {{context}}); | 38 {{input_field}}, {{context}}); |
37 {%- elif kind|is_union_kind %} | |
38 size += GetSerializedSize_({{input_field}}, true, {{context}}); | |
39 {%- else %} | |
40 size += GetSerializedSize_({{input_field}}, {{context}}); | |
41 {%- endif %} | 39 {%- endif %} |
42 {%- endfor %} | 40 {%- endfor %} |
43 {%- endmacro -%} | 41 {%- endmacro -%} |
44 | 42 |
45 {# Serializes the specified struct. | 43 {# Serializes the specified struct. |
46 |struct| is the struct definition. | 44 |struct| is the struct definition. |
47 |struct_display_name| is the display name for the struct that can be showed | 45 |struct_display_name| is the display name for the struct that can be showed |
48 in error/log messages, for example, "FooStruct", "FooMethod request". | 46 in error/log messages, for example, "FooStruct", "FooMethod request". |
49 |input_field_pattern| should be a pattern that contains one string | 47 |input_field_pattern| should be a pattern that contains one string |
50 placeholder, for example, "input->%s", "p_%s". The placeholder will be | 48 placeholder, for example, "input->%s", "p_%s". The placeholder will be |
(...skipping 21 matching lines...) Expand all Loading... |
72 {%- set input_field = "in_%s"|format(name) if input_may_be_temp | 70 {%- set input_field = "in_%s"|format(name) if input_may_be_temp |
73 else original_input_field %} | 71 else original_input_field %} |
74 {%- if input_may_be_temp %} | 72 {%- if input_may_be_temp %} |
75 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}}; | 73 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}}; |
76 {%- endif %} | 74 {%- endif %} |
77 | 75 |
78 {%- if kind|is_array_kind or kind|is_map_kind %} | 76 {%- if kind|is_array_kind or kind|is_map_kind %} |
79 const mojo::internal::ArrayValidateParams {{name}}_validate_params( | 77 const mojo::internal::ArrayValidateParams {{name}}_validate_params( |
80 {{kind|get_array_validate_params_ctor_args|indent(10)}}); | 78 {{kind|get_array_validate_params_ctor_args|indent(10)}}); |
81 mojo::internal::Serialize<{{serializer_type}}>( | 79 mojo::internal::Serialize<{{serializer_type}}>( |
82 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr, | 80 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr, |
83 &{{name}}_validate_params, {{context}}); | 81 &{{name}}_validate_params, {{context}}); |
84 {%- elif kind|is_struct_kind or kind|is_string_kind %} | 82 {%- elif kind|is_union_kind %} |
| 83 auto {{name}}_ptr = &{{output}}->{{name}}; |
| 84 mojo::internal::Serialize<{{serializer_type}}>( |
| 85 {{input_field}}, {{buffer}}, &{{name}}_ptr, true, {{context}}); |
| 86 {%- else %} |
85 mojo::internal::Serialize<{{serializer_type}}>( | 87 mojo::internal::Serialize<{{serializer_type}}>( |
86 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr, {{context}}); | 88 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr, {{context}}); |
87 {%- elif kind|is_union_kind %} | |
88 auto {{name}}_ptr = &{{output}}->{{name}}; | |
89 SerializeUnion_(std::move({{input_field}}), {{buffer}}, &{{name}}_ptr, true, | |
90 {{context}}); | |
91 {%- else %} | |
92 Serialize_(std::move({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr, | |
93 {{context}}); | |
94 {%- endif %} | 89 {%- endif %} |
95 {%- if not kind|is_nullable_kind %} | 90 {%- if not kind|is_nullable_kind %} |
96 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 91 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
97 {%- if kind|is_union_kind %} | 92 {%- if kind|is_union_kind %} |
98 {{output}}->{{name}}.is_null(), | 93 {{output}}->{{name}}.is_null(), |
99 {%- else %} | 94 {%- else %} |
100 !{{output}}->{{name}}.ptr, | 95 !{{output}}->{{name}}.ptr, |
101 {%- endif %} | 96 {%- endif %} |
102 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 97 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
103 "null {{name}} in {{struct_display_name}}"); | 98 "null {{name}} in {{struct_display_name}}"); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 {%- set last_checked_version = 0 %} | 157 {%- set last_checked_version = 0 %} |
163 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} | 158 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} |
164 {%- set output_field = output_field_pattern|format(pf.field.name) %} | 159 {%- set output_field = output_field_pattern|format(pf.field.name) %} |
165 {%- set name = pf.field.name %} | 160 {%- set name = pf.field.name %} |
166 {%- set kind = pf.field.kind %} | 161 {%- set kind = pf.field.kind %} |
167 {%- if pf.min_version > last_checked_version %} | 162 {%- if pf.min_version > last_checked_version %} |
168 {%- set last_checked_version = pf.min_version %} | 163 {%- set last_checked_version = pf.min_version %} |
169 if ({{input}}->header_.version < {{pf.min_version}}) | 164 if ({{input}}->header_.version < {{pf.min_version}}) |
170 break; | 165 break; |
171 {%- endif %} | 166 {%- endif %} |
172 {%- if kind|is_struct_kind or kind|is_string_kind or kind|is_array_kind or | 167 {%- set serializer_type = kind|unmapped_type_for_serializer %} |
173 kind|is_map_kind %} | 168 {%- if kind|is_union_kind %} |
174 {%- set serializer_type = kind|unmapped_type_for_serializer %} | 169 if (!mojo::internal::Deserialize<{{serializer_type}}>( |
| 170 &{{input}}->{{name}}, &{{output_field}}, {{context}})) { |
| 171 {{success}} = false; |
| 172 } |
| 173 {%- elif kind|is_object_kind %} |
175 if (!mojo::internal::Deserialize<{{serializer_type}}>( | 174 if (!mojo::internal::Deserialize<{{serializer_type}}>( |
176 {{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) { | 175 {{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) { |
177 {{success}} = false; | 176 {{success}} = false; |
178 } | 177 } |
179 {%- elif kind|is_union_kind %} | |
180 if (!Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}})) | |
181 {{success}} = false; | |
182 {%- elif kind|is_object_kind %} | |
183 if (!Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) | |
184 {{success}} = false; | |
185 {%- elif kind|is_interface_kind %} | 178 {%- elif kind|is_interface_kind %} |
186 mojo::internal::InterfaceDataToPointer( | 179 mojo::internal::InterfaceDataToPointer( |
187 &{{input}}->{{name}}, &{{output_field}}, {{context}}); | 180 &{{input}}->{{name}}, &{{output_field}}, {{context}}); |
188 {%- elif kind|is_interface_request_kind %} | 181 {%- elif kind|is_interface_request_kind %} |
189 {{output_field}}.Bind( | 182 {{output_field}}.Bind( |
190 ({{context}})->handles.TakeHandleAs<mojo::MessagePipeHandle>( | 183 ({{context}})->handles.TakeHandleAs<mojo::MessagePipeHandle>( |
191 {{input}}->{{name}})); | 184 {{input}}->{{name}})); |
192 {%- elif kind|is_any_handle_kind %} | 185 {%- elif kind|is_any_handle_kind %} |
193 {{output_field}} = ({{context}})->handles.TakeHandleAs< | 186 {{output_field}} = ({{context}})->handles.TakeHandleAs< |
194 typename decltype({{output_field}})::RawHandleType>( | 187 typename decltype({{output_field}})::RawHandleType>( |
195 {{input}}->{{name}}); | 188 {{input}}->{{name}}); |
196 {%- elif kind|is_associated_interface_kind %} | 189 {%- elif kind|is_associated_interface_kind %} |
197 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou
tput_field}}, ({{context}})->router.get()); | 190 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou
tput_field}}, ({{context}})->router.get()); |
198 {%- elif kind|is_associated_interface_request_kind %} | 191 {%- elif kind|is_associated_interface_request_kind %} |
199 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( | 192 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( |
200 &{{output_field}}, | 193 &{{output_field}}, |
201 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn
dReset(&{{input}}->{{name}}))); | 194 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn
dReset(&{{input}}->{{name}}))); |
202 {%- elif kind|is_enum_kind %} | 195 {%- elif kind|is_enum_kind %} |
203 {{output_field}} = static_cast<{{kind|get_qualified_name_for_kind}}>({{input
}}->{{name}}); | 196 {{output_field}} = static_cast<{{kind|get_qualified_name_for_kind}}>({{input
}}->{{name}}); |
204 {%- else %} | 197 {%- else %} |
205 {{output_field}} = {{input}}->{{name}}; | 198 {{output_field}} = {{input}}->{{name}}; |
206 {%- endif %} | 199 {%- endif %} |
207 {%- endfor %} | 200 {%- endfor %} |
208 } while (false); | 201 } while (false); |
209 {%- endmacro %} | 202 {%- endmacro %} |
OLD | NEW |