| OLD | NEW |
| 1 {%- import "struct_macros.tmpl" as struct_macros %} | 1 {%- import "struct_macros.tmpl" as struct_macros %} |
| 2 {%- set mojom_type = struct|get_qualified_name_for_kind %} | 2 {%- set data_view = struct|get_qualified_name_for_kind ~ "DataView" %} |
| 3 {%- set data_type = struct|get_qualified_name_for_kind(internal=True) %} | 3 {%- set data_type = struct|get_qualified_name_for_kind(internal=True) %} |
| 4 | 4 |
| 5 template <> | |
| 6 struct {{export_attribute}} StructTraits<{{mojom_type}}::DataView, {{mojom_type}
}Ptr> { | |
| 7 static bool IsNull(const {{mojom_type}}Ptr& input) { return !input; } | |
| 8 static void SetToNull({{mojom_type}}Ptr* output) { output->reset(); } | |
| 9 | |
| 10 {%- for field in struct.fields %} | |
| 11 {%- set return_ref = field.kind|is_object_kind or | |
| 12 field.kind|is_any_handle_or_interface_kind %} | |
| 13 {%- if return_ref %} | |
| 14 static decltype({{mojom_type}}::{{field.name}})& {{field.name}}( | |
| 15 {{mojom_type}}Ptr& input) { | |
| 16 return input->{{field.name}}; | |
| 17 } | |
| 18 {%- else %} | |
| 19 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( | |
| 20 const {{mojom_type}}Ptr& input) { | |
| 21 return input->{{field.name}}; | |
| 22 } | |
| 23 {%- endif %} | |
| 24 {%- endfor %} | |
| 25 | |
| 26 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output); | |
| 27 }; | |
| 28 | |
| 29 namespace internal { | 5 namespace internal { |
| 30 | 6 |
| 31 template <typename MaybeConstUserType> | 7 template <typename MaybeConstUserType> |
| 32 struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> { | 8 struct Serializer<{{data_view}}, MaybeConstUserType> { |
| 33 using UserType = typename std::remove_const<MaybeConstUserType>::type; | 9 using UserType = typename std::remove_const<MaybeConstUserType>::type; |
| 34 using Traits = StructTraits<{{mojom_type}}::DataView, UserType>; | 10 using Traits = StructTraits<{{data_view}}, UserType>; |
| 35 | 11 |
| 36 static size_t PrepareToSerialize(MaybeConstUserType& input, | 12 static size_t PrepareToSerialize(MaybeConstUserType& input, |
| 37 SerializationContext* context) { | 13 SerializationContext* context) { |
| 38 if (CallIsNullIfExists<Traits>(input)) | 14 if (CallIsNullIfExists<Traits>(input)) |
| 39 return 0; | 15 return 0; |
| 40 | 16 |
| 41 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context); | 17 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context); |
| 42 ALLOW_UNUSED_LOCAL(custom_context); | 18 ALLOW_UNUSED_LOCAL(custom_context); |
| 43 | 19 |
| 44 {{struct_macros.get_serialized_size( | 20 {{struct_macros.get_serialized_size( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 | 42 |
| 67 CustomContextHelper<Traits>::TearDown(input, custom_context); | 43 CustomContextHelper<Traits>::TearDown(input, custom_context); |
| 68 } | 44 } |
| 69 | 45 |
| 70 static bool Deserialize({{data_type}}* input, | 46 static bool Deserialize({{data_type}}* input, |
| 71 UserType* output, | 47 UserType* output, |
| 72 SerializationContext* context) { | 48 SerializationContext* context) { |
| 73 if (!input) | 49 if (!input) |
| 74 return CallSetToNullIfExists<Traits>(output); | 50 return CallSetToNullIfExists<Traits>(output); |
| 75 | 51 |
| 76 {{mojom_type}}::DataView data_view(input, context); | 52 {{data_view}} data_view(input, context); |
| 77 return Traits::Read(data_view, output); | 53 return Traits::Read(data_view, output); |
| 78 } | 54 } |
| 79 }; | 55 }; |
| 80 | 56 |
| 81 } // namespace internal | 57 } // namespace internal |
| OLD | NEW |