Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl

Issue 1968623002: Mojo C++ bindings: expose public <struct>DataView and StringDataView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@25_totally_new
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698