| // WARNING: This file is machine generated by fidlgen. |
| |
| #pragma once |
| |
| #include <fidl/test/protocols/cpp/fidl.h> |
| |
| #include "lib/fidl/cpp/fuzzing/traits.h" |
| #include "lib/fidl/cpp/internal/header.h" |
| // For ::std::max_element(). |
| #include <algorithm> |
| // For uint64_t. |
| #include <stdint.h> |
| |
| namespace fuzzing { |
| |
| using rights = ::fidl::test::protocols::rights; |
| using obj_type = ::fidl::test::protocols::obj_type; |
| using WithErrorSyntax_HandleInResult_Response = |
| ::fidl::test::protocols::WithErrorSyntax_HandleInResult_Response; |
| using WithErrorSyntax_HandleInResult_Result = |
| ::fidl::test::protocols::WithErrorSyntax_HandleInResult_Result; |
| using WithErrorSyntax_ResponseAsStruct_Response = |
| ::fidl::test::protocols::WithErrorSyntax_ResponseAsStruct_Response; |
| using WithErrorSyntax_ResponseAsStruct_Result = |
| ::fidl::test::protocols::WithErrorSyntax_ResponseAsStruct_Result; |
| using WithErrorSyntax_ErrorAsPrimitive_Response = |
| ::fidl::test::protocols::WithErrorSyntax_ErrorAsPrimitive_Response; |
| using WithErrorSyntax_ErrorAsPrimitive_Result = |
| ::fidl::test::protocols::WithErrorSyntax_ErrorAsPrimitive_Result; |
| using WithErrorSyntax_ErrorAsEnum_Response = |
| ::fidl::test::protocols::WithErrorSyntax_ErrorAsEnum_Response; |
| using TheUnion = ::fidl::test::protocols::TheUnion; |
| using ProtocolEnds = ::fidl::test::protocols::ProtocolEnds; |
| using ErrorEnum = ::fidl::test::protocols::ErrorEnum; |
| using WithErrorSyntax_ErrorAsEnum_Result = |
| ::fidl::test::protocols::WithErrorSyntax_ErrorAsEnum_Result; |
| |
| template <> |
| struct MinSize<rights> { |
| operator size_t() { return sizeof(rights); } |
| }; |
| template <> |
| struct Allocate<rights> { |
| rights operator()(FuzzInput* src, size_t* size) { |
| rights out; |
| ZX_ASSERT(*size >= sizeof(rights)); |
| ZX_ASSERT(src->CopyObject(&out)); |
| *size = sizeof(rights); |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<obj_type> { |
| operator size_t() { return sizeof(uint64_t); } |
| }; |
| template <> |
| struct Allocate<obj_type> { |
| obj_type operator()(FuzzInput* src, size_t* size) { |
| obj_type out; |
| uint64_t selector; |
| ZX_ASSERT(*size >= sizeof(uint64_t)); |
| ZX_ASSERT(src->CopyObject(&selector)); |
| *size = sizeof(uint64_t); |
| |
| switch (selector % 2) { |
| case 0: |
| out = obj_type::NONE; |
| break; |
| case 1: |
| out = obj_type::SOCKET; |
| break; |
| } |
| |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<WithErrorSyntax_HandleInResult_Response> { |
| operator size_t() { return MinSize<::zx::handle>(); } |
| }; |
| template <> |
| struct Allocate<WithErrorSyntax_HandleInResult_Response> { |
| WithErrorSyntax_HandleInResult_Response operator()(FuzzInput* src, |
| size_t* size) { |
| ZX_ASSERT(*size >= MinSize<WithErrorSyntax_HandleInResult_Response>()); |
| WithErrorSyntax_HandleInResult_Response out; |
| const size_t slack_per_member = |
| (*size - MinSize<WithErrorSyntax_HandleInResult_Response>()) / 1; |
| size_t out_size; |
| out_size = MinSize<::zx::handle>() + slack_per_member; |
| out.h = Allocate<::zx::handle>{}(src, &out_size); |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<WithErrorSyntax_HandleInResult_Result> { |
| operator size_t() { |
| size_t sizes[] = { |
| 0, |
| MinSize< |
| ::fidl::test::protocols::WithErrorSyntax_HandleInResult_Response>(), |
| MinSize<uint32_t>()}; |
| return 1 + *std::max_element(sizes, sizes + 2 + 1); |
| } |
| }; |
| template <> |
| struct Allocate<WithErrorSyntax_HandleInResult_Result> { |
| static_assert(2 > 0, "xunion must have at least one member"); |
| |
| WithErrorSyntax_HandleInResult_Result operator()(FuzzInput* src, |
| size_t* size) { |
| ZX_ASSERT(*size >= MinSize<WithErrorSyntax_HandleInResult_Result>()); |
| |
| uint8_t selector; |
| ZX_ASSERT(src->CopyBytes(&selector, 1)); |
| (*size)++; |
| |
| WithErrorSyntax_HandleInResult_Result out; |
| switch (selector % 2) { |
| case 0: { |
| out.set_response( |
| Allocate<::fidl::test::protocols:: |
| WithErrorSyntax_HandleInResult_Response>{}(src, size)); |
| break; |
| } |
| case 1: { |
| out.set_err(Allocate<uint32_t>{}(src, size)); |
| break; |
| } |
| } |
| |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<WithErrorSyntax_ResponseAsStruct_Response> { |
| operator size_t() { |
| return MinSize<int64_t>() + MinSize<int64_t>() + MinSize<int64_t>(); |
| } |
| }; |
| template <> |
| struct Allocate<WithErrorSyntax_ResponseAsStruct_Response> { |
| WithErrorSyntax_ResponseAsStruct_Response operator()(FuzzInput* src, |
| size_t* size) { |
| ZX_ASSERT(*size >= MinSize<WithErrorSyntax_ResponseAsStruct_Response>()); |
| WithErrorSyntax_ResponseAsStruct_Response out; |
| const size_t slack_per_member = |
| (*size - MinSize<WithErrorSyntax_ResponseAsStruct_Response>()) / 3; |
| size_t out_size; |
| out_size = MinSize<int64_t>() + slack_per_member; |
| out.a = Allocate<int64_t>{}(src, &out_size); |
| out_size = MinSize<int64_t>() + slack_per_member; |
| out.b = Allocate<int64_t>{}(src, &out_size); |
| out_size = MinSize<int64_t>() + slack_per_member; |
| out.c = Allocate<int64_t>{}(src, &out_size); |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<WithErrorSyntax_ResponseAsStruct_Result> { |
| operator size_t() { |
| size_t sizes[] = {0, |
| MinSize<::fidl::test::protocols:: |
| WithErrorSyntax_ResponseAsStruct_Response>(), |
| MinSize<uint32_t>()}; |
| return 1 + *std::max_element(sizes, sizes + 2 + 1); |
| } |
| }; |
| template <> |
| struct Allocate<WithErrorSyntax_ResponseAsStruct_Result> { |
| static_assert(2 > 0, "xunion must have at least one member"); |
| |
| WithErrorSyntax_ResponseAsStruct_Result operator()(FuzzInput* src, |
| size_t* size) { |
| ZX_ASSERT(*size >= MinSize<WithErrorSyntax_ResponseAsStruct_Result>()); |
| |
| uint8_t selector; |
| ZX_ASSERT(src->CopyBytes(&selector, 1)); |
| (*size)++; |
| |
| WithErrorSyntax_ResponseAsStruct_Result out; |
| switch (selector % 2) { |
| case 0: { |
| out.set_response( |
| Allocate<::fidl::test::protocols:: |
| WithErrorSyntax_ResponseAsStruct_Response>{}(src, |
| size)); |
| break; |
| } |
| case 1: { |
| out.set_err(Allocate<uint32_t>{}(src, size)); |
| break; |
| } |
| } |
| |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<WithErrorSyntax_ErrorAsPrimitive_Response> { |
| operator size_t() { return MinSize<uint8_t>(); } |
| }; |
| template <> |
| struct Allocate<WithErrorSyntax_ErrorAsPrimitive_Response> { |
| WithErrorSyntax_ErrorAsPrimitive_Response operator()(FuzzInput* src, |
| size_t* size) { |
| ZX_ASSERT(*size >= MinSize<WithErrorSyntax_ErrorAsPrimitive_Response>()); |
| WithErrorSyntax_ErrorAsPrimitive_Response out; |
| const size_t slack_per_member = |
| (*size - MinSize<WithErrorSyntax_ErrorAsPrimitive_Response>()) / 1; |
| size_t out_size; |
| out_size = MinSize<uint8_t>() + slack_per_member; |
| out.__reserved = Allocate<uint8_t>{}(src, &out_size); |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<WithErrorSyntax_ErrorAsPrimitive_Result> { |
| operator size_t() { |
| size_t sizes[] = {0, |
| MinSize<::fidl::test::protocols:: |
| WithErrorSyntax_ErrorAsPrimitive_Response>(), |
| MinSize<uint32_t>()}; |
| return 1 + *std::max_element(sizes, sizes + 2 + 1); |
| } |
| }; |
| template <> |
| struct Allocate<WithErrorSyntax_ErrorAsPrimitive_Result> { |
| static_assert(2 > 0, "xunion must have at least one member"); |
| |
| WithErrorSyntax_ErrorAsPrimitive_Result operator()(FuzzInput* src, |
| size_t* size) { |
| ZX_ASSERT(*size >= MinSize<WithErrorSyntax_ErrorAsPrimitive_Result>()); |
| |
| uint8_t selector; |
| ZX_ASSERT(src->CopyBytes(&selector, 1)); |
| (*size)++; |
| |
| WithErrorSyntax_ErrorAsPrimitive_Result out; |
| switch (selector % 2) { |
| case 0: { |
| out.set_response( |
| Allocate<::fidl::test::protocols:: |
| WithErrorSyntax_ErrorAsPrimitive_Response>{}(src, |
| size)); |
| break; |
| } |
| case 1: { |
| out.set_err(Allocate<uint32_t>{}(src, size)); |
| break; |
| } |
| } |
| |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<WithErrorSyntax_ErrorAsEnum_Response> { |
| operator size_t() { return MinSize<uint8_t>(); } |
| }; |
| template <> |
| struct Allocate<WithErrorSyntax_ErrorAsEnum_Response> { |
| WithErrorSyntax_ErrorAsEnum_Response operator()(FuzzInput* src, |
| size_t* size) { |
| ZX_ASSERT(*size >= MinSize<WithErrorSyntax_ErrorAsEnum_Response>()); |
| WithErrorSyntax_ErrorAsEnum_Response out; |
| const size_t slack_per_member = |
| (*size - MinSize<WithErrorSyntax_ErrorAsEnum_Response>()) / 1; |
| size_t out_size; |
| out_size = MinSize<uint8_t>() + slack_per_member; |
| out.__reserved = Allocate<uint8_t>{}(src, &out_size); |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<TheUnion> { |
| operator size_t() { |
| size_t sizes[] = {0, MinSize<uint32_t>()}; |
| return 1 + *std::max_element(sizes, sizes + 1 + 1); |
| } |
| }; |
| template <> |
| struct Allocate<TheUnion> { |
| static_assert(1 > 0, "xunion must have at least one member"); |
| |
| TheUnion operator()(FuzzInput* src, size_t* size) { |
| ZX_ASSERT(*size >= MinSize<TheUnion>()); |
| |
| uint8_t selector; |
| ZX_ASSERT(src->CopyBytes(&selector, 1)); |
| (*size)++; |
| |
| TheUnion out; |
| switch (selector % 1) { |
| case 0: { |
| out.set_v(Allocate<uint32_t>{}(src, size)); |
| break; |
| } |
| } |
| |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<ProtocolEnds> { |
| operator size_t() { |
| return MinSize<::fidl::InterfaceHandle< |
| ::fidl::test::protocols::DiscoverableProtocol>>() + |
| MinSize<::fidl::InterfaceRequest< |
| ::fidl::test::protocols::DiscoverableProtocol>>() + |
| MinSize<::fidl::InterfaceHandle< |
| ::fidl::test::protocols::DiscoverableProtocol>>() + |
| MinSize<::fidl::InterfaceRequest< |
| ::fidl::test::protocols::DiscoverableProtocol>>(); |
| } |
| }; |
| template <> |
| struct Allocate<ProtocolEnds> { |
| ProtocolEnds operator()(FuzzInput* src, size_t* size) { |
| ZX_ASSERT(*size >= MinSize<ProtocolEnds>()); |
| ProtocolEnds out; |
| const size_t slack_per_member = (*size - MinSize<ProtocolEnds>()) / 4; |
| size_t out_size; |
| out_size = MinSize<::fidl::InterfaceHandle< |
| ::fidl::test::protocols::DiscoverableProtocol>>() + |
| slack_per_member; |
| out.client = Allocate<::fidl::InterfaceHandle< |
| ::fidl::test::protocols::DiscoverableProtocol>>{}(src, &out_size); |
| out_size = MinSize<::fidl::InterfaceRequest< |
| ::fidl::test::protocols::DiscoverableProtocol>>() + |
| slack_per_member; |
| out.server = Allocate<::fidl::InterfaceRequest< |
| ::fidl::test::protocols::DiscoverableProtocol>>{}(src, &out_size); |
| out_size = MinSize<::fidl::InterfaceHandle< |
| ::fidl::test::protocols::DiscoverableProtocol>>() + |
| slack_per_member; |
| out.client_opt = Allocate<::fidl::InterfaceHandle< |
| ::fidl::test::protocols::DiscoverableProtocol>>{}(src, &out_size); |
| out_size = MinSize<::fidl::InterfaceRequest< |
| ::fidl::test::protocols::DiscoverableProtocol>>() + |
| slack_per_member; |
| out.server_opt = Allocate<::fidl::InterfaceRequest< |
| ::fidl::test::protocols::DiscoverableProtocol>>{}(src, &out_size); |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<ErrorEnum> { |
| operator size_t() { return sizeof(uint64_t); } |
| }; |
| template <> |
| struct Allocate<ErrorEnum> { |
| ErrorEnum operator()(FuzzInput* src, size_t* size) { |
| ErrorEnum out; |
| uint64_t selector; |
| ZX_ASSERT(*size >= sizeof(uint64_t)); |
| ZX_ASSERT(src->CopyObject(&selector)); |
| *size = sizeof(uint64_t); |
| |
| switch (selector % 2) { |
| case 0: |
| out = ErrorEnum::ERR_FOO; |
| break; |
| case 1: |
| out = ErrorEnum::ERR_BAR; |
| break; |
| } |
| |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<WithErrorSyntax_ErrorAsEnum_Result> { |
| operator size_t() { |
| size_t sizes[] = { |
| 0, |
| MinSize< |
| ::fidl::test::protocols::WithErrorSyntax_ErrorAsEnum_Response>(), |
| MinSize<::fidl::test::protocols::ErrorEnum>()}; |
| return 1 + *std::max_element(sizes, sizes + 2 + 1); |
| } |
| }; |
| template <> |
| struct Allocate<WithErrorSyntax_ErrorAsEnum_Result> { |
| static_assert(2 > 0, "xunion must have at least one member"); |
| |
| WithErrorSyntax_ErrorAsEnum_Result operator()(FuzzInput* src, size_t* size) { |
| ZX_ASSERT(*size >= MinSize<WithErrorSyntax_ErrorAsEnum_Result>()); |
| |
| uint8_t selector; |
| ZX_ASSERT(src->CopyBytes(&selector, 1)); |
| (*size)++; |
| |
| WithErrorSyntax_ErrorAsEnum_Result out; |
| switch (selector % 2) { |
| case 0: { |
| out.set_response( |
| Allocate<::fidl::test::protocols:: |
| WithErrorSyntax_ErrorAsEnum_Response>{}(src, size)); |
| break; |
| } |
| case 1: { |
| out.set_err(Allocate<::fidl::test::protocols::ErrorEnum>{}(src, size)); |
| break; |
| } |
| } |
| |
| return out; |
| } |
| }; |
| |
| } // namespace fuzzing |