blob: 4fe1879f9bb7697e9006b28be8042968e0fba1f5 [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
#include <fidl/test/arrays/cpp/natural_types.h>
#include "lib/fidl/cpp/internal/natural_types_implementation.h"
//
// Domain objects definitions (i.e. "natural types" in unified bindings)
//
namespace fidl {
namespace test {
namespace arrays {
extern "C" const fidl_type_t fidl_test_arrays_UnionSmallArrayTable;
const fidl_type_t* UnionSmallArray::FidlType =
&fidl_test_arrays_UnionSmallArrayTable;
UnionSmallArray::UnionSmallArray() {}
UnionSmallArray::~UnionSmallArray() { Destroy(); }
UnionSmallArray::UnionSmallArray(UnionSmallArray&& other) : tag_(other.tag_) {
switch (tag_) {
case ::fidl::test::arrays::UnionSmallArray::Tag::kA:
new (&a_)::std::array<uint32_t, 2>();
a_ = std::move(other.a_);
break;
case static_cast<fidl_xunion_tag_t>(
::fidl::test::arrays::UnionSmallArray::Tag::Invalid):
break;
}
}
UnionSmallArray& UnionSmallArray::operator=(UnionSmallArray&& other) {
if (this != &other) {
Destroy();
tag_ = other.tag_;
switch (tag_) {
case ::fidl::test::arrays::UnionSmallArray::Tag::kA:
new (&a_)::std::array<uint32_t, 2>();
a_ = std::move(other.a_);
break;
case static_cast<fidl_xunion_tag_t>(
::fidl::test::arrays::UnionSmallArray::Tag::Invalid):
break;
}
}
return *this;
}
UnionSmallArray UnionSmallArray::WithA(::std::array<uint32_t, 2>&& val) {
UnionSmallArray result;
result.set_a(std::move(val));
return result;
}
void UnionSmallArray::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::arrays::UnionSmallArray::Tag::kA: {
envelope_offset =
encoder->Alloc(::fidl::EncodingInlineSize<::std::array<uint32_t, 2>,
::fidl::Encoder>(encoder));
::fidl::Encode(encoder, &a_, 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 UnionSmallArray::Decode(::fidl::Decoder* decoder, UnionSmallArray* 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::arrays::UnionSmallArray::Tag::Invalid));
return;
}
value->EnsureStorageInitialized(xunion->tag);
const size_t envelope_offset = decoder->GetOffset(xunion->envelope.data);
switch (value->tag_) {
case ::fidl::test::arrays::UnionSmallArray::Tag::kA:
new (&value->a_)::std::array<uint32_t, 2>();
::fidl::Decode(decoder, &value->a_, envelope_offset);
break;
default:
break;
}
}
zx_status_t UnionSmallArray::Clone(UnionSmallArray* result) const {
result->Destroy();
result->tag_ = tag_;
switch (tag_) {
case ::fidl::test::arrays::UnionSmallArray::Tag::Invalid:
return ZX_OK;
case ::fidl::test::arrays::UnionSmallArray::Tag::kA:
new (&result->a_)::std::array<uint32_t, 2>();
return ::fidl::Clone(a_, &result->a_);
default:
return ZX_OK;
}
}
UnionSmallArray& UnionSmallArray::set_a(::std::array<uint32_t, 2> value) {
EnsureStorageInitialized(::fidl::test::arrays::UnionSmallArray::Tag::kA);
a_ = std::move(value);
return *this;
}
void UnionSmallArray::Destroy() {
switch (tag_) {
case ::fidl::test::arrays::UnionSmallArray::Tag::kA:
a_.~decltype(a_)();
break;
default:
break;
}
tag_ = static_cast<fidl_xunion_tag_t>(
::fidl::test::arrays::UnionSmallArray::Tag::Invalid);
}
void UnionSmallArray::EnsureStorageInitialized(::fidl_xunion_tag_t tag) {
if (tag_ != tag) {
Destroy();
tag_ = tag;
switch (tag_) {
case static_cast<fidl_xunion_tag_t>(
::fidl::test::arrays::UnionSmallArray::Tag::Invalid):
break;
case ::fidl::test::arrays::UnionSmallArray::Tag::kA:
new (&a_)::std::array<uint32_t, 2>();
break;
default:
break;
}
}
}
extern "C" const fidl_type_t fidl_test_arrays_UnionLargeArrayTable;
const fidl_type_t* UnionLargeArray::FidlType =
&fidl_test_arrays_UnionLargeArrayTable;
UnionLargeArray::UnionLargeArray() {}
UnionLargeArray::~UnionLargeArray() { Destroy(); }
UnionLargeArray::UnionLargeArray(UnionLargeArray&& other) : tag_(other.tag_) {
switch (tag_) {
case ::fidl::test::arrays::UnionLargeArray::Tag::kA:
new (&a_)::std::array<uint32_t, 100>();
a_ = std::move(other.a_);
break;
case static_cast<fidl_xunion_tag_t>(
::fidl::test::arrays::UnionLargeArray::Tag::Invalid):
break;
}
}
UnionLargeArray& UnionLargeArray::operator=(UnionLargeArray&& other) {
if (this != &other) {
Destroy();
tag_ = other.tag_;
switch (tag_) {
case ::fidl::test::arrays::UnionLargeArray::Tag::kA:
new (&a_)::std::array<uint32_t, 100>();
a_ = std::move(other.a_);
break;
case static_cast<fidl_xunion_tag_t>(
::fidl::test::arrays::UnionLargeArray::Tag::Invalid):
break;
}
}
return *this;
}
UnionLargeArray UnionLargeArray::WithA(::std::array<uint32_t, 100>&& val) {
UnionLargeArray result;
result.set_a(std::move(val));
return result;
}
void UnionLargeArray::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::arrays::UnionLargeArray::Tag::kA: {
envelope_offset =
encoder->Alloc(::fidl::EncodingInlineSize<::std::array<uint32_t, 100>,
::fidl::Encoder>(encoder));
::fidl::Encode(encoder, &a_, 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 UnionLargeArray::Decode(::fidl::Decoder* decoder, UnionLargeArray* 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::arrays::UnionLargeArray::Tag::Invalid));
return;
}
value->EnsureStorageInitialized(xunion->tag);
const size_t envelope_offset = decoder->GetOffset(xunion->envelope.data);
switch (value->tag_) {
case ::fidl::test::arrays::UnionLargeArray::Tag::kA:
new (&value->a_)::std::array<uint32_t, 100>();
::fidl::Decode(decoder, &value->a_, envelope_offset);
break;
default:
break;
}
}
zx_status_t UnionLargeArray::Clone(UnionLargeArray* result) const {
result->Destroy();
result->tag_ = tag_;
switch (tag_) {
case ::fidl::test::arrays::UnionLargeArray::Tag::Invalid:
return ZX_OK;
case ::fidl::test::arrays::UnionLargeArray::Tag::kA:
new (&result->a_)::std::array<uint32_t, 100>();
return ::fidl::Clone(a_, &result->a_);
default:
return ZX_OK;
}
}
UnionLargeArray& UnionLargeArray::set_a(::std::array<uint32_t, 100> value) {
EnsureStorageInitialized(::fidl::test::arrays::UnionLargeArray::Tag::kA);
a_ = std::move(value);
return *this;
}
void UnionLargeArray::Destroy() {
switch (tag_) {
case ::fidl::test::arrays::UnionLargeArray::Tag::kA:
a_.~decltype(a_)();
break;
default:
break;
}
tag_ = static_cast<fidl_xunion_tag_t>(
::fidl::test::arrays::UnionLargeArray::Tag::Invalid);
}
void UnionLargeArray::EnsureStorageInitialized(::fidl_xunion_tag_t tag) {
if (tag_ != tag) {
Destroy();
tag_ = tag;
switch (tag_) {
case static_cast<fidl_xunion_tag_t>(
::fidl::test::arrays::UnionLargeArray::Tag::Invalid):
break;
case ::fidl::test::arrays::UnionLargeArray::Tag::kA:
new (&a_)::std::array<uint32_t, 100>();
break;
default:
break;
}
}
}
extern "C" const fidl_type_t fidl_test_arrays_TableSmallArrayTable;
const fidl_type_t* TableSmallArray::FidlType =
&fidl_test_arrays_TableSmallArrayTable;
TableSmallArray::TableSmallArray() {}
TableSmallArray::TableSmallArray(TableSmallArray&& other) {
field_presence_ = other.field_presence_;
if (field_presence_.IsSet<0>()) {
Construct(&a_value_.value, std::move(other.a_value_.value));
}
_unknown_data = std::move(other._unknown_data);
}
TableSmallArray::~TableSmallArray() {
if (field_presence_.IsSet<0>()) {
Destruct(&a_value_.value);
}
}
TableSmallArray& TableSmallArray::operator=(TableSmallArray&& other) {
if (other.field_presence_.IsSet<0>()) {
if (field_presence_.IsSet<0>()) {
a_value_.value = std::move(other.a_value_.value);
} else {
field_presence_.Set<0>();
Construct(&a_value_.value, std::move(other.a_value_.value));
}
} else if (field_presence_.IsSet<0>()) {
field_presence_.Clear<0>();
Destruct(&a_value_.value);
}
_unknown_data = std::move(other._unknown_data);
return *this;
}
bool TableSmallArray::IsEmpty() const {
return field_presence_.IsEmpty() && _unknown_data.size() == 0;
}
void TableSmallArray::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
size_t max_ordinal = MaxOrdinal();
::fidl::EncodeVectorPointer(_encoder, max_ordinal, _offset);
if (max_ordinal == 0) return;
size_t base = _encoder->Alloc(max_ordinal * sizeof(fidl_envelope_t));
auto next_unknown = _unknown_data.begin();
if (field_presence_.IsSet<0>()) {
// Encode unknown fields that have an ordinal that should appear before this
// field.
while (next_unknown != _unknown_data.end() && next_unknown->first < 1) {
size_t envelope_base =
base + (next_unknown->first - 1) * sizeof(fidl_envelope_t);
::fidl::EncodeUnknownBytes(_encoder, &next_unknown->second,
envelope_base);
std::advance(next_unknown, 1);
}
const size_t length_before = _encoder->CurrentLength();
const size_t handles_before = _encoder->CurrentHandleCount();
::fidl::Encode(
_encoder, &a_value_.value,
_encoder->Alloc(::fidl::EncodingInlineSize<::std::array<uint32_t, 2>,
::fidl::Encoder>(_encoder)));
size_t envelope_base = base + (1 - 1) * sizeof(fidl_envelope_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 +
offsetof(fidl_envelope_t, presence)) =
FIDL_ALLOC_PRESENT;
}
// Encode any remaining unknown fields (i.e. ones that have an ordinal outside
// the range of known ordinals)
for (auto curr = next_unknown; curr != _unknown_data.end(); ++curr) {
size_t envelope_base = base + (curr->first - 1) * sizeof(fidl_envelope_t);
::fidl::EncodeUnknownBytes(_encoder, &curr->second, envelope_base);
}
}
void TableSmallArray::Decode(::fidl::Decoder* _decoder, TableSmallArray* _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) * sizeof(fidl_envelope_t);
uint64_t presence;
::fidl::Decode(_decoder, &presence,
envelope_base + offsetof(fidl_envelope_t, presence));
if (presence != 0) {
::fidl::Decode(_decoder, _value->mutable_a(),
_decoder->GetOffset(presence));
} else {
_value->clear_a();
}
} else {
goto done_1;
}
if (count > 1) {
for (uint64_t ordinal = 1; ordinal <= count; ordinal++) {
if (IsOrdinalKnown(ordinal)) continue;
size_t envelope_base = base + (ordinal - 1) * sizeof(fidl_envelope_t);
fidl_envelope_t* envelope =
_decoder->GetPtr<fidl_envelope_t>(envelope_base);
if (envelope->presence != 0) {
auto result = _value->_unknown_data.emplace(
std::piecewise_construct, std::forward_as_tuple(ordinal),
std::forward_as_tuple());
auto iter = result.first;
iter->second.resize(envelope->num_bytes);
::fidl::DecodeUnknownBytesContents(_decoder, &iter->second,
_decoder->GetOffset(envelope->data));
}
}
}
return;
// Clear unset values.
clear_all:
done_1:
_value->clear_a();
return;
}
zx_status_t TableSmallArray::Clone(TableSmallArray* result) const {
if (field_presence_.IsSet<0>()) {
zx_status_t _status = ::fidl::Clone(a_value_.value, result->mutable_a());
if (_status != ZX_OK) return _status;
} else {
result->clear_a();
}
return ::fidl::Clone(_unknown_data, &result->_unknown_data);
}
extern "C" const fidl_type_t fidl_test_arrays_TableLargeArrayTable;
const fidl_type_t* TableLargeArray::FidlType =
&fidl_test_arrays_TableLargeArrayTable;
TableLargeArray::TableLargeArray() {}
TableLargeArray::TableLargeArray(TableLargeArray&& other) {
field_presence_ = other.field_presence_;
if (field_presence_.IsSet<0>()) {
Construct(&a_value_.value, std::move(other.a_value_.value));
}
_unknown_data = std::move(other._unknown_data);
}
TableLargeArray::~TableLargeArray() {
if (field_presence_.IsSet<0>()) {
Destruct(&a_value_.value);
}
}
TableLargeArray& TableLargeArray::operator=(TableLargeArray&& other) {
if (other.field_presence_.IsSet<0>()) {
if (field_presence_.IsSet<0>()) {
a_value_.value = std::move(other.a_value_.value);
} else {
field_presence_.Set<0>();
Construct(&a_value_.value, std::move(other.a_value_.value));
}
} else if (field_presence_.IsSet<0>()) {
field_presence_.Clear<0>();
Destruct(&a_value_.value);
}
_unknown_data = std::move(other._unknown_data);
return *this;
}
bool TableLargeArray::IsEmpty() const {
return field_presence_.IsEmpty() && _unknown_data.size() == 0;
}
void TableLargeArray::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
size_t max_ordinal = MaxOrdinal();
::fidl::EncodeVectorPointer(_encoder, max_ordinal, _offset);
if (max_ordinal == 0) return;
size_t base = _encoder->Alloc(max_ordinal * sizeof(fidl_envelope_t));
auto next_unknown = _unknown_data.begin();
if (field_presence_.IsSet<0>()) {
// Encode unknown fields that have an ordinal that should appear before this
// field.
while (next_unknown != _unknown_data.end() && next_unknown->first < 1) {
size_t envelope_base =
base + (next_unknown->first - 1) * sizeof(fidl_envelope_t);
::fidl::EncodeUnknownBytes(_encoder, &next_unknown->second,
envelope_base);
std::advance(next_unknown, 1);
}
const size_t length_before = _encoder->CurrentLength();
const size_t handles_before = _encoder->CurrentHandleCount();
::fidl::Encode(
_encoder, &a_value_.value,
_encoder->Alloc(::fidl::EncodingInlineSize<::std::array<uint32_t, 100>,
::fidl::Encoder>(_encoder)));
size_t envelope_base = base + (1 - 1) * sizeof(fidl_envelope_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 +
offsetof(fidl_envelope_t, presence)) =
FIDL_ALLOC_PRESENT;
}
// Encode any remaining unknown fields (i.e. ones that have an ordinal outside
// the range of known ordinals)
for (auto curr = next_unknown; curr != _unknown_data.end(); ++curr) {
size_t envelope_base = base + (curr->first - 1) * sizeof(fidl_envelope_t);
::fidl::EncodeUnknownBytes(_encoder, &curr->second, envelope_base);
}
}
void TableLargeArray::Decode(::fidl::Decoder* _decoder, TableLargeArray* _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) * sizeof(fidl_envelope_t);
uint64_t presence;
::fidl::Decode(_decoder, &presence,
envelope_base + offsetof(fidl_envelope_t, presence));
if (presence != 0) {
::fidl::Decode(_decoder, _value->mutable_a(),
_decoder->GetOffset(presence));
} else {
_value->clear_a();
}
} else {
goto done_1;
}
if (count > 1) {
for (uint64_t ordinal = 1; ordinal <= count; ordinal++) {
if (IsOrdinalKnown(ordinal)) continue;
size_t envelope_base = base + (ordinal - 1) * sizeof(fidl_envelope_t);
fidl_envelope_t* envelope =
_decoder->GetPtr<fidl_envelope_t>(envelope_base);
if (envelope->presence != 0) {
auto result = _value->_unknown_data.emplace(
std::piecewise_construct, std::forward_as_tuple(ordinal),
std::forward_as_tuple());
auto iter = result.first;
iter->second.resize(envelope->num_bytes);
::fidl::DecodeUnknownBytesContents(_decoder, &iter->second,
_decoder->GetOffset(envelope->data));
}
}
}
return;
// Clear unset values.
clear_all:
done_1:
_value->clear_a();
return;
}
zx_status_t TableLargeArray::Clone(TableLargeArray* result) const {
if (field_presence_.IsSet<0>()) {
zx_status_t _status = ::fidl::Clone(a_value_.value, result->mutable_a());
if (_status != ZX_OK) return _status;
} else {
result->clear_a();
}
return ::fidl::Clone(_unknown_data, &result->_unknown_data);
}
extern "C" const fidl_type_t fidl_test_arrays_StructSmallArrayTable;
const fidl_type_t* StructSmallArray::FidlType =
&fidl_test_arrays_StructSmallArrayTable;
void StructSmallArray::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructSmallArray>::value) {
memcpy(_encoder->template GetPtr<StructSmallArray>(_offset), this,
sizeof(StructSmallArray));
} else {
::fidl::Encode(_encoder, &a, _offset + 0);
}
}
void StructSmallArray::Decode(::fidl::Decoder* _decoder,
StructSmallArray* _value, size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructSmallArray>::value) {
memcpy(_value, _decoder->template GetPtr<StructSmallArray>(_offset),
sizeof(StructSmallArray));
} else {
::fidl::Decode(_decoder, &_value->a, _offset + 0);
}
}
zx_status_t StructSmallArray::Clone(StructSmallArray* _result) const {
zx_status_t _status = ::fidl::Clone(a, &_result->a);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
extern "C" const fidl_type_t fidl_test_arrays_StructLargeArrayTable;
const fidl_type_t* StructLargeArray::FidlType =
&fidl_test_arrays_StructLargeArrayTable;
void StructLargeArray::Encode(
::fidl::Encoder* _encoder, size_t _offset,
cpp17::optional<::fidl::HandleInformation> maybe_handle_info) {
if (::fidl::IsMemcpyCompatible<StructLargeArray>::value) {
memcpy(_encoder->template GetPtr<StructLargeArray>(_offset), this,
sizeof(StructLargeArray));
} else {
::fidl::Encode(_encoder, &a, _offset + 0);
}
}
void StructLargeArray::Decode(::fidl::Decoder* _decoder,
StructLargeArray* _value, size_t _offset) {
if (::fidl::IsMemcpyCompatible<StructLargeArray>::value) {
memcpy(_value, _decoder->template GetPtr<StructLargeArray>(_offset),
sizeof(StructLargeArray));
} else {
::fidl::Decode(_decoder, &_value->a, _offset + 0);
}
}
zx_status_t StructLargeArray::Clone(StructLargeArray* _result) const {
zx_status_t _status = ::fidl::Clone(a, &_result->a);
if (_status != ZX_OK) return _status;
return ZX_OK;
}
} // namespace arrays
} // namespace test
} // namespace fidl