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

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

Issue 2007813004: Mojo C++ bindings: support attaching context object for StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
index 8f72cf64d82cfd7a31cc51898e4328ada99edf34..367c1522a6e25b3afc3887c8517a45e225c301e2 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl
@@ -17,10 +17,6 @@ struct StructTraits<{{mojom_type}}, {{mojom_type}}Ptr> {
{{mojom_type}}Ptr& input) {
return input->{{field.name}};
}
- static const decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
- const {{mojom_type}}Ptr& input) {
- return input->{{field.name}};
- }
{%- else %}
static decltype({{mojom_type}}::{{field.name}}) {{field.name}}(
const {{mojom_type}}Ptr& input) {
@@ -43,8 +39,13 @@ struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> {
SerializationContext* context) {
if (CallIsNullIfExists<Traits>(input))
return 0;
- {{struct_macros.get_serialized_size(struct, "Traits::%s(input)", "context",
- True)|indent(2)}}
+
+ void* custom_context = CustomContextHelper<Traits>::SetUp(input, context);
+ ALLOW_UNUSED_LOCAL(custom_context);
+
+ {{struct_macros.get_serialized_size(
+ struct, "CallWithContext(Traits::%s, input, custom_context)",
+ "context", True)|indent(2)}}
return size;
}
@@ -52,14 +53,20 @@ struct Serializer<{{mojom_type}}Ptr, MaybeConstUserType> {
Buffer* buffer,
{{data_type}}** output,
SerializationContext* context) {
- if (!CallIsNullIfExists<Traits>(input)) {
- {{struct_macros.serialize(struct, struct.name ~ " struct",
- "Traits::%s(input)", "result", "buffer",
- "context", True)|indent(4)}}
- *output = result;
- } else {
+ if (CallIsNullIfExists<Traits>(input)) {
*output = nullptr;
+ return;
}
+
+ void* custom_context = CustomContextHelper<Traits>::GetNext(context);
+
+ {{struct_macros.serialize(
+ struct, struct.name ~ " struct",
+ "CallWithContext(Traits::%s, input, custom_context)", "result",
+ "buffer", "context", True)|indent(4)}}
+ *output = result;
+
+ CustomContextHelper<Traits>::TearDown(input, custom_context);
}
static bool Deserialize({{data_type}}* input,
« no previous file with comments | « mojo/public/cpp/bindings/tests/struct_with_traits_impl_traits.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698