| OLD | NEW |
| 1 {%- set mojom_type = union|get_qualified_name_for_kind %} | 1 {%- set mojom_type = union|get_qualified_name_for_kind %} |
| 2 | 2 |
| 3 // static | 3 // static |
| 4 bool UnionTraits<{{mojom_type}}::DataView, {{mojom_type}}Ptr>::Read( | 4 bool UnionTraits<{{mojom_type}}::DataView, {{mojom_type}}Ptr>::Read( |
| 5 {{mojom_type}}::DataView input, | 5 {{mojom_type}}::DataView input, |
| 6 {{mojom_type}}Ptr* output) { | 6 {{mojom_type}}Ptr* output) { |
| 7 *output = {{mojom_type}}::New(); | 7 using UnionType = {{mojom_type}}; |
| 8 {{mojom_type}}Ptr& result = *output; | 8 using Tag = UnionType::Tag; |
| 9 | 9 |
| 10 internal::UnionAccessor<{{mojom_type}}> result_acc(result.get()); | |
| 11 switch (input.tag()) { | 10 switch (input.tag()) { |
| 12 {%- for field in union.fields %} | 11 {%- for field in union.fields %} |
| 13 case {{mojom_type}}::Tag::{{field.name|upper}}: { | 12 case Tag::{{field.name|upper}}: { |
| 14 {%- set name = field.name %} | 13 {%- set name = field.name %} |
| 15 {%- set kind = field.kind %} | 14 {%- set kind = field.kind %} |
| 16 {%- set serializer_type = kind|unmapped_type_for_serializer %} | 15 {%- set serializer_type = kind|unmapped_type_for_serializer %} |
| 17 {%- if kind|is_object_kind %} | 16 {%- if kind|is_object_kind %} |
| 18 result_acc.SwitchActive({{mojom_type}}::Tag::{{name|upper}}); | 17 {{kind|cpp_wrapper_type(True)}} result_{{name}}; |
| 19 if (!input.Read{{name|under_to_camel}}(result_acc.data()->{{name}})) | 18 if (!input.Read{{name|under_to_camel}}(&result_{{name}})) |
| 20 return false; | 19 return false; |
| 21 | 20 |
| 21 *output = UnionType::New{{field.name|under_to_camel}}( |
| 22 std::move(result_{{name}})); |
| 22 {%- elif kind|is_any_handle_kind %} | 23 {%- elif kind|is_any_handle_kind %} |
| 23 auto result_{{name}} = input.Take{{name|under_to_camel}}(); | 24 *output = UnionType::New{{field.name|under_to_camel}}( |
| 24 result->set_{{name}}(std::move(result_{{name}})); | 25 input.Take{{name|under_to_camel}}()); |
| 25 | 26 |
| 26 {%- elif kind|is_any_interface_kind %} | 27 {%- elif kind|is_any_interface_kind %} |
| 27 auto result_{{name}} = | 28 *output = UnionType::New{{field.name|under_to_camel}}( |
| 28 input.Take{{name|under_to_camel}}<typename std::remove_reference<declt
ype(result->get_{{name}}())>::type>(); | 29 input.Take{{name|under_to_camel}}<{{kind|cpp_wrapper_type(True)}}>()); |
| 29 result->set_{{name}}(std::move(result_{{name}})); | |
| 30 | 30 |
| 31 {%- elif kind|is_enum_kind %} | 31 {%- elif kind|is_enum_kind %} |
| 32 decltype(result->get_{{name}}()) result_{{name}}; | 32 {{kind|cpp_wrapper_type(True)}} result_{{name}}; |
| 33 if (!input.Read{{name|under_to_camel}}(&result_{{name}})) | 33 if (!input.Read{{name|under_to_camel}}(&result_{{name}})) |
| 34 return false; | 34 return false; |
| 35 result->set_{{name}}(result_{{name}}); | |
| 36 | 35 |
| 36 *output = UnionType::New{{field.name|under_to_camel}}(result_{{name}}); |
| 37 {%- else %} | 37 {%- else %} |
| 38 result->set_{{name}}(input.{{name}}()); | 38 *output = UnionType::New{{field.name|under_to_camel}}(input.{{name}}()); |
| 39 {%- endif %} | 39 {%- endif %} |
| 40 break; | 40 break; |
| 41 } | 41 } |
| 42 {%- endfor %} | 42 {%- endfor %} |
| 43 default: | 43 default: |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| OLD | NEW |