diff options
-rw-r--r-- | modules/codec/c++/data.hpp | 28 | ||||
-rw-r--r-- | modules/codec/c++/rpc.hpp | 4 | ||||
-rw-r--r-- | modules/codec/c++/schema.hpp | 11 |
3 files changed, 40 insertions, 3 deletions
diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp index a10ee9d..2adb5b7 100644 --- a/modules/codec/c++/data.hpp +++ b/modules/codec/c++/data.hpp @@ -126,8 +126,36 @@ public: bool operator<(const data<schema::Primitive<T,N>, Enc>& rhs) const { return get() < rhs.get(); } + + /** + * Casts + */ + template<typename Target> + data<Target, encode::Native> cast_to(){ + auto raw_to = static_cast<typename saw::native_data_type<Target>::type>(value_); + return {raw_to}; + } }; +template<typename TA, uint64_t NA, typename TB, uint64_t NB> +class data<schema::MixedPrecision<schema::Primitive<TA,NA>, schema::Primitive<TB,NB>>, encode::Native>{ +public: + using Schema = schema::MixedPrecision<schema::Primitive<TA,NA>, schema::Primitive<TB,NB>>; +private: + data<typename Schema::StorageSchema, encode::Native> value_; +public: + data():value_{}{} + + data(typename saw::native_data_type<typename Schema::InterfaceSchema>::type val__):value_{static_cast<typename saw::native_data_type<typename Schema::StorageSchema>::type>(val__)}{} + + typename saw::native_data_type<typename Schema::InterfaceSchema>::type get() const { + return value_.template cast_to<typename Schema::InterfaceSchema>().get(); + } + + void set(typename saw::native_data_type<typename Schema::InterfaceSchema>::type val){ + value_.set(val.template cast_to<typename Schema::StorageSchema>().get()); + } +}; template<typename... T, string_literal... literals> class data<schema::Union<schema::Member<T, literals>...>, encode::Native> { diff --git a/modules/codec/c++/rpc.hpp b/modules/codec/c++/rpc.hpp index 9f59455..6b606e2 100644 --- a/modules/codec/c++/rpc.hpp +++ b/modules/codec/c++/rpc.hpp @@ -75,11 +75,11 @@ class remote_address { * Reference Backend structure */ template<typename T> -class remote_context { +class remote_api { static_assert(always_false<T>, "Type of backend not supported"); /** - * Resolves an address on the remote + * Resolves an address for the remote */ conveyor<remote_address<T>> resolve_address(); diff --git a/modules/codec/c++/schema.hpp b/modules/codec/c++/schema.hpp index 3c5bce5..3d20c10 100644 --- a/modules/codec/c++/schema.hpp +++ b/modules/codec/c++/schema.hpp @@ -102,7 +102,7 @@ using Float64 = Primitive<FloatingPoint, 8>; /** * Classes allowing to distinguish Ints from VarInts */ -template<typename T, std::size_t MaxLen> +template<typename T, uint64_t MaxLen> struct VariableLengthPrimitive { static constexpr string_literal name = "VariableLengthPrimitive"; }; @@ -110,6 +110,15 @@ struct VariableLengthPrimitive { using VarInt = VariableLengthPrimitive<SignedInteger, 5>; using VarLong = VariableLengthPrimitive<SignedInteger, 10>; +template<typename PrimA, typename PrimB> +struct MixedPrecision { + using InterfaceSchema = PrimA; + using StorageSchema = PrimB; + + static_assert(is_primitive<PrimA>::value, "InterfaceSchema needs to be a Primitive"); + static_assert(is_primitive<PrimB>::value, "StorageSchema needs to be a Primitive"); +}; + /** * Classes enabling Rpc calls */ |