Index: mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl |
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl |
index 6a8254949795698009140db45bd03393bedcc70c..ecb64800289dcf1521b8e9b83f028657faea74b9 100644 |
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl |
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl |
@@ -91,6 +91,15 @@ |
return false; |
{%- endmacro %} |
+{#- Validates the specified struct field, which is supposed to be an enum. |
+ This macro is expanded by the Validate() method. #} |
+{%- macro _validate_enum(struct, packed_field) %} |
+{%- set name = packed_field.field.name %} |
+{%- set kind = packed_field.field.kind %} |
+ if (!mojo::internal::ValidateEnum(object->{{name}})) |
+ return false; |
+{%- endmacro %} |
+ |
// static |
{{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { |
return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); |
@@ -146,7 +155,8 @@ bool {{class_name}}::Validate(const void* data, |
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %} |
{%- set kind = packed_field.field.kind %} |
{%- if kind|is_object_kind or kind|is_any_handle_kind or |
- kind|is_interface_kind or kind|is_associated_kind %} |
+ kind|is_interface_kind or kind|is_associated_kind or |
+ kind|is_enum_kind %} |
{%- if packed_field.min_version > last_checked_version %} |
{%- set last_checked_version = packed_field.min_version %} |
if (object->header_.version < {{packed_field.min_version}}) |
@@ -156,8 +166,10 @@ bool {{class_name}}::Validate(const void* data, |
{{_validate_object(struct, packed_field)}} |
{%- elif kind|is_any_handle_kind or kind|is_interface_kind %} |
{{_validate_handle(struct, packed_field)}} |
-{%- else %} |
+{%- elif kind|is_associated_kind %} |
{{_validate_associated(struct, packed_field)}} |
+{%- else %} |
+{{_validate_enum(struct, packed_field)}} |
{%- endif %} |
{%- endif %} |
{%- endfor %} |