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

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

Issue 1524703002: [mojo] Support native types with mojom wire format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-5-pickles
Patch Set: doc 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 size_t GetSerializedSize_(const {{struct.name}}Ptr& input); 1 size_t GetSerializedSize_(const {{struct.name}}Ptr& input);
2 void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buffer, 2 void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buffer,
3 internal::{{struct.name}}_Data** output); 3 internal::{{struct.name}}_Data** output);
4 bool Deserialize_(internal::{{struct.name}}_Data* input, 4 bool Deserialize_(internal::{{struct.name}}_Data* input,
5 {{struct.name}}Ptr* output, 5 {{struct.name}}Ptr* output,
6 mojo::internal::SerializationContext* context); 6 mojo::internal::SerializationContext* context);
7
8 {%- if not variant %}
9
10 {# NOTE: Generated Reader instances are intentionally cheap to copy and devoid
11 of heap allocations. They should stay this way. #}
12 class {{struct.name}}_Reader {
13 public:
14 {{struct.name}}_Reader(internal::{{struct.name}}_Data* data,
15 mojo::internal::SerializationContext* context);
16
17 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
18 {%- set kind = pf.field.kind -%}
19 {%- set name = pf.field.name -%}
20 {%- if kind|is_struct_kind %}
21 {{kind|get_name_for_kind}}::Reader {{name}}() const;
22 {%- elif kind|is_union_kind %}
23 // TODO(rockot): Support reading unions. ({{name}}() omitted)
24 {%- elif kind|is_object_kind %}
25 // TODO(rockot): Support reading other object kinds. ({{name}}() omitted)
26 {%- elif kind|is_any_handle_kind %}
27 // TODO(rockot): Support reading handles. ({{name}}() omitted)
28 {%- elif kind|is_interface_kind %}
29 // TODO(rockot): Support reading interfaces. ({{name}}() omitted)
30 {%- elif kind|is_interface_request_kind %}
31 // TODO(rockot): Support reading interface requests. ({{name}}() omitted)
32 {%- elif kind|is_associated_kind %}
33 // TODO(rockot): Support reading associated kinds. ({{name}}() omitted)
34 {%- elif kind|is_enum_kind %}
35 {{kind|cpp_result_type}} {{name}}() const {
36 return static_cast<{{kind|cpp_result_type}}>(data_->{{name}});
37 }
38 {%- else %}
39 {{kind|cpp_result_type}} {{name}}() const { return data_->{{name}}; }
40 {%- endif %}
41 {%- endfor %}
42
43 private:
44 internal::{{struct.name}}_Data* data_;
45 mojo::internal::SerializationContext* context_;
46 };
47
48 template <typename NativeType>
49 struct {{struct.name}}_SerializerTraits_ {
50 static size_t GetSize(const NativeType& input) {
51 size_t size = sizeof(internal::{{struct.name}}_Data);
52 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
53 {%- if pf.field.kind|is_object_kind %}
54 NOTREACHED() << "Mojom struct traits only support POD fields at this time. "
55 << "Cannot determine the size of field {{pf.field.name}}";
56 {%- endif %}
57 {%- endfor %}
58 return size;
59 }
60
61 static void Serialize(const NativeType& input,
62 mojo::internal::Buffer* buffer,
63 internal::{{struct.name}}_Data** output) {
64 internal::{{struct.name}}_Data* result =
65 internal::{{struct.name}}_Data::New(buffer);
66 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
67 {%- set name = pf.field.name -%}
68 {%- set kind = pf.field.kind %}
69 result->{{name}} = mojo::StructTraits<{{struct.name}}, NativeType>
70 ::{{name}}(input);
71 {%- endfor %}
72 *output = result;
73 }
74
75 static bool Deserialize(internal::{{struct.name}}_Data* input,
76 NativeType* output,
77 mojo::internal::SerializationContext* context) {
78 return mojo::StructTraits<{{struct.name}}, NativeType>::Read(
79 {{struct.name}}_Reader(input, context), output);
80 }
81 };
82
83 {%- endif %} {# not variant #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698