Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl

Issue 1526533002: [mojo] Add pickling support for native-only structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-4-bool-deserialize
Patch Set: merge Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_native_only_kind %}
18 size += mojo::internal::GetSerializedSizeNative_(
19 {{input_field_pattern|format(pf.field.name)}});
20 {%- elif pf.field.kind|is_union_kind %}
18 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true ); 21 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true );
19 {%- else %} 22 {%- else %}
20 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}); 23 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}});
21 {%- endif %} 24 {%- endif %}
22 {%- endfor %} 25 {%- endfor %}
23 {%- endmacro -%} 26 {%- endmacro -%}
24 27
25 {# Serializes the specified struct. 28 {# Serializes the specified struct.
26 |struct| is the struct definition. 29 |struct| is the struct definition.
27 |struct_display_name| is the display name for the struct that can be showed 30 |struct_display_name| is the display name for the struct that can be showed
(...skipping 19 matching lines...) Expand all
47 {%- if kind|is_array_kind %} 50 {%- if kind|is_array_kind %}
48 const mojo::internal::ArrayValidateParams {{name}}_validate_params( 51 const mojo::internal::ArrayValidateParams {{name}}_validate_params(
49 {{kind|get_array_validate_params_ctor_args|indent(10)}}); 52 {{kind|get_array_validate_params_ctor_args|indent(10)}});
50 mojo::SerializeArray_(std::move({{input_field}}), {{buffer}}, 53 mojo::SerializeArray_(std::move({{input_field}}), {{buffer}},
51 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); 54 &{{output}}->{{name}}.ptr, &{{name}}_validate_params);
52 {%- elif kind|is_map_kind %} 55 {%- elif kind|is_map_kind %}
53 const mojo::internal::ArrayValidateParams {{name}}_validate_params( 56 const mojo::internal::ArrayValidateParams {{name}}_validate_params(
54 {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}}); 57 {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}});
55 mojo::SerializeMap_(std::move({{input_field}}), {{buffer}}, 58 mojo::SerializeMap_(std::move({{input_field}}), {{buffer}},
56 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); 59 &{{output}}->{{name}}.ptr, &{{name}}_validate_params);
60 {%- elif kind|is_native_only_kind %}
61 mojo::internal::SerializeNative_(
62 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr);
57 {%- elif kind|is_union_kind %} 63 {%- elif kind|is_union_kind %}
58 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}}; 64 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}};
59 SerializeUnion_(std::move({{input_field}}), {{buffer}}, &{{name}}_ptr, true); 65 SerializeUnion_(std::move({{input_field}}), {{buffer}}, &{{name}}_ptr, true);
60 {%- else %} 66 {%- else %}
61 Serialize_(std::move({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr); 67 Serialize_(std::move({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr);
62 {%- endif %} 68 {%- endif %}
63 {%- if not kind|is_nullable_kind %} 69 {%- if not kind|is_nullable_kind %}
64 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 70 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
65 {%- if kind|is_union_kind %} 71 {%- if kind|is_union_kind %}
66 {{output}}->{{name}}.is_null(), 72 {{output}}->{{name}}.is_null(),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 {%- set last_checked_version = 0 %} 131 {%- set last_checked_version = 0 %}
126 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} 132 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
127 {%- set output_field = output_field_pattern|format(pf.field.name) %} 133 {%- set output_field = output_field_pattern|format(pf.field.name) %}
128 {%- set name = pf.field.name %} 134 {%- set name = pf.field.name %}
129 {%- set kind = pf.field.kind %} 135 {%- set kind = pf.field.kind %}
130 {%- if pf.min_version > last_checked_version %} 136 {%- if pf.min_version > last_checked_version %}
131 {%- set last_checked_version = pf.min_version %} 137 {%- set last_checked_version = pf.min_version %}
132 if ({{input}}->header_.version < {{pf.min_version}}) 138 if ({{input}}->header_.version < {{pf.min_version}})
133 break; 139 break;
134 {%- endif %} 140 {%- endif %}
135 {%- if kind|is_object_kind %} 141 {%- if kind|is_native_only_kind %}
142 if (!DeserializeNative_(
143 {{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) {
144 {{success}} = false;
145 }
146 {%- elif kind|is_object_kind %}
136 {%- if kind|is_union_kind %} 147 {%- if kind|is_union_kind %}
137 if (!Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}})) 148 if (!Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}}))
138 {{success}} = false; 149 {{success}} = false;
139 {%- else %} 150 {%- else %}
140 if (!Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) 151 if (!Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}}))
141 {{success}} = false; 152 {{success}} = false;
142 {%- endif %} 153 {%- endif %}
143 {%- elif kind|is_interface_kind %} 154 {%- elif kind|is_interface_kind %}
144 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }}); 155 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }});
145 {%- elif kind|is_interface_request_kind %} 156 {%- elif kind|is_interface_request_kind %}
146 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}}))); 157 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}})));
147 {%- elif kind|is_any_handle_kind %} 158 {%- elif kind|is_any_handle_kind %}
148 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); 159 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}}));
149 {%- elif kind|is_associated_interface_kind %} 160 {%- elif kind|is_associated_interface_kind %}
150 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou tput_field}}, ({{context}})->router.get()); 161 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou tput_field}}, ({{context}})->router.get());
151 {%- elif kind|is_associated_interface_request_kind %} 162 {%- elif kind|is_associated_interface_request_kind %}
152 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( 163 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle(
153 &{{output_field}}, 164 &{{output_field}},
154 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn dReset(&{{input}}->{{name}}))); 165 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn dReset(&{{input}}->{{name}})));
155 {%- elif kind|is_enum_kind %} 166 {%- elif kind|is_enum_kind %}
156 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} }); 167 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} });
157 {%- else %} 168 {%- else %}
158 {{output_field}} = {{input}}->{{name}}; 169 {{output_field}} = {{input}}->{{name}};
159 {%- endif %} 170 {%- endif %}
160 {%- endfor %} 171 {%- endfor %}
161 } while (false); 172 } while (false);
162 {%- endmacro %} 173 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698