blob: f76504010afa01ba89c65d18ba1675d41a4c6f3c [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <fidl/test/nullable/cpp/fidl.h>
#include "lib/fidl/cpp/internal/implementation.h"
//
// Domain objects definitions (i.e. "natural types" in unified bindings)
//
namespace fidl {
namespace test {
namespace nullable {
extern "C" const fidl_type_t fidl_test_nullable_StructWithNullableVectorTable;
const fidl_type_t* StructWithNullableVector::FidlType =
&fidl_test_nullable_StructWithNullableVectorTable;
void StructWithNullableVector::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructWithNullableVector>::value) {
memcpy(_encoder->template GetPtr<StructWithNullableVector>(_offset), this,
sizeof(StructWithNullableVector));
} else {
::fidl::Encode(_encoder, &val, _offset + 0);
}
}
void StructWithNullableVector::Decode(::fidl::Decoder* _decoder,
StructWithNullableVector* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructWithNullableVector>::value) {
memcpy(_value, _decoder->template GetPtr<StructWithNullableVector>(_offset),
sizeof(StructWithNullableVector));
} else {
::fidl::Decode(_decoder, &_value->val, _offset + 0);
}
}
zx_status_t StructWithNullableVector::Clone(
StructWithNullableVector* _result) const {
zx_status_t _status = ::fidl::Clone(val, &_result->val);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
extern "C" const fidl_type_t fidl_test_nullable_StructWithNullableUnionTable;
const fidl_type_t* StructWithNullableUnion::FidlType =
&fidl_test_nullable_StructWithNullableUnionTable;
void StructWithNullableUnion::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructWithNullableUnion>::value) {
memcpy(_encoder->template GetPtr<StructWithNullableUnion>(_offset), this,
sizeof(StructWithNullableUnion));
} else {
::fidl::Encode(_encoder, &val, _offset + 0);
}
}
void StructWithNullableUnion::Decode(::fidl::Decoder* _decoder,
StructWithNullableUnion* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructWithNullableUnion>::value) {
memcpy(_value, _decoder->template GetPtr<StructWithNullableUnion>(_offset),
sizeof(StructWithNullableUnion));
} else {
::fidl::Decode(_decoder, &_value->val, _offset + 0);
}
}
zx_status_t StructWithNullableUnion::Clone(
StructWithNullableUnion* _result) const {
zx_status_t _status = ::fidl::Clone(val, &_result->val);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
extern "C" const fidl_type_t fidl_test_nullable_StructWithNullableStructTable;
const fidl_type_t* StructWithNullableStruct::FidlType =
&fidl_test_nullable_StructWithNullableStructTable;
void StructWithNullableStruct::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructWithNullableStruct>::value) {
memcpy(_encoder->template GetPtr<StructWithNullableStruct>(_offset), this,
sizeof(StructWithNullableStruct));
} else {
::fidl::Encode(_encoder, &val, _offset + 0);
}
}
void StructWithNullableStruct::Decode(::fidl::Decoder* _decoder,
StructWithNullableStruct* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructWithNullableStruct>::value) {
memcpy(_value, _decoder->template GetPtr<StructWithNullableStruct>(_offset),
sizeof(StructWithNullableStruct));
} else {
::fidl::Decode(_decoder, &_value->val, _offset + 0);
}
}
zx_status_t StructWithNullableStruct::Clone(
StructWithNullableStruct* _result) const {
zx_status_t _status = ::fidl::Clone(val, &_result->val);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
extern "C" const fidl_type_t fidl_test_nullable_StructWithNullableStringTable;
const fidl_type_t* StructWithNullableString::FidlType =
&fidl_test_nullable_StructWithNullableStringTable;
void StructWithNullableString::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructWithNullableString>::value) {
memcpy(_encoder->template GetPtr<StructWithNullableString>(_offset), this,
sizeof(StructWithNullableString));
} else {
::fidl::Encode(_encoder, &val, _offset + 0);
}
}
void StructWithNullableString::Decode(::fidl::Decoder* _decoder,
StructWithNullableString* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructWithNullableString>::value) {
memcpy(_value, _decoder->template GetPtr<StructWithNullableString>(_offset),
sizeof(StructWithNullableString));
} else {
::fidl::Decode(_decoder, &_value->val, _offset + 0);
}
}
zx_status_t StructWithNullableString::Clone(
StructWithNullableString* _result) const {
zx_status_t _status = ::fidl::Clone(val, &_result->val);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
#ifdef __Fuchsia__
extern "C" const fidl_type_t fidl_test_nullable_StructWithNullableRequestTable;
const fidl_type_t* StructWithNullableRequest::FidlType =
&fidl_test_nullable_StructWithNullableRequestTable;
void StructWithNullableRequest::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructWithNullableRequest>::value) {
memcpy(_encoder->template GetPtr<StructWithNullableRequest>(_offset), this,
sizeof(StructWithNullableRequest));
} else {
::fidl::Encode(_encoder, &val, _offset + 0);
}
}
void StructWithNullableRequest::Decode(::fidl::Decoder* _decoder,
StructWithNullableRequest* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructWithNullableRequest>::value) {
memcpy(_value,
_decoder->template GetPtr<StructWithNullableRequest>(_offset),
sizeof(StructWithNullableRequest));
} else {
::fidl::Decode(_decoder, &_value->val, _offset + 0);
}
}
zx_status_t StructWithNullableRequest::Clone(
StructWithNullableRequest* _result) const {
zx_status_t _status = ::fidl::Clone(val, &_result->val);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
#endif // __Fuchsia__
#ifdef __Fuchsia__
extern "C" const fidl_type_t fidl_test_nullable_StructWithNullableProtocolTable;
const fidl_type_t* StructWithNullableProtocol::FidlType =
&fidl_test_nullable_StructWithNullableProtocolTable;
void StructWithNullableProtocol::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructWithNullableProtocol>::value) {
memcpy(_encoder->template GetPtr<StructWithNullableProtocol>(_offset), this,
sizeof(StructWithNullableProtocol));
} else {
::fidl::Encode(_encoder, &val, _offset + 0);
}
}
void StructWithNullableProtocol::Decode(::fidl::Decoder* _decoder,
StructWithNullableProtocol* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructWithNullableProtocol>::value) {
memcpy(_value,
_decoder->template GetPtr<StructWithNullableProtocol>(_offset),
sizeof(StructWithNullableProtocol));
} else {
::fidl::Decode(_decoder, &_value->val, _offset + 0);
}
}
zx_status_t StructWithNullableProtocol::Clone(
StructWithNullableProtocol* _result) const {
zx_status_t _status = ::fidl::Clone(val, &_result->val);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
#endif // __Fuchsia__
#ifdef __Fuchsia__
extern "C" const fidl_type_t fidl_test_nullable_StructWithNullableHandleTable;
const fidl_type_t* StructWithNullableHandle::FidlType =
&fidl_test_nullable_StructWithNullableHandleTable;
void StructWithNullableHandle::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructWithNullableHandle>::value) {
memcpy(_encoder->template GetPtr<StructWithNullableHandle>(_offset), this,
sizeof(StructWithNullableHandle));
} else {
::fidl::Encode(_encoder, &val, _offset + 0,
::fidl::HandleInformation{
.object_type = ZX_OBJ_TYPE_VMO,
.rights = 0x80000000,
});
}
}
void StructWithNullableHandle::Decode(::fidl::Decoder* _decoder,
StructWithNullableHandle* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructWithNullableHandle>::value) {
memcpy(_value, _decoder->template GetPtr<StructWithNullableHandle>(_offset),
sizeof(StructWithNullableHandle));
} else {
::fidl::Decode(_decoder, &_value->val, _offset + 0);
}
}
zx_status_t StructWithNullableHandle::Clone(
StructWithNullableHandle* _result) const {
zx_status_t _status = ::fidl::Clone(val, &_result->val);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
#endif // __Fuchsia__
extern "C" const fidl_type_t fidl_test_nullable_SimpleUnionTable;
const fidl_type_t* SimpleUnion::FidlType = &fidl_test_nullable_SimpleUnionTable;
SimpleUnion::SimpleUnion() {}
SimpleUnion::~SimpleUnion() { Destroy(); }
SimpleUnion::SimpleUnion(SimpleUnion&& other) : tag_(other.tag_) {
switch (tag_) {
case ::fidl::test::nullable::SimpleUnion::Tag::kA:
a_ = std::move(other.a_);
break;
case ::fidl::test::nullable::SimpleUnion::Tag::kB:
b_ = std::move(other.b_);
break;
case static_cast<fidl_xunion_tag_t>(
::fidl::test::nullable::SimpleUnion::Tag::Invalid):
break;
}
}
SimpleUnion& SimpleUnion::operator=(SimpleUnion&& other) {
if (this != &other) {
Destroy();
tag_ = other.tag_;
switch (tag_) {
case ::fidl::test::nullable::SimpleUnion::Tag::kA:
a_ = std::move(other.a_);
break;
case ::fidl::test::nullable::SimpleUnion::Tag::kB:
b_ = std::move(other.b_);
break;
case static_cast<fidl_xunion_tag_t>(
::fidl::test::nullable::SimpleUnion::Tag::Invalid):
break;
}
}
return *this;
}
SimpleUnion SimpleUnion::WithA(int32_t&& val) {
SimpleUnion result;
result.set_a(std::move(val));
return result;
}
SimpleUnion SimpleUnion::WithB(float&& val) {
SimpleUnion result;
result.set_b(std::move(val));
return result;
}
void SimpleUnion::Encode(
::fidl::Encoder* encoder, size_t offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
const size_t length_before = encoder->CurrentLength();
const size_t handles_before = encoder->CurrentHandleCount();
size_t envelope_offset = 0;
switch (Which()) {
case ::fidl::test::nullable::SimpleUnion::Tag::kA: {
envelope_offset = encoder->Alloc(
::fidl::EncodingInlineSize<int32_t, ::fidl::Encoder>(encoder));
::fidl::Encode(encoder, &a_, envelope_offset);
break;
}
case ::fidl::test::nullable::SimpleUnion::Tag::kB: {
envelope_offset = encoder->Alloc(
::fidl::EncodingInlineSize<float, ::fidl::Encoder>(encoder));
::fidl::Encode(encoder, &b_, 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 =
static_cast<uint32_t>(encoder->CurrentLength() - length_before);
xunion->envelope.num_handles =
static_cast<uint32_t>(encoder->CurrentHandleCount() - handles_before);
xunion->envelope.presence = FIDL_ALLOC_PRESENT;
}
}
void SimpleUnion::Decode(::fidl::Decoder* decoder, SimpleUnion* 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>(
::fidl::test::nullable::SimpleUnion::Tag::Invalid));
return;
}
value->EnsureStorageInitialized(xunion->tag);
const size_t envelope_offset = decoder->GetOffset(xunion->envelope.data);
switch (value->tag_) {
case ::fidl::test::nullable::SimpleUnion::Tag::kA:
::fidl::Decode(decoder, &value->a_, envelope_offset);
break;
case ::fidl::test::nullable::SimpleUnion::Tag::kB:
::fidl::Decode(decoder, &value->b_, envelope_offset);
break;
default:
break;
}
}
zx_status_t SimpleUnion::Clone(SimpleUnion* result) const {
result->Destroy();
result->tag_ = tag_;
switch (tag_) {
case ::fidl::test::nullable::SimpleUnion::Tag::Invalid:
return ZX_OK;
case ::fidl::test::nullable::SimpleUnion::Tag::kA:
return ::fidl::Clone(a_, &result->a_);
case ::fidl::test::nullable::SimpleUnion::Tag::kB:
return ::fidl::Clone(b_, &result->b_);
default:
return ZX_OK;
}
}
SimpleUnion& SimpleUnion::set_a(int32_t value) {
EnsureStorageInitialized(::fidl::test::nullable::SimpleUnion::Tag::kA);
a_ = std::move(value);
return *this;
}
SimpleUnion& SimpleUnion::set_b(float value) {
EnsureStorageInitialized(::fidl::test::nullable::SimpleUnion::Tag::kB);
b_ = std::move(value);
return *this;
}
void SimpleUnion::Destroy() {
switch (tag_) {
case ::fidl::test::nullable::SimpleUnion::Tag::kA:
break;
case ::fidl::test::nullable::SimpleUnion::Tag::kB:
break;
default:
break;
}
tag_ = static_cast<fidl_xunion_tag_t>(
::fidl::test::nullable::SimpleUnion::Tag::Invalid);
}
void SimpleUnion::EnsureStorageInitialized(::fidl_xunion_tag_t tag) {
if (tag_ != tag) {
Destroy();
tag_ = tag;
switch (tag_) {
case static_cast<fidl_xunion_tag_t>(
::fidl::test::nullable::SimpleUnion::Tag::Invalid):
break;
case ::fidl::test::nullable::SimpleUnion::Tag::kA:
new (&a_) int32_t();
break;
case ::fidl::test::nullable::SimpleUnion::Tag::kB:
new (&b_) float();
break;
default:
break;
}
}
}
extern "C" const fidl_type_t fidl_test_nullable_Int32WrapperTable;
const fidl_type_t* Int32Wrapper::FidlType =
&fidl_test_nullable_Int32WrapperTable;
void Int32Wrapper::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<Int32Wrapper>::value) {
memcpy(_encoder->template GetPtr<Int32Wrapper>(_offset), this,
sizeof(Int32Wrapper));
} else {
::fidl::Encode(_encoder, &val, _offset + 0);
}
}
void Int32Wrapper::Decode(::fidl::Decoder* _decoder, Int32Wrapper* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<Int32Wrapper>::value) {
memcpy(_value, _decoder->template GetPtr<Int32Wrapper>(_offset),
sizeof(Int32Wrapper));
} else {
::fidl::Decode(_decoder, &_value->val, _offset + 0);
}
}
zx_status_t Int32Wrapper::Clone(Int32Wrapper* _result) const {
zx_status_t _status = ::fidl::Clone(val, &_result->val);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
//
// Proxies and stubs definitions
//
#ifdef __Fuchsia__
namespace _internal {
extern "C" const fidl_type_t fidl_test_nullable_SimpleProtocolAddRequestTable;
extern "C" const fidl_type_t fidl_test_nullable_SimpleProtocolAddResponseTable;
} // namespace _internal
SimpleProtocol::~SimpleProtocol() = default;
const fidl_type_t* ::fidl::test::nullable::SimpleProtocol_RequestDecoder::
GetType(uint64_t ordinal, bool* out_needs_response) {
switch (ordinal) {
case ::fidl::test::nullable::internal::kSimpleProtocol_Add_Ordinal:
*out_needs_response = true;
return &::fidl::test::nullable::_internal::
fidl_test_nullable_SimpleProtocolAddRequestTable;
default:
*out_needs_response = false;
return nullptr;
}
}
const fidl_type_t* SimpleProtocol_ResponseDecoder::GetType(uint64_t ordinal) {
switch (ordinal) {
case ::fidl::test::nullable::internal::kSimpleProtocol_Add_Ordinal:
return &::fidl::test::nullable::_internal::
fidl_test_nullable_SimpleProtocolAddResponseTable;
default:
return nullptr;
}
}
SimpleProtocol_EventSender::~SimpleProtocol_EventSender() = default;
SimpleProtocol_Sync::~SimpleProtocol_Sync() = default;
SimpleProtocol_Proxy::SimpleProtocol_Proxy(
::fidl::internal::ProxyController* controller)
: controller_(controller) {
(void)controller_;
}
SimpleProtocol_Proxy::~SimpleProtocol_Proxy() = default;
zx_status_t SimpleProtocol_Proxy::Dispatch_(
::fidl::HLCPPIncomingMessage 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>
SimpleProtocol_Add_ResponseHandler(SimpleProtocol::AddCallback&& callback) {
ZX_DEBUG_ASSERT_MSG(callback,
"Callback must not be empty for SimpleProtocol::Add\n");
return ::std::make_unique<::fidl::internal::SingleUseMessageHandler>(
[callback_ =
std::move(callback)](::fidl::HLCPPIncomingMessage&& message) {
::fidl::Decoder decoder(std::move(message));
callback_(::fidl::DecodeAs<int32_t>(&decoder, 16));
return ZX_OK;
},
&::fidl::test::nullable::_internal::
fidl_test_nullable_SimpleProtocolAddResponseTable);
}
} // namespace
void SimpleProtocol_Proxy::Add(int32_t a, int32_t b, AddCallback callback) {
::fidl::Encoder _encoder(
::fidl::test::nullable::internal::kSimpleProtocol_Add_Ordinal);
controller_->Send(&::fidl::test::nullable::_internal::
fidl_test_nullable_SimpleProtocolAddRequestTable,
::fidl::test::nullable::SimpleProtocol_RequestEncoder::Add(
&_encoder, &a, &b),
SimpleProtocol_Add_ResponseHandler(std::move(callback)));
}
SimpleProtocol_Stub::SimpleProtocol_Stub(
::fidl::test::nullable::SimpleProtocol_Stub::SimpleProtocol_clazz* impl)
: impl_(impl) {
(void)impl_;
}
SimpleProtocol_Stub::~SimpleProtocol_Stub() = default;
namespace {
class SimpleProtocol_Add_Responder final {
public:
SimpleProtocol_Add_Responder(::fidl::internal::PendingResponse response)
: response_(std::move(response)) {}
void operator()(int32_t sum) {
::fidl::Encoder _encoder(
::fidl::test::nullable::internal::kSimpleProtocol_Add_Ordinal);
response_.Send(&::fidl::test::nullable::_internal::
fidl_test_nullable_SimpleProtocolAddResponseTable,
::fidl::test::nullable::SimpleProtocol_ResponseEncoder::Add(
&_encoder, &sum));
}
private:
::fidl::internal::PendingResponse response_;
};
} // namespace
zx_status_t SimpleProtocol_Stub::Dispatch_(
::fidl::HLCPPIncomingMessage message,
::fidl::internal::PendingResponse response) {
bool needs_response;
const fidl_type_t* request_type =
::fidl::test::nullable::SimpleProtocol_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 ::fidl::test::nullable::internal::kSimpleProtocol_Add_Ordinal: {
::fidl::Decoder decoder(std::move(message));
impl_->Add(::fidl::DecodeAs<int32_t>(&decoder, 16),
::fidl::DecodeAs<int32_t>(&decoder, 20),
SimpleProtocol_Add_Responder(std::move(response)));
break;
}
default: {
status = ZX_ERR_NOT_SUPPORTED;
break;
}
}
return status;
}
SimpleProtocol_SyncProxy::SimpleProtocol_SyncProxy(::zx::channel channel)
: proxy_(::std::move(channel)) {}
SimpleProtocol_SyncProxy::~SimpleProtocol_SyncProxy() = default;
zx_status_t SimpleProtocol_SyncProxy::Add(int32_t a, int32_t b,
int32_t* out_sum) {
::fidl::Encoder _encoder(
::fidl::test::nullable::internal::kSimpleProtocol_Add_Ordinal);
::fidl::IncomingMessageBuffer buffer_;
::fidl::HLCPPIncomingMessage response_ = buffer_.CreateEmptyIncomingMessage();
zx_status_t status_ =
proxy_.Call(&::fidl::test::nullable::_internal::
fidl_test_nullable_SimpleProtocolAddRequestTable,
&::fidl::test::nullable::_internal::
fidl_test_nullable_SimpleProtocolAddResponseTable,
::fidl::test::nullable::SimpleProtocol_RequestEncoder::Add(
&_encoder, &a, &b),
&response_);
if (status_ != ZX_OK) return status_;
::fidl::Decoder decoder_(std::move(response_));
*out_sum = ::fidl::DecodeAs<int32_t>(&decoder_, 16);
return ZX_OK;
}
#endif // __Fuchsia__
} // namespace nullable
} // namespace test
} // namespace fidl