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

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

Issue 289333002: Mojo cpp bindings: validation logic for incoming messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify BoundsChecker 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 3
4 // static 4 // static
5 {{class_name}}* {{class_name}}::New(mojo::Buffer* buf, mojo::Buffer::Destructor dtor) { 5 {{class_name}}* {{class_name}}::New(mojo::Buffer* buf, mojo::Buffer::Destructor dtor) {
6 return new (buf->Allocate(sizeof({{class_name}}), dtor)) {{class_name}}(); 6 return new (buf->Allocate(sizeof({{class_name}}), dtor)) {{class_name}}();
7 } 7 }
8 8
9 // static
10 bool {{class_name}}::Validate(const void* data,
11 mojo::internal::BoundsChecker* bounds_checker) {
12 {{ struct_macros.validate(struct, class_name)|indent(2) }}
13 }
14
9 {{class_name}}::{{class_name}}() { 15 {{class_name}}::{{class_name}}() {
10 _header_.num_bytes = sizeof(*this); 16 _header_.num_bytes = sizeof(*this);
11 _header_.num_fields = {{struct.packed.packed_fields|length}}; 17 _header_.num_fields = {{struct.packed.packed_fields|length}};
12 } 18 }
13 19
14 size_t {{class_name}}::ComputeSize() const { 20 size_t {{class_name}}::ComputeSize() const {
15 size_t result = sizeof(*this); 21 size_t result = sizeof(*this);
16 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} 22 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
17 if ({{pf.field.name}}_.ptr) 23 if ({{pf.field.name}}_.ptr)
18 result += {{pf.field.name}}_.ptr->ComputeSize(); 24 result += {{pf.field.name}}_.ptr->ComputeSize();
(...skipping 26 matching lines...) Expand all
45 51
46 void {{class_name}}::EncodePointersAndHandles( 52 void {{class_name}}::EncodePointersAndHandles(
47 std::vector<mojo::Handle>* handles) { 53 std::vector<mojo::Handle>* handles) {
48 {{ struct_macros.encodes(struct)|indent(2) }} 54 {{ struct_macros.encodes(struct)|indent(2) }}
49 } 55 }
50 56
51 bool {{class_name}}::DecodePointersAndHandles(mojo::Message* message) { 57 bool {{class_name}}::DecodePointersAndHandles(mojo::Message* message) {
52 {{ struct_macros.decodes(struct)|indent(2) }} 58 {{ struct_macros.decodes(struct)|indent(2) }}
53 return true; 59 return true;
54 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698