| // WARNING: This file is machine generated by fidlgen. |
| |
| #include <placement_of_attributes.test.json.h> |
| |
| #include "lib/fidl/cpp/internal/implementation.h" |
| namespace example { |
| |
| #ifdef __Fuchsia__ |
| namespace { |
| |
| extern "C" const fidl_type_t v1_example_ExampleProtocolMethodRequestTable; |
| |
| } // namespace |
| |
| ExampleProtocol::~ExampleProtocol() = default; |
| |
| const fidl_type_t* ExampleProtocol_RequestDecoder::GetType( |
| uint64_t ordinal, bool* out_needs_response) { |
| switch (ordinal) { |
| case internal::kExampleProtocol_Method_Ordinal: |
| case internal::kExampleProtocol_Method_GenOrdinal: |
| *out_needs_response = false; |
| return &v1_example_ExampleProtocolMethodRequestTable; |
| default: |
| *out_needs_response = false; |
| return nullptr; |
| } |
| } |
| |
| const fidl_type_t* ExampleProtocol_ResponseDecoder::GetType(uint64_t ordinal) { |
| switch (ordinal) { |
| default: |
| return nullptr; |
| } |
| } |
| |
| ExampleProtocol_EventSender::~ExampleProtocol_EventSender() = default; |
| |
| ExampleProtocol_Sync::~ExampleProtocol_Sync() = default; |
| |
| ExampleProtocol_Proxy::ExampleProtocol_Proxy( |
| ::fidl::internal::ProxyController* controller) |
| : controller_(controller) { |
| (void)controller_; |
| } |
| |
| ExampleProtocol_Proxy::~ExampleProtocol_Proxy() = default; |
| |
| zx_status_t ExampleProtocol_Proxy::Dispatch_(::fidl::Message message) { |
| zx_status_t status = ZX_OK; |
| switch (message.ordinal()) { |
| default: { |
| status = ZX_ERR_NOT_SUPPORTED; |
| break; |
| } |
| } |
| return status; |
| } |
| |
| void ExampleProtocol_Proxy::Method(::exampleusing::Empty arg) { |
| ::fidl::Encoder _encoder(internal::kExampleProtocol_Method_GenOrdinal); |
| controller_->Send(&v1_example_ExampleProtocolMethodRequestTable, |
| ExampleProtocol_RequestEncoder::Method(&_encoder, &arg), |
| nullptr); |
| } |
| |
| ExampleProtocol_Stub::ExampleProtocol_Stub(ExampleProtocol_clazz* impl) |
| : impl_(impl) { |
| (void)impl_; |
| } |
| |
| ExampleProtocol_Stub::~ExampleProtocol_Stub() = default; |
| |
| namespace {} // namespace |
| |
| zx_status_t ExampleProtocol_Stub::Dispatch_( |
| ::fidl::Message message, ::fidl::internal::PendingResponse response) { |
| bool needs_response; |
| const fidl_type_t* request_type = ExampleProtocol_RequestDecoder::GetType( |
| message.ordinal(), &needs_response); |
| if (request_type == nullptr) { |
| return ZX_ERR_NOT_SUPPORTED; |
| } |
| if (response.needs_response() != needs_response) { |
| if (needs_response) { |
| FIDL_REPORT_DECODING_ERROR(message, request_type, |
| "Message needing a response with no txid"); |
| } else { |
| FIDL_REPORT_DECODING_ERROR(message, request_type, |
| "Message not needing a response with a txid"); |
| } |
| return ZX_ERR_INVALID_ARGS; |
| } |
| const char* error_msg = nullptr; |
| zx_status_t status = message.Decode(request_type, &error_msg); |
| if (status != ZX_OK) { |
| FIDL_REPORT_DECODING_ERROR(message, request_type, error_msg); |
| return status; |
| } |
| uint64_t ordinal = message.ordinal(); |
| switch (ordinal) { |
| case internal::kExampleProtocol_Method_Ordinal: |
| case internal::kExampleProtocol_Method_GenOrdinal: { |
| ::fidl::Decoder decoder(std::move(message)); |
| auto arg0 = ::fidl::DecodeAs<::exampleusing::Empty>(&decoder, 16); |
| impl_->Method(std::move(arg0)); |
| break; |
| } |
| default: { |
| status = ZX_ERR_NOT_SUPPORTED; |
| break; |
| } |
| } |
| return status; |
| } |
| |
| ExampleProtocol_SyncProxy::ExampleProtocol_SyncProxy(::zx::channel channel) |
| : proxy_(::std::move(channel)) {} |
| |
| ExampleProtocol_SyncProxy::~ExampleProtocol_SyncProxy() = default; |
| |
| zx_status_t ExampleProtocol_SyncProxy::Method(::exampleusing::Empty arg) { |
| ::fidl::Encoder _encoder(internal::kExampleProtocol_Method_GenOrdinal); |
| return proxy_.Send(&v1_example_ExampleProtocolMethodRequestTable, |
| ExampleProtocol_RequestEncoder::Method(&_encoder, &arg)); |
| } |
| |
| #endif // __Fuchsia__ |
| |
| extern "C" const fidl_type_t v1_example_ExampleXUnionTable; |
| const fidl_type_t* ExampleXUnion::FidlType = &v1_example_ExampleXUnionTable; |
| |
| ExampleXUnion::ExampleXUnion() {} |
| |
| ExampleXUnion::~ExampleXUnion() { Destroy(); } |
| |
| ExampleXUnion::ExampleXUnion(ExampleXUnion&& other) : tag_(other.tag_) { |
| switch (tag_) { |
| case Tag::kVariant: |
| variant_ = std::move(other.variant_); |
| break; |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| default: |
| new (&unknown_data_) decltype(unknown_data_); |
| unknown_data_ = std::move(other.unknown_data_); |
| break; |
| } |
| } |
| |
| ExampleXUnion& ExampleXUnion::operator=(ExampleXUnion&& other) { |
| if (this != &other) { |
| Destroy(); |
| tag_ = other.tag_; |
| switch (tag_) { |
| case Tag::kVariant: |
| variant_ = std::move(other.variant_); |
| break; |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| default: |
| new (&unknown_data_) decltype(unknown_data_); |
| unknown_data_ = std::move(other.unknown_data_); |
| break; |
| } |
| } |
| return *this; |
| } |
| |
| ExampleXUnion ExampleXUnion::WithVariant(uint32_t&& val) { |
| ExampleXUnion result; |
| result.set_variant(std::move(val)); |
| return result; |
| } |
| |
| void ExampleXUnion::Encode(::fidl::Encoder* encoder, size_t offset) { |
| const size_t length_before = encoder->CurrentLength(); |
| const size_t handles_before = encoder->CurrentHandleCount(); |
| |
| size_t envelope_offset = 0; |
| |
| switch (tag_) { |
| case Tag::kVariant: { |
| envelope_offset = encoder->Alloc( |
| ::fidl::EncodingInlineSize<uint32_t, ::fidl::Encoder>(encoder)); |
| ::fidl::Encode(encoder, &variant_, envelope_offset); |
| break; |
| } |
| case Tag::kUnknown: |
| default: |
| break; |
| } |
| |
| fidl_xunion_t* xunion = encoder->GetPtr<fidl_xunion_t>(offset); |
| assert(xunion->envelope.presence == FIDL_ALLOC_ABSENT); |
| |
| if (envelope_offset) { |
| xunion->tag = tag_; |
| xunion->envelope.num_bytes = encoder->CurrentLength() - length_before; |
| xunion->envelope.num_handles = |
| encoder->CurrentHandleCount() - handles_before; |
| xunion->envelope.presence = FIDL_ALLOC_PRESENT; |
| } |
| } |
| |
| void ExampleXUnion::Decode(::fidl::Decoder* decoder, ExampleXUnion* value, |
| size_t offset) { |
| fidl_xunion_t* xunion = decoder->GetPtr<fidl_xunion_t>(offset); |
| |
| if (!xunion->envelope.data) { |
| value->EnsureStorageInitialized( |
| static_cast<fidl_xunion_tag_t>(Tag::Invalid)); |
| return; |
| } |
| |
| value->EnsureStorageInitialized(xunion->tag); |
| |
| const size_t envelope_offset = decoder->GetOffset(xunion->envelope.data); |
| |
| switch (value->tag_) { |
| case Tag::kVariant: |
| ::fidl::Decode(decoder, &value->variant_, envelope_offset); |
| break; |
| default: |
| value->unknown_data_.resize(xunion->envelope.num_bytes); |
| memcpy(value->unknown_data_.data(), xunion->envelope.data, |
| xunion->envelope.num_bytes); |
| break; |
| } |
| } |
| |
| zx_status_t ExampleXUnion::Clone(ExampleXUnion* result) const { |
| result->Destroy(); |
| result->tag_ = tag_; |
| switch (tag_) { |
| case Tag::kVariant: |
| return ::fidl::Clone(variant_, &result->variant_); |
| default: |
| return ZX_OK; |
| } |
| } |
| |
| ExampleXUnion& ExampleXUnion::set_variant(uint32_t value) { |
| EnsureStorageInitialized(Tag::kVariant); |
| variant_ = std::move(value); |
| return *this; |
| } |
| |
| void ExampleXUnion::Destroy() { |
| switch (tag_) { |
| case Tag::kVariant: |
| break; |
| |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| default: |
| unknown_data_.~vector(); |
| break; |
| } |
| tag_ = static_cast<fidl_xunion_tag_t>(Tag::Invalid); |
| } |
| |
| void ExampleXUnion::EnsureStorageInitialized(::fidl_xunion_tag_t tag) { |
| if (tag_ != tag) { |
| Destroy(); |
| tag_ = tag; |
| switch (tag_) { |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| case Tag::kVariant: |
| new (&variant_) uint32_t(); |
| break; |
| default: |
| new (&unknown_data_) decltype(unknown_data_); |
| break; |
| } |
| } |
| } |
| extern "C" const fidl_type_t v1_example_ExampleUnionTable; |
| const fidl_type_t* ExampleUnion::FidlType = &v1_example_ExampleUnionTable; |
| |
| ExampleUnion::ExampleUnion() {} |
| |
| ExampleUnion::~ExampleUnion() { Destroy(); } |
| |
| ExampleUnion::ExampleUnion(ExampleUnion&& other) : tag_(other.tag_) { |
| switch (tag_) { |
| case Tag::kVariant: |
| variant_ = std::move(other.variant_); |
| break; |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| } |
| } |
| |
| ExampleUnion& ExampleUnion::operator=(ExampleUnion&& other) { |
| if (this != &other) { |
| Destroy(); |
| tag_ = other.tag_; |
| switch (tag_) { |
| case Tag::kVariant: |
| variant_ = std::move(other.variant_); |
| break; |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| } |
| } |
| return *this; |
| } |
| |
| ExampleUnion ExampleUnion::WithVariant(uint32_t&& val) { |
| ExampleUnion result; |
| result.set_variant(std::move(val)); |
| return result; |
| } |
| |
| void ExampleUnion::Encode(::fidl::Encoder* encoder, size_t offset) { |
| const size_t length_before = encoder->CurrentLength(); |
| const size_t handles_before = encoder->CurrentHandleCount(); |
| |
| size_t envelope_offset = 0; |
| |
| switch (tag_) { |
| case Tag::kVariant: { |
| envelope_offset = encoder->Alloc( |
| ::fidl::EncodingInlineSize<uint32_t, ::fidl::Encoder>(encoder)); |
| ::fidl::Encode(encoder, &variant_, envelope_offset); |
| break; |
| } |
| default: |
| break; |
| } |
| |
| fidl_xunion_t* xunion = encoder->GetPtr<fidl_xunion_t>(offset); |
| assert(xunion->envelope.presence == FIDL_ALLOC_ABSENT); |
| |
| if (envelope_offset) { |
| xunion->tag = tag_; |
| xunion->envelope.num_bytes = encoder->CurrentLength() - length_before; |
| xunion->envelope.num_handles = |
| encoder->CurrentHandleCount() - handles_before; |
| xunion->envelope.presence = FIDL_ALLOC_PRESENT; |
| } |
| } |
| |
| void ExampleUnion::Decode(::fidl::Decoder* decoder, ExampleUnion* value, |
| size_t offset) { |
| fidl_xunion_t* xunion = decoder->GetPtr<fidl_xunion_t>(offset); |
| |
| if (!xunion->envelope.data) { |
| value->EnsureStorageInitialized( |
| static_cast<fidl_xunion_tag_t>(Tag::Invalid)); |
| return; |
| } |
| |
| value->EnsureStorageInitialized(xunion->tag); |
| |
| const size_t envelope_offset = decoder->GetOffset(xunion->envelope.data); |
| |
| switch (value->tag_) { |
| case Tag::kVariant: |
| ::fidl::Decode(decoder, &value->variant_, envelope_offset); |
| break; |
| } |
| } |
| |
| zx_status_t ExampleUnion::Clone(ExampleUnion* result) const { |
| result->Destroy(); |
| result->tag_ = tag_; |
| switch (tag_) { |
| case Tag::kVariant: |
| return ::fidl::Clone(variant_, &result->variant_); |
| default: |
| return ZX_OK; |
| } |
| } |
| |
| ExampleUnion& ExampleUnion::set_variant(uint32_t value) { |
| EnsureStorageInitialized(Tag::kVariant); |
| variant_ = std::move(value); |
| return *this; |
| } |
| |
| void ExampleUnion::Destroy() { |
| switch (tag_) { |
| case Tag::kVariant: |
| break; |
| |
| default: |
| break; |
| } |
| tag_ = static_cast<fidl_xunion_tag_t>(Tag::Invalid); |
| } |
| |
| void ExampleUnion::EnsureStorageInitialized(::fidl_xunion_tag_t tag) { |
| if (tag_ != tag) { |
| Destroy(); |
| tag_ = tag; |
| switch (tag_) { |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| case Tag::kVariant: |
| new (&variant_) uint32_t(); |
| break; |
| default: |
| break; |
| } |
| } |
| } |
| extern "C" const fidl_type_t v1_example_ExampleTableTable; |
| const fidl_type_t* ExampleTable::FidlType = &v1_example_ExampleTableTable; |
| |
| ExampleTable::ExampleTable() : has_member_(false) {} |
| |
| ExampleTable::ExampleTable(ExampleTable&& other) { |
| has_member_ = other.has_member_; |
| if (has_member_) { |
| Construct(&member_value_.value, std::move(other.member_value_.value)); |
| } |
| } |
| |
| ExampleTable::~ExampleTable() { |
| if (has_member_) { |
| Destruct(&member_value_.value); |
| } |
| } |
| |
| ExampleTable& ExampleTable::operator=(ExampleTable&& other) { |
| if (other.has_member_) { |
| if (has_member_) { |
| member_value_.value = std::move(other.member_value_.value); |
| } else { |
| has_member_ = true; |
| Construct(&member_value_.value, std::move(other.member_value_.value)); |
| } |
| } else if (has_member_) { |
| has_member_ = false; |
| Destruct(&member_value_.value); |
| } |
| return *this; |
| } |
| |
| bool ExampleTable::IsEmpty() const { |
| if (has_member_) return false; |
| return true; |
| } |
| |
| void ExampleTable::Encode(::fidl::Encoder* _encoder, size_t _offset) { |
| size_t max_ordinal = 0; |
| if (has_member_) max_ordinal = 1; |
| ::fidl::EncodeVectorPointer(_encoder, max_ordinal, _offset); |
| if (max_ordinal == 0) return; |
| size_t base = _encoder->Alloc(max_ordinal * 2 * sizeof(uint64_t)); |
| if (has_member_) { |
| const size_t length_before = _encoder->CurrentLength(); |
| const size_t handles_before = _encoder->CurrentHandleCount(); |
| ::fidl::Encode( |
| _encoder, &member_value_.value, |
| _encoder->Alloc( |
| ::fidl::EncodingInlineSize<uint32_t, ::fidl::Encoder>(_encoder))); |
| size_t envelope_base = base + (1 - 1) * 2 * sizeof(uint64_t); |
| uint64_t num_bytes_then_num_handles = |
| (_encoder->CurrentLength() - length_before) | |
| ((_encoder->CurrentHandleCount() - handles_before) << 32); |
| ::fidl::Encode(_encoder, &num_bytes_then_num_handles, envelope_base); |
| *_encoder->GetPtr<uintptr_t>(envelope_base + sizeof(uint64_t)) = |
| FIDL_ALLOC_PRESENT; |
| } |
| } |
| |
| void ExampleTable::Decode(::fidl::Decoder* _decoder, ExampleTable* _value, |
| size_t _offset) { |
| fidl_vector_t* encoded = _decoder->GetPtr<fidl_vector_t>(_offset); |
| size_t base; |
| size_t count; |
| if (!encoded->data) { |
| goto clear_all; |
| } |
| |
| base = _decoder->GetOffset(encoded->data); |
| count = encoded->count; |
| if (count >= 1) { |
| size_t envelope_base = base + (1 - 1) * 2 * sizeof(uint64_t); |
| uint64_t presence; |
| ::fidl::Decode(_decoder, &presence, envelope_base + sizeof(uint64_t)); |
| if (presence != 0) { |
| ::fidl::Decode(_decoder, _value->mutable_member(), |
| _decoder->GetOffset(presence)); |
| } else { |
| _value->clear_member(); |
| } |
| } else { |
| goto done_1; |
| } |
| |
| return; |
| |
| // Clear unset values. |
| clear_all: |
| done_1: |
| _value->clear_member(); |
| return; |
| } |
| |
| zx_status_t ExampleTable::Clone(ExampleTable* result) const { |
| if (has_member_) { |
| zx_status_t _status = |
| ::fidl::Clone(member_value_.value, result->mutable_member()); |
| if (_status != ZX_OK) return _status; |
| } else { |
| result->clear_member(); |
| } |
| return ZX_OK; |
| } |
| extern "C" const fidl_type_t v1_example_ExampleStructTable; |
| const fidl_type_t* ExampleStruct::FidlType = &v1_example_ExampleStructTable; |
| |
| void ExampleStruct::Encode(::fidl::Encoder* _encoder, size_t _offset) { |
| ::fidl::Encode(_encoder, &member, _offset + 0); |
| } |
| |
| void ExampleStruct::Decode(::fidl::Decoder* _decoder, ExampleStruct* value, |
| size_t _offset) { |
| ::fidl::Decode(_decoder, &value->member, _offset + 0); |
| } |
| |
| zx_status_t ExampleStruct::Clone(ExampleStruct* _result) const { |
| zx_status_t _status = ::fidl::Clone(member, &_result->member); |
| if (_status != ZX_OK) return _status; |
| return ZX_OK; |
| } |
| } // namespace example |