{% macro _check_err() -%}
if (err !== validator.validationError.NONE)
return err;
{%- endmacro %}
{%- macro _validate_field(field, offset, name) %}
{%- if field.kind|is_string_kind %}
// validate {{name}}
err = messageValidator.validateStringPointer({{offset}}, {{field|validate_nullable_params}})
{{_check_err()}}
{%- elif field.kind|is_array_kind %}
// validate {{name}}
err = messageValidator.validateArrayPointer({{offset}}, {{field|validate_array_params}});
{{_check_err()}}
{%- elif field.kind|is_struct_kind %}
// validate {{name}}
err = messageValidator.validateStructPointer({{offset}}, {{field|validate_struct_params}});
{{_check_err()}}
{%- elif field.kind|is_map_kind %}
// validate {{name}}
err = messageValidator.validateMapPointer({{offset}}, {{field|validate_map_params}});
{{_check_err()}}
{%- elif field.kind|is_interface_kind or field.kind|is_pending_remote_kind %}
// validate {{name}}
err = messageValidator.validateInterface({{offset}}, {{field|validate_nullable_params}});
{{_check_err()}}
{%- elif field.kind|is_pending_receiver_kind %}
// validate {{name}}
err = messageValidator.validateInterfaceRequest({{offset}}, {{field|validate_nullable_params}})
{{_check_err()}}
{%- elif field.kind|is_pending_associated_remote_kind %}
// validate {{name}}
err = messageValidator.validateAssociatedInterface({{offset}}, {{field|validate_nullable_params}});
{{_check_err()}}
{%- elif field.kind|is_pending_associated_receiver_kind %}
// validate {{name}}
err = messageValidator.validateAssociatedInterfaceRequest({{offset}}, {{field|validate_nullable_params}})
{{_check_err()}}
{%- elif field.kind|is_any_handle_kind %}
// validate {{name}}
err = messageValidator.validateHandle({{offset}}, {{field|validate_nullable_params}})
{{_check_err()}}
{%- elif field.kind|is_enum_kind %}
// validate {{name}}
err = messageValidator.validateEnum({{offset}}, {{field|validate_enum_params}});
{{_check_err()}}
{%- endif %}
{%- endmacro %}
{%- macro validate_struct_field(field, offset, name) %}
{%- if field.kind|is_union_kind %}
// validate {{name}}
err = messageValidator.validateUnion({{offset}}, {{field|validate_union_params}});
{{_check_err()}}
{%- else -%}
{{_validate_field(field, offset, name)}}
{%- endif %}
{%- endmacro %}
{%- macro validate_union_field(field, offset, name) %}
{%- if field.kind|is_union_kind %}
// validate {{name}}
err = messageValidator.validateNestedUnion({{offset}}, {{field|validate_union_params}});
{{_check_err()}}
{%- else %}
{{_validate_field(field, offset, name)}}
{%- endif %}
{%- endmacro %}