| // chromeos/services/machine_learning/public/mojom/tensor.mojom-shared.cc is auto generated by mojom_bindings_generator.py, do not edit |
| |
| // Copyright 2016 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "chromeos/services/machine_learning/public/mojom/tensor.mojom-shared.h" |
| |
| // Used to support stream output operator for enums. |
| // TODO(dcheng): Consider omitting this somehow if not needed. |
| #include <ostream> |
| #include <utility> |
| |
| #include "base/strings/stringprintf.h" |
| #include "mojo/public/cpp/bindings/lib/validate_params.h" |
| #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
| #include "mojo/public/cpp/bindings/lib/validation_util.h" |
| #include "third_party/perfetto/include/perfetto/tracing/traced_value.h" |
| |
| #include "chromeos/services/machine_learning/public/mojom/tensor.mojom-params-data.h" |
| namespace chromeos { |
| namespace machine_learning { |
| namespace mojom { |
| |
| namespace internal { |
| // static |
| bool ValueList_Data::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context, |
| bool inlined) { |
| if (!data) { |
| DCHECK(!inlined); |
| return true; |
| } |
| |
| // If it is inlined, the alignment is already enforced by its enclosing |
| // object. We don't have to validate that. |
| DCHECK(!inlined || mojo::internal::IsAligned(data)); |
| |
| if (!inlined && |
| !mojo::internal::ValidateNonInlinedUnionHeaderAndClaimMemory( |
| data, validation_context)) { |
| return false; |
| } |
| |
| const ValueList_Data* object = static_cast<const ValueList_Data*>(data); |
| |
| if (inlined && object->is_null()) |
| return true; |
| |
| switch (object->tag) { |
| |
| case ValueList_Tag::kStringList: { |
| |
| if (!mojo::internal::ValidatePointerNonNullable( |
| object->data.f_string_list, 1, validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateStruct(object->data.f_string_list, validation_context)) |
| return false; |
| return true; |
| } |
| case ValueList_Tag::kFloatList: { |
| |
| if (!mojo::internal::ValidatePointerNonNullable( |
| object->data.f_float_list, 2, validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateStruct(object->data.f_float_list, validation_context)) |
| return false; |
| return true; |
| } |
| case ValueList_Tag::kInt64List: { |
| |
| if (!mojo::internal::ValidatePointerNonNullable( |
| object->data.f_int64_list, 3, validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateStruct(object->data.f_int64_list, validation_context)) |
| return false; |
| return true; |
| } |
| default: { |
| |
| ReportValidationError( |
| validation_context, |
| mojo::internal::VALIDATION_ERROR_UNKNOWN_UNION_TAG, |
| "unknown tag in ValueList"); |
| return false; |
| } |
| } |
| } |
| |
| |
| // static |
| bool StringList_Data::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| if (!data) |
| return true; |
| if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory( |
| data, 16, validation_context)) { |
| return false; |
| } |
| |
| // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if |
| // the message comes from an older version. |
| [[maybe_unused]] const StringList_Data* object = |
| static_cast<const StringList_Data*>(data); |
| |
| if (!mojo::internal::ValidatePointerNonNullable( |
| object->value, 1, validation_context)) { |
| return false; |
| } |
| const mojo::internal::ContainerValidateParams value_validate_params( |
| 0, false, new mojo::internal::ContainerValidateParams(0, false, nullptr)); |
| if (!mojo::internal::ValidateContainer(object->value, validation_context, |
| &value_validate_params)) { |
| return false; |
| } |
| |
| return true; |
| } |
| |
| StringList_Data::StringList_Data() |
| : header_({sizeof(*this), 0}) {} |
| |
| |
| // static |
| bool FloatList_Data::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| if (!data) |
| return true; |
| if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory( |
| data, 16, validation_context)) { |
| return false; |
| } |
| |
| // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if |
| // the message comes from an older version. |
| [[maybe_unused]] const FloatList_Data* object = |
| static_cast<const FloatList_Data*>(data); |
| |
| if (!mojo::internal::ValidatePointerNonNullable( |
| object->value, 1, validation_context)) { |
| return false; |
| } |
| const mojo::internal::ContainerValidateParams value_validate_params( |
| 0, false, nullptr); |
| if (!mojo::internal::ValidateContainer(object->value, validation_context, |
| &value_validate_params)) { |
| return false; |
| } |
| |
| return true; |
| } |
| |
| FloatList_Data::FloatList_Data() |
| : header_({sizeof(*this), 0}) {} |
| |
| |
| // static |
| bool Int64List_Data::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| if (!data) |
| return true; |
| if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory( |
| data, 16, validation_context)) { |
| return false; |
| } |
| |
| // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if |
| // the message comes from an older version. |
| [[maybe_unused]] const Int64List_Data* object = |
| static_cast<const Int64List_Data*>(data); |
| |
| if (!mojo::internal::ValidatePointerNonNullable( |
| object->value, 1, validation_context)) { |
| return false; |
| } |
| const mojo::internal::ContainerValidateParams value_validate_params( |
| 0, false, nullptr); |
| if (!mojo::internal::ValidateContainer(object->value, validation_context, |
| &value_validate_params)) { |
| return false; |
| } |
| |
| return true; |
| } |
| |
| Int64List_Data::Int64List_Data() |
| : header_({sizeof(*this), 0}) {} |
| |
| |
| // static |
| bool Tensor_Data::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| if (!data) |
| return true; |
| if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory( |
| data, 32, validation_context)) { |
| return false; |
| } |
| |
| // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if |
| // the message comes from an older version. |
| [[maybe_unused]] const Tensor_Data* object = |
| static_cast<const Tensor_Data*>(data); |
| |
| if (!mojo::internal::ValidateInlinedUnionNonNullable( |
| object->data, 1, validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateInlinedUnion(object->data, validation_context)) |
| return false; |
| |
| if (!mojo::internal::ValidatePointerNonNullable( |
| object->shape, 2, validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateStruct(object->shape, validation_context)) |
| return false; |
| |
| return true; |
| } |
| |
| Tensor_Data::Tensor_Data() |
| : header_({sizeof(*this), 0}) {} |
| |
| } // namespace internal |
| } // namespace mojom |
| } // namespace machine_learning |
| } // namespace chromeos |