summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/codec/c++/schema_hash.h67
-rw-r--r--modules/codec/tests/schema.cpp7
2 files changed, 73 insertions, 1 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() {
diff --git a/modules/codec/tests/schema.cpp b/modules/codec/tests/schema.cpp
index 71e806d..31c68f2 100644
--- a/modules/codec/tests/schema.cpp
+++ b/modules/codec/tests/schema.cpp
@@ -44,6 +44,10 @@ struct schema_hash_test_multi {
namespace schema {
using namespace saw::schema;
+
+using HashIface = Interface<
+ Member<Function<Tuple<UInt16>, UInt32>, "foo">
+>;
}
SAW_TEST("Schema Hashes"){
@@ -62,7 +66,8 @@ SAW_TEST("Schema Hashes"){
schema_test_pair<schema::SignedInteger, 2923333106>,
schema_test_pair<schema::UnsignedInteger, 3300532028>,
schema_test_pair<schema::FloatingPoint, 1860828258>,
- schema_test_pair<schema::String, 1669061438>
+ schema_test_pair<schema::String, 1669061438>,
+ schema_test_pair<schema::HashIface, 3365712860>
>::check();
}
}