| OLD | NEW |
| 1 {%- set mojom_type = union|get_qualified_name_for_kind %} | 1 {%- set data_view = union|get_qualified_name_for_kind ~ "DataView" %} |
| 2 {%- set data_type = union|get_qualified_name_for_kind(internal=True) %} | 2 {%- set data_type = union|get_qualified_name_for_kind(internal=True) %} |
| 3 | 3 |
| 4 template <> | |
| 5 struct {{export_attribute}} UnionTraits<{{mojom_type}}::DataView, | |
| 6 {{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 static {{mojom_type}}::Tag GetTag(const {{mojom_type}}Ptr& input) { | |
| 11 return input->which(); | |
| 12 } | |
| 13 | |
| 14 {%- for field in union.fields %} | |
| 15 {%- set return_ref = field.kind|is_object_kind or | |
| 16 field.kind|is_any_handle_or_interface_kind %} | |
| 17 {%- if return_ref %} | |
| 18 static decltype(std::declval<{{mojom_type}}>().get_{{field.name}}()) | |
| 19 {{field.name}}({{mojom_type}}Ptr& input) { | |
| 20 return input->get_{{field.name}}(); | |
| 21 } | |
| 22 {%- else %} | |
| 23 static decltype(std::declval<{{mojom_type}}>().get_{{field.name}}()) | |
| 24 {{field.name}}(const {{mojom_type}}Ptr& input) { | |
| 25 return input->get_{{field.name}}(); | |
| 26 } | |
| 27 {%- endif %} | |
| 28 {%- endfor %} | |
| 29 | |
| 30 static bool Read({{mojom_type}}::DataView input, {{mojom_type}}Ptr* output); | |
| 31 }; | |
| 32 | |
| 33 namespace internal { | 4 namespace internal { |
| 34 | 5 |
| 35 template <typename MaybeConstUserType> | 6 template <typename MaybeConstUserType> |
| 36 struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> { | 7 struct Serializer<{{data_view}}, MaybeConstUserType> { |
| 37 using UserType = typename std::remove_const<MaybeConstUserType>::type; | 8 using UserType = typename std::remove_const<MaybeConstUserType>::type; |
| 38 using Traits = UnionTraits<{{mojom_type}}::DataView, UserType>; | 9 using Traits = UnionTraits<{{data_view}}, UserType>; |
| 39 | 10 |
| 40 static size_t PrepareToSerialize(MaybeConstUserType& input, | 11 static size_t PrepareToSerialize(MaybeConstUserType& input, |
| 41 bool inlined, | 12 bool inlined, |
| 42 SerializationContext* context) { | 13 SerializationContext* context) { |
| 43 size_t size = inlined ? 0 : sizeof({{data_type}}); | 14 size_t size = inlined ? 0 : sizeof({{data_type}}); |
| 44 | 15 |
| 45 if (CallIsNullIfExists<Traits>(input)) | 16 if (CallIsNullIfExists<Traits>(input)) |
| 46 return size; | 17 return size; |
| 47 | 18 |
| 48 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context); | 19 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context); |
| 49 ALLOW_UNUSED_LOCAL(custom_context); | 20 ALLOW_UNUSED_LOCAL(custom_context); |
| 50 | 21 |
| 51 switch (CallWithContext(Traits::GetTag, input, custom_context)) { | 22 switch (CallWithContext(Traits::GetTag, input, custom_context)) { |
| 52 {%- for field in union.fields %} | 23 {%- for field in union.fields %} |
| 53 {%- set name = field.name %} | 24 {%- set name = field.name %} |
| 54 case {{mojom_type}}::Tag::{{name|upper}}: { | 25 case {{data_view}}::Tag::{{name|upper}}: { |
| 55 {%- if field.kind|is_object_kind %} | 26 {%- if field.kind|is_object_kind %} |
| 56 {%- set kind = field.kind %} | 27 {%- set kind = field.kind %} |
| 57 {%- set serializer_type = kind|unmapped_type_for_serializer %} | 28 {%- set serializer_type = kind|unmapped_type_for_serializer %} |
| 58 decltype(CallWithContext(Traits::{{name}}, input, custom_context)) | 29 decltype(CallWithContext(Traits::{{name}}, input, custom_context)) |
| 59 in_{{name}} = CallWithContext(Traits::{{name}}, input, | 30 in_{{name}} = CallWithContext(Traits::{{name}}, input, |
| 60 custom_context); | 31 custom_context); |
| 61 {%- if kind|is_union_kind %} | 32 {%- if kind|is_union_kind %} |
| 62 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>( | 33 size += mojo::internal::PrepareToSerialize<{{serializer_type}}>( |
| 63 in_{{name}}, false, context); | 34 in_{{name}}, false, context); |
| 64 {%- else %} | 35 {%- else %} |
| (...skipping 30 matching lines...) Expand all Loading... |
| 95 ALLOW_UNUSED_LOCAL(result); | 66 ALLOW_UNUSED_LOCAL(result); |
| 96 // TODO(azani): Handle unknown and objects. | 67 // TODO(azani): Handle unknown and objects. |
| 97 // Set the not-null flag. | 68 // Set the not-null flag. |
| 98 result->size = kUnionDataSize; | 69 result->size = kUnionDataSize; |
| 99 result->tag = CallWithContext(Traits::GetTag, input, custom_context); | 70 result->tag = CallWithContext(Traits::GetTag, input, custom_context); |
| 100 switch (result->tag) { | 71 switch (result->tag) { |
| 101 {%- for field in union.fields %} | 72 {%- for field in union.fields %} |
| 102 {%- set name = field.name %} | 73 {%- set name = field.name %} |
| 103 {%- set kind = field.kind %} | 74 {%- set kind = field.kind %} |
| 104 {%- set serializer_type = kind|unmapped_type_for_serializer %} | 75 {%- set serializer_type = kind|unmapped_type_for_serializer %} |
| 105 case {{mojom_type}}::Tag::{{field.name|upper}}: { | 76 case {{data_view}}::Tag::{{field.name|upper}}: { |
| 106 decltype(CallWithContext(Traits::{{name}}, input, custom_context)) | 77 decltype(CallWithContext(Traits::{{name}}, input, custom_context)) |
| 107 in_{{name}} = CallWithContext(Traits::{{name}}, input, | 78 in_{{name}} = CallWithContext(Traits::{{name}}, input, |
| 108 custom_context); | 79 custom_context); |
| 109 {%- if kind|is_object_kind %} | 80 {%- if kind|is_object_kind %} |
| 110 typename decltype(result->data.f_{{name}})::BaseType* ptr; | 81 typename decltype(result->data.f_{{name}})::BaseType* ptr; |
| 111 {%- if kind|is_union_kind %} | 82 {%- if kind|is_union_kind %} |
| 112 mojo::internal::Serialize<{{serializer_type}}>( | 83 mojo::internal::Serialize<{{serializer_type}}>( |
| 113 in_{{name}}, buffer, &ptr, false, context); | 84 in_{{name}}, buffer, &ptr, false, context); |
| 114 {%- elif kind|is_array_kind or kind|is_map_kind %} | 85 {%- elif kind|is_array_kind or kind|is_map_kind %} |
| 115 const ContainerValidateParams {{name}}_validate_params( | 86 const ContainerValidateParams {{name}}_validate_params( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 126 |
| 156 CustomContextHelper<Traits>::TearDown(input, custom_context); | 127 CustomContextHelper<Traits>::TearDown(input, custom_context); |
| 157 } | 128 } |
| 158 | 129 |
| 159 static bool Deserialize({{data_type}}* input, | 130 static bool Deserialize({{data_type}}* input, |
| 160 UserType* output, | 131 UserType* output, |
| 161 SerializationContext* context) { | 132 SerializationContext* context) { |
| 162 if (!input || input->is_null()) | 133 if (!input || input->is_null()) |
| 163 return CallSetToNullIfExists<Traits>(output); | 134 return CallSetToNullIfExists<Traits>(output); |
| 164 | 135 |
| 165 {{mojom_type}}::DataView data_view(input, context); | 136 {{data_view}} data_view(input, context); |
| 166 return Traits::Read(data_view, output); | 137 return Traits::Read(data_view, output); |
| 167 } | 138 } |
| 168 }; | 139 }; |
| 169 | 140 |
| 170 } // namespace internal | 141 } // namespace internal |
| OLD | NEW |