| // WARNING: This file is machine generated by fidlgen. |
| |
| #pragma once |
| |
| #include <lib/fidl/llcpp/array.h> |
| #include <lib/fidl/llcpp/envelope.h> |
| #include <lib/fidl/llcpp/message.h> |
| #include <lib/fidl/llcpp/message_storage.h> |
| #include <lib/fidl/llcpp/object_view.h> |
| #include <lib/fidl/llcpp/string_view.h> |
| #include <lib/fidl/llcpp/traits.h> |
| #include <lib/fidl/llcpp/wire_types.h> |
| #include <lib/stdcompat/optional.h> |
| |
| #include <cinttypes> |
| #ifdef __Fuchsia__ |
| #include <lib/zx/channel.h> |
| |
| #endif // __Fuchsia__ |
| |
| #include <fidl/test.error/cpp/common_types.h> |
| #include <fidl/test.error/cpp/markers.h> |
| |
| namespace test_error { |
| |
| namespace wire { |
| struct ExampleFooResponse; |
| |
| struct ExampleFooTopResponse; |
| |
| struct ExampleFooRequest; |
| |
| class ExampleFooResult; |
| |
| extern "C" const fidl_type_t test_error_Example_foo_ResultTable; |
| |
| class ExampleFooResult { |
| public: |
| using Response = test_error::wire::ExampleFooResponse; |
| |
| ExampleFooResult() : ordinal_(::test_error::wire::ExampleFooResult::Ordinal::Invalid), envelope_{} {} |
| |
| ExampleFooResult(const ExampleFooResult&) = default; |
| ExampleFooResult& operator=(const ExampleFooResult&) = default; |
| ExampleFooResult(ExampleFooResult&&) = default; |
| ExampleFooResult& operator=(ExampleFooResult&&) = default; |
| |
| enum class Tag : fidl_xunion_tag_t { |
| kResponse = 1, // 0x1 |
| kErr = 2, // 0x2 |
| }; |
| |
| bool has_invalid_tag() const { return ordinal_ == ::test_error::wire::ExampleFooResult::Ordinal::Invalid; } |
| |
| bool is_response() const { return ordinal_ == ::test_error::wire::ExampleFooResult::Ordinal::kResponse; } |
| |
| static ExampleFooResult WithResponse(::fidl::ObjectView<::test_error::wire::ExampleFooResponse> val) { |
| ExampleFooResult result; |
| result.ordinal_ = ::test_error::wire::ExampleFooResult::Ordinal::kResponse; |
| result.envelope_.As<::test_error::wire::ExampleFooResponse>().set_data(std::move(val)); |
| return result; |
| } |
| |
| template <typename... Args> |
| static ExampleFooResult WithResponse(::fidl::AnyArena& allocator, Args&&... args) { |
| return WithResponse(::fidl::ObjectView<::test_error::wire::ExampleFooResponse>(allocator, |
| std::forward<Args>(args)...)); |
| } |
| |
| ::test_error::wire::ExampleFooResponse& response() { |
| ZX_ASSERT(ordinal_ == ::test_error::wire::ExampleFooResult::Ordinal::kResponse); |
| return envelope_.As<::test_error::wire::ExampleFooResponse>().get_data(); |
| } |
| const ::test_error::wire::ExampleFooResponse& response() const { |
| ZX_ASSERT(ordinal_ == ::test_error::wire::ExampleFooResult::Ordinal::kResponse); |
| return envelope_.As<::test_error::wire::ExampleFooResponse>().get_data(); |
| } |
| |
| bool is_err() const { return ordinal_ == ::test_error::wire::ExampleFooResult::Ordinal::kErr; } |
| |
| static ExampleFooResult WithErr(uint32_t val) { |
| ExampleFooResult result; |
| result.ordinal_ = ::test_error::wire::ExampleFooResult::Ordinal::kErr; |
| result.envelope_.As<uint32_t>().set_data(std::move(val)); |
| return result; |
| } |
| |
| uint32_t& err() { |
| ZX_ASSERT(ordinal_ == ::test_error::wire::ExampleFooResult::Ordinal::kErr); |
| return envelope_.As<uint32_t>().get_data(); |
| } |
| const uint32_t& err() const { |
| ZX_ASSERT(ordinal_ == ::test_error::wire::ExampleFooResult::Ordinal::kErr); |
| return envelope_.As<uint32_t>().get_data(); |
| } |
| ::test_error::wire::ExampleFooResult::Tag Which() const { |
| ZX_ASSERT(!has_invalid_tag()); |
| return static_cast<::test_error::wire::ExampleFooResult::Tag>(ordinal_); |
| } |
| |
| private: |
| enum class Ordinal : fidl_xunion_tag_t { |
| Invalid = 0, |
| kResponse = 1, // 0x1 |
| kErr = 2, // 0x2 |
| }; |
| |
| static void SizeAndOffsetAssertionHelper(); |
| ::test_error::wire::ExampleFooResult::Ordinal ordinal_; |
| FIDL_ALIGNDECL |
| ::fidl::UntypedEnvelope envelope_; |
| }; |
| |
| extern "C" const fidl_type_t test_error_Example_foo_ResponseTable; |
| |
| struct ExampleFooResponse { |
| int64_t y = {}; |
| }; |
| |
| extern "C" const fidl_type_t test_error_ExampleFooTopResponseTable; |
| |
| struct ExampleFooTopResponse { |
| using Result = test_error::wire::ExampleFooResult; |
| |
| ::test_error::wire::ExampleFooResult result = {}; |
| }; |
| |
| extern "C" const fidl_type_t test_error_ExampleFooRequestTable; |
| |
| struct ExampleFooRequest { |
| ::fidl::StringView s = {}; |
| }; |
| |
| } // namespace wire |
| } // namespace test_error |
| namespace fidl { |
| |
| // TODO(fxbug.dev/95833) Remove this. |
| template <> |
| struct DeprecatedCTypeTraits<::test_error::wire::ExampleFooResponse> { |
| static constexpr const fidl_type_t* kType = &::test_error::wire::test_error_Example_foo_ResponseTable; |
| }; |
| |
| template <> |
| struct TypeTraits<::test_error::wire::ExampleFooResponse> { |
| static constexpr uint32_t kMaxNumHandles = 0; |
| static constexpr uint32_t kMaxDepth = 0; |
| static constexpr uint32_t kPrimarySize = 8; |
| static constexpr uint32_t kPrimarySizeV1 = 8; |
| [[maybe_unused]] static constexpr uint32_t kMaxOutOfLine = 0; |
| static constexpr uint32_t kMaxOutOfLineV1 = 0; |
| static constexpr bool kHasEnvelope = false; |
| static constexpr bool kHasPointer = false; |
| }; |
| |
| template <> |
| struct IsFidlType<::test_error::wire::ExampleFooResponse> : public std::true_type {}; |
| template <> |
| struct IsStruct<::test_error::wire::ExampleFooResponse> : public std::true_type {}; |
| static_assert(std::is_standard_layout_v<::test_error::wire::ExampleFooResponse>); |
| static_assert(offsetof(::test_error::wire::ExampleFooResponse, y) == 0); |
| static_assert(sizeof(::test_error::wire::ExampleFooResponse) == TypeTraits<::test_error::wire::ExampleFooResponse>::kPrimarySize); |
| |
| template <bool IsRecursive> |
| struct ::fidl::internal::WireCodingTraits<::test_error::wire::ExampleFooResponse, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> { |
| static constexpr size_t inline_size = 8; |
| static constexpr auto kMembers = std::make_tuple(::fidl::internal::WireStructMemberCodingInfo<int64_t, fidl::internal::WireCodingConstraintEmpty, IsRecursive>()); |
| static constexpr bool kHasPadding = false; |
| using Base = WireStructCodingTraitsBase<::test_error::wire::ExampleFooResponse, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>; |
| static constexpr bool is_memcpy_compatible = Base::is_memcpy_compatible; |
| |
| static void Encode( |
| internal::WireEncoder* encoder, ::test_error::wire::ExampleFooResponse* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| if constexpr (is_memcpy_compatible) { |
| memcpy(position.As<void>(), value, sizeof(::test_error::wire::ExampleFooResponse)); |
| } else { |
| internal::WireCodingTraits<int64_t, fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Encode(encoder, &value->y, position + 0, recursion_depth); |
| } |
| } |
| static void Decode( |
| internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| if constexpr (!Base::are_members_memcpy_compatible) { |
| internal::WireCodingTraits<int64_t, fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Decode( |
| decoder, position + 0, recursion_depth); |
| } |
| } |
| }; |
| |
| // TODO(fxbug.dev/95833) Remove this. |
| template <> |
| struct DeprecatedCTypeTraits<::test_error::wire::ExampleFooTopResponse> { |
| static constexpr const fidl_type_t* kType = &::test_error::wire::test_error_ExampleFooTopResponseTable; |
| }; |
| |
| template <> |
| struct TypeTraits<::test_error::wire::ExampleFooTopResponse> { |
| static constexpr uint32_t kMaxNumHandles = 0; |
| static constexpr uint32_t kMaxDepth = 1; |
| static constexpr uint32_t kPrimarySize = 16; |
| static constexpr uint32_t kPrimarySizeV1 = 24; |
| [[maybe_unused]] static constexpr uint32_t kMaxOutOfLine = 8; |
| static constexpr uint32_t kMaxOutOfLineV1 = 8; |
| static constexpr bool kHasEnvelope = true; |
| static constexpr bool kHasPointer = true; |
| }; |
| |
| template <> |
| struct IsFidlType<::test_error::wire::ExampleFooTopResponse> : public std::true_type {}; |
| template <> |
| struct IsStruct<::test_error::wire::ExampleFooTopResponse> : public std::true_type {}; |
| static_assert(std::is_standard_layout_v<::test_error::wire::ExampleFooTopResponse>); |
| static_assert(offsetof(::test_error::wire::ExampleFooTopResponse, result) == 0); |
| static_assert(sizeof(::test_error::wire::ExampleFooTopResponse) == TypeTraits<::test_error::wire::ExampleFooTopResponse>::kPrimarySize); |
| |
| template <bool IsRecursive> |
| struct ::fidl::internal::WireCodingTraits<::test_error::wire::ExampleFooTopResponse, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> { |
| static constexpr size_t inline_size = 16; |
| static constexpr auto kMembers = std::make_tuple(::fidl::internal::WireStructMemberCodingInfo<::test_error::wire::ExampleFooResult, fidl::internal::WireCodingConstraintUnion<false>, IsRecursive>()); |
| static constexpr bool kHasPadding = false; |
| using Base = WireStructCodingTraitsBase<::test_error::wire::ExampleFooTopResponse, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>; |
| static constexpr bool is_memcpy_compatible = Base::is_memcpy_compatible; |
| |
| static void Encode( |
| internal::WireEncoder* encoder, ::test_error::wire::ExampleFooTopResponse* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| if constexpr (is_memcpy_compatible) { |
| memcpy(position.As<void>(), value, sizeof(::test_error::wire::ExampleFooTopResponse)); |
| } else { |
| internal::WireCodingTraits<::test_error::wire::ExampleFooResult, fidl::internal::WireCodingConstraintUnion<false>, IsRecursive>::Encode(encoder, &value->result, position + 0, recursion_depth); |
| } |
| } |
| static void Decode( |
| internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| if constexpr (!Base::are_members_memcpy_compatible) { |
| internal::WireCodingTraits<::test_error::wire::ExampleFooResult, fidl::internal::WireCodingConstraintUnion<false>, IsRecursive>::Decode( |
| decoder, position + 0, recursion_depth); |
| } |
| } |
| }; |
| |
| // TODO(fxbug.dev/95833) Remove this. |
| template <> |
| struct DeprecatedCTypeTraits<::test_error::wire::ExampleFooRequest> { |
| static constexpr const fidl_type_t* kType = &::test_error::wire::test_error_ExampleFooRequestTable; |
| }; |
| |
| template <> |
| struct TypeTraits<::test_error::wire::ExampleFooRequest> { |
| static constexpr uint32_t kMaxNumHandles = 0; |
| static constexpr uint32_t kMaxDepth = 1; |
| static constexpr uint32_t kPrimarySize = 16; |
| static constexpr uint32_t kPrimarySizeV1 = 16; |
| [[maybe_unused]] static constexpr uint32_t kMaxOutOfLine = 4294967295; |
| static constexpr uint32_t kMaxOutOfLineV1 = 4294967295; |
| static constexpr bool kHasEnvelope = false; |
| static constexpr bool kHasPointer = true; |
| }; |
| |
| template <> |
| struct IsFidlType<::test_error::wire::ExampleFooRequest> : public std::true_type {}; |
| template <> |
| struct IsStruct<::test_error::wire::ExampleFooRequest> : public std::true_type {}; |
| static_assert(std::is_standard_layout_v<::test_error::wire::ExampleFooRequest>); |
| static_assert(offsetof(::test_error::wire::ExampleFooRequest, s) == 0); |
| static_assert(sizeof(::test_error::wire::ExampleFooRequest) == TypeTraits<::test_error::wire::ExampleFooRequest>::kPrimarySize); |
| |
| template <bool IsRecursive> |
| struct ::fidl::internal::WireCodingTraits<::test_error::wire::ExampleFooRequest, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> { |
| static constexpr size_t inline_size = 16; |
| static constexpr auto kMembers = std::make_tuple(::fidl::internal::WireStructMemberCodingInfo<::fidl::StringView, fidl::internal::WireCodingConstraintString<false>, IsRecursive>()); |
| static constexpr bool kHasPadding = false; |
| using Base = WireStructCodingTraitsBase<::test_error::wire::ExampleFooRequest, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>; |
| static constexpr bool is_memcpy_compatible = Base::is_memcpy_compatible; |
| |
| static void Encode( |
| internal::WireEncoder* encoder, ::test_error::wire::ExampleFooRequest* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| if constexpr (is_memcpy_compatible) { |
| memcpy(position.As<void>(), value, sizeof(::test_error::wire::ExampleFooRequest)); |
| } else { |
| internal::WireCodingTraits<::fidl::StringView, fidl::internal::WireCodingConstraintString<false>, IsRecursive>::Encode(encoder, &value->s, position + 0, recursion_depth); |
| } |
| } |
| static void Decode( |
| internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| if constexpr (!Base::are_members_memcpy_compatible) { |
| internal::WireCodingTraits<::fidl::StringView, fidl::internal::WireCodingConstraintString<false>, IsRecursive>::Decode( |
| decoder, position + 0, recursion_depth); |
| } |
| } |
| }; |
| |
| template <> |
| struct TypeTraits<::test_error::wire::ExampleFooResult> { |
| static constexpr uint32_t kMaxNumHandles = 0; |
| static constexpr uint32_t kMaxDepth = 1; |
| static constexpr uint32_t kPrimarySize = 16; |
| static constexpr uint32_t kPrimarySizeV1 = 24; |
| [[maybe_unused]] static constexpr uint32_t kMaxOutOfLine = 8; |
| static constexpr uint32_t kMaxOutOfLineV1 = 8; |
| static constexpr bool kHasEnvelope = true; |
| static constexpr bool kHasPointer = true; |
| }; |
| |
| template <> |
| struct IsFidlType<::test_error::wire::ExampleFooResult> : public std::true_type {}; |
| template <> |
| struct IsUnion<::test_error::wire::ExampleFooResult> : public std::true_type {}; |
| static_assert(std::is_standard_layout_v<::test_error::wire::ExampleFooResult>); |
| |
| template <typename Constraint, bool IsRecursive> |
| struct ::fidl::internal::WireCodingTraits<::test_error::wire::ExampleFooResult, Constraint, IsRecursive> { |
| static constexpr size_t inline_size = 16; |
| static constexpr bool is_memcpy_compatible = false; |
| |
| static void Encode(internal::WireEncoder* encoder, ::test_error::wire::ExampleFooResult* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| fidl_xunion_v2_t* u = reinterpret_cast<fidl_xunion_v2_t*>(value); |
| |
| if (unlikely(u->tag == 0)) { |
| if constexpr (Constraint::is_optional) { |
| *position.As<fidl_xunion_v2_t>() = {}; |
| return; |
| } |
| encoder->SetError(kCodingErrorInvalidUnionTag); |
| return; |
| } |
| |
| RecursionDepth<IsRecursive> inner_depth = recursion_depth.Add(encoder, 1); |
| if (!inner_depth.IsValid()) { |
| return; |
| } |
| |
| *position.As<fidl_xunion_tag_t>() = u->tag; |
| |
| size_t inline_size; |
| switch (u->tag) { |
| case 1: // ::test_error::wire::ExampleFooResult::Tag::kResponse |
| inline_size = ::fidl::internal::WireCodingTraits<::test_error::wire::ExampleFooResponse, fidl::internal::WireCodingConstraintEmpty, IsRecursive>::inline_size; |
| break; |
| case 2: // ::test_error::wire::ExampleFooResult::Tag::kErr |
| inline_size = ::fidl::internal::WireCodingTraits<uint32_t, fidl::internal::WireCodingConstraintEmpty, IsRecursive>::inline_size; |
| break; |
| default: |
| inline_size = 0; |
| break; |
| } |
| ::fidl::internal::EncodeFn<IsRecursive> encode_fn; |
| switch (u->tag) { |
| case 1: // ::test_error::wire::ExampleFooResult::Tag::kResponse |
| encode_fn = ::fidl::internal::MakeEncodeFn<::test_error::wire::ExampleFooResponse, fidl::internal::WireCodingConstraintEmpty, IsRecursive>(); |
| break; |
| case 2: // ::test_error::wire::ExampleFooResult::Tag::kErr |
| encode_fn = ::fidl::internal::MakeEncodeFn<uint32_t, fidl::internal::WireCodingConstraintEmpty, IsRecursive>(); |
| break; |
| default: |
| encode_fn = nullptr; |
| break; |
| } |
| WireEncodeEnvelope(inline_size, encode_fn, encoder, &u->envelope, position + sizeof(fidl_xunion_tag_t), inner_depth); |
| } |
| |
| static void Decode(internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| ::test_error::wire::ExampleFooResult::Tag tag = *position.As<::test_error::wire::ExampleFooResult::Tag>(); |
| if (unlikely(static_cast<uint64_t>(tag) == 0)) { |
| if constexpr (!Constraint::is_optional) { |
| decoder->SetError(kCodingErrorInvalidUnionTag); |
| return; |
| } |
| static_assert(sizeof(fidl_envelope_v2_t) == sizeof(uint64_t)); |
| if (*(position + sizeof(fidl_xunion_tag_t)).As<uint64_t>() != 0) { |
| decoder->SetError(kCodingErrorZeroTagButNonZeroEnvelope); |
| } |
| return; |
| } |
| |
| RecursionDepth<IsRecursive> inner_depth = recursion_depth.Add(decoder, 1); |
| if (!inner_depth.IsValid()) { |
| return; |
| } |
| |
| size_t inline_size; |
| switch (tag) { |
| case ::test_error::wire::ExampleFooResult::Tag::kResponse: |
| inline_size = ::fidl::internal::WireCodingTraits<::test_error::wire::ExampleFooResponse, fidl::internal::WireCodingConstraintEmpty, IsRecursive>::inline_size; |
| break; |
| case ::test_error::wire::ExampleFooResult::Tag::kErr: |
| inline_size = ::fidl::internal::WireCodingTraits<uint32_t, fidl::internal::WireCodingConstraintEmpty, IsRecursive>::inline_size; |
| break; |
| default: |
| inline_size = 0; |
| break; |
| } |
| DecodeFn<IsRecursive> decode_fn; |
| switch (tag) { |
| case ::test_error::wire::ExampleFooResult::Tag::kResponse: |
| decode_fn = ::fidl::internal::MakeDecodeFn<::test_error::wire::ExampleFooResponse, fidl::internal::WireCodingConstraintEmpty, IsRecursive>(); |
| break; |
| case ::test_error::wire::ExampleFooResult::Tag::kErr: |
| decode_fn = ::fidl::internal::MakeDecodeFn<uint32_t, fidl::internal::WireCodingConstraintEmpty, IsRecursive>(); |
| break; |
| default: |
| decode_fn = nullptr; |
| break; |
| } |
| ::fidl::internal::WireDecodeStrictEnvelope(inline_size, decode_fn, decoder, position + sizeof(fidl_xunion_tag_t), inner_depth); |
| } |
| }; |
| |
| // Top-level union. |
| template <bool IsRecursive> |
| struct ::fidl::internal::WireCodingTraits<::test_error::wire::ExampleFooResult, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> |
| : public ::fidl::internal::WireCodingTraits<::test_error::wire::ExampleFooResult, ::fidl::internal::WireCodingConstraintUnion<false>, IsRecursive> {}; |
| |
| } // namespace fidl |