From 3b203777a84373fe71a28224a4cd0e22608ede52 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Mon, 29 Jul 2024 18:25:08 +0200 Subject: forst tests on primitives successfull --- modules/codec/c++/args.hpp | 10 ++++++++-- modules/codec/c++/forst.hpp | 33 +++++++++++++++++++++++++++------ modules/codec/c++/forst.tmpl.hpp | 2 +- modules/codec/c++/stream_value.hpp | 2 +- modules/codec/tests/forst.cpp | 12 +++++++++--- 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/modules/codec/c++/args.hpp b/modules/codec/c++/args.hpp index 78664c8..a2b338b 100644 --- a/modules/codec/c++/args.hpp +++ b/modules/codec/c++/args.hpp @@ -70,7 +70,7 @@ struct args_decode...>,sche using SchemaTuple = schema::Tuple; template - static error_or decode_struct_member(data& to, std::string_view name, std::string_view value){ + static error_or decode_struct_member(data& to, std::string_view name, std::string_view value){ if constexpr ( i < sizeof...(Str) ) { static constexpr string_literal Literal = parameter_key_pack_type::literal; @@ -82,7 +82,13 @@ struct args_decode...>,sche return decode_struct_member(to, name, value); } - return make_error{"Couldn't decode argument"}; + return make_error("Couldn't decode argument"); + } + + template + static error_or decode_tuple_member(data& to, std::string_view value){ + + return make_error(); } static error_or decode(data& from, data& to){ diff --git a/modules/codec/c++/forst.hpp b/modules/codec/c++/forst.hpp index 4415b1f..e45ccbe 100644 --- a/modules/codec/c++/forst.hpp +++ b/modules/codec/c++/forst.hpp @@ -3,6 +3,7 @@ #include #include "data.hpp" +#include "stream_value.hpp" namespace saw { @@ -33,9 +34,11 @@ private: uint64_t displacement_; public: data(): - buff_{heap()}, + buff_{share(N)}, displacement_{0u} - {} + { + buff_->write_advance(N); + } /** * Constructor for root elements @@ -43,7 +46,9 @@ public: data(our buff): buff_{std::move(buff)}, displacement_{0u} - {} + { + buff_->write_advance(N); + } /** * Constructor for child elements @@ -51,20 +56,36 @@ public: data(our buff, uint64_t dsp): buff_{std::move(buff)}, displacement_{dsp} - {} + { + buff_->write_advance(N); + } /** * Get values */ typename native_data_type::type get(){ - return {}; + 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){ - (void) 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); + } } }; diff --git a/modules/codec/c++/forst.tmpl.hpp b/modules/codec/c++/forst.tmpl.hpp index 52a4273..1dc0ac1 100644 --- a/modules/codec/c++/forst.tmpl.hpp +++ b/modules/codec/c++/forst.tmpl.hpp @@ -27,7 +27,7 @@ struct forst_codec_info { public: static constexpr uint64_t layers = 1u; - static constexpr uint64_t static_size = 8u; + static constexpr uint64_t static_size = forst_codec_info::MetaSchema>::static_size; template static uint64_t dynamic_size (const data& dat) noexcept { diff --git a/modules/codec/c++/stream_value.hpp b/modules/codec/c++/stream_value.hpp index 80613ea..6679162 100644 --- a/modules/codec/c++/stream_value.hpp +++ b/modules/codec/c++/stream_value.hpp @@ -10,7 +10,7 @@ namespace saw { /** - * Helper class to encode/decode any primtive type into/from litte endian. + * Helper class to encode/decode any primitive type into/from litte endian. * The shift class does this by shifting bytes. This type of procedure is * platform independent. So it does not matter if the memory layout is * little endian or big endian diff --git a/modules/codec/tests/forst.cpp b/modules/codec/tests/forst.cpp index 8e715c9..1d9c0c3 100644 --- a/modules/codec/tests/forst.cpp +++ b/modules/codec/tests/forst.cpp @@ -69,12 +69,18 @@ SAW_TEST("Codec Forst Static Size Info"){ } } -SAW_TEST("Codec Forst Dynamic Size Info"){ +SAW_TEST("Codec Forst Primitive"){ using namespace saw; - data::MetaSchema> meta_dat; + data forst_dat; - data forst_dat{meta_dat}; + uint64_t foo = 4213u; + + forst_dat.set(foo); + + uint64_t val = forst_dat.get(); + + SAW_EXPECT(val == foo, "Unexpected value"); } } } -- cgit v1.2.3