| // WARNING: This file is machine generated by fidlgen. |
| |
| #include <nullable.test.json.llcpp.h> |
| |
| #include <memory> |
| |
| namespace llcpp { |
| |
| namespace fidl { |
| namespace test { |
| namespace nullable { |
| |
| namespace { |
| |
| [[maybe_unused]] constexpr uint64_t kSimpleProtocol_Add_Ordinal = |
| 0x11fe4d2400000000lu; |
| [[maybe_unused]] constexpr uint64_t kSimpleProtocol_Add_GenOrdinal = |
| 0x113010d7832f175dlu; |
| extern "C" const fidl_type_t |
| v1_fidl_test_nullable_SimpleProtocolAddRequestTable; |
| extern "C" const fidl_type_t |
| v1_fidl_test_nullable_SimpleProtocolAddResponseTable; |
| |
| } // namespace |
| template <> |
| SimpleProtocol::ResultOf::Add_Impl<SimpleProtocol::AddResponse>::Add_Impl( |
| ::zx::unowned_channel _client_end, int32_t a, int32_t b) { |
| constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize< |
| AddRequest, ::fidl::MessageDirection::kSending>(); |
| ::fidl::internal::AlignedBuffer<_kWriteAllocSize> _write_bytes_inlined; |
| auto& _write_bytes_array = _write_bytes_inlined; |
| uint8_t* _write_bytes = _write_bytes_array.view().data(); |
| memset(_write_bytes, 0, AddRequest::PrimarySize); |
| auto& _request = *reinterpret_cast<AddRequest*>(_write_bytes); |
| _request.a = std::move(a); |
| _request.b = std::move(b); |
| ::fidl::BytePart _request_bytes(_write_bytes, _kWriteAllocSize, |
| sizeof(AddRequest)); |
| ::fidl::DecodedMessage<AddRequest> _decoded_request( |
| std::move(_request_bytes)); |
| Super::SetResult(SimpleProtocol::InPlace::Add(std::move(_client_end), |
| std::move(_decoded_request), |
| Super::response_buffer())); |
| } |
| |
| SimpleProtocol::ResultOf::Add SimpleProtocol::SyncClient::Add(int32_t a, |
| int32_t b) { |
| return ResultOf::Add(::zx::unowned_channel(this->channel_), std::move(a), |
| std::move(b)); |
| } |
| |
| SimpleProtocol::ResultOf::Add SimpleProtocol::Call::Add( |
| ::zx::unowned_channel _client_end, int32_t a, int32_t b) { |
| return ResultOf::Add(std::move(_client_end), std::move(a), std::move(b)); |
| } |
| |
| template <> |
| SimpleProtocol::UnownedResultOf::Add_Impl< |
| SimpleProtocol::AddResponse>::Add_Impl(::zx::unowned_channel _client_end, |
| ::fidl::BytePart _request_buffer, |
| int32_t a, int32_t b, |
| ::fidl::BytePart _response_buffer) { |
| if (_request_buffer.capacity() < AddRequest::PrimarySize) { |
| Super::SetFailure(::fidl::DecodeResult<AddResponse>( |
| ZX_ERR_BUFFER_TOO_SMALL, |
| ::fidl::internal::kErrorRequestBufferTooSmall)); |
| return; |
| } |
| memset(_request_buffer.data(), 0, AddRequest::PrimarySize); |
| auto& _request = *reinterpret_cast<AddRequest*>(_request_buffer.data()); |
| _request.a = std::move(a); |
| _request.b = std::move(b); |
| _request_buffer.set_actual(sizeof(AddRequest)); |
| ::fidl::DecodedMessage<AddRequest> _decoded_request( |
| std::move(_request_buffer)); |
| Super::SetResult(SimpleProtocol::InPlace::Add(std::move(_client_end), |
| std::move(_decoded_request), |
| std::move(_response_buffer))); |
| } |
| |
| SimpleProtocol::UnownedResultOf::Add SimpleProtocol::SyncClient::Add( |
| ::fidl::BytePart _request_buffer, int32_t a, int32_t b, |
| ::fidl::BytePart _response_buffer) { |
| return UnownedResultOf::Add(::zx::unowned_channel(this->channel_), |
| std::move(_request_buffer), std::move(a), |
| std::move(b), std::move(_response_buffer)); |
| } |
| |
| SimpleProtocol::UnownedResultOf::Add SimpleProtocol::Call::Add( |
| ::zx::unowned_channel _client_end, ::fidl::BytePart _request_buffer, |
| int32_t a, int32_t b, ::fidl::BytePart _response_buffer) { |
| return UnownedResultOf::Add(std::move(_client_end), |
| std::move(_request_buffer), std::move(a), |
| std::move(b), std::move(_response_buffer)); |
| } |
| |
| ::fidl::DecodeResult<SimpleProtocol::AddResponse> SimpleProtocol::InPlace::Add( |
| ::zx::unowned_channel _client_end, |
| ::fidl::DecodedMessage<AddRequest> params, |
| ::fidl::BytePart response_buffer) { |
| SimpleProtocol::SetTransactionHeaderFor::AddRequest(params); |
| auto _encode_request_result = ::fidl::Encode(std::move(params)); |
| if (_encode_request_result.status != ZX_OK) { |
| return ::fidl::DecodeResult<SimpleProtocol::AddResponse>::FromFailure( |
| std::move(_encode_request_result)); |
| } |
| auto _call_result = ::fidl::Call<AddRequest, AddResponse>( |
| std::move(_client_end), std::move(_encode_request_result.message), |
| std::move(response_buffer)); |
| if (_call_result.status != ZX_OK) { |
| return ::fidl::DecodeResult<SimpleProtocol::AddResponse>::FromFailure( |
| std::move(_call_result)); |
| } |
| return ::fidl::Decode(std::move(_call_result.message)); |
| } |
| |
| bool SimpleProtocol::TryDispatch(Interface* impl, fidl_msg_t* msg, |
| ::fidl::Transaction* txn) { |
| if (msg->num_bytes < sizeof(fidl_message_header_t)) { |
| zx_handle_close_many(msg->handles, msg->num_handles); |
| txn->Close(ZX_ERR_INVALID_ARGS); |
| return true; |
| } |
| fidl_message_header_t* hdr = |
| reinterpret_cast<fidl_message_header_t*>(msg->bytes); |
| zx_status_t status = fidl_validate_txn_header(hdr); |
| if (status != ZX_OK) { |
| txn->Close(status); |
| return true; |
| } |
| switch (hdr->ordinal) { |
| case kSimpleProtocol_Add_Ordinal: |
| case kSimpleProtocol_Add_GenOrdinal: { |
| auto result = ::fidl::DecodeAs<AddRequest>(msg); |
| if (result.status != ZX_OK) { |
| txn->Close(ZX_ERR_INVALID_ARGS); |
| return true; |
| } |
| auto message = result.message.message(); |
| impl->Add(std::move(message->a), std::move(message->b), |
| Interface::AddCompleter::Sync(txn)); |
| return true; |
| } |
| default: { |
| return false; |
| } |
| } |
| } |
| |
| bool SimpleProtocol::Dispatch(Interface* impl, fidl_msg_t* msg, |
| ::fidl::Transaction* txn) { |
| bool found = TryDispatch(impl, msg, txn); |
| if (!found) { |
| zx_handle_close_many(msg->handles, msg->num_handles); |
| txn->Close(ZX_ERR_NOT_SUPPORTED); |
| } |
| return found; |
| } |
| |
| void SimpleProtocol::Interface::AddCompleterBase::Reply(int32_t sum) { |
| constexpr uint32_t _kWriteAllocSize = ::fidl::internal::ClampedMessageSize< |
| AddResponse, ::fidl::MessageDirection::kSending>(); |
| FIDL_ALIGNDECL uint8_t _write_bytes[_kWriteAllocSize] = {}; |
| auto& _response = *reinterpret_cast<AddResponse*>(_write_bytes); |
| SimpleProtocol::SetTransactionHeaderFor::AddResponse( |
| ::fidl::DecodedMessage<AddResponse>(::fidl::BytePart( |
| reinterpret_cast<uint8_t*>(&_response), AddResponse::PrimarySize, |
| AddResponse::PrimarySize))); |
| _response.sum = std::move(sum); |
| ::fidl::BytePart _response_bytes(_write_bytes, _kWriteAllocSize, |
| sizeof(AddResponse)); |
| CompleterBase::SendReply( |
| ::fidl::DecodedMessage<AddResponse>(std::move(_response_bytes))); |
| } |
| |
| void SimpleProtocol::Interface::AddCompleterBase::Reply( |
| ::fidl::BytePart _buffer, int32_t sum) { |
| if (_buffer.capacity() < AddResponse::PrimarySize) { |
| CompleterBase::Close(ZX_ERR_INTERNAL); |
| return; |
| } |
| auto& _response = *reinterpret_cast<AddResponse*>(_buffer.data()); |
| SimpleProtocol::SetTransactionHeaderFor::AddResponse( |
| ::fidl::DecodedMessage<AddResponse>(::fidl::BytePart( |
| reinterpret_cast<uint8_t*>(&_response), AddResponse::PrimarySize, |
| AddResponse::PrimarySize))); |
| _response.sum = std::move(sum); |
| _buffer.set_actual(sizeof(AddResponse)); |
| CompleterBase::SendReply( |
| ::fidl::DecodedMessage<AddResponse>(std::move(_buffer))); |
| } |
| |
| void SimpleProtocol::Interface::AddCompleterBase::Reply( |
| ::fidl::DecodedMessage<AddResponse> params) { |
| SimpleProtocol::SetTransactionHeaderFor::AddResponse(params); |
| CompleterBase::SendReply(std::move(params)); |
| } |
| |
| void SimpleProtocol::SetTransactionHeaderFor::AddRequest( |
| const ::fidl::DecodedMessage<SimpleProtocol::AddRequest>& _msg) { |
| fidl_init_txn_header(&_msg.message()->_hdr, 0, |
| kSimpleProtocol_Add_GenOrdinal); |
| _msg.message()->_hdr.flags[0] |= FIDL_TXN_HEADER_UNION_FROM_XUNION_FLAG; |
| } |
| void SimpleProtocol::SetTransactionHeaderFor::AddResponse( |
| const ::fidl::DecodedMessage<SimpleProtocol::AddResponse>& _msg) { |
| fidl_init_txn_header(&_msg.message()->_hdr, 0, |
| kSimpleProtocol_Add_GenOrdinal); |
| _msg.message()->_hdr.flags[0] |= FIDL_TXN_HEADER_UNION_FROM_XUNION_FLAG; |
| } |
| |
| void ::llcpp::fidl::test::nullable::SimpleUnion:: |
| SizeAndOffsetAssertionHelper() { |
| static_assert(sizeof(SimpleUnion) == sizeof(fidl_xunion_t)); |
| static_assert(offsetof(SimpleUnion, ordinal_) == |
| offsetof(fidl_xunion_t, tag)); |
| static_assert(offsetof(SimpleUnion, envelope_) == |
| offsetof(fidl_xunion_t, envelope)); |
| } |
| |
| } // namespace nullable |
| } // namespace test |
| } // namespace fidl |
| } // namespace llcpp |