summaryrefslogtreecommitdiff
path: root/modules/codec
diff options
context:
space:
mode:
authorClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-29 18:25:08 +0200
committerClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-29 18:25:08 +0200
commit3b203777a84373fe71a28224a4cd0e22608ede52 (patch)
tree1de8d1957041721198674ea36e855afd9064bc51 /modules/codec
parente6005faaf9f581148edd3e32bf402c2af7eb36ab (diff)
forst tests on primitives successfull
Diffstat (limited to 'modules/codec')
-rw-r--r--modules/codec/c++/args.hpp10
-rw-r--r--modules/codec/c++/forst.hpp33
-rw-r--r--modules/codec/c++/forst.tmpl.hpp2
-rw-r--r--modules/codec/c++/stream_value.hpp2
-rw-r--r--modules/codec/tests/forst.cpp12
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<schema::Args<schema::Struct<schema::Member<Str,Lits>...>,sche
using SchemaTuple = schema::Tuple<Tup...>;
template<uint64_t i>
- static error_or<void> decode_struct_member(data<Schema, ToDec>& to, std::string_view name, std::string_view value){
+ static error_or<void> decode_struct_member(data<SchemaStruct, ToDec>& to, std::string_view name, std::string_view value){
if constexpr ( i < sizeof...(Str) ) {
static constexpr string_literal Literal = parameter_key_pack_type<i,Lits...>::literal;
@@ -82,7 +82,13 @@ struct args_decode<schema::Args<schema::Struct<schema::Member<Str,Lits>...>,sche
return decode_struct_member<i+1u>(to, name, value);
}
- return make_error<err::not_found>{"Couldn't decode argument"};
+ return make_error<err::not_found>("Couldn't decode argument");
+ }
+
+ template<uint64_t i>
+ static error_or<void> decode_tuple_member(data<SchemaTuple, ToDec>& to, std::string_view value){
+
+ return make_error<err::not_implemented>();
}
static error_or<void> decode(data<Schema, encode::Args>& from, data<Schema,ToDec>& 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 <forstio/buffer.hpp>
#include "data.hpp"
+#include "stream_value.hpp"
namespace saw {
@@ -33,9 +34,11 @@ private:
uint64_t displacement_;
public:
data():
- buff_{heap<array_buffer>()},
+ buff_{share<array_buffer>(N)},
displacement_{0u}
- {}
+ {
+ buff_->write_advance(N);
+ }
/**
* Constructor for root elements
@@ -43,7 +46,9 @@ public:
data(our<buffer> buff):
buff_{std::move(buff)},
displacement_{0u}
- {}
+ {
+ buff_->write_advance(N);
+ }
/**
* Constructor for child elements
@@ -51,20 +56,36 @@ public:
data(our<buffer> buff, uint64_t dsp):
buff_{std::move(buff)},
displacement_{dsp}
- {}
+ {
+ buff_->write_advance(N);
+ }
/**
* Get values
*/
typename native_data_type<Schema>::type get(){
- return {};
+ typename native_data_type<Schema>::type val;
+
+ typename native_data_type<schema::Primitive<schema::UnsignedInteger,N>>::type raw = 0;
+
+ for (size_t i = 0; i < N; ++i) {
+ raw |= (static_cast<typename native_data_type<Schema>::type>(buff_->read(i+displacement_)) << (i * 8));
+ }
+
+ memcpy(&val, &raw, N);
+ return val;
}
/**
* Set values
*/
void set(typename native_data_type<Schema>::type val){
- (void) val;
+ typename native_data_type<schema::Primitive<schema::UnsignedInteger,N>>::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<schema::String> {
public:
static constexpr uint64_t layers = 1u;
- static constexpr uint64_t static_size = 8u;
+ static constexpr uint64_t static_size = forst_codec_info<typename meta_schema<schema::String>::MetaSchema>::static_size;
template<typename Encoding>
static uint64_t dynamic_size (const data<schema::String, Encoding>& 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<typename meta_schema<TestStruct>::MetaSchema> meta_dat;
+ data<UInt64, encode::KelForst> forst_dat;
- data<TestStruct, encode::Forst> forst_dat{meta_dat};
+ uint64_t foo = 4213u;
+
+ forst_dat.set(foo);
+
+ uint64_t val = forst_dat.get();
+
+ SAW_EXPECT(val == foo, "Unexpected value");
}
}
}