| 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 | 8 |
| 9 {%- for field in struct.fields %} | 9 {%- for field in struct.fields %} |
| 10 {%- set return_ref = field.kind|is_object_kind or | 10 {%- set return_ref = field.kind|is_object_kind or |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 return input->{{field.name}}; | 21 return input->{{field.name}}; |
| 22 } | 22 } |
| 23 {%- else %} | 23 {%- else %} |
| 24 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( | 24 static decltype({{mojom_type}}::{{field.name}}) {{field.name}}( |
| 25 const {{mojom_type}}Ptr& input) { | 25 const {{mojom_type}}Ptr& input) { |
| 26 return input->{{field.name}}; | 26 return input->{{field.name}}; |
| 27 } | 27 } |
| 28 {%- endif %} | 28 {%- endif %} |
| 29 {%- endfor %} | 29 {%- endfor %} |
| 30 | 30 |
| 31 static bool ReadFromRawData({{data_type}}* input, | 31 static bool ReadFromDataView({{mojom_type}}DataView input, |
| 32 {{mojom_type}}Ptr* output, | 32 {{mojom_type}}Ptr* output); |
| 33 internal::SerializationContext* context); | |
| 34 }; | 33 }; |
| 35 | 34 |
| 36 namespace internal { | 35 namespace internal { |
| 37 | 36 |
| 38 template <typename MaybeConstUserType> | 37 template <typename MaybeConstUserType> |
| 39 struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> { | 38 struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> { |
| 40 using UserType = typename std::remove_const<MaybeConstUserType>::type; | 39 using UserType = typename std::remove_const<MaybeConstUserType>::type; |
| 41 using Traits = StructTraits<{{mojom_type}}, UserType>; | 40 using Traits = StructTraits<{{mojom_type}}, UserType>; |
| 42 | 41 |
| 43 static size_t PrepareToSerialize(MaybeConstUserType& input, | 42 static size_t PrepareToSerialize(MaybeConstUserType& input, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 59 "context", True)|indent(4)}} | 58 "context", True)|indent(4)}} |
| 60 *output = result; | 59 *output = result; |
| 61 } else { | 60 } else { |
| 62 *output = nullptr; | 61 *output = nullptr; |
| 63 } | 62 } |
| 64 } | 63 } |
| 65 | 64 |
| 66 static bool Deserialize({{data_type}}* input, | 65 static bool Deserialize({{data_type}}* input, |
| 67 UserType* output, | 66 UserType* output, |
| 68 SerializationContext* context) { | 67 SerializationContext* context) { |
| 69 return ReadCaller<Traits, HasReadFromRawDataMethod<Traits>::value>::Run( | 68 return ReadCaller<Traits, HasReadFromDataViewMethod<Traits>::value>::Run( |
| 70 input, output, context); | 69 input, output, context); |
| 71 } | 70 } |
| 72 | 71 |
| 73 | 72 |
| 74 public: | 73 public: |
| 75 template <typename Traits, bool use_read_from_raw_data> | 74 template <typename Traits, bool use_read_from_data_view> |
| 76 struct ReadCaller; | 75 struct ReadCaller; |
| 77 | 76 |
| 78 template <typename Traits> | 77 template <typename Traits> |
| 79 struct ReadCaller<Traits, false> { | 78 struct ReadCaller<Traits, false> { |
| 80 static bool Run({{data_type}}* input, | 79 static bool Run({{data_type}}* input, |
| 81 UserType* output, | 80 UserType* output, |
| 82 SerializationContext* context) { | 81 SerializationContext* context) { |
| 83 {{mojom_type}}_Reader reader(input, context); | 82 {{mojom_type}}_Reader reader(input, context); |
| 84 return Traits::Read(reader, output); | 83 return Traits::Read(reader, output); |
| 85 } | 84 } |
| 86 }; | 85 }; |
| 87 | 86 |
| 88 template <typename Traits> | 87 template <typename Traits> |
| 89 struct ReadCaller<Traits, true> { | 88 struct ReadCaller<Traits, true> { |
| 90 static bool Run({{data_type}}* input, | 89 static bool Run({{data_type}}* input, |
| 91 UserType* output, | 90 UserType* output, |
| 92 SerializationContext* context) { | 91 SerializationContext* context) { |
| 93 return Traits::ReadFromRawData(input, output, context); | 92 {{mojom_type}}DataView data_view(input, context); |
| 93 return Traits::ReadFromDataView(data_view, output); |
| 94 } | 94 } |
| 95 }; | 95 }; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } // namespace internal | 98 } // namespace internal |
| OLD | NEW |