• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

afxres / binary-cxx / 40208267149

25 Oct 2026 03:41PM UTC coverage: 99.306% (+0.1%) from 99.192%
40208267149

push

github

afxres
New experimental tuple object converter

92 of 94 new or added lines in 6 files covered. (97.87%)

1002 of 1009 relevant lines covered (99.31%)

234.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/code/binary-experimental/include/binary/experimental/components/TupleObjectConverter.hpp
1
#ifndef BINARY_EXPERIMENTAL_COMPONENTS_TUPLEOBJECTCONVERTER_HPP
2
#define BINARY_EXPERIMENTAL_COMPONENTS_TUPLEOBJECTCONVERTER_HPP
3

4
#include <cstddef>
5
#include <span>
6
#include <tuple>
7
#include <type_traits>
8
#include <utility>
9

10
#include "binary/ConverterExtensions.hpp"
11
#include "binary/components/MemberAccessor.hpp"
12
#include "binary/experimental/helpers/ConverterDecodeAutoMethodHelper.hpp"
13
#include "binary/experimental/helpers/ConverterEncodeAutoMethodHelper.hpp"
14
#include "binary/experimental/helpers/GetConverterHelper.hpp"
15
#include "binary/experimental/internal/Define.hpp"
16
#include "binary/internal/Module.hpp"
17

18
namespace binary::experimental::components {
19
namespace detail {
20
template <typename T, typename Schema, size_t Index>
21
struct TupleObjectMember {
22
    using Members = std::remove_const_t<decltype(Schema::Members)>;
23
    using DescriptorType = std::tuple_element_t<Index, Members>;
24
    using AccessorType = std::remove_cvref_t<decltype(std::declval<DescriptorType&>().Accessor)>;
25
    using MemberType = std::remove_cv_t<typename ::binary::components::AccessorValue<T, AccessorType>::Type>;
26
    using ElementConverterType = typename ::binary::experimental::helpers::GetConverterHelper<MemberType>::Type;
27

28
    static constexpr auto Length() {
29
        return ElementConverterType::Length();
30
    }
31

32
    template <bool Last>
33
    static void Encode(Allocator& allocator, const T& item) {
15 ✔
34
        const auto& descriptor = std::get<Index>(Schema::Members);
15 ✔
35
        if constexpr (Last) {
36
            ElementConverterType::Encode(allocator, descriptor.Accessor.Get(item));
5 ✔
37
        } else {
38
            ::binary::experimental::helpers::ConverterEncodeAutoMethodHelper<ElementConverterType>::Invoke(allocator, descriptor.Accessor.Get(item));
10 ✔
39
        }
40
    }
15 ✔
41

42
    template <bool Last>
43
    static void Decode(T& item, std::span<const std::byte>& span) {
8 ✔
44
        if constexpr (Last) {
45
            std::get<Index>(Schema::Members).Accessor.Set(item, ElementConverterType::Decode(span));
2 ✔
46
        } else {
47
            std::get<Index>(Schema::Members).Accessor.Set(item, ::binary::experimental::helpers::ConverterDecodeAutoMethodHelper<ElementConverterType>::Invoke(span));
6 ✔
48
        }
49
    }
8 ✔
50
};
51

52
template <typename T, typename Schema, size_t... Index>
53
constexpr size_t GetTupleObjectLength(std::index_sequence<Index...>) {
4 ✔
54
    return ::binary::internal::GetConverterLength(std::array<size_t, sizeof...(Index)>{detail::TupleObjectMember<T, Schema, Index>::Length()...});
4 ✔
55
}
56
}
57

58
template <typename T, typename Schema>
59
class TupleObjectConverter {
60
private:
61
    using Members = std::remove_const_t<decltype(Schema::Members)>;
62
    static constexpr size_t MemberCount = std::tuple_size_v<Members>;
63

64
    template <size_t IsAuto, size_t... Index>
65
    static void EncodeInternal(Allocator& allocator, const T& item, std::index_sequence<Index...>) {
6 ✔
66
        (detail::TupleObjectMember<T, Schema, Index>::template Encode<(IsAuto == 0 && Index + 1 == MemberCount)>(allocator, item), ...);
6 ✔
67
    }
6 ✔
68

69
    template <size_t IsAuto, size_t... Index>
70
    static void DecodeInternal(T& result, std::span<const std::byte>& span, std::index_sequence<Index...>) {
3 ✔
71
        (detail::TupleObjectMember<T, Schema, Index>::template Decode<(IsAuto == 0 && Index + 1 == MemberCount)>(result, span), ...);
3 ✔
72
    }
3 ✔
73

74
public:
75
    BINARY_EXPERIMENTAL_DEFINE_STATIC_LENGTH_METHOD() {
4 ✔
76
        return detail::GetTupleObjectLength<T, Schema>(std::make_index_sequence<MemberCount>());
4 ✔
77
    }
78

79
    BINARY_EXPERIMENTAL_DEFINE_STATIC_ENCODE_METHOD(T) {
5 ✔
80
        EncodeInternal<0>(allocator, item, std::make_index_sequence<MemberCount>());
5 ✔
81
    }
5 ✔
82

83
    BINARY_EXPERIMENTAL_DEFINE_STATIC_ENCODE_AUTO_METHOD(T) {
1 ✔
84
        EncodeInternal<1>(allocator, item, std::make_index_sequence<MemberCount>());
1 ✔
85
    }
1 ✔
86

87
    BINARY_EXPERIMENTAL_DEFINE_STATIC_DECODE_METHOD(T) {
2 ✔
88
        std::span<const std::byte> copy = span;
2 ✔
89
        T result{};
2 ✔
90
        DecodeInternal<0>(result, copy, std::make_index_sequence<MemberCount>());
2 ✔
91
        return result;
3 ✔
NEW
92
    }
×
93

94
    BINARY_EXPERIMENTAL_DEFINE_STATIC_DECODE_AUTO_METHOD(T) {
1 ✔
95
        T result{};
1 ✔
96
        DecodeInternal<1>(result, span, std::make_index_sequence<MemberCount>());
1 ✔
97
        return result;
1 ✔
NEW
98
    }
×
99
};
100
}
101

102
namespace binary::experimental::helpers {
103
template <typename T>
104
    requires requires { GetTupleObjectSchema(static_cast<std::remove_cv_t<T>*>(nullptr)); }
105
struct GetConverterHelper<T> {
106
    using Type = ::binary::experimental::components::TupleObjectConverter<T, std::remove_cvref_t<decltype(GetTupleObjectSchema(static_cast<std::remove_cv_t<T>*>(nullptr)))>>;
107
};
108
}
109

110
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc