summaryrefslogtreecommitdiff
path: root/modules/codec/c++/csv.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/c++/csv.hpp')
-rw-r--r--modules/codec/c++/csv.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/modules/codec/c++/csv.hpp b/modules/codec/c++/csv.hpp
index 2d11bff..82010d7 100644
--- a/modules/codec/c++/csv.hpp
+++ b/modules/codec/c++/csv.hpp
@@ -12,6 +12,23 @@ struct Csv {};
}
namespace impl {
+struct csv_helper {
+ static bool is_whitespace(int8_t ch){
+ /**
+ * @TODO supply relevant control characters for checks.
+ * Newlines are whitespace technically, but also control characters in CSV.
+ * Contrary to JSON for example.
+ */
+ return ch == '\t' || ch == ' ';
+ }
+
+ static void skip_whitespace(buffer_view& buff){
+ while(buff.read_composite_length() > 0 && csv_helper::is_whitespace(buff.read())){
+ buff.read_advance(1u);
+ }
+ }
+};
+
template<typename Schema, typename FromDecode>
struct csv_encode {
static_assert(always_false<Schema, FromDecode>, "Case not supported");
@@ -176,6 +193,33 @@ struct csv_encode<schema::Primitive<T,N>, FromDecode> {
return make_void();
}
};
+
+template<typename Schema, typename FromDecode>
+struct csv_decode {
+ static_assert(always_false<Schema, FromDecode>, "Case not supported");
+};
+
+template<typename T, size_t Dim, typename FromDecode>
+struct csv_decode<schema::Array<T,Dim>, FromDecode> {
+ static_assert(Dim == 1, "Only one dimension is allowed.");
+ static_assert(!is_array<T>::value, "Array of an array is not allowed.");
+ static_assert(is_tuple<T>::value || is_struct<T>::value, "Only struct or tuples allowed inside a csv array");
+
+ using Schema = schema::Array<T,Dim>;
+
+ static error_or<void> decode(data<Schema, encode::Csv>& from, data<Schema, FromDecode>& to){
+ buffer_view view{from.get_buffer()};
+ if constexpr (is_struct<T>::value) {
+ auto eov = csv_decode<T, FromDecode>::check_header(view);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+
+ uint64_t len{};
+ return make_error<err::not_implemented>();
+ }
+};
}
template<typename Schema>