| 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 StructTraits<{{mojom_type}}, {{mojom_type}}Ptr> { | 6 struct StructTraits<{{mojom_type}}, {{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_kind or | 12 field.kind|is_any_handle_kind or |
| 13 field.kind|is_interface_kind or | 13 field.kind|is_interface_kind or |
| 14 field.kind|is_associated_kind %} | 14 field.kind|is_associated_kind %} |
| 15 {%- if return_ref %} | 15 {%- if return_ref %} |
| 16 static decltype({{mojom_type}}::{{field.name}})& {{field.name}}( | 16 static decltype({{mojom_type}}::{{field.name}})& {{field.name}}( |
| 17 {{mojom_type}}Ptr& input) { | 17 {{mojom_type}}Ptr& input) { |
| 18 return input->{{field.name}}; | 18 return input->{{field.name}}; |
| 19 } | 19 } |
| 20 static const decltype({{mojom_type}}::{{field.name}})& {{field.name}}( | |
| 21 const {{mojom_type}}Ptr& input) { | |
| 22 return input->{{field.name}}; | |
| 23 } | |
| 24 {%- else %} | 20 {%- else %} |
| 25 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( | 21 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( |
| 26 const {{mojom_type}}Ptr& input) { | 22 const {{mojom_type}}Ptr& input) { |
| 27 return input->{{field.name}}; | 23 return input->{{field.name}}; |
| 28 } | 24 } |
| 29 {%- endif %} | 25 {%- endif %} |
| 30 {%- endfor %} | 26 {%- endfor %} |
| 31 | 27 |
| 32 static bool Read({{mojom_type}}DataView input, {{mojom_type}}Ptr* output); | 28 static bool Read({{mojom_type}}DataView input, {{mojom_type}}Ptr* output); |
| 33 }; | 29 }; |
| 34 | 30 |
| 35 namespace internal { | 31 namespace internal { |
| 36 | 32 |
| 37 template <typename MaybeConstUserType> | 33 template <typename MaybeConstUserType> |
| 38 struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> { | 34 struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> { |
| 39 using UserType = typename std::remove_const<MaybeConstUserType>::type; | 35 using UserType = typename std::remove_const<MaybeConstUserType>::type; |
| 40 using Traits = StructTraits<{{mojom_type}}, UserType>; | 36 using Traits = StructTraits<{{mojom_type}}, UserType>; |
| 41 | 37 |
| 42 static size_t PrepareToSerialize(MaybeConstUserType& input, | 38 static size_t PrepareToSerialize(MaybeConstUserType& input, |
| 43 SerializationContext* context) { | 39 SerializationContext* context) { |
| 44 if (CallIsNullIfExists<Traits>(input)) | 40 if (CallIsNullIfExists<Traits>(input)) |
| 45 return 0; | 41 return 0; |
| 46 {{struct_macros.get_serialized_size(struct, "Traits::%s(input)", "context", | 42 |
| 47 True)|indent(2)}} | 43 void* custom_context = CustomContextHelper<Traits>::SetUp(input, context); |
| 44 ALLOW_UNUSED_LOCAL(custom_context); |
| 45 |
| 46 {{struct_macros.get_serialized_size( |
| 47 struct, "CallWithContext(Traits::%s, input, custom_context)", |
| 48 "context", True)|indent(2)}} |
| 48 return size; | 49 return size; |
| 49 } | 50 } |
| 50 | 51 |
| 51 static void Serialize(MaybeConstUserType& input, | 52 static void Serialize(MaybeConstUserType& input, |
| 52 Buffer* buffer, | 53 Buffer* buffer, |
| 53 {{data_type}}** output, | 54 {{data_type}}** output, |
| 54 SerializationContext* context) { | 55 SerializationContext* context) { |
| 55 if (!CallIsNullIfExists<Traits>(input)) { | 56 if (CallIsNullIfExists<Traits>(input)) { |
| 56 {{struct_macros.serialize(struct, struct.name ~ " struct", | |
| 57 "Traits::%s(input)", "result", "buffer", | |
| 58 "context", True)|indent(4)}} | |
| 59 *output = result; | |
| 60 } else { | |
| 61 *output = nullptr; | 57 *output = nullptr; |
| 58 return; |
| 62 } | 59 } |
| 60 |
| 61 void* custom_context = CustomContextHelper<Traits>::GetNext(context); |
| 62 |
| 63 {{struct_macros.serialize( |
| 64 struct, struct.name ~ " struct", |
| 65 "CallWithContext(Traits::%s, input, custom_context)", "result", |
| 66 "buffer", "context", True)|indent(4)}} |
| 67 *output = result; |
| 68 |
| 69 CustomContextHelper<Traits>::TearDown(input, custom_context); |
| 63 } | 70 } |
| 64 | 71 |
| 65 static bool Deserialize({{data_type}}* input, | 72 static bool Deserialize({{data_type}}* input, |
| 66 UserType* output, | 73 UserType* output, |
| 67 SerializationContext* context) { | 74 SerializationContext* context) { |
| 68 if (!input) | 75 if (!input) |
| 69 return CallSetToNullIfExists<Traits>(output); | 76 return CallSetToNullIfExists<Traits>(output); |
| 70 | 77 |
| 71 {{mojom_type}}DataView data_view(input, context); | 78 {{mojom_type}}DataView data_view(input, context); |
| 72 return Traits::Read(data_view, output); | 79 return Traits::Read(data_view, output); |
| 73 } | 80 } |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 } // namespace internal | 83 } // namespace internal |
| OLD | NEW |