OLD | NEW |
---|---|
1 {%- macro validate(struct, class_name) %} | 1 {%- macro validate(struct, class_name) %} |
2 if (!data) | 2 if (!data) |
3 return true; | 3 return true; |
4 | 4 |
5 if (!ValidateStructHeader( | 5 if (!ValidateStructHeader( |
6 data, sizeof({{class_name}}), | 6 data, sizeof({{class_name}}), |
7 {{struct.packed.packed_fields|length}}, bounds_checker)) { | 7 {{struct.packed.packed_fields|length}}, bounds_checker)) { |
8 return false; | 8 return false; |
9 } | 9 } |
10 | 10 |
11 const {{class_name}}* object = static_cast<const {{class_name}}*>(data); | 11 const {{class_name}}* object = static_cast<const {{class_name}}*>(data); |
12 MOJO_ALLOW_UNUSED_LOCAL(object); | 12 MOJO_ALLOW_UNUSED_LOCAL(object); |
13 | 13 |
14 {%- for packed_field in struct.packed.packed_fields %} | 14 {%- for packed_field in struct.packed.packed_fields %} |
15 {%- set name = packed_field.field.name %} | 15 {%- set name = packed_field.field.name %} |
16 {%- set kind = packed_field.field.kind %} | 16 {%- set kind = packed_field.field.kind %} |
17 {%- if kind|is_object_kind %} | 17 {%- if kind|is_union_kind %} |
18 {%- if not kind|is_nullable_kind %} | |
yzshen1
2015/02/17 19:34:35
(Please note that this part has been under signifi
azani
2015/02/18 00:27:57
Done.
| |
19 if (object->{{name}}.is_null()) { | |
20 ReportValidationError( | |
21 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | |
22 "null {{name}} field in {{struct.name}} struct"); | |
23 return false; | |
24 } | |
25 {%- endif %} | |
26 // We already claimed the union's memory as part of the struct, so we don't | |
27 // try to claim the union's memory when validating the union. | |
28 if (!{{kind.name}}::Data_::Validate(&object->{{name}}, bounds_checker, false)) { | |
yzshen1
2015/02/17 19:34:35
Do you think it make sense to make |false| a templ
azani
2015/02/18 00:27:57
It seems like we would just shift the inconsistenc
| |
29 return false; | |
30 } | |
31 {%- elif kind|is_object_kind %} | |
18 {%- set wrapper_type = kind|cpp_wrapper_type %} | 32 {%- set wrapper_type = kind|cpp_wrapper_type %} |
19 {%- if not kind|is_nullable_kind %} | 33 {%- if not kind|is_nullable_kind %} |
20 if (!object->{{name}}.offset) { | 34 if (!object->{{name}}.offset) { |
21 ReportValidationError( | 35 ReportValidationError( |
22 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 36 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
23 "null {{name}} field in {{struct.name}} struct"); | 37 "null {{name}} field in {{struct.name}} struct"); |
24 return false; | 38 return false; |
25 } | 39 } |
26 {%- endif %} | 40 {%- endif %} |
27 if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) { | 41 if (!mojo::internal::ValidateEncodedPointer(&object->{{name}}.offset)) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 {%- set offset = last_field.offset + last_field.size %} | 112 {%- set offset = last_field.offset + last_field.size %} |
99 {%- set pad = offset|get_pad(8) -%} | 113 {%- set pad = offset|get_pad(8) -%} |
100 {%- if pad > 0 %} | 114 {%- if pad > 0 %} |
101 uint8_t padfinal_[{{pad}}]; | 115 uint8_t padfinal_[{{pad}}]; |
102 {%- endif %} | 116 {%- endif %} |
103 {%- endif %} | 117 {%- endif %} |
104 {%- endmacro %} | 118 {%- endmacro %} |
105 | 119 |
106 {%- macro encodes(struct) -%} | 120 {%- macro encodes(struct) -%} |
107 {%- for pf in struct.packed.packed_fields %} | 121 {%- for pf in struct.packed.packed_fields %} |
108 {%- if pf.field.kind|is_object_kind %} | 122 {%- if pf.field.kind|is_union_kind %} |
123 // TODO(azani): Encode pointers and handles. | |
124 {%- elif pf.field.kind|is_object_kind %} | |
109 mojo::internal::Encode(&{{pf.field.name}}, handles); | 125 mojo::internal::Encode(&{{pf.field.name}}, handles); |
110 {%- elif pf.field.kind|is_any_handle_kind %} | 126 {%- elif pf.field.kind|is_any_handle_kind %} |
111 mojo::internal::EncodeHandle(&{{pf.field.name}}, handles); | 127 mojo::internal::EncodeHandle(&{{pf.field.name}}, handles); |
112 {%- endif %} | 128 {%- endif %} |
113 {%- endfor %} | 129 {%- endfor %} |
114 {%- endmacro -%} | 130 {%- endmacro -%} |
115 | 131 |
116 {%- macro decodes(struct) -%} | 132 {%- macro decodes(struct) -%} |
117 {%- for pf in struct.packed.packed_fields %} | 133 {%- for pf in struct.packed.packed_fields %} |
118 {%- if pf.field.kind|is_object_kind %} | 134 {%- if pf.field.kind|is_union_kind %} |
135 // TODO(azani): Decode pointers and handles. | |
136 {%- elif pf.field.kind|is_object_kind %} | |
119 mojo::internal::Decode(&{{pf.field.name}}, handles); | 137 mojo::internal::Decode(&{{pf.field.name}}, handles); |
120 {%- elif pf.field.kind|is_any_handle_kind %} | 138 {%- elif pf.field.kind|is_any_handle_kind %} |
121 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); | 139 mojo::internal::DecodeHandle(&{{pf.field.name}}, handles); |
122 {%- endif %} | 140 {%- endif %} |
123 {%- endfor %} | 141 {%- endfor %} |
124 {%- endmacro -%} | 142 {%- endmacro -%} |
OLD | NEW |