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

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

Issue 1520153002: [mojo] Allow value deserialization to fail (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-3-misc-support
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
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/union_serialization_declaration.tmpl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 size_t GetSerializedSize_(const {{union.name}}Ptr& input, bool inlined) { 1 size_t GetSerializedSize_(const {{union.name}}Ptr& input, bool inlined) {
2 size_t size = 0U; 2 size_t size = 0U;
3 if (!inlined) { 3 if (!inlined) {
4 size += sizeof(internal::{{union.name}}_Data); 4 size += sizeof(internal::{{union.name}}_Data);
5 } 5 }
6 6
7 if (!input) 7 if (!input)
8 return size; 8 return size;
9 9
10 mojo::internal::UnionAccessor<{{union.name}}> input_acc(input.get()); 10 mojo::internal::UnionAccessor<{{union.name}}> input_acc(input.get());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 {%- endfor %} 86 {%- endfor %}
87 } 87 }
88 } else if (inlined) { 88 } else if (inlined) {
89 result->set_null(); 89 result->set_null();
90 } else { 90 } else {
91 result = nullptr; 91 result = nullptr;
92 } 92 }
93 *output = result; 93 *output = result;
94 } 94 }
95 95
96 void Deserialize_(internal::{{union.name}}_Data* input, 96 bool Deserialize_(internal::{{union.name}}_Data* input,
97 {{union.name}}Ptr* output, 97 {{union.name}}Ptr* output,
98 mojo::internal::SerializationContext* context) { 98 mojo::internal::SerializationContext* context) {
99 bool success = true;
99 if (input && !input->is_null()) { 100 if (input && !input->is_null()) {
100 {{union.name}}Ptr result({{union.name}}::New()); 101 {{union.name}}Ptr result({{union.name}}::New());
101 mojo::internal::UnionAccessor<{{union.name}}> result_acc(result.get()); 102 mojo::internal::UnionAccessor<{{union.name}}> result_acc(result.get());
102 switch (input->tag) { 103 switch (input->tag) {
103 {% for field in union.fields %} 104 {% for field in union.fields %}
104 case {{union.name}}::Tag::{{field.name|upper}}: { 105 case {{union.name}}::Tag::{{field.name|upper}}: {
105 {% if field.kind|is_object_kind %} 106 {% if field.kind|is_object_kind %}
106 result_acc.SwitchActive({{union.name}}::Tag::{{field.name|upper}}); 107 result_acc.SwitchActive({{union.name}}::Tag::{{field.name|upper}});
107 Deserialize_(input->data.f_{{field.name}}.ptr, result_acc.data()->{{fiel d.name}}, context); 108 if (!Deserialize_(input->data.f_{{field.name}}.ptr, result_acc.data()->{ {field.name}}, context))
109 success = false;
108 {% elif field.kind|is_any_handle_kind %} 110 {% elif field.kind|is_any_handle_kind %}
109 {{field.kind|cpp_wrapper_type}}* {{field.name}} = 111 {{field.kind|cpp_wrapper_type}}* {{field.name}} =
110 reinterpret_cast<{{field.kind|cpp_wrapper_type}}*>(&input->data.f_{{ field.name}}); 112 reinterpret_cast<{{field.kind|cpp_wrapper_type}}*>(&input->data.f_{{ field.name}});
111 result->set_{{field.name}}({{field.name}}->Pass()); 113 result->set_{{field.name}}({{field.name}}->Pass());
112 {% elif field.kind|is_interface_kind %} 114 {% elif field.kind|is_interface_kind %}
113 {{field.kind|cpp_wrapper_type}} {{field.name}}_out; 115 {{field.kind|cpp_wrapper_type}} {{field.name}}_out;
114 mojo::internal::Interface_Data* {{field.name}}_in = 116 mojo::internal::Interface_Data* {{field.name}}_in =
115 reinterpret_cast<mojo::internal::Interface_Data*>( 117 reinterpret_cast<mojo::internal::Interface_Data*>(
116 &input->data.f_{{field.name}}); 118 &input->data.f_{{field.name}});
117 mojo::internal::InterfaceDataToPointer( 119 mojo::internal::InterfaceDataToPointer(
118 {{field.name}}_in, &{{field.name}}_out); 120 {{field.name}}_in, &{{field.name}}_out);
119 result->set_{{field.name}}({{field.name}}_out.Pass()); 121 result->set_{{field.name}}({{field.name}}_out.Pass());
120 {%- elif field.kind|is_associated_kind %} 122 {%- elif field.kind|is_associated_kind %}
121 // TODO(yzshen): add deserialization logic for associated kinds. 123 // TODO(yzshen): add deserialization logic for associated kinds.
122 {% elif field.kind|is_enum_kind %} 124 {% elif field.kind|is_enum_kind %}
123 result->set_{{field.name}}(static_cast<{{field.kind|cpp_wrapper_type}}>( input->data.f_{{field.name}})); 125 result->set_{{field.name}}(static_cast<{{field.kind|cpp_wrapper_type}}>( input->data.f_{{field.name}}));
124 {% else %} 126 {% else %}
125 result->set_{{field.name}}(input->data.f_{{field.name}}); 127 result->set_{{field.name}}(input->data.f_{{field.name}});
126 {%- endif %} 128 {%- endif %}
127 break; 129 break;
128 } 130 }
129 {%- endfor %} 131 {%- endfor %}
130 } 132 }
131 *output = result.Pass(); 133 *output = result.Pass();
132 } else { 134 } else {
133 output->reset(); 135 output->reset();
134 } 136 }
137 return success;
135 } 138 }
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/union_serialization_declaration.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698