diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-01-22 19:05:23 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-01-22 19:06:03 +0100 |
commit | 2dd333c909748e7e735be3e302c8e7a0993bbbec (patch) | |
tree | 638da8607f01d5855d4550a11a75c15fa3f2c602 /modules/codec/c++ | |
parent | 4b6e8ee2292d5f78b5568eec5734b702c6cb0a94 (diff) |
codec: Adding more hashing cases
Diffstat (limited to 'modules/codec/c++')
-rw-r--r-- | modules/codec/c++/schema_hash.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/modules/codec/c++/schema_hash.h b/modules/codec/c++/schema_hash.h index 48e8d6c..29afa5e 100644 --- a/modules/codec/c++/schema_hash.h +++ b/modules/codec/c++/schema_hash.h @@ -100,6 +100,31 @@ struct schema_hash_seed<schema::Array<T,N>> { } }; +template<typename... T> +struct schema_hash_seed<schema::Tuple<T...>> { + using Schema = schema::Tuple<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+1) < sizeof...(T) ){ + return apply_ele<i+1>(seed); + } + return seed; + } + + + static constexpr uint32_t apply(uint32_t seed){ + seed = hash_literal<Schema::name>::apply(seed); + if constexpr (sizeof...(T) > 0){ + seed = apply_ele<0>(seed); + } + return seed; + } +}; + template<typename... V, string_literal... K> struct schema_hash_seed<schema::Struct<schema::Member<V,K>...>> { using Schema = schema::Struct<schema::Member<V,K>...>; @@ -129,6 +154,48 @@ struct schema_hash_seed<schema::Struct<schema::Member<V,K>...>> { } }; +template<typename Req, typename Resp> +struct schema_hash_seed<schema::Function<Req, Resp>> { + using Schema = schema::Function<Req,Resp>; + + static constexpr uint32_t apply(uint32_t seed){ + seed = hash_literal<Schema::name>::apply(seed); + seed = schema_hash_seed<Req>::apply(seed); + seed = schema_hash_seed<Resp>::apply(seed); + return seed; + } +}; + +template<typename... T, string_literal... Names> +struct schema_hash_seed<schema::Interface<schema::Member<T, Names>...>> { + using Schema = schema::Interface<schema::Member<T,Names>...>; + + template<uint64_t i> + static constexpr uint32_t apply_ele(uint32_t seed){ + using Type = typename parameter_pack_type<i,T...>::type; + constexpr string_literal Lit = parameter_key_pack_type<i,Names...>::literal; + using MemberT = schema::Member<Type,Lit>; + + seed = hash_literal<MemberT::name>::apply(seed); + seed = schema_hash_seed<Type>::apply(seed); + seed = hash_literal<Lit>::apply(seed); + + if constexpr ( (i+1) < sizeof...(T) ){ + return apply_ele<i+1>(seed); + } + + return seed; + } + + static constexpr uint32_t apply(uint32_t seed){ + seed = hash_literal<Schema::name>::apply(seed); + if constexpr ( sizeof...(T) > 0){ + seed = apply_ele<0>(seed); + } + return seed; + } +}; + template<typename Schema> struct schema_hash { static constexpr uint32_t apply() { |