| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 |input_may_be_temp|: please see the comments of get_serialized_size. | 53 |input_may_be_temp|: please see the comments of get_serialized_size. |
| 54 This macro is expanded to do serialization for both: | 54 This macro is expanded to do serialization for both: |
| 55 - user-defined structs: the input is an instance of the corresponding struct | 55 - user-defined structs: the input is an instance of the corresponding struct |
| 56 wrapper class. | 56 wrapper class. |
| 57 - method parameters/response parameters: the input is a list of | 57 - method parameters/response parameters: the input is a list of |
| 58 arguments. #} | 58 arguments. #} |
| 59 {%- macro serialize(struct, struct_display_name, input_field_pattern, output, | 59 {%- macro serialize(struct, struct_display_name, input_field_pattern, output, |
| 60 buffer, context, input_may_be_temp=False) -%} | 60 buffer, context, input_may_be_temp=False) -%} |
| 61 auto {{output}} = | 61 auto {{output}} = |
| 62 {{struct|get_qualified_name_for_kind(internal=True)}}::New({{buffer}}); | 62 {{struct|get_qualified_name_for_kind(internal=True)}}::New({{buffer}}); |
| 63 ALLOW_UNUSED_LOCAL({{output}}); |
| 63 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} | 64 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} |
| 64 {%- set input_field = input_field_pattern|format(pf.field.name) %} | 65 {%- set input_field = input_field_pattern|format(pf.field.name) %} |
| 65 {%- set name = pf.field.name %} | 66 {%- set name = pf.field.name %} |
| 66 {%- set kind = pf.field.kind %} | 67 {%- set kind = pf.field.kind %} |
| 67 {%- set serializer_type = kind|unmapped_type_for_serializer %} | 68 {%- set serializer_type = kind|unmapped_type_for_serializer %} |
| 68 {%- if kind|is_object_kind %} | 69 {%- if kind|is_object_kind %} |
| 69 {%- set original_input_field = input_field_pattern|format(name) %} | 70 {%- set original_input_field = input_field_pattern|format(name) %} |
| 70 {%- set input_field = "in_%s"|format(name) if input_may_be_temp | 71 {%- set input_field = "in_%s"|format(name) if input_may_be_temp |
| 71 else original_input_field %} | 72 else original_input_field %} |
| 72 {%- if input_may_be_temp %} | 73 {%- if input_may_be_temp %} |
| 73 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}}; | 74 decltype({{original_input_field}}) in_{{name}} = {{original_input_field}}; |
| 74 {%- endif %} | 75 {%- endif %} |
| 75 | |
| 76 {%- if kind|is_array_kind or kind|is_map_kind %} | 76 {%- if kind|is_array_kind or kind|is_map_kind %} |
| 77 typename decltype({{output}}->{{name}})::BaseType* {{name}}_ptr; |
| 77 const mojo::internal::ContainerValidateParams {{name}}_validate_params( | 78 const mojo::internal::ContainerValidateParams {{name}}_validate_params( |
| 78 {{kind|get_container_validate_params_ctor_args|indent(10)}}); | 79 {{kind|get_container_validate_params_ctor_args|indent(10)}}); |
| 79 mojo::internal::Serialize<{{serializer_type}}>( | 80 mojo::internal::Serialize<{{serializer_type}}>( |
| 80 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr, | 81 {{input_field}}, {{buffer}}, &{{name}}_ptr, &{{name}}_validate_params, |
| 81 &{{name}}_validate_params, {{context}}); | 82 {{context}}); |
| 83 {{output}}->{{name}}.Set({{name}}_ptr); |
| 82 {%- elif kind|is_union_kind %} | 84 {%- elif kind|is_union_kind %} |
| 83 auto {{name}}_ptr = &{{output}}->{{name}}; | 85 auto {{name}}_ptr = &{{output}}->{{name}}; |
| 84 mojo::internal::Serialize<{{serializer_type}}>( | 86 mojo::internal::Serialize<{{serializer_type}}>( |
| 85 {{input_field}}, {{buffer}}, &{{name}}_ptr, true, {{context}}); | 87 {{input_field}}, {{buffer}}, &{{name}}_ptr, true, {{context}}); |
| 86 {%- else %} | 88 {%- else %} |
| 89 typename decltype({{output}}->{{name}})::BaseType* {{name}}_ptr; |
| 87 mojo::internal::Serialize<{{serializer_type}}>( | 90 mojo::internal::Serialize<{{serializer_type}}>( |
| 88 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr, {{context}}); | 91 {{input_field}}, {{buffer}}, &{{name}}_ptr, {{context}}); |
| 92 {{output}}->{{name}}.Set({{name}}_ptr); |
| 89 {%- endif %} | 93 {%- endif %} |
| 90 {%- if not kind|is_nullable_kind %} | 94 {%- if not kind|is_nullable_kind %} |
| 91 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 95 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| 92 {%- if kind|is_union_kind %} | |
| 93 {{output}}->{{name}}.is_null(), | 96 {{output}}->{{name}}.is_null(), |
| 94 {%- else %} | |
| 95 !{{output}}->{{name}}.ptr, | |
| 96 {%- endif %} | |
| 97 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 97 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
| 98 "null {{name}} in {{struct_display_name}}"); | 98 "null {{name}} in {{struct_display_name}}"); |
| 99 {%- endif %} | 99 {%- endif %} |
| 100 | 100 |
| 101 {%- elif kind|is_any_handle_or_interface_kind %} | 101 {%- elif kind|is_any_handle_or_interface_kind %} |
| 102 mojo::internal::Serialize<{{serializer_type}}>( | 102 mojo::internal::Serialize<{{serializer_type}}>( |
| 103 {{input_field}}, &{{output}}->{{name}}, {{context}}); | 103 {{input_field}}, &{{output}}->{{name}}, {{context}}); |
| 104 {%- if not kind|is_nullable_kind %} | 104 {%- if not kind|is_nullable_kind %} |
| 105 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 105 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| 106 !mojo::internal::IsHandleOrInterfaceValid({{output}}->{{name}}), | 106 !mojo::internal::IsHandleOrInterfaceValid({{output}}->{{name}}), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 {%- if kind|is_object_kind or kind|is_enum_kind %} | 144 {%- if kind|is_object_kind or kind|is_enum_kind %} |
| 145 if (!{{input}}.Read{{name|under_to_camel}}(&{{output_field}})) | 145 if (!{{input}}.Read{{name|under_to_camel}}(&{{output_field}})) |
| 146 {{success}} = false; | 146 {{success}} = false; |
| 147 {%- elif kind|is_any_handle_or_interface_kind %} | 147 {%- elif kind|is_any_handle_or_interface_kind %} |
| 148 {{output_field}} = {{input}}.Take{{name|under_to_camel}}(); | 148 {{output_field}} = {{input}}.Take{{name|under_to_camel}}(); |
| 149 {%- else %} | 149 {%- else %} |
| 150 {{output_field}} = {{input}}.{{name}}(); | 150 {{output_field}} = {{input}}.{{name}}(); |
| 151 {%- endif %} | 151 {%- endif %} |
| 152 {%- endfor %} | 152 {%- endfor %} |
| 153 {%- endmacro %} | 153 {%- endmacro %} |
| OLD | NEW |