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

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

Issue 2637393002: Make mojom-generated C++ string constants really constant. (Closed)
Patch Set: Created 3 years, 11 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
OLDNEW
1 {%- import "validation_macros.tmpl" as validation_macros %} 1 {%- import "validation_macros.tmpl" as validation_macros %}
2 {%- set class_name = struct.name ~ "_Data" %} 2 {%- set class_name = struct.name ~ "_Data" %}
3 3
4 // static 4 // static
5 bool {{class_name}}::Validate( 5 bool {{class_name}}::Validate(
6 const void* data, 6 const void* data,
7 mojo::internal::ValidationContext* validation_context) { 7 mojo::internal::ValidationContext* validation_context) {
8 if (!data) 8 if (!data)
9 return true; 9 return true;
10 10
11 if (!ValidateStructHeaderAndClaimMemory(data, validation_context)) 11 if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
12 return false; 12 return false;
13 13
14 // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if 14 // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
15 // the message comes from an older version. 15 // the message comes from an older version.
16 const {{class_name}}* object = static_cast<const {{class_name}}*>(data); 16 const {{class_name}}* object = static_cast<const {{class_name}}*>(data);
17 17
18 static const struct { 18 static constexpr struct {
19 uint32_t version; 19 uint32_t version;
20 uint32_t num_bytes; 20 uint32_t num_bytes;
21 } kVersionSizes[] = { 21 } kVersionSizes[] = {
22 {%- for version in struct.versions -%} 22 {%- for version in struct.versions -%}
23 { {{version.version}}, {{version.num_bytes}} }{% if not loop.last %}, {% end if -%} 23 { {{version.version}}, {{version.num_bytes}} }{% if not loop.last %}, {% end if -%}
24 {%- endfor -%} 24 {%- endfor -%}
25 }; 25 };
26 26
27 if (object->header_.version <= 27 if (object->header_.version <=
28 kVersionSizes[arraysize(kVersionSizes) - 1].version) { 28 kVersionSizes[arraysize(kVersionSizes) - 1].version) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return true; 61 return true;
62 {%- endif %} 62 {%- endif %}
63 {%- set field_expr = "object->" ~ packed_field.field.name %} 63 {%- set field_expr = "object->" ~ packed_field.field.name %}
64 {{validation_macros.validate_field(packed_field.field, field_expr, struct.name, true)}} 64 {{validation_macros.validate_field(packed_field.field, field_expr, struct.name, true)}}
65 {%- endif %} 65 {%- endif %}
66 {%- endfor %} 66 {%- endfor %}
67 67
68 return true; 68 return true;
69 } 69 }
70 70
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698