| // WARNING: This file is machine generated by fidlgen. |
| |
| #include <error.test.json.h> |
| |
| #include "lib/fidl/cpp/internal/implementation.h" |
| namespace fidl { |
| namespace test { |
| namespace json { |
| |
| extern "C" const fidl_type_t fidl_test_json_Example_foo_ResponseTable; |
| const fidl_type_t* Example_foo_Response::FidlType = |
| &fidl_test_json_Example_foo_ResponseTable; |
| |
| void Example_foo_Response::Encode(::fidl::Encoder* _encoder, size_t _offset) { |
| if (::fidl::IsMemcpyCompatible<Example_foo_Response>::value) { |
| memcpy(_encoder->template GetPtr<Example_foo_Response>(_offset), this, |
| sizeof(Example_foo_Response)); |
| } else { |
| ::fidl::Encode(_encoder, &y, _offset + 0); |
| } |
| } |
| |
| void Example_foo_Response::Decode(::fidl::Decoder* _decoder, |
| Example_foo_Response* _value, |
| size_t _offset) { |
| if (::fidl::IsMemcpyCompatible<Example_foo_Response>::value) { |
| memcpy(_value, _decoder->template GetPtr<Example_foo_Response>(_offset), |
| sizeof(Example_foo_Response)); |
| } else { |
| ::fidl::Decode(_decoder, &_value->y, _offset + 0); |
| } |
| } |
| |
| zx_status_t Example_foo_Response::Clone(Example_foo_Response* _result) const { |
| zx_status_t _status = ::fidl::Clone(y, &_result->y); |
| if (_status != ZX_OK) return _status; |
| return ZX_OK; |
| } |
| extern "C" const fidl_type_t fidl_test_json_Example_foo_ResultTable; |
| const fidl_type_t* Example_foo_Result::FidlType = |
| &fidl_test_json_Example_foo_ResultTable; |
| |
| Example_foo_Result::Example_foo_Result() {} |
| |
| Example_foo_Result::~Example_foo_Result() { Destroy(); } |
| |
| Example_foo_Result::Example_foo_Result(Example_foo_Result&& other) |
| : tag_(other.tag_) { |
| switch (tag_) { |
| case Tag::kResponse: |
| new (&response_) class Example_foo_Response(); |
| response_ = std::move(other.response_); |
| break; |
| case Tag::kErr: |
| err_ = std::move(other.err_); |
| break; |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| } |
| } |
| |
| Example_foo_Result& Example_foo_Result::operator=(Example_foo_Result&& other) { |
| if (this != &other) { |
| Destroy(); |
| tag_ = other.tag_; |
| switch (tag_) { |
| case Tag::kResponse: |
| new (&response_) class Example_foo_Response(); |
| response_ = std::move(other.response_); |
| break; |
| case Tag::kErr: |
| err_ = std::move(other.err_); |
| break; |
| case static_cast<fidl_xunion_tag_t>(Tag::Invalid): |
| break; |
| } |
| } |
| return *this; |
| } |
| |
| Example_foo_Result Example_foo_Result::WithResponse( |
| class Example_foo_Response&& val) { |
| Example_foo_Result result; |
| result.set_response(std::move(val)); |
| return result; |
| } |
| Example_foo_Result Example_foo_Result::WithErr(uint32_t&& val) { |
| Example_foo_Result result; |
| result.set_err(std::move(val)); |
| return result; |
| } |
| |
| void Example_foo_Result::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::kResponse: { |
| envelope_offset = |
| encoder->Alloc(::fidl::EncodingInlineSize<class Example_foo_Response, |
| ::fidl::Encoder>(encoder)); |
| ::fidl::Encode(encoder, &response_, envelope_offset); |
| break; |
| } |
| case Tag::kErr: { |
| envelope_offset = encoder->Alloc( |
| ::fidl::EncodingInlineSize<uint32_t, ::fidl::Encoder>(encoder)); |
| ::fidl::Encode(encoder, &err_, 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 Example_foo_Result::Decode(::fidl::Decoder* decoder, |
| Example_foo_Result* 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::kResponse: |
| new (&value->response_) class Example_foo_Response(); |
| ::fidl::Decode(decoder, &value->response_, envelope_offset); |
| break; |
| case Tag::kErr: |
| ::fidl::Decode(decoder, &value->err_, envelope_offset); |
| break; |
| } |
| } |
| |
| zx_status_t Example_foo_Result::Clone(Example_foo_Result* result) const { |
| result->Destroy(); |
| result->tag_ = tag_; |
| switch (tag_) { |
| case Tag::Invalid: |
| return ZX_OK; |
| case Tag::kResponse: |
| new (&result->response_) class Example_foo_Response(); |
| return ::fidl::Clone(response_, &result->response_); |
| case Tag::kErr: |
| return ::fidl::Clone(err_, &result->err_); |
| default: |
| return ZX_OK; |
| } |
| } |
| |
| Example_foo_Result& Example_foo_Result::set_response( |
| class Example_foo_Response value) { |
| EnsureStorageInitialized(Tag::kResponse); |
| response_ = std::move(value); |
| return *this; |
| } |
| |
| Example_foo_Result& Example_foo_Result::set_err(uint32_t value) { |
| EnsureStorageInitialized(Tag::kErr); |
| err_ = std::move(value); |
| return *this; |
| } |
| |
| void Example_foo_Result::Destroy() { |
| switch (tag_) { |
| case Tag::kResponse: |
| response_.~decltype(response_)(); |
| break; |
| case Tag::kErr: |
| break; |
| |
| default: |
| break; |
| } |
| tag_ = static_cast<fidl_xunion_tag_t>(Tag::Invalid); |
| } |
| |
| void Example_foo_Result::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::kResponse: |
| new (&response_) class Example_foo_Response(); |
| break; |
| case Tag::kErr: |
| new (&err_) uint32_t(); |
| break; |
| default: |
| break; |
| } |
| } |
| } |
| #ifdef __Fuchsia__ |
| namespace { |
| |
| extern "C" const fidl_type_t fidl_test_json_ExamplefooRequestTable; |
| extern "C" const fidl_type_t fidl_test_json_ExamplefooResponseTable; |
| |
| } // namespace |
| |
| Example::~Example() = default; |
| |
| const fidl_type_t* Example_RequestDecoder::GetType(uint64_t ordinal, |
| bool* out_needs_response) { |
| switch (ordinal) { |
| case internal::kExample_foo_Ordinal: |
| *out_needs_response = true; |
| return &fidl_test_json_ExamplefooRequestTable; |
| default: |
| *out_needs_response = false; |
| return nullptr; |
| } |
| } |
| |
| const fidl_type_t* Example_ResponseDecoder::GetType(uint64_t ordinal) { |
| switch (ordinal) { |
| case internal::kExample_foo_Ordinal: |
| return &fidl_test_json_ExamplefooResponseTable; |
| default: |
| return nullptr; |
| } |
| } |
| |
| Example_EventSender::~Example_EventSender() = default; |
| |
| Example_Sync::~Example_Sync() = default; |
| |
| Example_Proxy::Example_Proxy(::fidl::internal::ProxyController* controller) |
| : controller_(controller) { |
| (void)controller_; |
| } |
| |
| Example_Proxy::~Example_Proxy() = default; |
| |
| zx_status_t Example_Proxy::Dispatch_(::fidl::Message message) { |
| zx_status_t status = ZX_OK; |
| switch (message.ordinal()) { |
| default: { |
| status = ZX_ERR_NOT_SUPPORTED; |
| break; |
| } |
| } |
| return status; |
| } |
| |
| namespace { |
| |
| ::std::unique_ptr<::fidl::internal::SingleUseMessageHandler> |
| Example_foo_ResponseHandler(Example::fooCallback callback) { |
| ZX_DEBUG_ASSERT_MSG(callback, |
| "Callback must not be empty for Example::foo\n"); |
| return ::std::make_unique<::fidl::internal::SingleUseMessageHandler>( |
| [callback_ = std::move(callback)](::fidl::Message message) { |
| const char* error_msg = nullptr; |
| zx_status_t status = |
| message.Decode(&fidl_test_json_ExamplefooResponseTable, &error_msg); |
| if (status != ZX_OK) { |
| FIDL_REPORT_DECODING_ERROR( |
| message, &fidl_test_json_ExamplefooResponseTable, error_msg); |
| return status; |
| } |
| ::fidl::Decoder decoder(std::move(message)); |
| callback_(::fidl::DecodeAs<Example_foo_Result>(&decoder, 16)); |
| return ZX_OK; |
| }); |
| } |
| |
| } // namespace |
| void Example_Proxy::foo(::std::string s, fooCallback callback) { |
| ::fidl::Encoder _encoder(internal::kExample_foo_Ordinal); |
| controller_->Send(&fidl_test_json_ExamplefooRequestTable, |
| Example_RequestEncoder::foo(&_encoder, &s), |
| Example_foo_ResponseHandler(std::move(callback))); |
| } |
| |
| Example_Stub::Example_Stub(Example_clazz* impl) : impl_(impl) { (void)impl_; } |
| |
| Example_Stub::~Example_Stub() = default; |
| |
| namespace { |
| |
| class Example_foo_Responder final { |
| public: |
| Example_foo_Responder(::fidl::internal::PendingResponse response) |
| : response_(std::move(response)) {} |
| |
| void operator()(Example_foo_Result result) { |
| ::fidl::Encoder _encoder(internal::kExample_foo_Ordinal); |
| response_.Send(&fidl_test_json_ExamplefooResponseTable, |
| Example_ResponseEncoder::foo(&_encoder, &result)); |
| } |
| |
| private: |
| ::fidl::internal::PendingResponse response_; |
| }; |
| |
| } // namespace |
| |
| zx_status_t Example_Stub::Dispatch_( |
| ::fidl::Message message, ::fidl::internal::PendingResponse response) { |
| bool needs_response; |
| const fidl_type_t* request_type = |
| Example_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::kExample_foo_Ordinal: { |
| ::fidl::Decoder decoder(std::move(message)); |
| impl_->foo(::fidl::DecodeAs<::std::string>(&decoder, 16), |
| Example_foo_Responder(std::move(response))); |
| break; |
| } |
| default: { |
| status = ZX_ERR_NOT_SUPPORTED; |
| break; |
| } |
| } |
| return status; |
| } |
| |
| Example_SyncProxy::Example_SyncProxy(::zx::channel channel) |
| : proxy_(::std::move(channel)) {} |
| |
| Example_SyncProxy::~Example_SyncProxy() = default; |
| |
| zx_status_t Example_SyncProxy::foo(::std::string s, |
| Example_foo_Result* out_result) { |
| ::fidl::Encoder _encoder(internal::kExample_foo_Ordinal); |
| ::fidl::MessageBuffer buffer_; |
| ::fidl::Message response_ = buffer_.CreateEmptyMessage(); |
| zx_status_t status_ = |
| proxy_.Call(&fidl_test_json_ExamplefooRequestTable, |
| &fidl_test_json_ExamplefooResponseTable, |
| Example_RequestEncoder::foo(&_encoder, &s), &response_); |
| if (status_ != ZX_OK) return status_; |
| ::fidl::Decoder decoder_(std::move(response_)); |
| *out_result = ::fidl::DecodeAs<Example_foo_Result>(&decoder_, 16); |
| return ZX_OK; |
| } |
| |
| #endif // __Fuchsia__ |
| |
| } // namespace json |
| } // namespace test |
| } // namespace fidl |