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