Index: mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl |
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl |
index 8b82f7f404206e492e905bf85c96a6f486628fb8..18573432a8959f5cd0d43c66982f99b1ef857321 100644 |
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl |
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl |
@@ -1,8 +1,8 @@ |
size_t GetSerializedSize_(const {{union.name}}Ptr& input) { |
+ size_t size = sizeof(internal::{{union.name}}_Data); |
if (!input) |
- return 0; |
+ return size; |
yzshen1
2015/03/26 07:30:15
I think this is incorrect.
When a struct calculate
azani
2015/03/26 22:27:40
Removed that function because it was unused and th
yzshen1
2015/03/27 16:26:33
It seems the problem is not addressed. You could t
yzshen1
2015/03/27 21:52:42
This comment is not addressed.
azani
2015/03/30 22:21:03
Sorry, I finally understood what you meant. I've a
yzshen1
2015/03/30 22:55:18
It seems better to follow the same style as Serial
|
- size_t size = sizeof(internal::{{union.name}}_Data); |
switch (input->which()) { |
{% for field in union.fields %} |
{% if field.kind|is_string_kind %} |
@@ -17,14 +17,26 @@ size_t GetSerializedSize_(const {{union.name}}Ptr& input) { |
return size; |
} |
+size_t GetUnionInUnionSerializedSize_(const {{union.name}}Ptr& input) { |
yzshen1
2015/03/26 07:30:15
The names seem confusing.
Maybe we should just fol
azani
2015/03/26 22:27:40
It was unused, so this was premature anyways.
|
+ if (!input) |
+ return 0; |
-void Serialize_({{union.name}}Ptr input, mojo::internal::Buffer* buf, |
- internal::{{union.name}}_Data** output) { |
+ return GetSerializedSize_(input); |
+} |
+ |
+void SerializeUnion_({{union.name}}Ptr input, mojo::internal::Buffer* buf, |
+ internal::{{union.name}}_Data** output, bool inlined) { |
+ internal::{{union.name}}_Data* result = nullptr; |
+ if (inlined) { |
+ result = *output; |
+ } else { |
+ result = internal::{{union.name}}_Data::New(buf); |
+ } |
if (input) { |
mojo::internal::UnionAccessor<{{union.name}}> input_acc(input.get()); |
- internal::{{union.name}}_Data* result = |
- internal::{{union.name}}_Data::New(buf); |
// TODO(azani): Handle unknown and objects. |
+ // Set the not-null flag. |
+ result->size = 16; |
result->tag = input->which(); |
switch (input->which()) { |
{% for field in union.fields %} |
@@ -38,15 +50,13 @@ void Serialize_({{union.name}}Ptr input, mojo::internal::Buffer* buf, |
break; |
{%- endfor %} |
} |
- *output = result; |
- } else { |
- *output = nullptr; |
} |
+ *output = result; |
} |
void Deserialize_(internal::{{union.name}}_Data* input, |
{{union.name}}Ptr* output) { |
- if (input) { |
+ if (input && !input->is_null()) { |
{{union.name}}Ptr result({{union.name}}::New()); |
mojo::internal::UnionAccessor<{{union.name}}> result_acc(result.get()); |
switch (input->tag) { |