| // WARNING: This file is machine generated by fidlgen. |
| |
| #include <fidl/test/handlesintypes/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 handlesintypes { |
| |
| #ifdef __Fuchsia__ |
| |
| extern "C" const fidl_type_t fidl_test_handlesintypes_UnionWithHandleTable; |
| const fidl_type_t* UnionWithHandle::FidlType = |
| &fidl_test_handlesintypes_UnionWithHandleTable; |
| |
| UnionWithHandle::UnionWithHandle() {} |
| |
| UnionWithHandle::~UnionWithHandle() { Destroy(); } |
| |
| UnionWithHandle::UnionWithHandle(UnionWithHandle&& other) : tag_(other.tag_) { |
| switch (tag_) { |
| case ::fidl::test::handlesintypes::UnionWithHandle::Tag::kH: |
| new (&h_)::zx::vmo(); |
| h_ = std::move(other.h_); |
| break; |
| case static_cast<fidl_xunion_tag_t>( |
| ::fidl::test::handlesintypes::UnionWithHandle::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 ::fidl::test::handlesintypes::UnionWithHandle::Tag::kH: |
| new (&h_)::zx::vmo(); |
| h_ = std::move(other.h_); |
| break; |
| case static_cast<fidl_xunion_tag_t>( |
| ::fidl::test::handlesintypes::UnionWithHandle::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, |
| 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::handlesintypes::UnionWithHandle::Tag::kH: { |
| envelope_offset = encoder->Alloc( |
| ::fidl::EncodingInlineSize<::zx::vmo, ::fidl::Encoder>(encoder)); |
| ::fidl::Encode(encoder, &h_, envelope_offset, |
| ::fidl::HandleInformation{ |
| .object_type = ZX_OBJ_TYPE_VMO, |
| .rights = 0x80000000, |
| }); |
| break; |
| } |
| case ::fidl::test::handlesintypes::UnionWithHandle::Tag::kUnknown: |
| envelope_offset = encoder->Alloc(unknown_data_.bytes.size()); |
| ::fidl::EncodeUnknownDataContents(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 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>( |
| ::fidl::test::handlesintypes::UnionWithHandle::Tag::Invalid)); |
| return; |
| } |
| |
| value->EnsureStorageInitialized(xunion->tag); |
| |
| const size_t envelope_offset = decoder->GetOffset(xunion->envelope.data); |
| |
| switch (value->tag_) { |
| case ::fidl::test::handlesintypes::UnionWithHandle::Tag::kH: |
| new (&value->h_)::zx::vmo(); |
| ::fidl::Decode(decoder, &value->h_, envelope_offset); |
| break; |
| default: |
| |
| value->unknown_data_.bytes.resize(xunion->envelope.num_bytes); |
| value->unknown_data_.handles.resize(xunion->envelope.num_handles); |
| ::fidl::DecodeUnknownDataContents(decoder, &value->unknown_data_, |
| envelope_offset); |
| break; |
| } |
| } |
| |
| zx_status_t UnionWithHandle::Clone(UnionWithHandle* result) const { |
| result->Destroy(); |
| result->tag_ = tag_; |
| switch (tag_) { |
| case ::fidl::test::handlesintypes::UnionWithHandle::Tag::Invalid: |
| return ZX_OK; |
| case ::fidl::test::handlesintypes::UnionWithHandle::Tag::kH: |
| new (&result->h_)::zx::vmo(); |
| return ::fidl::Clone(h_, &result->h_); |
| default: |
| new (&result->unknown_data_) decltype(unknown_data_); |
| return ::fidl::Clone(unknown_data_, &result->unknown_data_); |
| return ZX_OK; |
| } |
| } |
| |
| UnionWithHandle& UnionWithHandle::set_h(::zx::vmo value) { |
| EnsureStorageInitialized( |
| ::fidl::test::handlesintypes::UnionWithHandle::Tag::kH); |
| h_ = std::move(value); |
| return *this; |
| } |
| UnionWithHandle& UnionWithHandle::SetUnknownData( |
| fidl_xunion_tag_t ordinal, std::vector<uint8_t> bytes, |
| std::vector<zx::handle> handles) { |
| EnsureStorageInitialized(ordinal); |
| unknown_data_.bytes = std::move(bytes); |
| unknown_data_.handles = std::move(handles); |
| return *this; |
| } |
| |
| void UnionWithHandle::Destroy() { |
| switch (tag_) { |
| case ::fidl::test::handlesintypes::UnionWithHandle::Tag::kH: |
| h_.~decltype(h_)(); |
| break; |
| |
| case static_cast<fidl_xunion_tag_t>( |
| ::fidl::test::handlesintypes::UnionWithHandle::Tag::Invalid): |
| break; |
| default: |
| unknown_data_.~decltype(unknown_data_)(); |
| break; |
| } |
| tag_ = static_cast<fidl_xunion_tag_t>( |
| ::fidl::test::handlesintypes::UnionWithHandle::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>( |
| ::fidl::test::handlesintypes::UnionWithHandle::Tag::Invalid): |
| break; |
| case ::fidl::test::handlesintypes::UnionWithHandle::Tag::kH: |
| new (&h_)::zx::vmo(); |
| break; |
| default: |
| new (&unknown_data_) decltype(unknown_data_); |
| break; |
| } |
| } |
| } |
| #endif // __Fuchsia__ |
| |
| #ifdef __Fuchsia__ |
| |
| extern "C" const fidl_type_t fidl_test_handlesintypes_TableWithHandleTable; |
| const fidl_type_t* TableWithHandle::FidlType = |
| &fidl_test_handlesintypes_TableWithHandleTable; |
| |
| TableWithHandle::TableWithHandle() {} |
| |
| TableWithHandle::TableWithHandle(TableWithHandle&& other) { |
| field_presence_ = other.field_presence_; |
| if (field_presence_.IsSet<0>()) { |
| Construct(&h_value_.value, std::move(other.h_value_.value)); |
| } |
| _unknown_data = std::move(other._unknown_data); |
| } |
| |
| TableWithHandle::~TableWithHandle() { |
| if (field_presence_.IsSet<0>()) { |
| Destruct(&h_value_.value); |
| } |
| } |
| |
| TableWithHandle& TableWithHandle::operator=(TableWithHandle&& other) { |
| if (other.field_presence_.IsSet<0>()) { |
| if (field_presence_.IsSet<0>()) { |
| h_value_.value = std::move(other.h_value_.value); |
| } else { |
| field_presence_.Set<0>(); |
| Construct(&h_value_.value, std::move(other.h_value_.value)); |
| } |
| } else if (field_presence_.IsSet<0>()) { |
| field_presence_.Clear<0>(); |
| Destruct(&h_value_.value); |
| } |
| _unknown_data = std::move(other._unknown_data); |
| return *this; |
| } |
| |
| bool TableWithHandle::IsEmpty() const { |
| return field_presence_.IsEmpty() && _unknown_data.size() == 0; |
| } |
| |
| void TableWithHandle::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::EncodeUnknownData(_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, &h_value_.value, |
| _encoder->Alloc( |
| ::fidl::EncodingInlineSize<::zx::vmo, ::fidl::Encoder>(_encoder)), |
| ::fidl::HandleInformation{.object_type = ZX_OBJ_TYPE_VMO, |
| .rights = 0x80000000}); |
| 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::EncodeUnknownData(_encoder, &curr->second, envelope_base); |
| } |
| } |
| |
| 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) * 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_h(), |
| _decoder->GetOffset(presence)); |
| } else { |
| _value->clear_h(); |
| } |
| } 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.bytes.resize(envelope->num_bytes); |
| iter->second.handles.resize(envelope->num_handles); |
| ::fidl::DecodeUnknownDataContents(_decoder, &iter->second, |
| _decoder->GetOffset(envelope->data)); |
| } |
| } |
| } |
| |
| return; |
| |
| // Clear unset values. |
| clear_all: |
| done_1: |
| _value->clear_h(); |
| return; |
| } |
| |
| zx_status_t TableWithHandle::Clone(TableWithHandle* result) const { |
| if (field_presence_.IsSet<0>()) { |
| zx_status_t _status = ::fidl::Clone(h_value_.value, result->mutable_h()); |
| if (_status != ZX_OK) return _status; |
| } else { |
| result->clear_h(); |
| } |
| return ::fidl::Clone(_unknown_data, &result->_unknown_data); |
| } |
| #endif // __Fuchsia__ |
| |
| #ifdef __Fuchsia__ |
| |
| extern "C" const fidl_type_t fidl_test_handlesintypes_HandlesInTypesTable; |
| const fidl_type_t* HandlesInTypes::FidlType = |
| &fidl_test_handlesintypes_HandlesInTypesTable; |
| |
| void HandlesInTypes::Encode( |
| ::fidl::Encoder* _encoder, size_t _offset, |
| cpp17::optional<::fidl::HandleInformation> maybe_handle_info) { |
| if (::fidl::IsMemcpyCompatible<HandlesInTypes>::value) { |
| memcpy(_encoder->template GetPtr<HandlesInTypes>(_offset), this, |
| sizeof(HandlesInTypes)); |
| } else { |
| ::fidl::Encode(_encoder, &normal_handle, _offset + 0, |
| ::fidl::HandleInformation{ |
| .object_type = ZX_OBJ_TYPE_VMO, |
| .rights = 0x80000000, |
| }); |
| |
| ::fidl::Encode(_encoder, &handle_in_vec, _offset + 8, |
| ::fidl::HandleInformation{ |
| .object_type = ZX_OBJ_TYPE_VMO, |
| .rights = 0x80000000, |
| }); |
| |
| ::fidl::Encode(_encoder, &handle_in_array, _offset + 24, |
| ::fidl::HandleInformation{ |
| .object_type = ZX_OBJ_TYPE_VMO, |
| .rights = 0x80000000, |
| }); |
| |
| ::fidl::Encode(_encoder, &handle_in_mixed_vec_array, _offset + 48, |
| ::fidl::HandleInformation{ |
| .object_type = ZX_OBJ_TYPE_VMO, |
| .rights = 0x80000000, |
| }); |
| ::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) { |
| if (::fidl::IsMemcpyCompatible<HandlesInTypes>::value) { |
| memcpy(_value, _decoder->template GetPtr<HandlesInTypes>(_offset), |
| sizeof(HandlesInTypes)); |
| } else { |
| ::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; |
| } |
| #endif // __Fuchsia__ |
| |
| } // namespace handlesintypes |
| } // namespace test |
| } // namespace fidl |