blob: 39acce4f78f3754e6fca3b65e95ac2066c52e2f0 [file] [log] [blame]
// 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 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:
*out_needs_response = false;
return &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_Ordinal);
controller_->Send(&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: {
::fidl::Decoder decoder(std::move(message));
impl_->Method(::fidl::DecodeAs<::exampleusing::Empty>(&decoder, 16));
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_Ordinal);
return proxy_.Send(&example_ExampleProtocolMethodRequestTable,
ExampleProtocol_RequestEncoder::Method(&_encoder, &arg));
}
#endif // __Fuchsia__
extern "C" const fidl_type_t example_ExampleXUnionTable;
const fidl_type_t* ExampleXUnion::FidlType = &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 (Which()) {
case Tag::kVariant: {
envelope_offset = encoder->Alloc(
::fidl::EncodingInlineSize<uint32_t, ::fidl::Encoder>(encoder));
::fidl::Encode(encoder, &variant_, envelope_offset);
break;
}
case Tag::kUnknown:
envelope_offset = encoder->Alloc(unknown_data_.bytes.size());
::fidl::Encode(encoder, &unknown_data_, 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 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_.bytes.resize(xunion->envelope.num_bytes);
::fidl::Decode(decoder, &value->unknown_data_, envelope_offset);
break;
}
}
zx_status_t ExampleXUnion::Clone(ExampleXUnion* result) const {
result->Destroy();
result->tag_ = tag_;
switch (tag_) {
case Tag::Invalid:
return ZX_OK;
case Tag::kVariant:
return ::fidl::Clone(variant_, &result->variant_);
default:
new (&result->unknown_data_) decltype(unknown_data_);
return ::fidl::Clone(unknown_data_, &result->unknown_data_);
return ZX_OK;
}
}
ExampleXUnion& ExampleXUnion::set_variant(uint32_t value) {
EnsureStorageInitialized(Tag::kVariant);
variant_ = std::move(value);
return *this;
}
ExampleXUnion& ExampleXUnion::_experimental_set_unknown_data(
fidl_xunion_tag_t ordinal, std::vector<uint8_t> bytes) {
EnsureStorageInitialized(ordinal);
unknown_data_.bytes = std::move(bytes);
return *this;
}
void ExampleXUnion::Destroy() {
switch (tag_) {
case Tag::kVariant:
break;
case static_cast<fidl_xunion_tag_t>(Tag::Invalid):
break;
default:
unknown_data_.~decltype(unknown_data_)();
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 example_ExampleUnionTable;
const fidl_type_t* ExampleUnion::FidlType = &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 (Which()) {
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 =
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 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;
default:
break;
}
}
zx_status_t ExampleUnion::Clone(ExampleUnion* result) const {
result->Destroy();
result->tag_ = tag_;
switch (tag_) {
case Tag::Invalid:
return ZX_OK;
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 example_ExampleTableTable;
const fidl_type_t* ExampleTable::FidlType = &example_ExampleTableTable;
ExampleTable::ExampleTable() {}
ExampleTable::ExampleTable(ExampleTable&& other) {
field_presence_ = other.field_presence_;
if (field_presence_.IsSet<0>()) {
Construct(&member_value_.value, std::move(other.member_value_.value));
}
}
ExampleTable::~ExampleTable() {
if (field_presence_.IsSet<0>()) {
Destruct(&member_value_.value);
}
}
ExampleTable& ExampleTable::operator=(ExampleTable&& other) {
if (other.field_presence_.IsSet<0>()) {
if (field_presence_.IsSet<0>()) {
member_value_.value = std::move(other.member_value_.value);
} else {
field_presence_.Set<0>();
Construct(&member_value_.value, std::move(other.member_value_.value));
}
} else if (field_presence_.IsSet<0>()) {
field_presence_.Clear<0>();
Destruct(&member_value_.value);
}
return *this;
}
bool ExampleTable::IsEmpty() const { return field_presence_.IsEmpty(); }
void ExampleTable::Encode(::fidl::Encoder* _encoder, size_t _offset) {
size_t max_ordinal = field_presence_.MaxSetIndex() + 1ll;
::fidl::EncodeVectorPointer(_encoder, max_ordinal, _offset);
if (max_ordinal == 0) return;
size_t base = _encoder->Alloc(max_ordinal * 2 * sizeof(uint64_t));
if (field_presence_.IsSet<0>()) {
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 (field_presence_.IsSet<0>()) {
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 example_ExampleStructTable;
const fidl_type_t* ExampleStruct::FidlType = &example_ExampleStructTable;
void ExampleStruct::Encode(::fidl::Encoder* _encoder, size_t _offset) {
if (::fidl::IsMemcpyCompatible<ExampleStruct>::value) {
memcpy(_encoder->template GetPtr<ExampleStruct>(_offset), this,
sizeof(ExampleStruct));
} else {
::fidl::Encode(_encoder, &member, _offset + 0);
}
}
void ExampleStruct::Decode(::fidl::Decoder* _decoder, ExampleStruct* _value,
size_t _offset) {
if (::fidl::IsMemcpyCompatible<ExampleStruct>::value) {
memcpy(_value, _decoder->template GetPtr<ExampleStruct>(_offset),
sizeof(ExampleStruct));
} else {
::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