From 8a7c83e646656361ab322467ad96eb6a6b09a074 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Wed, 24 Jul 2024 15:55:35 +0200 Subject: wip --- modules/codec/c++/csv.hpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'modules/codec/c++') 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 struct csv_encode { static_assert(always_false, "Case not supported"); @@ -176,6 +193,33 @@ struct csv_encode, FromDecode> { return make_void(); } }; + +template +struct csv_decode { + static_assert(always_false, "Case not supported"); +}; + +template +struct csv_decode, FromDecode> { + static_assert(Dim == 1, "Only one dimension is allowed."); + static_assert(!is_array::value, "Array of an array is not allowed."); + static_assert(is_tuple::value || is_struct::value, "Only struct or tuples allowed inside a csv array"); + + using Schema = schema::Array; + + static error_or decode(data& from, data& to){ + buffer_view view{from.get_buffer()}; + if constexpr (is_struct::value) { + auto eov = csv_decode::check_header(view); + if(eov.is_error()){ + return eov; + } + } + + uint64_t len{}; + return make_error(); + } +}; } template -- cgit v1.2.3