1{%- set mojom_type = struct|get_qualified_name_for_kind %} 2 3template <> 4struct {{export_attribute}} StructTraits<{{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{%- for field in struct.fields %} 10{%- set return_ref = field.kind|is_object_kind or 11 field.kind|is_any_handle_or_interface_kind %} 12{# We want the field accessor to be const whenever possible to allow 13 structs to be used as map keys. 14 TODO(tibell): Make this check more precise to deal with e.g. 15 custom types which don't contain handles but require non-const 16 reference for serialization. #} 17{%- set maybe_const = "" if field.kind|contains_handles_or_interfaces else "const" %} 18{%- if return_ref %} 19 static {{maybe_const}} decltype({{mojom_type}}::{{field.name}})& {{field.name}}( 20 {{maybe_const}} {{mojom_type}}Ptr& input) { 21 return input->{{field.name}}; 22 } 23{%- else %} 24 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( 25 const {{mojom_type}}Ptr& input) { 26 return input->{{field.name}}; 27 } 28{%- endif %} 29{%- endfor %} 30 31 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output); 32}; 33