| 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 This macro is expanded to compute seriailized size for both: | 8 This macro is expanded to compute seriailized size for both: |
| 9 - user-defined structs: the input is an instance of the corresponding struct | 9 - user-defined structs: the input is an instance of the corresponding struct |
| 10 wrapper class. | 10 wrapper class. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 |input| is the name of the input struct instance. | 106 |input| is the name of the input struct instance. |
| 107 |output_field_pattern| should be a pattern that contains one string | 107 |output_field_pattern| should be a pattern that contains one string |
| 108 placeholder, for example, "result->%s", "p_%s". The placeholder will be | 108 placeholder, for example, "result->%s", "p_%s". The placeholder will be |
| 109 substituted with struct field names to refer to the output fields. | 109 substituted with struct field names to refer to the output fields. |
| 110 This macro is expanded to do deserialization for both: | 110 This macro is expanded to do deserialization for both: |
| 111 - user-defined structs: the output is an instance of the corresponding | 111 - user-defined structs: the output is an instance of the corresponding |
| 112 struct wrapper class. | 112 struct wrapper class. |
| 113 - method parameters/response parameters: the output is a list of | 113 - method parameters/response parameters: the output is a list of |
| 114 arguments. #} | 114 arguments. #} |
| 115 |context| is the name of the serialization context. | 115 |context| is the name of the serialization context. |
| 116 {%- macro deserialize(struct, input, output_field_pattern, context) -%} | 116 |success| is the name of a bool variable to track success of the operation. |
| 117 {%- macro deserialize(struct, input, output_field_pattern, context, success) -%} |
| 117 do { | 118 do { |
| 118 // NOTE: The memory backing |{{input}}| may has be smaller than | 119 // NOTE: The memory backing |{{input}}| may has be smaller than |
| 119 // |sizeof(*{{input}})| if the message comes from an older version. | 120 // |sizeof(*{{input}})| if the message comes from an older version. |
| 120 {#- Before deserialize fields introduced at a certain version, we need to add | 121 {#- Before deserialize fields introduced at a certain version, we need to add |
| 121 a version check, which makes sure we skip further deserialization if | 122 a version check, which makes sure we skip further deserialization if |
| 122 |input| is from an earlier version. |last_checked_version| records the | 123 |input| is from an earlier version. |last_checked_version| records the |
| 123 last version that we have added such version check. #} | 124 last version that we have added such version check. #} |
| 124 {%- set last_checked_version = 0 %} | 125 {%- set last_checked_version = 0 %} |
| 125 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} | 126 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} |
| 126 {%- set output_field = output_field_pattern|format(pf.field.name) %} | 127 {%- set output_field = output_field_pattern|format(pf.field.name) %} |
| 127 {%- set name = pf.field.name %} | 128 {%- set name = pf.field.name %} |
| 128 {%- set kind = pf.field.kind %} | 129 {%- set kind = pf.field.kind %} |
| 129 {%- if pf.min_version > last_checked_version %} | 130 {%- if pf.min_version > last_checked_version %} |
| 130 {%- set last_checked_version = pf.min_version %} | 131 {%- set last_checked_version = pf.min_version %} |
| 131 if ({{input}}->header_.version < {{pf.min_version}}) | 132 if ({{input}}->header_.version < {{pf.min_version}}) |
| 132 break; | 133 break; |
| 133 {%- endif %} | 134 {%- endif %} |
| 134 {%- if kind|is_object_kind %} | 135 {%- if kind|is_object_kind %} |
| 135 {%- if kind|is_union_kind %} | 136 {%- if kind|is_union_kind %} |
| 136 Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}}); | 137 if (!Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}})) |
| 138 {{success}} = false; |
| 137 {%- else %} | 139 {%- else %} |
| 138 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}}); | 140 if (!Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) |
| 141 {{success}} = false; |
| 139 {%- endif %} | 142 {%- endif %} |
| 140 {%- elif kind|is_interface_kind %} | 143 {%- elif kind|is_interface_kind %} |
| 141 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field
}}); | 144 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field
}}); |
| 142 {%- elif kind|is_interface_request_kind %} | 145 {%- elif kind|is_interface_request_kind %} |
| 143 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(&
{{input}}->{{name}}))); | 146 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(&
{{input}}->{{name}}))); |
| 144 {%- elif kind|is_any_handle_kind %} | 147 {%- elif kind|is_any_handle_kind %} |
| 145 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); | 148 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); |
| 146 {%- elif kind|is_associated_interface_kind %} | 149 {%- elif kind|is_associated_interface_kind %} |
| 147 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou
tput_field}}, ({{context}})->router.get()); | 150 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou
tput_field}}, ({{context}})->router.get()); |
| 148 {%- elif kind|is_associated_interface_request_kind %} | 151 {%- elif kind|is_associated_interface_request_kind %} |
| 149 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( | 152 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( |
| 150 &{{output_field}}, | 153 &{{output_field}}, |
| 151 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn
dReset(&{{input}}->{{name}}))); | 154 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn
dReset(&{{input}}->{{name}}))); |
| 152 {%- elif kind|is_enum_kind %} | 155 {%- elif kind|is_enum_kind %} |
| 153 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name}
}); | 156 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name}
}); |
| 154 {%- else %} | 157 {%- else %} |
| 155 {{output_field}} = {{input}}->{{name}}; | 158 {{output_field}} = {{input}}->{{name}}; |
| 156 {%- endif %} | 159 {%- endif %} |
| 157 {%- endfor %} | 160 {%- endfor %} |
| 158 } while (false); | 161 } while (false); |
| 159 {%- endmacro %} | 162 {%- endmacro %} |
| OLD | NEW |