From 6c8e3d1786a5de4ae562c03693b8dad9dd0ab26e Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Sat, 10 Jun 2023 17:21:29 +0200 Subject: tests,c++: Intermediate commit preparing testing and json --- src/codec-json/json.tmpl.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/codec-json/json.tmpl.h') diff --git a/src/codec-json/json.tmpl.h b/src/codec-json/json.tmpl.h index d29f29c..3699e10 100644 --- a/src/codec-json/json.tmpl.h +++ b/src/codec-json/json.tmpl.h @@ -9,11 +9,31 @@ class json_encode_impl { static_assert(always_false, "This schema type is not being handle by the json encoding."); }; -template -class json_encode_impl, RootSchema, FromEncode> { +template +class json_encode_impl, RootSchema, FromEncode> { static ErrorOr encode(const data& from, data& to, size_t ptr) { auto val = from.get(); - auto tc_result = std::to_chars(); + std::array data; + auto tc_result = std::to_chars(reinterpret_cast(data.data()), reinrepret_cast(data.data())+data.size(), val); + + if(tc_result.ec != std::errc{}){ + return make_error(); + } + + size_t bytes_written = 0; + for(auto ptr = data.data(); ptr != tc_result.ptr; ++ptr){ + ++bytes_written; + } + + auto& buff = to.get_buffer(); + error err = buff.write_require_length(bytes_written); + if(!err.template is_type()){ + return std::move(err); + } + + for(auto ptr = data.data(); ptr != tc_result.ptr; ++ptr){ + buff.push(ptr[0]); + } return Void{}; } -- cgit v1.2.3