diff options
author | Claudius 'keldu' Holeksa <mail@keldu.de> | 2024-07-29 14:53:48 +0200 |
---|---|---|
committer | Claudius 'keldu' Holeksa <mail@keldu.de> | 2024-07-29 14:53:48 +0200 |
commit | 44f6a2ec37e35cf96419885be27afeab9ea84ec5 (patch) | |
tree | cbdd97513095ece2c1f23433b8e15196b147e7cc /modules/codec/c++ | |
parent | 773fffb0c3596c93ae1522f6ef5eaaed4ad54e14 (diff) |
wip
Diffstat (limited to 'modules/codec/c++')
-rw-r--r-- | modules/codec/c++/data.hpp | 4 | ||||
-rw-r--r-- | modules/codec/c++/schema_hash.hpp | 27 |
2 files changed, 29 insertions, 2 deletions
diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp index a17f123..8e92622 100644 --- a/modules/codec/c++/data.hpp +++ b/modules/codec/c++/data.hpp @@ -21,7 +21,9 @@ struct Default {}; } namespace encode { -struct Native {}; +struct Native { + static constexpr string_literal name = "encode::Native"; +}; } template<typename Schema, typename Encode, typename Storage = storage::Default> class codec; diff --git a/modules/codec/c++/schema_hash.hpp b/modules/codec/c++/schema_hash.hpp index 4b537e1..d653bf4 100644 --- a/modules/codec/c++/schema_hash.hpp +++ b/modules/codec/c++/schema_hash.hpp @@ -15,7 +15,9 @@ struct hash_literal { template<typename Schema> struct schema_hash_seed { - static_assert(always_false<Schema>, "Not schema_hashable"); + static constexpr uint32_t apply(uint32_t seed){ + return hash_literal<Schema::name>::apply(seed); + } }; template<> @@ -125,6 +127,29 @@ struct schema_hash_seed<schema::Tuple<T...>> { } }; +template<typename... T> +struct schema_hash_seed<tmpl_group<T...>> { + template<uint64_t i> + static constexpr uint32_t apply_ele(uint32_t seed){ + using Type = typename parameter_pack_type<i,T...>::type; + + seed = schema_hash_seed<Type>::apply(seed); + if constexpr ( (i+1u) < sizeof...(T) ){ + return apply_ele<i+1u>(seed); + } + + return seed; + } + + static constexpr uint32_t apply(uint32_t seed){ + seed = hash_literal<tmpl_group<T...>::name>::apply(seed); + if constexpr (sizeof...(T)>0u){ + seed = apply_ele<0u>(seed); + } + return seed; + } +}; + template<typename V, string_literal K> struct schema_hash_seed<schema::Member<V,K>> { using Schema = schema::Member<V,K>; |