#pragma once #include #include "data.hpp" #include "stream_value.hpp" namespace saw { namespace encode { struct KelForst {}; } } #include "forst.tmpl.hpp" namespace saw { template <> class data { private: own buff_; public: data(own buff): buff_{std::move(buff)} {} }; template class data, encode::KelForst> { public: using Schema = schema::Primitive; private: our buff_; uint64_t displacement_; public: data(): buff_{share(N)}, displacement_{0u} { buff_->write_advance(N); } /** * Constructor for root elements */ data(our buff): buff_{std::move(buff)}, displacement_{0u} { buff_->write_advance(N); } /** * Constructor for child elements */ data(our buff, uint64_t dsp): buff_{std::move(buff)}, displacement_{dsp} { buff_->write_advance(N); } /** * Get values */ typename native_data_type::type get(){ typename native_data_type::type val; typename native_data_type>::type raw = 0; for (size_t i = 0; i < N; ++i) { raw |= (static_cast::type>(buff_->read(i+displacement_)) << (i * 8)); } memcpy(&val, &raw, N); return val; } /** * Set values */ void set(typename native_data_type::type val){ typename native_data_type>::type raw{}; memcpy(&raw, &val, N); for (size_t i = 0; i < N; ++i) { buff_->read(i+displacement_) = raw >> (i * 8); } } }; template class data...>, encode::KelForst> { public: using Schema = schema::Struct...>; private: /** * Buffer holding the whole packet */ our buff_; /** * Displacement to show the starting point */ uint64_t displacement_; public: data(): buff_{share(impl::forst_codec_info::static_size)}, displacement_{0u} { } /** * Constructor for root elements */ data(our buff): buff_{std::move(buff)}, displacement_{0u} {} /** * Constructor for child elements */ data(our buff, uint64_t dsp): buff_{std::move(buff)}, displacement_{dsp} {} }; }