summaryrefslogtreecommitdiff
path: root/modules/codec/c++/schema.hpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-03-23 17:48:09 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-03-23 17:48:09 +0100
commitc64c76e273084cfd5b8628fb268e803957fc3025 (patch)
treeebbc9bfa647617ba5c3c7c226f051a2933ccc3a5 /modules/codec/c++/schema.hpp
parent7d096b9b3057617475d223330aaa6b321e0bd59a (diff)
codec, io_codec: forst and rpc work
Diffstat (limited to 'modules/codec/c++/schema.hpp')
-rw-r--r--modules/codec/c++/schema.hpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/modules/codec/c++/schema.hpp b/modules/codec/c++/schema.hpp
index 37615c5..a992a84 100644
--- a/modules/codec/c++/schema.hpp
+++ b/modules/codec/c++/schema.hpp
@@ -135,6 +135,91 @@ struct Interface<Member<Function<Requests, Responses>,Names>...> {
// NOLINTEND
} // namespace schema
+
+template<typename T, typename Schema>
+struct schema_has_member{
+ static_assert(
+ always_false<T, Schema>,
+ "Not supported schema case");
+};
+
+/**
+ * Checks if identical type exists in schema structure
+ */
+template<typename T, typename... Members>
+struct schema_has_member<T, schema::Struct<Members...>> {
+private:
+ template<size_t i>
+ static constexpr bool value_element() {
+ if constexpr ( i < sizeof...(Members) ){
+ using MT = typename parameter_pack_type<i, Members...>::type;
+ if constexpr ( std::is_same_v<T,MT> ) {
+ return true;
+ } else {
+ return value_element<i+1u>();
+ }
+ }
+ return false;
+ }
+public:
+ static constexpr bool value = value_element<0>();
+};
+
+/**
+ *
+ */
+template<string_literal Key, typename Schema>
+struct schema_has_key {
+ static_assert(
+ always_false<Schema>,
+ "Not supported schema case");
+};
+
+template<string_literal Key, typename... Members>
+struct schema_has_key<Key, schema::Struct<Members...>> {
+private:
+ template<size_t i>
+ static constexpr bool value_element() {
+ if constexpr ( i < sizeof...(Members) ){
+ using MT = typename parameter_pack_type<i, Members...>::type;
+
+ if constexpr ( Key == MT::KeyLiteral ) {
+ return true;
+ }else{
+ return value_element<i+1u>();
+ }
+ }
+ return false;
+ }
+public:
+ static constexpr bool value = value_element<0>();
+};
+
+template<string_literal Name, typename Iface>
+struct schema_member_index {
+ static_assert(
+ always_false<Iface>,
+ "Not supported schema case");
+};
+
+template<string_literal Name, typename... MemberVals, string_literal... MemberKeys >
+struct schema_member_index<Name, schema::Interface<schema::Member<MemberVals, MemberKeys>...>> {
+ static constexpr uint64_t value = parameter_key_pack_index<Name, MemberKeys...>::value;
+};
+
+template<string_literal Name, typename Iface>
+struct schema_member_type {
+ static_assert(
+ always_false<Iface>,
+ "Not supported schema case");
+};
+
+template<string_literal Name, typename... MemberVals, string_literal... MemberKeys >
+struct schema_member_type<Name, schema::Interface<schema::Member<MemberVals, MemberKeys>...>> {
+
+ using type = typename parameter_pack_type<schema_member_index<Name, schema::Interface<schema::Member<MemberVals,MemberKeys>...>>::value, MemberVals...>::type;
+};
+
template <class T> struct is_struct {
constexpr static bool value = false;
};