1{%- set mojom_type = union|get_qualified_name_for_kind %} 2 3template <> 4struct {{export_attribute}} UnionTraits<{{mojom_type}}::DataView, 5 {{mojom_type}}Ptr> { 6 static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; } 7 static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); } 8 9 static {{mojom_type}}::Tag GetTag(const {{mojom_type}}Ptr& input) { 10 return input->which(); 11 } 12 13{%- for field in union.fields %} 14{%- set maybe_const_in = "" if field.kind|contains_handles_or_interfaces else "const" %} 15{%- set maybe_const_out = "" if field.kind|contains_handles_or_interfaces or not field.kind|is_reference_kind else "const" %} 16{# We want the field accessor to be const whenever possible to allow 17 structs to be used as map keys. #} 18 static {{maybe_const_out}} {{field.kind|cpp_union_trait_getter_return_type}} {{field.name}}({{maybe_const_in}} {{mojom_type}}Ptr& input) { 19 return input->get_{{field.name}}(); 20 } 21{%- endfor %} 22 23 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output); 24}; 25