32 template <
size_t N,
typename T,
template <
size_t,
typename>
typename U,
typename =
void>
39 template <
size_t N,
typename T,
template <
size_t,
typename>
typename U>
40 static constexpr size_t field_index<N, T, U, std::void_t<
decltype(U<N, T>::field_name)>> = 1 + field_index<N + 1, T, U>;
44 template<
typename ... input_t>
46 decltype(std::tuple_cat(
47 std::declval<input_t>()...
51 template <
typename T,
typename... Ts>
constexpr bool tuple_contains_type<T, std::tuple<Ts...>> = std::disjunction_v<std::is_same<T, Ts>...>;
54 template <
typename T,
typename... Rest>
constexpr int get_tuple_index<T, std::tuple<T, Rest...>> = 0;
55 template <
typename T,
typename First,
typename... Rest>
constexpr int get_tuple_index<T, std::tuple<First, Rest...>> = 1 +
get_tuple_index<T, std::tuple<Rest...>>;
58 template<std::size_t... indices,
class LoopBody>
59 void loop_impl(std::index_sequence<indices...>, LoopBody&& loop_body) {
60 (loop_body(std::integral_constant<std::size_t, indices>{}), ...);
63 template<std::
size_t N,
class LoopBody>
64 void loop(LoopBody&& loop_body) {
65 loop_impl(std::make_index_sequence<N>{}, std::forward<LoopBody>(loop_body));
72 template <
typename T1,
typename T2>
struct DiffType {};
81 template <
typename T, auto Condition,
bool StoredAsOptional = true>
90 return (t->*Condition)();
94 template <
typename T,
typename S = VarType<
int>,
size_t N = 0>
99 static constexpr size_t size = N;
100 static_assert(std::is_same_v<S, void> || N == 0,
"Can't specify a size type if N > 0");
105 template <
typename T, auto ReadFunc, auto WriteFunc, auto SerializeFunc>
108 template <
typename T>
constexpr bool IsArray =
false;
109 template <
typename T,
size_t N>
constexpr bool IsArray<std::array<T, N>> =
true;
110 template <
typename T>
constexpr bool IsVector =
false;
111 template <
typename T>
constexpr bool IsVector<std::vector<T>> =
true;
113 template <
typename T,
typename U,
size_t N>
constexpr bool IsGenericVector<Vector<T, U, N>> =
true;
114 template <
typename T>
constexpr bool IsMap =
false;
115 template <
typename K,
typename V>
constexpr bool IsMap<std::map<K, V>> =
true;
117 template <
typename T>
constexpr bool IsVarType<VarType<T>> =
true;
119 template <
typename T>
constexpr bool IsOptional<std::optional<T>> =
true;
120 template <
typename T>
constexpr bool IsPair =
false;
121 template <
typename T1,
typename T2>
constexpr bool IsPair<std::pair<T1, T2>> =
true;
122 template <
typename T>
constexpr bool IsBitset =
false;
123 template <
size_t N>
constexpr bool IsBitset<std::bitset<N>> =
true;
125 template <
typename T, auto C,
bool b>
constexpr bool IsConditioned<Conditioned<T, C, b>> =
true;
127 template <
typename T, auto R, auto W, auto S>
constexpr bool IsCustomType<CustomType<T, R, W, S>> =
true;
129 template <
typename T>
constexpr bool IsSharedPtr<std::shared_ptr<T>> =
true;
152#ifdef PROTOCOLCRAFT_DETAILED_PARSING
153 template <
typename T>
struct OffsetType {
using type = size_t; };
154 template <
typename T>
struct OffsetType<
std::optional<T>> {
using type =
typename OffsetType<T>::type; };
155 template <
typename T>
struct OffsetType<
std::vector<T>> {
using type = std::pair<size_t, std::vector<typename OffsetType<T>::type>>; };
156 template <
typename T,
size_t N>
struct OffsetType<
std::array<T, N>> {
using type = std::pair<size_t, std::array<typename OffsetType<T>::type, N>>; };
157 template <
typename T1,
typename T2>
struct OffsetType<
std::pair<T1, T2>> {
using type = std::pair<size_t, std::pair<typename OffsetType<T1>::type,
typename OffsetType<T2>::type>>; };
158 template <
typename K,
typename V>
struct OffsetType<
std::map<K, V>> {
using type = std::pair<size_t, std::map<K, typename OffsetType<V>::type>>; };
constexpr bool IsConditioned
static constexpr size_t field_index
Default case, see field_index specialization for implementation details.
constexpr bool IsCustomType
constexpr bool tuple_contains_type
constexpr bool IsSharedPtr
void loop_impl(std::index_sequence< indices... >, LoopBody &&loop_body)
constexpr int get_tuple_index
constexpr bool IsOptional
void loop(LoopBody &&loop_body)
constexpr bool dependant_false
To be used in constexpr else to fail compilation in a C++ compliant way.
constexpr bool IsGenericVector
decltype(std::tuple_cat(std::declval< input_t >()...)) tuple_cat_t
Concat multiple tuples in one big tuple.
A type wrapper to conditionally serialize a type.
static bool Evaluate(const typename GetClassFromConditionPtr< decltype(Condition)>::Class *t)
static constexpr bool stored_as_optional
Just a simple type wrapper that will store with T1 and serialize as T2 (can be used for Enum/VarInt f...
typename SerializedType< T >::storage_type storage_type
std::optional< typename SerializedType< T >::storage_type > storage_type
typename SerializedType< T >::storage_type storage_type
std::vector< typename SerializedType< T >::storage_type > storage_type
std::vector< typename SerializedType< T >::storage_type > storage_type
std::array< typename SerializedType< T >::storage_type, N > storage_type
std::array< typename SerializedType< T >::storage_type, N > storage_type
std::array< T, N > serialization_type
std::map< typename SerializedType< K >::storage_type, typename SerializedType< V >::storage_type > storage_type
std::map< K, V > serialization_type
std::optional< T > serialization_type
std::optional< typename SerializedType< T >::storage_type > storage_type
std::pair< typename SerializedType< T1 >::storage_type, typename SerializedType< T2 >::storage_type > storage_type
std::pair< T1, T2 > serialization_type
std::vector< typename SerializedType< T >::storage_type > storage_type
std::vector< T > serialization_type
static constexpr size_t size