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

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

Issue 1524703002: [mojo] Support native types with mojom wire format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-5-pickles
Patch Set: doc 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_native_only_kind %} 17 {%- set name = pf.field.name -%}
18 {%- set kind = pf.field.kind -%}
19 {%- if kind|is_native_only_kind %}
18 size += mojo::internal::GetSerializedSizeNative_( 20 size += mojo::internal::GetSerializedSizeNative_(
19 {{input_field_pattern|format(pf.field.name)}}); 21 {{input_field_pattern|format(name)}});
20 {%- elif pf.field.kind|is_union_kind %} 22 {%- elif kind|is_typemapped_kind %}
21 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true ); 23 size +=
24 {{kind|get_name_for_kind}}_SerializerTraits_<{{kind|cpp_wrapper_type}}>
25 ::GetSize({{input_field_pattern|format(name)}});
26 {%- elif kind|is_union_kind %}
27 size += GetSerializedSize_({{input_field_pattern|format(name)}}, true);
22 {%- else %} 28 {%- else %}
23 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}); 29 size += GetSerializedSize_({{input_field_pattern|format(name)}});
24 {%- endif %} 30 {%- endif %}
25 {%- endfor %} 31 {%- endfor %}
26 {%- endmacro -%} 32 {%- endmacro -%}
27 33
28 {# Serializes the specified struct. 34 {# Serializes the specified struct.
29 |struct| is the struct definition. 35 |struct| is the struct definition.
30 |struct_display_name| is the display name for the struct that can be showed 36 |struct_display_name| is the display name for the struct that can be showed
31 in error/log messages, for example, "FooStruct", "FooMethod request". 37 in error/log messages, for example, "FooStruct", "FooMethod request".
32 |input_field_pattern| should be a pattern that contains one string 38 |input_field_pattern| should be a pattern that contains one string
33 placeholder, for example, "input->%s", "p_%s". The placeholder will be 39 placeholder, for example, "input->%s", "p_%s". The placeholder will be
(...skipping 19 matching lines...) Expand all
53 mojo::SerializeArray_(std::move({{input_field}}), {{buffer}}, 59 mojo::SerializeArray_(std::move({{input_field}}), {{buffer}},
54 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); 60 &{{output}}->{{name}}.ptr, &{{name}}_validate_params);
55 {%- elif kind|is_map_kind %} 61 {%- elif kind|is_map_kind %}
56 const mojo::internal::ArrayValidateParams {{name}}_validate_params( 62 const mojo::internal::ArrayValidateParams {{name}}_validate_params(
57 {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}}); 63 {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}});
58 mojo::SerializeMap_(std::move({{input_field}}), {{buffer}}, 64 mojo::SerializeMap_(std::move({{input_field}}), {{buffer}},
59 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); 65 &{{output}}->{{name}}.ptr, &{{name}}_validate_params);
60 {%- elif kind|is_native_only_kind %} 66 {%- elif kind|is_native_only_kind %}
61 mojo::internal::SerializeNative_( 67 mojo::internal::SerializeNative_(
62 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr); 68 {{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr);
69 {%- elif kind|is_typemapped_kind %}
70 {{kind|get_name_for_kind}}_SerializerTraits_<{{kind|cpp_wrapper_type}}>
71 ::Serialize({{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr);
63 {%- elif kind|is_union_kind %} 72 {%- elif kind|is_union_kind %}
64 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}}; 73 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}};
65 SerializeUnion_(std::move({{input_field}}), {{buffer}}, &{{name}}_ptr, true); 74 SerializeUnion_(std::move({{input_field}}), {{buffer}}, &{{name}}_ptr, true);
66 {%- else %} 75 {%- else %}
67 Serialize_(std::move({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr); 76 Serialize_(std::move({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr);
68 {%- endif %} 77 {%- endif %}
69 {%- if not kind|is_nullable_kind %} 78 {%- if not kind|is_nullable_kind %}
70 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 79 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
71 {%- if kind|is_union_kind %} 80 {%- if kind|is_union_kind %}
72 {{output}}->{{name}}.is_null(), 81 {{output}}->{{name}}.is_null(),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 {%- if pf.min_version > last_checked_version %} 145 {%- if pf.min_version > last_checked_version %}
137 {%- set last_checked_version = pf.min_version %} 146 {%- set last_checked_version = pf.min_version %}
138 if ({{input}}->header_.version < {{pf.min_version}}) 147 if ({{input}}->header_.version < {{pf.min_version}})
139 break; 148 break;
140 {%- endif %} 149 {%- endif %}
141 {%- if kind|is_native_only_kind %} 150 {%- if kind|is_native_only_kind %}
142 if (!DeserializeNative_( 151 if (!DeserializeNative_(
143 {{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) { 152 {{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) {
144 {{success}} = false; 153 {{success}} = false;
145 } 154 }
155 {%- elif kind|is_typemapped_kind %}
156 if (!{{kind|get_name_for_kind}}_SerializerTraits_<{{kind|cpp_wrapper_type}}>
157 ::Deserialize(
158 {{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) {
159 {{success}} = false;
160 }
146 {%- elif kind|is_object_kind %} 161 {%- elif kind|is_object_kind %}
147 {%- if kind|is_union_kind %} 162 {%- if kind|is_union_kind %}
148 if (!Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}})) 163 if (!Deserialize_(&{{input}}->{{name}}, &{{output_field}}, {{context}}))
149 {{success}} = false; 164 {{success}} = false;
150 {%- else %} 165 {%- else %}
151 if (!Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}})) 166 if (!Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}, {{context}}))
152 {{success}} = false; 167 {{success}} = false;
153 {%- endif %} 168 {%- endif %}
154 {%- elif kind|is_interface_kind %} 169 {%- elif kind|is_interface_kind %}
155 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }}); 170 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }});
156 {%- elif kind|is_interface_request_kind %} 171 {%- elif kind|is_interface_request_kind %}
157 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}}))); 172 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}})));
158 {%- elif kind|is_any_handle_kind %} 173 {%- elif kind|is_any_handle_kind %}
159 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); 174 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}}));
160 {%- elif kind|is_associated_interface_kind %} 175 {%- elif kind|is_associated_interface_kind %}
161 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou tput_field}}, ({{context}})->router.get()); 176 mojo::internal::AssociatedInterfaceDataToPtrInfo(&{{input}}->{{name}}, &{{ou tput_field}}, ({{context}})->router.get());
162 {%- elif kind|is_associated_interface_request_kind %} 177 {%- elif kind|is_associated_interface_request_kind %}
163 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle( 178 mojo::internal::AssociatedInterfaceRequestHelper::SetHandle(
164 &{{output_field}}, 179 &{{output_field}},
165 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn dReset(&{{input}}->{{name}}))); 180 ({{context}})->router->CreateLocalEndpointHandle(mojo::internal::FetchAn dReset(&{{input}}->{{name}})));
166 {%- elif kind|is_enum_kind %} 181 {%- elif kind|is_enum_kind %}
167 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} }); 182 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} });
168 {%- else %} 183 {%- else %}
169 {{output_field}} = {{input}}->{{name}}; 184 {{output_field}} = {{input}}->{{name}};
170 {%- endif %} 185 {%- endif %}
171 {%- endfor %} 186 {%- endfor %}
172 } while (false); 187 } while (false);
173 {%- endmacro %} 188 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698