| OLD | NEW |
| 1 {%- set class_name = struct.name ~ "_Data" %} | 1 {%- set class_name = struct.name ~ "_Data" %} |
| 2 | 2 |
| 3 {#- Validates the specified struct field, which is supposed to be an object | 3 {#- Validates the specified struct field, which is supposed to be an object |
| 4 (struct/array/string/map/union). | 4 (struct/array/string/map/union). |
| 5 This macro is expanded by the Validate() method. #} | 5 This macro is expanded by the Validate() method. #} |
| 6 {%- macro _validate_object(struct, packed_field) %} | 6 {%- macro _validate_object(struct, packed_field) %} |
| 7 {%- set name = packed_field.field.name %} | 7 {%- set name = packed_field.field.name %} |
| 8 {%- set kind = packed_field.field.kind %} | 8 {%- set kind = packed_field.field.kind %} |
| 9 {%- if not kind|is_nullable_kind %} | 9 {%- if not kind|is_nullable_kind %} |
| 10 {%- if kind|is_union_kind %} | 10 {%- if kind|is_union_kind %} |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (!mojo::internal::ValidateInterfaceIdNonNullable( | 84 if (!mojo::internal::ValidateInterfaceIdNonNullable( |
| 85 {{name}}_interface_id, | 85 {{name}}_interface_id, |
| 86 "invalid {{name}} field in {{struct.name}} struct")) { | 86 "invalid {{name}} field in {{struct.name}} struct")) { |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 89 {%- endif %} | 89 {%- endif %} |
| 90 if (!mojo::internal::ValidateAssociatedInterfaceId({{name}}_interface_id)) | 90 if (!mojo::internal::ValidateAssociatedInterfaceId({{name}}_interface_id)) |
| 91 return false; | 91 return false; |
| 92 {%- endmacro %} | 92 {%- endmacro %} |
| 93 | 93 |
| 94 {#- Validates the specified struct field, which is supposed to be an enum. |
| 95 This macro is expanded by the Validate() method. #} |
| 96 {%- macro _validate_enum(struct, packed_field) %} |
| 97 {%- set name = packed_field.field.name %} |
| 98 {%- set kind = packed_field.field.kind %} |
| 99 if (!mojo::internal::ValidateEnum(object->{{name}})) |
| 100 return false; |
| 101 {%- endmacro %} |
| 102 |
| 94 // static | 103 // static |
| 95 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { | 104 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { |
| 96 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); | 105 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); |
| 97 } | 106 } |
| 98 | 107 |
| 99 // static | 108 // static |
| 100 bool {{class_name}}::Validate(const void* data, | 109 bool {{class_name}}::Validate(const void* data, |
| 101 mojo::internal::BoundsChecker* bounds_checker) { | 110 mojo::internal::BoundsChecker* bounds_checker) { |
| 102 if (!data) | 111 if (!data) |
| 103 return true; | 112 return true; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 148 } |
| 140 | 149 |
| 141 {#- Before validating fields introduced at a certain version, we need to add | 150 {#- Before validating fields introduced at a certain version, we need to add |
| 142 a version check, which makes sure we skip further validation if |object| | 151 a version check, which makes sure we skip further validation if |object| |
| 143 is from an earlier version. |last_checked_version| records the last | 152 is from an earlier version. |last_checked_version| records the last |
| 144 version that we have added such version check. #} | 153 version that we have added such version check. #} |
| 145 {%- set last_checked_version = 0 %} | 154 {%- set last_checked_version = 0 %} |
| 146 {%- for packed_field in struct.packed.packed_fields_in_ordinal_order %} | 155 {%- for packed_field in struct.packed.packed_fields_in_ordinal_order %} |
| 147 {%- set kind = packed_field.field.kind %} | 156 {%- set kind = packed_field.field.kind %} |
| 148 {%- if kind|is_object_kind or kind|is_any_handle_kind or | 157 {%- if kind|is_object_kind or kind|is_any_handle_kind or |
| 149 kind|is_interface_kind or kind|is_associated_kind %} | 158 kind|is_interface_kind or kind|is_associated_kind or |
| 159 kind|is_enum_kind %} |
| 150 {%- if packed_field.min_version > last_checked_version %} | 160 {%- if packed_field.min_version > last_checked_version %} |
| 151 {%- set last_checked_version = packed_field.min_version %} | 161 {%- set last_checked_version = packed_field.min_version %} |
| 152 if (object->header_.version < {{packed_field.min_version}}) | 162 if (object->header_.version < {{packed_field.min_version}}) |
| 153 return true; | 163 return true; |
| 154 {%- endif %} | 164 {%- endif %} |
| 155 {%- if kind|is_object_kind %} | 165 {%- if kind|is_object_kind %} |
| 156 {{_validate_object(struct, packed_field)}} | 166 {{_validate_object(struct, packed_field)}} |
| 157 {%- elif kind|is_any_handle_kind or kind|is_interface_kind %} | 167 {%- elif kind|is_any_handle_kind or kind|is_interface_kind %} |
| 158 {{_validate_handle(struct, packed_field)}} | 168 {{_validate_handle(struct, packed_field)}} |
| 169 {%- elif kind|is_associated_kind %} |
| 170 {{_validate_associated(struct, packed_field)}} |
| 159 {%- else %} | 171 {%- else %} |
| 160 {{_validate_associated(struct, packed_field)}} | 172 {{_validate_enum(struct, packed_field)}} |
| 161 {%- endif %} | 173 {%- endif %} |
| 162 {%- endif %} | 174 {%- endif %} |
| 163 {%- endfor %} | 175 {%- endfor %} |
| 164 | 176 |
| 165 return true; | 177 return true; |
| 166 } | 178 } |
| 167 | 179 |
| 168 void {{class_name}}::EncodePointersAndHandles( | 180 void {{class_name}}::EncodePointersAndHandles( |
| 169 std::vector<mojo::Handle>* handles) { | 181 std::vector<mojo::Handle>* handles) { |
| 170 MOJO_CHECK(header_.version == {{struct.versions[-1].version}}); | 182 MOJO_CHECK(header_.version == {{struct.versions[-1].version}}); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 mojo::internal::DecodeHandle(&{{name}}, handles); | 217 mojo::internal::DecodeHandle(&{{name}}, handles); |
| 206 {%- endif %} | 218 {%- endif %} |
| 207 {%- endif %} | 219 {%- endif %} |
| 208 {%- endfor %} | 220 {%- endfor %} |
| 209 } | 221 } |
| 210 | 222 |
| 211 {{class_name}}::{{class_name}}() { | 223 {{class_name}}::{{class_name}}() { |
| 212 header_.num_bytes = sizeof(*this); | 224 header_.num_bytes = sizeof(*this); |
| 213 header_.version = {{struct.versions[-1].version}}; | 225 header_.version = {{struct.versions[-1].version}}; |
| 214 } | 226 } |
| OLD | NEW |