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

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

Issue 1520153002: [mojo] Allow value deserialization to fail (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-3-misc-support
Patch Set: merge Created 5 years 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 size_t GetSerializedSize_(const {{struct.name}}Ptr& input) { 2 size_t GetSerializedSize_(const {{struct.name}}Ptr& input) {
3 if (!input) 3 if (!input)
4 return 0; 4 return 0;
5 {{struct_macros.get_serialized_size(struct, "input->%s")}} 5 {{struct_macros.get_serialized_size(struct, "input->%s")}}
6 return size; 6 return size;
7 } 7 }
8 8
9 void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buf, 9 void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buf,
10 internal::{{struct.name}}_Data** output) { 10 internal::{{struct.name}}_Data** output) {
11 if (input) { 11 if (input) {
12 {{struct_macros.serialize(struct, struct.name ~ " struct", "input->%s", "res ult", "buf")|indent(2)}} 12 {{struct_macros.serialize(struct, struct.name ~ " struct", "input->%s", "res ult", "buf")|indent(2)}}
13 *output = result; 13 *output = result;
14 } else { 14 } else {
15 *output = nullptr; 15 *output = nullptr;
16 } 16 }
17 } 17 }
18 18
19 void Deserialize_(internal::{{struct.name}}_Data* input, 19 bool Deserialize_(internal::{{struct.name}}_Data* input,
20 {{struct.name}}Ptr* output, 20 {{struct.name}}Ptr* output,
21 mojo::internal::SerializationContext* context) { 21 mojo::internal::SerializationContext* context) {
22 bool success = true;
22 if (input) { 23 if (input) {
23 {{struct.name}}Ptr result({{struct.name}}::New()); 24 {{struct.name}}Ptr result({{struct.name}}::New());
24 {{struct_macros.deserialize(struct, "input", "result->%s", "context")|indent (2)}} 25 {{struct_macros.deserialize(struct, "input", "result->%s", "context", "succe ss")|indent(2)}}
25 *output = result.Pass(); 26 *output = result.Pass();
26 } else { 27 } else {
27 output->reset(); 28 output->reset();
28 } 29 }
30 return success;
29 } 31 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698