summaryrefslogtreecommitdiff
path: root/modules/codec
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec')
-rw-r--r--modules/codec/c++/data.hpp1
-rw-r--r--modules/codec/c++/forst.tmpl.hpp86
-rw-r--r--modules/codec/c++/transport.hpp3
-rw-r--r--modules/codec/tests/forst.cpp33
4 files changed, 118 insertions, 5 deletions
diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp
index d8208d0..a17f123 100644
--- a/modules/codec/c++/data.hpp
+++ b/modules/codec/c++/data.hpp
@@ -502,7 +502,6 @@ class data<schema::Array<T,Dim>, encode::Native, storage::Default> {
value_.resize(get_full_size());
}
-
template<size_t i = 0>
error_or<void> add(saw::data<T,encode::Native, storage::Default> data){
/** @todo
diff --git a/modules/codec/c++/forst.tmpl.hpp b/modules/codec/c++/forst.tmpl.hpp
index a52f0b9..52a4273 100644
--- a/modules/codec/c++/forst.tmpl.hpp
+++ b/modules/codec/c++/forst.tmpl.hpp
@@ -2,7 +2,7 @@ namespace saw {
namespace impl {
/**
- * This class provides
+ * This class provides basic info on sizes of the encode::Forst
*/
template<typename Schema>
struct forst_codec_info {
@@ -11,21 +11,42 @@ struct forst_codec_info {
template<typename T, uint64_t N>
struct forst_codec_info<schema::Primitive<T,N>> {
-private:
public:
static constexpr uint64_t layers = 0u;
+
+ static constexpr uint64_t static_size = N;
+
+ template<typename Encoding>
+ static uint64_t dynamic_size(const data<schema::Primitive<T,N>, Encoding>&) noexcept {
+ return 0u;
+ }
};
template<>
struct forst_codec_info<schema::String> {
public:
static constexpr uint64_t layers = 1u;
+
+ static constexpr uint64_t static_size = 8u;
+
+ template<typename Encoding>
+ static uint64_t dynamic_size (const data<schema::String, Encoding>& dat) noexcept {
+ return dat.size() * 1u;
+ }
};
template<typename T, uint64_t N>
struct forst_codec_info<schema::Array<T,N>> {
public:
static constexpr uint64_t layers = 1u + forst_codec_info<T>::layers;
+
+ /// Dimension and the relative pointer
+ static constexpr uint64_t static_size = 8u * N + 8u;
+
+ template<typename Encoding>
+ static uint64_t dynamic_size (const data<schema::String, Encoding>& dat) {
+ return dat.size() * forst_codec_info<T>::static_size;
+ }
};
template<typename... Members>
@@ -46,8 +67,40 @@ public:
}
return 0u;
}
+
public:
static constexpr uint64_t layers = max_layers<0u>();
+
+public:
+ template<uint64_t i>
+ static constexpr uint64_t static_size_calc(){
+ if constexpr ( i < sizeof...(Members) ) {
+ using MT = typename parameter_pack_type<i, Members...>::type;
+
+ constexpr uint64_t layer_i = forst_codec_info<typename MT::ValueType>::static_size + static_size_calc<i+1u>();
+ return layer_i;
+ }
+ return 0u;
+ }
+
+public:
+ static constexpr uint64_t static_size = static_size_calc<0>();
+
+ template<typename Encoding, uint64_t i>
+ static uint64_t dynamic_size_calc(const data<schema::Struct<Members...>, Encoding>& dat) noexcept {
+ if constexpr ( i < sizeof...(Members) ){
+ using MT = typename parameter_pack_type<i, Members...>::type;
+
+ constexpr uint64_t layer_i = forst_codec_info<typename MT::ValueType>::dynamic_size(dat) + dynamic_size_calc<i+1u>(dat);
+ return layer_i;
+ }
+ return 0u;
+ }
+public:
+ template<typename Encoding>
+ static uint64_t dynamic_size(const data<schema::Struct<Members...>, Encoding>& dat) noexcept {
+ return dynamic_size_calc<0u>(dat);
+ }
};
template<typename... T>
@@ -70,6 +123,35 @@ public:
}
public:
static constexpr uint64_t layers = max_layers<0u>();
+public:
+ template<uint64_t i>
+ static constexpr uint64_t static_size_calc(){
+ if constexpr ( i < sizeof...(T) ) {
+ using MT = typename parameter_pack_type<i, T...>::type;
+
+ constexpr uint64_t layer_i = forst_codec_info<MT>::static_size + layer_size_calc<i+1u>();
+ }
+ return 0u;
+ }
+
+public:
+ static constexpr uint64_t static_size = static_size_calc<0>();
+
+ template<typename Encoding, uint64_t i>
+ static uint64_t dynamic_size_calc(const data<schema::Tuple<T...>, Encoding>& dat) noexcept {
+ if constexpr ( i < sizeof...(T) ){
+ using MT = typename parameter_pack_type<i, T...>::type;
+
+ constexpr uint64_t layer_i = forst_codec_info<MT>::dynamic_size(dat) + dynamic_size_calc<i+1u>(dat);
+ return layer_i;
+ }
+ return 0u;
+ }
+public:
+ template<typename Encoding>
+ static uint64_t dynamic_size(const data<schema::Tuple<T...>, Encoding>& dat) noexcept {
+ return dynamic_size_calc<0u>(dat);
+ }
};
}
}
diff --git a/modules/codec/c++/transport.hpp b/modules/codec/c++/transport.hpp
index 430f719..110ab3d 100644
--- a/modules/codec/c++/transport.hpp
+++ b/modules/codec/c++/transport.hpp
@@ -21,6 +21,9 @@ private:
public:
error_or<buffer_view> view_slice(buffer& buff) const {
(void) buff;
+
+ buffer_view view{buff};
+
return make_error<err::not_implemented>();
}
diff --git a/modules/codec/tests/forst.cpp b/modules/codec/tests/forst.cpp
index 28501c9..8e9ac49 100644
--- a/modules/codec/tests/forst.cpp
+++ b/modules/codec/tests/forst.cpp
@@ -5,7 +5,7 @@
#include <iostream>
namespace {
-namespace schema {
+namespace sch {
using namespace saw::schema;
using TestStruct = Struct<
@@ -18,7 +18,7 @@ using TestArray = Array<
TestStruct
>;
-SAW_TEST("Codec Forst Info"){
+SAW_TEST("Codec Forst Layer Info"){
using namespace saw;
{
@@ -38,5 +38,34 @@ SAW_TEST("Codec Forst Info"){
SAW_EXPECT(depth == 2, "Layer info is wrong");
}
}
+
+SAW_TEST("Codec Forst Static Size Info"){
+ using namespace saw;
+
+ {
+ uint64_t depth = impl::forst_codec_info<schema::String>::static_size;
+ SAW_EXPECT(depth == 8u, "Static size is wrong");
+ }
+ {
+ uint64_t size = impl::forst_codec_info<schema::UInt8>::static_size;
+ SAW_EXPECT(size == 1u, "Static size is wrong");
+ }
+ {
+ uint64_t size = impl::forst_codec_info<schema::UInt16>::static_size;
+ SAW_EXPECT(size == 2u, "Static size is wrong");
+ }
+ {
+ uint64_t size = impl::forst_codec_info<schema::UInt32>::static_size;
+ SAW_EXPECT(size == 4u, "Static size is wrong");
+ }
+ {
+ uint64_t size = impl::forst_codec_info<schema::UInt64>::static_size;
+ SAW_EXPECT(size == 8u, "Static size is wrong");
+ }
+ {
+ uint64_t size = impl::forst_codec_info<TestStruct>::static_size;
+ SAW_EXPECT(size == 17u, std::string{"Static size is wrong: "} + std::to_string(size));
+ }
+}
}
}