| // 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. |
| |
| #ifndef MOJO_PUBLIC_INTERFACES_BINDINGS_TESTS_VERSIONING_TEST_SERVICE_MOJOM_SHARED_H_ |
| #define MOJO_PUBLIC_INTERFACES_BINDINGS_TESTS_VERSIONING_TEST_SERVICE_MOJOM_SHARED_H_ |
| |
| #include <stdint.h> |
| |
| #include <functional> |
| #include <ostream> |
| #include <type_traits> |
| #include <utility> |
| |
| #include "base/compiler_specific.h" |
| #include "base/containers/flat_map.h" |
| #include "mojo/public/cpp/bindings/array_data_view.h" |
| #include "mojo/public/cpp/bindings/enum_traits.h" |
| #include "mojo/public/cpp/bindings/interface_data_view.h" |
| #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| #include "mojo/public/cpp/bindings/lib/serialization.h" |
| #include "mojo/public/cpp/bindings/map_data_view.h" |
| #include "mojo/public/cpp/bindings/string_data_view.h" |
| #include "mojo/public/interfaces/bindings/tests/versioning_test_service.mojom-shared-internal.h" |
| |
| #include "mojo/public/cpp/bindings/lib/interface_serialization.h" |
| |
| |
| #include "mojo/public/cpp/bindings/native_enum.h" |
| #include "mojo/public/cpp/bindings/lib/native_struct_serialization.h" |
| |
| #ifdef KYTHE_IS_RUNNING |
| #pragma kythe_inline_metadata "Metadata comment" |
| #endif |
| |
| |
| namespace mojo { |
| namespace test { |
| namespace versioning { |
| class DateDataView; |
| |
| class EmployeeDataView; |
| |
| |
| |
| } // namespace versioning |
| } // namespace test |
| } // namespace mojo |
| |
| namespace mojo { |
| namespace internal { |
| |
| template <> |
| struct MojomTypeTraits<::mojo::test::versioning::DateDataView> { |
| using Data = ::mojo::test::versioning::internal::Date_Data; |
| using DataAsArrayElement = Pointer<Data>; |
| static constexpr MojomTypeCategory category = MojomTypeCategory::STRUCT; |
| }; |
| |
| template <> |
| struct MojomTypeTraits<::mojo::test::versioning::EmployeeDataView> { |
| using Data = ::mojo::test::versioning::internal::Employee_Data; |
| using DataAsArrayElement = Pointer<Data>; |
| static constexpr MojomTypeCategory category = MojomTypeCategory::STRUCT; |
| }; |
| |
| } // namespace internal |
| } // namespace mojo |
| |
| |
| namespace mojo { |
| namespace test { |
| namespace versioning { |
| |
| |
| // @generated_from: mojo.test.versioning.Department |
| enum class Department : int32_t { |
| |
| // @generated_from: mojo.test.versioning.Department.SALES |
| SALES, |
| |
| // @generated_from: mojo.test.versioning.Department.DEV |
| DEV, |
| kMinValue = 0, |
| kMaxValue = 1, |
| }; |
| |
| std::ostream& operator<<(std::ostream& os, Department value); |
| inline bool IsKnownEnumValue(Department value) { |
| return internal::Department_Data::IsKnownValue( |
| static_cast<int32_t>(value)); |
| } |
| // Interface base classes. They are used for type safety check. |
| class HumanResourceDatabaseInterfaceBase {}; |
| |
| using HumanResourceDatabasePtrDataView = |
| mojo::InterfacePtrDataView<HumanResourceDatabaseInterfaceBase>; |
| using HumanResourceDatabaseRequestDataView = |
| mojo::InterfaceRequestDataView<HumanResourceDatabaseInterfaceBase>; |
| using HumanResourceDatabaseAssociatedPtrInfoDataView = |
| mojo::AssociatedInterfacePtrInfoDataView<HumanResourceDatabaseInterfaceBase>; |
| using HumanResourceDatabaseAssociatedRequestDataView = |
| mojo::AssociatedInterfaceRequestDataView<HumanResourceDatabaseInterfaceBase>; |
| class DateDataView { |
| public: |
| DateDataView() {} |
| |
| DateDataView( |
| internal::Date_Data* data, |
| mojo::internal::SerializationContext* context) |
| : data_(data) {} |
| |
| bool is_null() const { return !data_; } |
| uint16_t year() const { |
| return data_->year; |
| } |
| uint8_t month() const { |
| return data_->month; |
| } |
| uint8_t day() const { |
| return data_->day; |
| } |
| private: |
| internal::Date_Data* data_ = nullptr; |
| }; |
| |
| class EmployeeDataView { |
| public: |
| EmployeeDataView() {} |
| |
| EmployeeDataView( |
| internal::Employee_Data* data, |
| mojo::internal::SerializationContext* context) |
| : data_(data), context_(context) {} |
| |
| bool is_null() const { return !data_; } |
| uint64_t employee_id() const { |
| return data_->employee_id; |
| } |
| inline void GetNameDataView( |
| mojo::StringDataView* output); |
| |
| template <typename UserType> |
| WARN_UNUSED_RESULT bool ReadName(UserType* output) { |
| auto* pointer = data_->name.Get(); |
| return mojo::internal::Deserialize<mojo::StringDataView>( |
| pointer, output, context_); |
| } |
| template <typename UserType> |
| WARN_UNUSED_RESULT bool ReadDepartment(UserType* output) const { |
| auto data_value = data_->department; |
| return mojo::internal::Deserialize<::mojo::test::versioning::Department>( |
| data_value, output); |
| } |
| |
| Department department() const { |
| return static_cast<Department>(data_->department); |
| } |
| inline void GetBirthdayDataView( |
| DateDataView* output); |
| |
| template <typename UserType> |
| WARN_UNUSED_RESULT bool ReadBirthday(UserType* output) { |
| auto* pointer = data_->header_.version >= 1 |
| ? data_->birthday.Get() : nullptr; |
| return mojo::internal::Deserialize<::mojo::test::versioning::DateDataView>( |
| pointer, output, context_); |
| } |
| private: |
| internal::Employee_Data* data_ = nullptr; |
| mojo::internal::SerializationContext* context_ = nullptr; |
| }; |
| |
| |
| |
| } // namespace versioning |
| } // namespace test |
| } // namespace mojo |
| |
| namespace std { |
| |
| template <> |
| struct hash<::mojo::test::versioning::Department> |
| : public mojo::internal::EnumHashImpl<::mojo::test::versioning::Department> {}; |
| |
| } // namespace std |
| |
| namespace mojo { |
| |
| |
| template <> |
| struct EnumTraits<::mojo::test::versioning::Department, ::mojo::test::versioning::Department> { |
| static ::mojo::test::versioning::Department ToMojom(::mojo::test::versioning::Department input) { return input; } |
| static bool FromMojom(::mojo::test::versioning::Department input, ::mojo::test::versioning::Department* output) { |
| *output = input; |
| return true; |
| } |
| }; |
| |
| namespace internal { |
| |
| template <typename MaybeConstUserType> |
| struct Serializer<::mojo::test::versioning::Department, MaybeConstUserType> { |
| using UserType = typename std::remove_const<MaybeConstUserType>::type; |
| using Traits = EnumTraits<::mojo::test::versioning::Department, UserType>; |
| |
| static void Serialize(UserType input, int32_t* output) { |
| *output = static_cast<int32_t>(Traits::ToMojom(input)); |
| } |
| |
| static bool Deserialize(int32_t input, UserType* output) { |
| return Traits::FromMojom(static_cast<::mojo::test::versioning::Department>(input), output); |
| } |
| }; |
| |
| } // namespace internal |
| |
| |
| namespace internal { |
| |
| template <typename MaybeConstUserType> |
| struct Serializer<::mojo::test::versioning::DateDataView, MaybeConstUserType> { |
| using UserType = typename std::remove_const<MaybeConstUserType>::type; |
| using Traits = StructTraits<::mojo::test::versioning::DateDataView, UserType>; |
| |
| static void Serialize(MaybeConstUserType& input, |
| Buffer* buffer, |
| ::mojo::test::versioning::internal::Date_Data::BufferWriter* output, |
| SerializationContext* context) { |
| if (CallIsNullIfExists<Traits>(input)) |
| return; |
| (*output).Allocate(buffer); |
| (*output)->year = Traits::year(input); |
| (*output)->month = Traits::month(input); |
| (*output)->day = Traits::day(input); |
| } |
| |
| static bool Deserialize(::mojo::test::versioning::internal::Date_Data* input, |
| UserType* output, |
| SerializationContext* context) { |
| if (!input) |
| return CallSetToNullIfExists<Traits>(output); |
| |
| ::mojo::test::versioning::DateDataView data_view(input, context); |
| return Traits::Read(data_view, output); |
| } |
| }; |
| |
| } // namespace internal |
| |
| |
| namespace internal { |
| |
| template <typename MaybeConstUserType> |
| struct Serializer<::mojo::test::versioning::EmployeeDataView, MaybeConstUserType> { |
| using UserType = typename std::remove_const<MaybeConstUserType>::type; |
| using Traits = StructTraits<::mojo::test::versioning::EmployeeDataView, UserType>; |
| |
| static void Serialize(MaybeConstUserType& input, |
| Buffer* buffer, |
| ::mojo::test::versioning::internal::Employee_Data::BufferWriter* output, |
| SerializationContext* context) { |
| if (CallIsNullIfExists<Traits>(input)) |
| return; |
| (*output).Allocate(buffer); |
| (*output)->employee_id = Traits::employee_id(input); |
| decltype(Traits::name(input)) in_name = Traits::name(input); |
| typename decltype((*output)->name)::BaseType::BufferWriter |
| name_writer; |
| mojo::internal::Serialize<mojo::StringDataView>( |
| in_name, buffer, &name_writer, context); |
| (*output)->name.Set( |
| name_writer.is_null() ? nullptr : name_writer.data()); |
| MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| (*output)->name.is_null(), |
| mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
| "null name in Employee struct"); |
| mojo::internal::Serialize<::mojo::test::versioning::Department>( |
| Traits::department(input), &(*output)->department); |
| decltype(Traits::birthday(input)) in_birthday = Traits::birthday(input); |
| typename decltype((*output)->birthday)::BaseType::BufferWriter |
| birthday_writer; |
| mojo::internal::Serialize<::mojo::test::versioning::DateDataView>( |
| in_birthday, buffer, &birthday_writer, context); |
| (*output)->birthday.Set( |
| birthday_writer.is_null() ? nullptr : birthday_writer.data()); |
| } |
| |
| static bool Deserialize(::mojo::test::versioning::internal::Employee_Data* input, |
| UserType* output, |
| SerializationContext* context) { |
| if (!input) |
| return CallSetToNullIfExists<Traits>(output); |
| |
| ::mojo::test::versioning::EmployeeDataView data_view(input, context); |
| return Traits::Read(data_view, output); |
| } |
| }; |
| |
| } // namespace internal |
| |
| } // namespace mojo |
| |
| |
| namespace mojo { |
| namespace test { |
| namespace versioning { |
| |
| |
| |
| inline void EmployeeDataView::GetNameDataView( |
| mojo::StringDataView* output) { |
| auto pointer = data_->name.Get(); |
| *output = mojo::StringDataView(pointer, context_); |
| } |
| inline void EmployeeDataView::GetBirthdayDataView( |
| DateDataView* output) { |
| auto pointer = data_->header_.version >= 1 |
| ? data_->birthday.Get() : nullptr; |
| *output = DateDataView(pointer, context_); |
| } |
| |
| |
| |
| } // namespace versioning |
| } // namespace test |
| } // namespace mojo |
| |
| #endif // MOJO_PUBLIC_INTERFACES_BINDINGS_TESTS_VERSIONING_TEST_SERVICE_MOJOM_SHARED_H_
|
| /* Metadata comment
|
| eyJtZXRhIjogW3siZW5kIjogMjE5OCwgImJlZ2luIjogMjE4OCwgImVkZ2UiOiAiJS9reXRoZS9l
|
| ZGdlL2dlbmVyYXRlcyIsICJ0eXBlIjogImFuY2hvcl9kZWZpbmVzIiwgInZuYW1lIjogeyJjb3Jw
|
| dXMiOiAiY2hy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