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

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

Issue 289333002: Mojo cpp bindings: validation logic for incoming messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 {%- import "struct_macros.tmpl" as struct_macros %} 1 {%- import "struct_macros.tmpl" as struct_macros %}
2 {%- set class_name = struct.name ~ "_Data" %} 2 {%- set class_name = struct.name ~ "_Data" %}
3 class {{class_name}} { 3 class {{class_name}} {
4 public: 4 public:
5 static {{class_name}}* New(mojo::internal::Buffer* buf) { 5 static {{class_name}}* New(mojo::internal::Buffer* buf) {
6 return new (buf->Allocate(sizeof({{class_name}}))) 6 return new (buf->Allocate(sizeof({{class_name}})))
7 {{class_name}}(); 7 {{class_name}}();
8 } 8 }
9 9
10 static bool Validate(const void* data,
11 mojo::internal::BoundsChecker* bounds_checker) {
12 {{ struct_macros.validate(struct, class_name)|indent(4) }}
13 }
14
10 mojo::internal::StructHeader header_; 15 mojo::internal::StructHeader header_;
11 {{struct_macros.fields(struct)}} 16 {{struct_macros.fields(struct)}}
12 17
13 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles) { 18 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles) {
14 {{ struct_macros.encodes(struct)|indent(4) }} 19 {{ struct_macros.encodes(struct)|indent(4) }}
15 } 20 }
16 21
17 bool DecodePointersAndHandles(mojo::Message* message) { 22 bool DecodePointersAndHandles(mojo::Message* message) {
18 {{ struct_macros.decodes(struct)|indent(4) }} 23 {{ struct_macros.decodes(struct)|indent(4) }}
19 return true; 24 return true;
20 } 25 }
21 26
22 private: 27 private:
23 {{class_name}}() { 28 {{class_name}}() {
24 header_.num_bytes = sizeof(*this); 29 header_.num_bytes = sizeof(*this);
25 header_.num_fields = {{struct.packed.packed_fields|length}}; 30 header_.num_fields = {{struct.packed.packed_fields|length}};
26 } 31 }
27 }; 32 };
28 MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}}, 33 MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}},
29 bad_sizeof_{{class_name}}); 34 bad_sizeof_{{class_name}});
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698