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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 placeholder, for example, "result->%s", "p_%s". The placeholder will be | 141 placeholder, for example, "result->%s", "p_%s". The placeholder will be |
142 substituted with struct field names to refer to the output fields. | 142 substituted with struct field names to refer to the output fields. |
143 |context| is the name of the serialization context. | 143 |context| is the name of the serialization context. |
144 |success| is the name of a bool variable to track success of the operation. | 144 |success| is the name of a bool variable to track success of the operation. |
145 This macro is expanded to do deserialization for both: | 145 This macro is expanded to do deserialization for both: |
146 - user-defined structs: the output is an instance of the corresponding | 146 - user-defined structs: the output is an instance of the corresponding |
147 struct wrapper class. | 147 struct wrapper class. |
148 - method parameters/response parameters: the output is a list of | 148 - method parameters/response parameters: the output is a list of |
149 arguments. #} | 149 arguments. #} |
150 {%- macro deserialize(struct, input, output_field_pattern, success) -%} | 150 {%- macro deserialize(struct, input, output_field_pattern, success) -%} |
151 DCHECK(!{{input}}.is_null()); | |
152 | |
153 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} | 151 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} |
154 {%- set output_field = output_field_pattern|format(pf.field.name) %} | 152 {%- set output_field = output_field_pattern|format(pf.field.name) %} |
155 {%- set name = pf.field.name %} | 153 {%- set name = pf.field.name %} |
156 {%- set kind = pf.field.kind %} | 154 {%- set kind = pf.field.kind %} |
157 {%- if kind|is_object_kind %} | 155 {%- if kind|is_object_kind %} |
158 if (!{{input}}.Read{{name|under_to_camel}}(&{{output_field}})) | 156 if (!{{input}}.Read{{name|under_to_camel}}(&{{output_field}})) |
159 {{success}} = false; | 157 {{success}} = false; |
160 {%- elif kind|is_interface_kind or kind|is_any_handle_kind or | 158 {%- elif kind|is_interface_kind or kind|is_any_handle_kind or |
161 kind|is_associated_kind %} | 159 kind|is_associated_kind %} |
162 {{output_field}} = {{input}}.Take{{name|under_to_camel}}(); | 160 {{output_field}} = {{input}}.Take{{name|under_to_camel}}(); |
163 {%- else %} | 161 {%- else %} |
164 {{output_field}} = {{input}}.{{name}}(); | 162 {{output_field}} = {{input}}.{{name}}(); |
165 {%- endif %} | 163 {%- endif %} |
166 {%- endfor %} | 164 {%- endfor %} |
167 {%- endmacro %} | 165 {%- endmacro %} |
OLD | NEW |