blob: 1b8b54fced595f88acc3ef09d7c9b5bdfb7ee2ff [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <handles_in_types.test.json.h>
#include "lib/fidl/cpp/internal/implementation.h"
namespace test {
namespace name {
extern "C" const fidl_type_t v1_test_name_UnionWithHandleTable;
const fidl_type_t* UnionWithHandle::FidlType =
&v1_test_name_UnionWithHandleTable;
UnionWithHandle::UnionWithHandle() {}
UnionWithHandle::~UnionWithHandle() { Destroy(); }
UnionWithHandle::UnionWithHandle(UnionWithHandle&& other) : tag_(other.tag_) {
switch (tag_) {
case Tag::kH:
new (&h_)::zx::vmo();
h_ = std::move(other.h_);
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;
}
}
UnionWithHandle& UnionWithHandle::operator=(UnionWithHandle&& other) {
if (this != &other) {
Destroy();
tag_ = other.tag_;
switch (tag_) {
case Tag::kH:
new (&h_)::zx::vmo();
h_ = std::move(other.h_);
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;
}
UnionWithHandle UnionWithHandle::WithH(::zx::vmo&& val) {
UnionWithHandle result;
result.set_h(std::move(val));
return result;
}
void UnionWithHandle::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::kH: {
envelope_offset = encoder->Alloc(
::fidl::EncodingInlineSize<::zx::vmo, ::fidl::Encoder>(encoder));
::fidl::Encode(encoder, &h_, 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 UnionWithHandle::Decode(::fidl::Decoder* decoder, UnionWithHandle* 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::kH:
new (&value->h_)::zx::vmo();
::fidl::Decode(decoder, &value->h_, 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 UnionWithHandle::Clone(UnionWithHandle* result) const {
result->Destroy();
result->tag_ = tag_;
switch (tag_) {
case Tag::kH:
new (&result->h_)::zx::vmo();
return ::fidl::Clone(h_, &result->h_);
default:
return ZX_OK;
}
}
UnionWithHandle& UnionWithHandle::set_h(::zx::vmo value) {
EnsureStorageInitialized(Tag::kH);
h_ = std::move(value);
return *this;
}
void UnionWithHandle::Destroy() {
switch (tag_) {
case Tag::kH:
h_.~decltype(h_)();
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 UnionWithHandle::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::kH:
new (&h_)::zx::vmo();
break;
default:
new (&unknown_data_) decltype(unknown_data_);
break;
}
}
}
extern "C" const fidl_type_t v1_test_name_TableWithHandleTable;
const fidl_type_t* TableWithHandle::FidlType =
&v1_test_name_TableWithHandleTable;
TableWithHandle::TableWithHandle() : has_h_(false) {}
TableWithHandle::TableWithHandle(TableWithHandle&& other) {
has_h_ = other.has_h_;
if (has_h_) {
Construct(&h_value_.value, std::move(other.h_value_.value));
}
}
TableWithHandle::~TableWithHandle() {
if (has_h_) {
Destruct(&h_value_.value);
}
}
TableWithHandle& TableWithHandle::operator=(TableWithHandle&& other) {
if (other.has_h_) {
if (has_h_) {
h_value_.value = std::move(other.h_value_.value);
} else {
has_h_ = true;
Construct(&h_value_.value, std::move(other.h_value_.value));
}
} else if (has_h_) {
has_h_ = false;
Destruct(&h_value_.value);
}
return *this;
}
bool TableWithHandle::IsEmpty() const {
if (has_h_) return false;
return true;
}
void TableWithHandle::Encode(::fidl::Encoder* _encoder, size_t _offset) {
size_t max_ordinal = 0;
if (has_h_) 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_h_) {
const size_t length_before = _encoder->CurrentLength();
const size_t handles_before = _encoder->CurrentHandleCount();
::fidl::Encode(
_encoder, &h_value_.value,
_encoder->Alloc(
::fidl::EncodingInlineSize<::zx::vmo, ::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 TableWithHandle::Decode(::fidl::Decoder* _decoder, TableWithHandle* _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_h(),
_decoder->GetOffset(presence));
} else {
_value->clear_h();
}
} else {
goto done_1;
}
return;
// Clear unset values.
clear_all:
done_1:
_value->clear_h();
return;
}
zx_status_t TableWithHandle::Clone(TableWithHandle* result) const {
if (has_h_) {
zx_status_t _status = ::fidl::Clone(h_value_.value, result->mutable_h());
if (_status != ZX_OK) return _status;
} else {
result->clear_h();
}
return ZX_OK;
}
extern "C" const fidl_type_t v1_test_name_HandlesInTypesTable;
const fidl_type_t* HandlesInTypes::FidlType = &v1_test_name_HandlesInTypesTable;
void HandlesInTypes::Encode(::fidl::Encoder* _encoder, size_t _offset) {
::fidl::Encode(_encoder, &normal_handle, _offset + 0);
::fidl::Encode(_encoder, &handle_in_vec, _offset + 8);
::fidl::Encode(_encoder, &handle_in_array, _offset + 24);
::fidl::Encode(_encoder, &handle_in_mixed_vec_array, _offset + 48);
::fidl::Encode(_encoder, &table_with_handle, _offset + 64);
::fidl::Encode(_encoder, &union_with_handle, _offset + 80);
}
void HandlesInTypes::Decode(::fidl::Decoder* _decoder, HandlesInTypes* value,
size_t _offset) {
::fidl::Decode(_decoder, &value->normal_handle, _offset + 0);
::fidl::Decode(_decoder, &value->handle_in_vec, _offset + 8);
::fidl::Decode(_decoder, &value->handle_in_array, _offset + 24);
::fidl::Decode(_decoder, &value->handle_in_mixed_vec_array, _offset + 48);
::fidl::Decode(_decoder, &value->table_with_handle, _offset + 64);
::fidl::Decode(_decoder, &value->union_with_handle, _offset + 80);
}
zx_status_t HandlesInTypes::Clone(HandlesInTypes* _result) const {
zx_status_t _status = ::fidl::Clone(normal_handle, &_result->normal_handle);
if (_status != ZX_OK) return _status;
_status = ::fidl::Clone(handle_in_vec, &_result->handle_in_vec);
if (_status != ZX_OK) return _status;
_status = ::fidl::Clone(handle_in_array, &_result->handle_in_array);
if (_status != ZX_OK) return _status;
_status = ::fidl::Clone(handle_in_mixed_vec_array,
&_result->handle_in_mixed_vec_array);
if (_status != ZX_OK) return _status;
_status = ::fidl::Clone(table_with_handle, &_result->table_with_handle);
if (_status != ZX_OK) return _status;
_status = ::fidl::Clone(union_with_handle, &_result->union_with_handle);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
} // namespace name
} // namespace test