| 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. |
| 11 - method parameters/response parameters: the input is a list of | 11 - method parameters/response parameters: the input is a list of |
| 12 arguments. | 12 arguments. |
| 13 It declares |size| of type size_t to store the resulting size. #} | 13 It declares |size| of type size_t to store the resulting size. #} |
| 14 {%- macro get_serialized_size(struct, input_field_pattern) -%} | 14 {%- macro get_serialized_size(struct, input_field_pattern) -%} |
| 15 size_t size = sizeof(internal::{{struct.name}}_Data); | 15 size_t size = sizeof(internal::{{struct.name}}_Data); |
| 16 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is
_object_kind %} | 16 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is
_object_kind %} |
| 17 {%- if pf.field.kind|is_union_kind %} | 17 {%- if pf.field.kind|is_union_kind %} |
| 18 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true
); | 18 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true
); |
| 19 {%- elif pf.field.kind|is_native_kind %} |
| 20 // TODO(rockot): Support sizing of native kinds. This requires adding support |
| 21 // to IPC::ParamTraits. It's not checked and is only used for preallocating |
| 22 // space, so for now we just short the size result and let the buffer grow |
| 23 // a little dynamically when needed. |
| 19 {%- else %} | 24 {%- else %} |
| 20 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}); | 25 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}); |
| 21 {%- endif %} | 26 {%- endif %} |
| 22 {%- endfor %} | 27 {%- endfor %} |
| 23 {%- endmacro -%} | 28 {%- endmacro -%} |
| 24 | 29 |
| 25 {# Serializes the specified struct. | 30 {# Serializes the specified struct. |
| 26 |struct| is the struct definition. | 31 |struct| is the struct definition. |
| 27 |struct_display_name| is the display name for the struct that can be showed | 32 |struct_display_name| is the display name for the struct that can be showed |
| 28 in error/log messages, for example, "FooStruct", "FooMethod request". | 33 in error/log messages, for example, "FooStruct", "FooMethod request". |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 mojo::SerializeArray_(std::move({{input_field}}), {{buffer}}, | 55 mojo::SerializeArray_(std::move({{input_field}}), {{buffer}}, |
| 51 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); | 56 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); |
| 52 {%- elif kind|is_map_kind %} | 57 {%- elif kind|is_map_kind %} |
| 53 const mojo::internal::ArrayValidateParams {{name}}_validate_params( | 58 const mojo::internal::ArrayValidateParams {{name}}_validate_params( |
| 54 {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}}); | 59 {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}}); |
| 55 mojo::SerializeMap_(std::move({{input_field}}), {{buffer}}, | 60 mojo::SerializeMap_(std::move({{input_field}}), {{buffer}}, |
| 56 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); | 61 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); |
| 57 {%- elif kind|is_union_kind %} | 62 {%- elif kind|is_union_kind %} |
| 58 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}}; | 63 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}}; |
| 59 SerializeUnion_(std::move({{input_field}}), {{buffer}}, &{{name}}_ptr, true); | 64 SerializeUnion_(std::move({{input_field}}), {{buffer}}, &{{name}}_ptr, true); |
| 65 {%- elif kind|is_native_kind %} |
| 66 mojo::internal::SerializeNative_( |
| 67 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr); |
| 60 {%- else %} | 68 {%- else %} |
| 61 Serialize_(std::move({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr); | 69 Serialize_(std::move({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr); |
| 62 {%- endif %} | 70 {%- endif %} |
| 63 {%- if not kind|is_nullable_kind %} | 71 {%- if not kind|is_nullable_kind %} |
| 64 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 72 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| 65 {%- if kind|is_union_kind %} | 73 {%- if kind|is_union_kind %} |
| 66 {{output}}->{{name}}.is_null(), | 74 {{output}}->{{name}}.is_null(), |
| 67 {%- else %} | 75 {%- else %} |
| 68 !{{output}}->{{name}}.ptr, | 76 !{{output}}->{{name}}.ptr, |
| 69 {%- endif %} | 77 {%- endif %} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 {%- set output_field = output_field_pattern|format(pf.field.name) %} | 134 {%- set output_field = output_field_pattern|format(pf.field.name) %} |
| 127 {%- set name = pf.field.name %} | 135 {%- set name = pf.field.name %} |
| 128 {%- set kind = pf.field.kind %} | 136 {%- set kind = pf.field.kind %} |
| 129 {%- if pf.min_version > last_checked_version %} | 137 {%- if pf.min_version > last_checked_version %} |
| 130 {%- set last_checked_version = pf.min_version %} | 138 {%- set last_checked_version = pf.min_version %} |
| 131 if ({{input}}->header_.version < {{pf.min_version}}) | 139 if ({{input}}->header_.version < {{pf.min_version}}) |
| 132 break; | 140 break; |
| 133 {%- endif %} | 141 {%- endif %} |
| 134 {%- if kind|is_object_kind %} | 142 {%- if kind|is_object_kind %} |
| 135 {%- if kind|is_union_kind %} | 143 {%- if kind|is_union_kind %} |
| 136 Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}}); | 144 if (!Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}})) |
| 145 return false; |
| 146 {%- elif kind|is_native_kind %} |
| 147 if (!DeserializeNative_( |
| 148 {{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) { |
| 149 return false; |
| 150 } |
| 137 {%- else %} | 151 {%- else %} |
| 138 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}}); | 152 if (!Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) |
| 153 return false; |
| 139 {%- endif %} | 154 {%- endif %} |
| 140 {%- elif kind|is_interface_kind %} | 155 {%- elif kind|is_interface_kind %} |
| 141 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field
}}); | 156 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field
}}); |
| 142 {%- elif kind|is_interface_request_kind %} | 157 {%- elif kind|is_interface_request_kind %} |
| 143 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(&
{{input}}->{{name}}))); | 158 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(&
{{input}}->{{name}}))); |
| 144 {%- elif kind|is_any_handle_kind %} | 159 {%- elif kind|is_any_handle_kind %} |
| 145 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); | 160 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); |
| 146 {%- elif kind|is_associated_interface_kind %} | 161 {%- elif kind|is_associated_interface_kind %} |
| 147 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou
tput_field}}, ({{context}})->router.get()); | 162 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou
tput_field}}, ({{context}})->router.get()); |
| 148 {%- elif kind|is_associated_interface_request_kind %} | 163 {%- elif kind|is_associated_interface_request_kind %} |
| 149 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( | 164 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( |
| 150 &{{output_field}}, | 165 &{{output_field}}, |
| 151 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn
dReset(&{{input}}->{{name}}))); | 166 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn
dReset(&{{input}}->{{name}}))); |
| 152 {%- elif kind|is_enum_kind %} | 167 {%- elif kind|is_enum_kind %} |
| 153 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name}
}); | 168 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name}
}); |
| 154 {%- else %} | 169 {%- else %} |
| 155 {{output_field}} = {{input}}->{{name}}; | 170 {{output_field}} = {{input}}->{{name}}; |
| 156 {%- endif %} | 171 {%- endif %} |
| 157 {%- endfor %} | 172 {%- endfor %} |
| 158 } while (false); | 173 } while (false); |
| 159 {%- endmacro %} | 174 {%- endmacro %} |
| OLD | NEW |